Support cloning volumes in provisioning flow

This commit is contained in:
Joshua Boniface 2020-01-08 19:52:54 -05:00
parent 9342bc4959
commit d00e532611
1 changed files with 34 additions and 7 deletions

View File

@ -973,6 +973,16 @@ def create_vm(self, vm_name, vm_profile, define_vm=True, start_vm=True):
# Verify that there is enough disk space free to provision all VM disks # Verify that there is enough disk space free to provision all VM disks
pools = dict() pools = dict()
for volume in vm_data['volumes']: for volume in vm_data['volumes']:
if volume['source_volume'] is not None:
if not volume['pool'] in pools:
pools[volume['pool']], status = pvc_ceph.getVolumeInformation(zk_conn, volume['pool'], volume['source_volume'])['disk_size_gb']
if not status:
raise ClusterError('The source volume {}/{} could not be found'.format(volume['pool'], volume['source_volume']))
else:
pools[volume['pool']], status += pvc_ceph.getVolumeInformation(zk_conn, volume['pool'], volume['source_volume'])['disk_size_gb']
if not status:
raise ClusterError('The source volume {}/{} could not be found'.format(volume['pool'], volume['source_volume']))
else:
if not volume['pool'] in pools: if not volume['pool'] in pools:
pools[volume['pool']] = volume['disk_size_gb'] pools[volume['pool']] = volume['disk_size_gb']
else: else:
@ -993,6 +1003,8 @@ def create_vm(self, vm_name, vm_profile, define_vm=True, start_vm=True):
# Verify that every specified filesystem is valid # Verify that every specified filesystem is valid
used_filesystems = list() used_filesystems = list()
for volume in vm_data['volumes']: for volume in vm_data['volumes']:
if volume['source_volume'] is not None:
continue
if volume['filesystem'] and volume['filesystem'] not in used_filesystems: if volume['filesystem'] and volume['filesystem'] not in used_filesystems:
used_filesystems.append(volume['filesystem']) used_filesystems.append(volume['filesystem'])
@ -1181,6 +1193,12 @@ def create_vm(self, vm_name, vm_profile, define_vm=True, start_vm=True):
time.sleep(1) time.sleep(1)
for volume in vm_data['volumes']: for volume in vm_data['volumes']:
if volume['source_volume'] is not None:
success, message = pvc_ceph.clone_volume(zk_conn, volume['pool'], "{}_{}".format(vm_name, volume['disk_id']), volume['source_volume'])
print(message)
if not success:
raise ClusterError('Failed to clone volume "{}" to "{}"'.format(volume['source_volume'], volume['disk_id']))
else:
success, message = pvc_ceph.add_volume(zk_conn, volume['pool'], "{}_{}".format(vm_name, volume['disk_id']), "{}G".format(volume['disk_size_gb'])) success, message = pvc_ceph.add_volume(zk_conn, volume['pool'], "{}_{}".format(vm_name, volume['disk_id']), "{}G".format(volume['disk_size_gb']))
print(message) print(message)
if not success: if not success:
@ -1195,6 +1213,9 @@ def create_vm(self, vm_name, vm_profile, define_vm=True, start_vm=True):
time.sleep(1) time.sleep(1)
for volume in vm_data['volumes']: for volume in vm_data['volumes']:
if volume['source_volume'] is not None:
continue
if not volume['filesystem']: if not volume['filesystem']:
continue continue
@ -1232,6 +1253,9 @@ def create_vm(self, vm_name, vm_profile, define_vm=True, start_vm=True):
temp_dir = stdout.strip() temp_dir = stdout.strip()
for volume in vm_data['volumes']: for volume in vm_data['volumes']:
if volume['source_volume'] is not None:
continue
if not volume['mountpoint'] or volume['mountpoint'] == 'swap': if not volume['mountpoint'] or volume['mountpoint'] == 'swap':
continue continue
@ -1281,6 +1305,9 @@ 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 volume['source_volume'] is not None:
continue
if is_script_install: if is_script_install:
# Unmount the volume # Unmount the volume
if volume['mountpoint'] and volume['mountpoint'] != 'swap': if volume['mountpoint'] and volume['mountpoint'] != 'swap':