From c4703b9af799ca8ae7526ff89cfff67fdf9dd00f Mon Sep 17 00:00:00 2001 From: Remi Bergsma Date: Wed, 11 Oct 2023 15:46:38 +0200 Subject: [PATCH] Specify target_host --- cosmicops/empty_host.py | 7 +++++-- empty_host.py | 5 +++-- rolling_reboot.py | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cosmicops/empty_host.py b/cosmicops/empty_host.py index f29b149..89c8b48 100644 --- a/cosmicops/empty_host.py +++ b/cosmicops/empty_host.py @@ -17,7 +17,7 @@ from cosmicops import CosmicOps, RebootAction, logging -def empty_host(profile, shutdown, skip_disable, dry_run, host): +def empty_host(profile, shutdown, skip_disable, dry_run, host, target_host): click_log.basic_config() log_to_slack = True @@ -35,7 +35,10 @@ def empty_host(profile, shutdown, skip_disable, dry_run, host): if not host.disable(): raise RuntimeError(f"Failed to disable host '{host['name']}'") - (total, success, failed) = host.empty() + if target_host: + target_host = co.get_host(name=target_host) + + (total, success, failed) = host.empty(target=target_host) result_message = f"Result: {success} successful, {failed} failed out of {total} total VMs" if not failed and shutdown: diff --git a/empty_host.py b/empty_host.py index b4effbd..b2bcffa 100755 --- a/empty_host.py +++ b/empty_host.py @@ -30,7 +30,8 @@ @click.option('--dry-run/--exec', is_flag=True, default=True, show_default=True, help='Enable/disable dry-run') @click_log.simple_verbosity_option(logging.getLogger(), default="INFO", show_default=True) @click.argument('host') -def main(profile, shutdown, skip_disable, dry_run, host): +@click.argument('target_host') +def main(profile, shutdown, skip_disable, dry_run, host, target_host): """Empty HOST by migrating VMs to another host in the same cluster.""" click_log.basic_config() @@ -39,7 +40,7 @@ def main(profile, shutdown, skip_disable, dry_run, host): logging.info('Running in dry-run mode, will only show changes') try: - logging.info(empty_host(profile, shutdown, skip_disable, dry_run, host)) + logging.info(empty_host(profile, shutdown, skip_disable, dry_run, host, target_host)) except RuntimeError as err: logging.error(err) sys.exit(1) diff --git a/rolling_reboot.py b/rolling_reboot.py index 4c07af3..2859612 100755 --- a/rolling_reboot.py +++ b/rolling_reboot.py @@ -48,8 +48,9 @@ @click.option('--dry-run/--exec', is_flag=True, default=True, show_default=True, help='Enable/disable dry-run') @click_log.simple_verbosity_option(logging.getLogger(), default="INFO", show_default=True) @click.argument('cluster') +@click.argument('target_host') def main(profile, ignore_hosts, only_hosts, skip_os_version, reboot_action, pre_empty_script, post_empty_script, - post_reboot_script, dry_run, cluster): + post_reboot_script, dry_run, cluster, target_host): """Perform rolling reboot of hosts in CLUSTER""" click_log.basic_config() @@ -90,7 +91,8 @@ def main(profile, ignore_hosts, only_hosts, skip_os_version, reboot_action, pre_ hosts.sort(key=itemgetter('name')) - target_host = None + if target_host: + target_host = co.get_host(name=target_host) for host in hosts: logging.slack_value = host['name'] logging.zone_name = host['zonename']