Effort is made to ensure a VM always have a status and Unused VM statuses are removed

This commit is contained in:
ahmadbilalkhalid 2019-11-27 12:12:29 +05:00
commit f3f2f6127a
11 changed files with 86 additions and 77 deletions

View file

@ -114,14 +114,15 @@ def get_start_command_args(vm_entry, vnc_sock_filename: str, migration=False, mi
vm_uuid = vm_entry.uuid
vm_networks = vm_entry.network
command = "-drive file={},format=raw,if=virtio,cache=none".format(
command = "-name {}_{}".format(vm_entry.owner, vm_entry.name)
command += " -drive file={},format=raw,if=virtio,cache=none".format(
image_storage_handler.qemu_path_string(vm_uuid)
)
command += " -device virtio-rng-pci -vnc unix:{}".format(vnc_sock_filename)
command += " -m {} -smp cores={},threads={}".format(
vm_memory, vm_cpus, threads_per_core
)
command += " -name {}".format(vm_uuid)
if migration:
command += " -incoming tcp:[::]:{}".format(migration_port)
@ -198,7 +199,7 @@ def create(vm_entry: VMEntry):
vm_hdd = int(bitmath.parse_string_unsafe(vm_entry.specs["os-ssd"]).to_MB())
if image_storage_handler.make_vm_image(src=vm_entry.image_uuid, dest=vm_entry.uuid):
if not image_storage_handler.resize_vm_image(path=vm_entry.uuid, size=vm_hdd):
vm_entry.status = "ERROR"
vm_entry.status = VMStatus.error
else:
logger.info("New VM Created")
@ -208,9 +209,10 @@ def start(vm_entry: VMEntry, destination_host_key=None, migration_port=None):
# VM already running. No need to proceed further.
if _vm:
logger.info("VM %s already running", vm_entry.uuid)
logger.info("VM %s already running" % vm_entry.uuid)
return
else:
logger.info("Trying to start %s" % vm_entry.uuid)
if destination_host_key:
launch_vm(vm_entry, migration=True, migration_port=migration_port,
destination_host_key=destination_host_key)
@ -288,7 +290,7 @@ def transfer(request_event):
def launch_vm(vm_entry, migration=False, migration_port=None, destination_host_key=None):
logger.info("Starting %s", vm_entry.key)
logger.info("Starting %s" % vm_entry.key)
vm = create_vm_object(vm_entry, migration=migration, migration_port=migration_port)
try: