Skip to content

Commit

Permalink
Specify target_host
Browse files Browse the repository at this point in the history
  • Loading branch information
remibergsma committed Oct 11, 2023
1 parent e164f7b commit c4703b9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
7 changes: 5 additions & 2 deletions cosmicops/empty_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions empty_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions rolling_reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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']
Expand Down

0 comments on commit c4703b9

Please sign in to comment.