def init():
"""Return top level command handler"""
@click.command()
@click.option('--cell', required=True,
envvar='TREADMILL_CELL',
callback=cli.handle_context_opt,
expose_value=False)
@click.option('--monitor', nargs=2, type=click.Tuple([str, int]),
multiple=True, required=True)
@click.option('--once', help='Run once.', is_flag=True, default=False)
@click.option('--interval', help='Wait interval between checks.',
default=_DEFAULT_INTERVAL)
@click.argument('name')
def controller(monitor, once, interval, name):
"""Control app monitors across cells"""
monitors = list(monitor)
while True:
intended_total = 0
actual_total = 0
intended = 0
for cellname, count in monitors:
if cellname == context.GLOBAL.cell:
intended = count
else:
actual = _count(cellname, name)
_LOGGER.info('state for cell %s, actual: %s, intended: %s',
cellname, actual, count)
intended_total += count
actual_total += actual
missing = intended_total - actual_total
# If there are missing instances, start them locally. If there are
# extra instances (missing < 0) just keep the indended state for
# the cell.
my_count = intended + max(0, missing)
_LOGGER.info('intended: %s, actual: %s, missing: %s, my count: %s',
intended_total, actual_total, missing, my_count)
_configure_monitor(name, my_count)
if once:
break
time.sleep(utils.to_seconds(interval))
return controller
评论列表
文章目录