Skip provisioning process steps if script is "empty"

This commit is contained in:
Joshua Boniface 2020-01-05 16:35:55 -05:00
parent d1331401d8
commit 8b05dfea7b
1 changed files with 80 additions and 68 deletions

View File

@ -892,6 +892,13 @@ def create_vm(self, vm_name, vm_profile, define_vm=True, start_vm=True):
db_cur.execute(query, args) db_cur.execute(query, args)
vm_data['script'] = db_cur.fetchone()['script'] vm_data['script'] = db_cur.fetchone()['script']
if vm_data['script']['name'] == 'empty':
# We do not have a script; skip it
is_script_install = False
else:
is_script_install = True
close_database(db_conn, db_cur) close_database(db_conn, db_cur)
print("VM configuration data:\n{}".format(json.dumps(vm_data, sort_keys=True, indent=2))) print("VM configuration data:\n{}".format(json.dumps(vm_data, sort_keys=True, indent=2)))
@ -982,6 +989,7 @@ def create_vm(self, vm_name, vm_profile, define_vm=True, start_vm=True):
self.update_state(state='RUNNING', meta={'current': 3, 'total': 10, 'status': 'Preparing provisioning script'}) self.update_state(state='RUNNING', meta={'current': 3, 'total': 10, 'status': 'Preparing provisioning script'})
time.sleep(1) time.sleep(1)
if is_script_install:
# Write the script out to a temporary file # Write the script out to a temporary file
retcode, stdout, stderr = run_os_command("mktemp") retcode, stdout, stderr = run_os_command("mktemp")
if retcode: if retcode:
@ -1052,6 +1060,7 @@ def create_vm(self, vm_name, vm_profile, define_vm=True, start_vm=True):
print("Created {} filesystem on {}:\n{}".format(volume['filesystem'], rbd_volume, stdout)) print("Created {} filesystem on {}:\n{}".format(volume['filesystem'], rbd_volume, stdout))
if is_script_install:
# Create temporary directory # Create temporary directory
retcode, stdout, stderr = run_os_command("mktemp -d") retcode, stdout, stderr = run_os_command("mktemp -d")
if retcode: if retcode:
@ -1082,6 +1091,7 @@ def create_vm(self, vm_name, vm_profile, define_vm=True, start_vm=True):
self.update_state(state='RUNNING', meta={'current': 6, 'total': 10, 'status': 'Executing provisioning script'}) self.update_state(state='RUNNING', meta={'current': 6, 'total': 10, 'status': 'Executing provisioning script'})
time.sleep(1) time.sleep(1)
if is_script_install:
print("Running installer script") print("Running installer script")
# Parse the script arguments # Parse the script arguments
@ -1107,6 +1117,7 @@ def create_vm(self, vm_name, vm_profile, define_vm=True, start_vm=True):
time.sleep(1) time.sleep(1)
for volume in list(reversed(vm_data['volumes'])): for volume in list(reversed(vm_data['volumes'])):
if is_script_install:
# Unmount the volume # Unmount the volume
if volume['mountpoint']: if volume['mountpoint']:
print("Cleaning up mount {}{}".format(temp_dir, volume['mountpoint'])) print("Cleaning up mount {}{}".format(temp_dir, volume['mountpoint']))
@ -1127,6 +1138,7 @@ def create_vm(self, vm_name, vm_profile, define_vm=True, start_vm=True):
print("Cleaning up temporary directories and files") print("Cleaning up temporary directories and files")
if is_script_install:
# Remove temporary mount directory (don't fail if not removed) # Remove temporary mount directory (don't fail if not removed)
retcode, stdout, stderr = run_os_command("rmdir {}".format(temp_dir)) retcode, stdout, stderr = run_os_command("rmdir {}".format(temp_dir))
if retcode: if retcode: