Skip to content

Commit 3ce57a1

Browse files
committed
By default do not preserve downloads
1 parent 296cc6d commit 3ce57a1

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

xenserver_rolling_reboot.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import time
2929
import os
3030
import getopt
31+
import glob
3132
from cloudstackops import cloudstackops
3233
from cloudstackops import xenserver
3334
# Fabric
@@ -63,6 +64,9 @@ def handleArguments(argv):
6364
post_empty_script = 'xenserver_post_empty_script.sh'
6465
global patch_list_file
6566
patch_list_file = 'xenserver_patches_to_install.txt'
67+
global preserve_downloads
68+
preserve_downloads = False
69+
6670
# Usage message
6771
help = "Usage: ./" + os.path.basename(__file__) + ' [options]' + \
6872
'\n --config-profile -c <profilename>\t\tSpecify the CloudMonkey profile name to ' \
@@ -78,6 +82,7 @@ def handleArguments(argv):
7882
'\n --post-empty-script\t\t\t\tBash script to run on hypervisor after a hypervisor has no more VMs running' \
7983
'\n --patch-list-file\t\t\t\tText file with URLs of patches to download and install. One per line. ' \
8084
'(expected in same folder as this script)' + \
85+
'\n --preserve-downloads\t\t\t\tPreserve downloads instead of wiping them and downloading again.' + \
8186
'\n --debug\t\t\t\t\tEnable debug mode' + \
8287
'\n --exec\t\t\t\t\tExecute for real' + \
8388
'\n --prepare\t\t\t\t\tExecute some prepare commands'
@@ -86,7 +91,7 @@ def handleArguments(argv):
8691
opts, args = getopt.getopt(
8792
argv, "hc:n:t:p", [
8893
"credentials-file=", "clustername=", "ignore-hosts=", "threads=", "pre-empty-script=",
89-
"post-empty-script=", "patch-list-file=", "halt", "debug", "exec", "prepare"])
94+
"post-empty-script=", "patch-list-file=", "preserve-downloads", "halt", "debug", "exec", "prepare"])
9095
except getopt.GetoptError as e:
9196
print "Error: " + str(e)
9297
print help
@@ -112,6 +117,8 @@ def handleArguments(argv):
112117
post_empty_script = arg
113118
elif opt in ("--patch-list-file"):
114119
patch_list_file = arg
120+
elif opt in ("--preserve-downloads"):
121+
preserve_downloads = True
115122
elif opt in ("--debug"):
116123
DEBUG = 1
117124
elif opt in ("--exec"):
@@ -218,6 +225,7 @@ def handleArguments(argv):
218225
print " - For any hypervisor it will do this (poolmaster " + poolmaster.name + " first):"
219226
print " - put it to Disabled aka Maintenance in XenServer"
220227
print " - download the patches in file --patch-list-file '" + patch_list_file + "'"
228+
print " (preserve downloads is set to " + str(preserve_downloads) + ")"
221229
print " - execute the --pre-empty-script script '" + pre_empty_script + "' on the hypervisor"
222230
print " - live migrate all VMs off of it using XenServer evacuate command"
223231
print " - execute the --post-empty-script script '" + post_empty_script + "' on the hypervisor"
@@ -270,6 +278,13 @@ def handleArguments(argv):
270278
sys.exit(1)
271279

272280
# Download all XenServer patches
281+
if not preserve_downloads:
282+
print "Note: Deleting previously downloaded patches"
283+
files = glob.glob('xenserver_patches/*.zip')
284+
for f in files:
285+
print "Note: Removing previously downloaded patch " + f
286+
os.remove(f)
287+
273288
print "Note: Reading patches list '%s'" % patch_list_file
274289
with open(patch_list_file) as file_pointer:
275290
patches = file_pointer.read().splitlines()

0 commit comments

Comments
 (0)