a
This commit is contained in:
parent
f704772c6c
commit
6bb6f31f7f
2 changed files with 36 additions and 39 deletions
8
main.py
8
main.py
|
@ -100,16 +100,12 @@ def main():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# If the event is directed toward me OR I am destination of a InitVMMigration
|
# If the event is directed toward me OR I am destination of a InitVMMigration
|
||||||
if ((hasattr(request_event, "hostname") and
|
if (request_event.hostname == host.key or request_event.destination == host.key):
|
||||||
request_event.hostname == host.key) or
|
logging.debug("EVENT: %s", request_event)
|
||||||
(hasattr(request_event, "destination") and
|
|
||||||
request_event.destination == host.key)):
|
|
||||||
|
|
||||||
request_pool.client.client.delete(request_event.key)
|
request_pool.client.client.delete(request_event.key)
|
||||||
vm_entry = vm_pool.get(request_event.uuid)
|
vm_entry = vm_pool.get(request_event.uuid)
|
||||||
|
|
||||||
logging.debug("EVENT: %s", request_event)
|
|
||||||
|
|
||||||
if request_event.type == RequestType.StartVM:
|
if request_event.type == RequestType.StartVM:
|
||||||
virtualmachine.start(vm_entry)
|
virtualmachine.start(vm_entry)
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
import traceback
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from os.path import join
|
from os.path import join
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
@ -169,22 +169,7 @@ def start(vm_entry: VMEntry):
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
create(vm_entry)
|
create(vm_entry)
|
||||||
|
launch_vm(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)
|
|
||||||
|
|
||||||
|
|
||||||
@need_running_vm
|
@need_running_vm
|
||||||
|
@ -276,29 +261,45 @@ def init_migration(vm_entry, destination_host_key):
|
||||||
logging.info("%s Already running", _vm.key)
|
logging.info("%s Already running", _vm.key)
|
||||||
return
|
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)
|
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:
|
try:
|
||||||
vm.handle.launch()
|
vm.handle.launch()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# We don't care whether MachineError or any other error occurred
|
|
||||||
logging.exception(e)
|
logging.exception(e)
|
||||||
vm.handle.shutdown()
|
|
||||||
|
if migration:
|
||||||
|
# We don't care whether MachineError or any other error occurred
|
||||||
|
vm.handle.shutdown()
|
||||||
|
else:
|
||||||
|
# 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:
|
else:
|
||||||
vm_entry.in_migration = True
|
|
||||||
vm_entry.vnc_socket = vm.vnc_socket_file
|
vm_entry.vnc_socket = vm.vnc_socket_file
|
||||||
|
|
||||||
vm_pool.put(vm_entry)
|
|
||||||
|
|
||||||
running_vms.append(vm)
|
running_vms.append(vm)
|
||||||
|
|
||||||
r = RequestEntry.from_scratch(
|
if migration:
|
||||||
type=RequestType.TransferVM,
|
vm_entry.in_migration = True
|
||||||
hostname=vm_entry.hostname,
|
r = RequestEntry.from_scratch(
|
||||||
parameters={"host": get_ipv4_address(), "port": 4444},
|
type=RequestType.TransferVM,
|
||||||
uuid=vm_entry.uuid,
|
hostname=vm_entry.hostname,
|
||||||
destination_host_key=destination_host_key,
|
parameters={"host": get_ipv4_address(), "port": 4444},
|
||||||
)
|
uuid=vm_entry.uuid,
|
||||||
request_pool.put(r)
|
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)
|
||||||
|
|
Loading…
Reference in a new issue