Skip to content

Commit

Permalink
Adding proxy_host feature
Browse files Browse the repository at this point in the history
  • Loading branch information
remibergsma committed Oct 13, 2023
1 parent dac0d3a commit 09bff6e
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions rolling_reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@
help='Script to run on host after live migrations have completed')
@click.option('--post-reboot-script', metavar='<script>', help='Script to run after host has rebooted')
@click.option('--dry-run/--exec', is_flag=True, default=True, show_default=True, help='Enable/disable dry-run')
@click.option('--target-host', help='Target hypervisor the migrate VMS to', required=False)
@click.option('--proxy-host', help='Hypervisor the migrate VMS to, after which we migrate them back to origin', required=False)
@click_log.simple_verbosity_option(logging.getLogger(), default="INFO", show_default=True)
@click.argument('cluster')
@click.argument('target_host', required=False)
def main(profile, ignore_hosts, only_hosts, skip_os_version, reboot_action, pre_empty_script, post_empty_script,
post_reboot_script, dry_run, target_host, cluster):
post_reboot_script, dry_run, proxy_host, cluster, target_host):
"""Perform rolling reboot of hosts in CLUSTER"""

click_log.basic_config()
Expand All @@ -75,6 +76,19 @@ def main(profile, ignore_hosts, only_hosts, skip_os_version, reboot_action, pre_
hosts = cluster.get_all_hosts()
logging.debug(f"Found hosts: {hosts}")

if proxy_host:
proxy_host = co.get_host(name=proxy_host)
if proxy_host is None:
logging.info(f"Cannot find proxy host {proxy_host} in Cosmic!")
sys.exit(1)

logging.info(f"Using proxy host: migrate ALL VMs to {proxy_host['name']}, then back to origin")
if not ignore_hosts:
logging.info(f"Adding proxy host {proxy_host['name']} to ignore list")
ignore_hosts = proxy_host['name']
else:
ignore_hosts += f",{proxy_host['name']}"

if ignore_hosts:
ignore_hosts = ignore_hosts.replace(' ', '').split(',')
logging.info(f"Ignoring hosts: {str(ignore_hosts)}")
Expand All @@ -93,6 +107,7 @@ def main(profile, ignore_hosts, only_hosts, skip_os_version, reboot_action, pre_

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 All @@ -119,6 +134,8 @@ def main(profile, ignore_hosts, only_hosts, skip_os_version, reboot_action, pre_
log_to_slack)

while True:
if proxy_host:
target_host = proxy_host
(_, _, failed) = host.empty(target=target_host)
if failed == 0:
break
Expand Down Expand Up @@ -155,6 +172,15 @@ def main(profile, ignore_hosts, only_hosts, skip_os_version, reboot_action, pre_

host.restart_vms_with_shutdown_policy()

if proxy_host:
logging.info(f"Host '{host['name']}' is now empty (VMs are on proxy host {proxy_host['name']}). "
f"Will now migrate VMs back to origin {host['name']}...", log_to_slack)
while True:
(_, _, failed) = proxy_host.empty(target=host)
if failed == 0:
break
logging.info(f"Host '{host['name']}' is done. It should now have the same VMs as before", log_to_slack)

target_host = host


Expand Down

0 comments on commit 09bff6e

Please sign in to comment.