Skip to content

Commit 3073f2c

Browse files
committed
Add flag to halt hypervisor instead of reboot
1 parent 1ed8679 commit 3073f2c

2 files changed

Lines changed: 26 additions & 10 deletions

File tree

cloudstackops/xenserver.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
# Class to handle XenServer patching
5050
class xenserver():
5151

52-
def __init__(self, ssh_user='root', threads = 5):
52+
def __init__(self, ssh_user='root', threads=5):
5353
self.ssh_user = ssh_user
5454
self.threads = threads
5555

@@ -166,7 +166,7 @@ def host_evacuate(self, host):
166166
return False
167167

168168
# Reboot a host when all conditions are met
169-
def host_reboot(self, host):
169+
def host_reboot(self, host, halt_hypervisor=False):
170170
# Disbale host
171171
if self.host_disable(host) is False:
172172
print "Error: Disabling host " + host.name + " failed."
@@ -184,10 +184,14 @@ def host_reboot(self, host):
184184
print "Note: Host " + host.name + " has no VMs running, continuing"
185185

186186
# Finally reboot it
187-
print "Note: Rebooting host " + host.name
188187
try:
189188
with settings(host_string=self.ssh_user + "@" + host.ipaddress):
190-
fab.run("xe host-reboot host=" + host.name)
189+
if halt_hypervisor:
190+
print "Note: Halting host " + host.name
191+
fab.run("xe host-shutdown host=" + host.name)
192+
else:
193+
print "Note: Rebooting host " + host.name
194+
fab.run("xe host-reboot host=" + host.name)
191195
except:
192196
print "Error: Rebooting host " + host.name + " failed."
193197
return False

xenserver_rolling_reboot.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,27 @@ def handleArguments(argv):
5555
ignoreHosts = ''
5656
global threads
5757
threads = 5
58+
global halt_hypervisor
59+
halt_hypervisor = False
5860

5961
# Usage message
6062
help = "Usage: ./" + os.path.basename(__file__) + ' [options]' + \
61-
'\n --config-profile -c <profilename>\t\tSpecify the CloudMonkey profile name to get the credentials from (or specify in ./config file)' + \
63+
'\n --config-profile -c <profilename>\t\tSpecify the CloudMonkey profile name to ' \
64+
'get the credentials from (or specify in ./config file)' + \
6265
'\n --clustername -n <clustername> \t\tName of the cluster to work with' + \
63-
'\n --ignore-hosts <list>\t\t\t\tSkip work on the specified hosts (for example if you need to resume): Example: --ignore-hosts="host1, host2" ' + \
66+
'\n --ignore-hosts <list>\t\t\t\tSkip work on the specified hosts (for example if you need to resume): ' \
67+
'Example: --ignore-hosts="host1, host2" ' + \
6468
'\n --threads <nr>\t\t\t\tUse this number or concurrent migration threads" ' + \
69+
'\n --halt\t\t\t\t\tInstead of the default reboot, halt the hypervisor (useful in case of hardware ' \
70+
'upgrades)" ' + \
6571
'\n --debug\t\t\t\t\tEnable debug mode' + \
6672
'\n --exec\t\t\t\t\tExecute for real' + \
6773
'\n --prepare\t\t\t\t\tExecute some prepare commands'
6874

6975
try:
7076
opts, args = getopt.getopt(
7177
argv, "hc:n:t:p", [
72-
"credentials-file=", "clustername=", "ignore-hosts=", "threads=", "debug", "exec", "prepare"])
78+
"credentials-file=", "clustername=", "ignore-hosts=", "threads=", "halt", "debug", "exec", "prepare"])
7379
except getopt.GetoptError as e:
7480
print "Error: " + str(e)
7581
print help
@@ -87,6 +93,8 @@ def handleArguments(argv):
8793
threads = arg
8894
elif opt in ("--ignore-hosts"):
8995
ignoreHostList = arg
96+
elif opt in ("--halt"):
97+
halt_hypervisor = True
9098
elif opt in ("--debug"):
9199
DEBUG = 1
92100
elif opt in ("--exec"):
@@ -179,6 +187,10 @@ def handleArguments(argv):
179187
checkBonds = True
180188
c.printHypervisors(clusterID, poolmaster.name, checkBonds)
181189

190+
if halt_hypervisor:
191+
print "Warning: Instead of reboot, we will halt the hypervisor. You need to start it yourself for the script to" \
192+
" continue moving to the next hypervisor."
193+
182194
if DRYRUN == 1:
183195
print
184196
print "Warning: We are running in DRYRUN mode."
@@ -189,7 +201,7 @@ def handleArguments(argv):
189201
print " - For any hypervisor it will do this (poolmaster " + poolmaster.name + " first):"
190202
print " - put it to Disabled aka Maintenance in XenServer"
191203
print " - live migrate all VMs off of it using XenServer evacuate command"
192-
print " - when empty, it will reboot the hypervisor"
204+
print " - when empty, it will reboot the hypervisor (halting is " + str(halt_hypervisor) + ")"
193205
print " - will wait for it to come back online (checks SSH connection)"
194206
print " - set the hypervisor to Enabled in XenServer"
195207
print " - continues to the next hypervisor"
@@ -239,7 +251,7 @@ def handleArguments(argv):
239251
vm_count = x.host_get_vms(poolmaster)
240252
if vm_count:
241253
print "Note: " + poolmaster.name + " (poolmaster) has " + vm_count + " VMs running."
242-
reboot_result = x.host_reboot(poolmaster)
254+
reboot_result = x.host_reboot(poolmaster, halt_hypervisor)
243255
if reboot_result is False:
244256
print "Error: Stopping sequence, as a reboot failed. Please investigate."
245257
x.roll_back(poolmaster)
@@ -268,7 +280,7 @@ def handleArguments(argv):
268280
vm_count = x.host_get_vms(h)
269281
if vm_count:
270282
print "Note: " + h.name + " has " + vm_count + " VMs running."
271-
reboot_result = x.host_reboot(h)
283+
reboot_result = x.host_reboot(h, halt_hypervisor)
272284
if reboot_result is False:
273285
print "Error: Stopping sequence, as a reboot failed. Please investigate."
274286
x.roll_back(h)

0 commit comments

Comments
 (0)