This commit is contained in:
ahmadbilalkhalid 2019-09-17 10:35:19 +05:00
parent f704772c6c
commit 6bb6f31f7f
2 changed files with 36 additions and 39 deletions

View file

@ -100,16 +100,12 @@ def main():
continue
# If the event is directed toward me OR I am destination of a InitVMMigration
if ((hasattr(request_event, "hostname") and
request_event.hostname == host.key) or
(hasattr(request_event, "destination") and
request_event.destination == host.key)):
if (request_event.hostname == host.key or request_event.destination == host.key):
logging.debug("EVENT: %s", request_event)
request_pool.client.client.delete(request_event.key)
vm_entry = vm_pool.get(request_event.uuid)
logging.debug("EVENT: %s", request_event)
if request_event.type == RequestType.StartVM:
virtualmachine.start(vm_entry)

View file

@ -9,7 +9,7 @@ import os
import subprocess
import tempfile
import time
import traceback
from functools import wraps
from os.path import join
from typing import Union
@ -169,22 +169,7 @@ def start(vm_entry: VMEntry):
return
else:
create(vm_entry)
logging.info("Starting %s", vm_entry.key)
vm = create_vm_object(vm_entry)
try:
vm.handle.launch()
except (qmp.QEMUMachineError, TypeError, Exception):
vm_entry.declare_killed()
vm_entry.add_log("Machine Error occurred | %s", traceback.format_exc())
vm_entry.vnc_socket = vm.vnc_socket_file
vm_pool.put(vm_entry)
else:
running_vms.append(vm)
vm_entry.status = VMStatus.running
vm_entry.add_log("Started successfully")
vm_pool.put(vm_entry)
launch_vm(vm_entry)
@need_running_vm
@ -276,24 +261,33 @@ def init_migration(vm_entry, destination_host_key):
logging.info("%s Already running", _vm.key)
return
launch_vm(vm_entry, migration=True, migration_port=4444,
destination_host_key=destination_host_key)
def launch_vm(vm_entry, migration=False, migration_port=None, destination_host_key=None):
logging.info("Starting %s", vm_entry.key)
vm = create_vm_object(vm_entry, migration=True, migration_port=4444)
vm = create_vm_object(vm_entry, migration=migration, migration_port=migration_port)
try:
vm.handle.launch()
except Exception as e:
# We don't care whether MachineError or any other error occurred
logging.exception(e)
if migration:
# We don't care whether MachineError or any other error occurred
vm.handle.shutdown()
else:
vm_entry.in_migration = True
vm_entry.vnc_socket = vm.vnc_socket_file
# Error during typical launch of a vm
vm_entry.add_log("Error Occurred while starting VM")
vm_entry.declare_killed()
vm_pool.put(vm_entry)
else:
vm_entry.vnc_socket = vm.vnc_socket_file
running_vms.append(vm)
if migration:
vm_entry.in_migration = True
r = RequestEntry.from_scratch(
type=RequestType.TransferVM,
hostname=vm_entry.hostname,
@ -302,3 +296,10 @@ def init_migration(vm_entry, destination_host_key):
destination_host_key=destination_host_key,
)
request_pool.put(r)
else:
# Typical launching of a vm
vm_entry.status = VMStatus.running
vm_entry.add_log("Started successfully")
vm_pool.put(vm_entry)