This commit is contained in:
ahmadbilalkhalid 2019-09-07 15:32:23 +05:00
parent 0c474d35a3
commit 4e0829a26e
2 changed files with 14 additions and 12 deletions

View File

@ -6,7 +6,7 @@ from ucloud_common.host import HostPool
from ucloud_common.request import RequestPool
from decouple import config
WITHOUT_CEPH = config("WITHOUT_CEPH", False)
WITHOUT_CEPH = config("WITHOUT_CEPH", False, cast=bool)
logging.basicConfig(
level=logging.DEBUG,

View File

@ -39,10 +39,10 @@ class VM:
def get_start_command_args(vm_entry, vnc_sock_filename: str, migration=False, migration_port=4444):
threads_per_core = 1
vm_memory = int(bitmath.Byte(int(vm_entry.specs["ram"])).to_MB())
vm_cpus = int(vm_entry.specs["cpu"])
vm_uuid = vm_entry.uuid
threads_per_core = 1
if WITHOUT_CEPH:
command = f"-drive file={os.path.join('/var/vm', vm_uuid)},format=raw,if=virtio,cache=none"
@ -65,13 +65,13 @@ def create_vm_object(vm_entry, migration=False, migration_port=4444):
# REQUIREMENT: Use Unix Socket instead of TCP Port for VNC
vnc_sock_file = tempfile.NamedTemporaryFile()
qemu_args = get_start_command_args(vm_entry=vm_entry,
vnc_sock_filename=vnc_sock_file.name,
migration=migration,
migration_port=migration_port)
qemu_machine = qmp.QEMUMachine("/usr/bin/qemu-system-x86_64",
args=get_start_command_args(vm_entry,
vnc_sock_file.name,
migration=migration,
migration_port=migration_port
)
)
args=qemu_args)
return VM(vm_entry.key, qemu_machine, vnc_sock_file)
@ -87,12 +87,12 @@ def need_running_vm(func):
try:
status = vm.handle.command("query-status")
logging.debug(f"VM Status Check - {status}")
except OSError:
except Exception as exception:
logging.info(
f"{func.__name__} failed - VM {e.key} - Unknown Error"
f"{func.__name__} failed - VM {e} {exception} - Unknown Error"
)
return func(e)
else:
return func(e)
else:
logging.info(
f"{func.__name__} failed because VM {e.key} is not running"
@ -129,6 +129,8 @@ def create(vm_entry: VMEntry):
# This exception catches all other exceptions
# i.e FileNotFound (BaseImage), pool Does Not Exists etc.
logging.exception(e)
vm_entry.status = "ERROR"
else:
try:
subprocess.check_output(_command_to_extend)