Handle creating swap in provisioner

This commit is contained in:
Joshua Boniface 2020-01-05 15:07:48 -05:00
parent c39c6e8d86
commit 9d06aa111b
1 changed files with 16 additions and 6 deletions

View File

@ -965,6 +965,11 @@ def create_vm(self, vm_name, vm_profile, define_vm=True, start_vm=True):
used_filesystems.append(volume['filesystem']) used_filesystems.append(volume['filesystem'])
for filesystem in used_filesystems: for filesystem in used_filesystems:
if filesystem == 'swap':
retcode, stdout, stderr = run_os_command("which mkswap")
if retcode:
raise ProvisioningError("Failed to find binary for mkswap: {}".format(filesystem, stderr))
else:
retcode, stdout, stderr = run_os_command("which mkfs.{}".format(filesystem)) retcode, stdout, stderr = run_os_command("which mkfs.{}".format(filesystem))
if retcode: if retcode:
raise ProvisioningError("Failed to find binary for mkfs.{}: {}".format(filesystem, stderr)) raise ProvisioningError("Failed to find binary for mkfs.{}: {}".format(filesystem, stderr))
@ -1036,6 +1041,11 @@ def create_vm(self, vm_name, vm_profile, define_vm=True, start_vm=True):
raise ProvisioningError('Failed to map volume "{}": {}'.format(rbd_volume, stderr)) raise ProvisioningError('Failed to map volume "{}": {}'.format(rbd_volume, stderr))
# Create the filesystem # Create the filesystem
if filesystem == 'swap':
retcode, stdout, stderr = run_os_command("mkswap -f /dev/rbd/{}".format(rbd_volume))
if retcode:
raise ProvisioningError('Failed to create swap on "{}": {}'.format(rbd_volume, stderr))
else:
retcode, stdout, stderr = run_os_command("mkfs.{} {} /dev/rbd/{}".format(volume['filesystem'], filesystem_args, rbd_volume)) retcode, stdout, stderr = run_os_command("mkfs.{} {} /dev/rbd/{}".format(volume['filesystem'], filesystem_args, rbd_volume))
if retcode: if retcode:
raise ProvisioningError('Failed to create {} filesystem on "{}": {}'.format(volume['filesystem'], rbd_volume, stderr)) raise ProvisioningError('Failed to create {} filesystem on "{}": {}'.format(volume['filesystem'], rbd_volume, stderr))