@@ -61,6 +61,8 @@ def handleArguments(argv):
6161 pre_empty_script = 'xenserver_pre_empty_script.sh'
6262 global post_empty_script
6363 post_empty_script = 'xenserver_post_empty_script.sh'
64+ global patch_list_file
65+ patch_list_file = 'xenserver_patches_to_install.txt'
6466 # Usage message
6567 help = "Usage: ./" + os .path .basename (__file__ ) + ' [options]' + \
6668 '\n --config-profile -c <profilename>\t \t Specify the CloudMonkey profile name to ' \
@@ -74,6 +76,7 @@ def handleArguments(argv):
7476 '\n --pre-empty-script\t \t \t \t Bash script to run on hypervisor before starting the live migrations to empty ' \
7577 'hypervisor (expected in same folder as this script)' + \
7678 '\n --post-empty-script\t \t \t \t Bash script to run on hypervisor after a hypervisor has no more VMs running' \
79+ '\n --patch-list-file\t \t \t \t Text file with URLs of patches to download and install. One per line. ' \
7780 '(expected in same folder as this script)' + \
7881 '\n --debug\t \t \t \t \t Enable debug mode' + \
7982 '\n --exec\t \t \t \t \t Execute for real' + \
@@ -83,7 +86,7 @@ def handleArguments(argv):
8386 opts , args = getopt .getopt (
8487 argv , "hc:n:t:p" , [
8588 "credentials-file=" , "clustername=" , "ignore-hosts=" , "threads=" , "pre-empty-script=" ,
86- "post-empty-script=" , "halt" , "debug" , "exec" , "prepare" ])
89+ "post-empty-script=" , "patch-list-file=" , " halt" , "debug" , "exec" , "prepare" ])
8790 except getopt .GetoptError as e :
8891 print "Error: " + str (e )
8992 print help
@@ -107,6 +110,8 @@ def handleArguments(argv):
107110 pre_empty_script = arg
108111 elif opt in ("--post-empty-script" ):
109112 post_empty_script = arg
113+ elif opt in ("--patch-list-file" ):
114+ patch_list_file = arg
110115 elif opt in ("--debug" ):
111116 DEBUG = 1
112117 elif opt in ("--exec" ):
@@ -137,7 +142,7 @@ def handleArguments(argv):
137142c = cloudstackops .CloudStackOps (DEBUG , DRYRUN )
138143
139144# Init XenServer class
140- x = xenserver .xenserver ('root' , threads )
145+ x = xenserver .xenserver ('root' , threads , pre_empty_script , post_empty_script )
141146c .xenserver = x
142147
143148# make credentials file known to our class
@@ -212,7 +217,10 @@ def handleArguments(argv):
212217 print " - Turn OFF XenServer poolHA for " + clustername
213218 print " - For any hypervisor it will do this (poolmaster " + poolmaster .name + " first):"
214219 print " - put it to Disabled aka Maintenance in XenServer"
220+ print " - download the patches in file --patch-list-file '" + patch_list_file + "'"
221+ print " - execute the --pre-empty-script script '" + pre_empty_script + "' on the hypervisor"
215222 print " - live migrate all VMs off of it using XenServer evacuate command"
223+ print " - execute the --post-empty-script script '" + post_empty_script + "' on the hypervisor"
216224 print " - when empty, it will reboot the hypervisor (halting is " + str (halt_hypervisor ) + ")"
217225 print " - will wait for it to come back online (checks SSH connection)"
218226 print " - set the hypervisor to Enabled in XenServer"
@@ -261,6 +269,19 @@ def handleArguments(argv):
261269 disconnect_all ()
262270 sys .exit (1 )
263271
272+ # Download all XenServer patches
273+ print "Note: Reading patches list '%s'" % patch_list_file
274+ with open (patch_list_file ) as file_pointer :
275+ patches = file_pointer .read ().splitlines ()
276+
277+ for patch_url in patches :
278+ print "Note: Processing patch '%s'" % patch_url
279+ x .download_patch (patch_url )
280+
281+ # Upload the patches to poolmaster, then to XenServer
282+ x .put_patches_to_poolmaster (poolmaster )
283+ x .upload_patches_to_xenserver (poolmaster )
284+
264285 # Migrate all VMs off of pool master
265286 vm_count = x .host_get_vms (poolmaster )
266287 if vm_count :
0 commit comments