Compare commits

..

5 Commits

Author SHA1 Message Date
df6e11ae7a Properly handle missing source_volume from OVAs 2022-10-19 13:18:12 -04:00
de2135db42 Add missing ceph import 2022-10-19 13:10:40 -04:00
72e093c2c4 Move conversion to install() step
Seems more clear to me than doing it in prepare()
2022-10-19 13:09:29 -04:00
60e32f7795 Add missing imports 2022-10-19 13:07:34 -04:00
23e7d84f53 Add output messages during OVA prepare 2022-10-19 12:58:11 -04:00
2 changed files with 30 additions and 12 deletions

View File

@ -280,9 +280,12 @@ class VMBuilderScript(VMBuilder):
from pvcapid.Daemon import config
import daemon_lib.common as pvc_common
import daemon_lib.ceph as pvc_ceph
import os
# First loop: Create the destination disks
print("Creating destination disk volumes")
for volume in self.vm_data["volumes"]:
print(f"Processing volume {volume['volume_name']}")
with open_zk(config) as zkhandler:
success, message = pvc_ceph.add_volume(
zkhandler,
@ -297,7 +300,9 @@ class VMBuilderScript(VMBuilder):
)
# Second loop: Map the destination disks
print("Mapping destination disk volumes")
for volume in self.vm_data["volumes"]:
print(f"Processing volume {volume['volume_name']}")
dst_volume_name = f"{self.vm_name}_{volume['disk_id']}"
dst_volume = f"{volume['pool']}/{dst_volume_name}"
@ -312,7 +317,9 @@ class VMBuilderScript(VMBuilder):
raise ProvisioningError(f"Failed to map volume '{dst_volume}'.")
# Third loop: Map the source disks
print("Mapping source disk volumes")
for volume in self.vm_data["volumes"]:
print(f"Processing volume {volume['volume_name']}")
src_volume_name = volume["volume_name"]
src_volume = f"{volume['pool']}/{src_volume_name}"
@ -326,7 +333,16 @@ class VMBuilderScript(VMBuilder):
if not success:
raise ProvisioningError(f"Failed to map volume '{src_volume}'.")
# Fourth loop: Convert the source (usually VMDK) volume to the raw destination volume
def install(self):
"""
install(): Perform the installation
Convert the mapped source volumes to the mapped destination volumes
"""
# Run any imports first
import daemon_lib.common as pvc_common
for volume in self.vm_data["volumes"]:
src_volume_name = volume["volume_name"]
src_volume = f"{volume['pool']}/{src_volume_name}"
@ -335,6 +351,9 @@ class VMBuilderScript(VMBuilder):
dst_volume = f"{volume['pool']}/{dst_volume_name}"
dst_devpath = f"/dev/rbd/{dst_volume}"
print(
f"Converting {volume['volume_format']} {src_volume} at {src_devpath} to {dst_volume} at {dst_devpath}"
)
retcode, stdout, stderr = pvc_common.run_os_command(
f"qemu-img convert -C -f {volume['volume_format']} -O raw {src_devpath} {dst_devpath}"
)
@ -343,15 +362,6 @@ class VMBuilderScript(VMBuilder):
f"Failed to convert {volume['volume_format']} volume '{src_volume}' to raw volume '{dst_volume}' with qemu-img: {stderr}"
)
def install(self):
"""
install(): Perform the installation
Noop for OVA deploys as no further tasks are performed.
"""
pass
def cleanup(self):
"""
cleanup(): Perform any cleanup required due to prepare()/install()
@ -361,6 +371,11 @@ class VMBuilderScript(VMBuilder):
here, be warned that doing so might cause loops. Do this only if you really need to.
"""
# Run any imports first
from pvcapid.vmbuilder import open_zk
from pvcapid.Daemon import config
import daemon_lib.ceph as pvc_ceph
for volume in list(reversed(self.vm_data["volumes"])):
src_volume_name = volume["volume_name"]
src_volume = f"{volume['pool']}/{src_volume_name}"

View File

@ -447,9 +447,12 @@ def create_vm(
# Verify that every specified filesystem is valid
used_filesystems = list()
for volume in vm_data["volumes"]:
if volume["source_volume"] is not None:
if volume.get("source_volume") is not None:
continue
if volume["filesystem"] and volume["filesystem"] not in used_filesystems:
if (
volume.get("filesystem") is not None
and volume["filesystem"] not in used_filesystems
):
used_filesystems.append(volume["filesystem"])
for filesystem in used_filesystems: