a
This commit is contained in:
parent
0c474d35a3
commit
4e0829a26e
2 changed files with 14 additions and 12 deletions
|
@ -6,7 +6,7 @@ from ucloud_common.host import HostPool
|
||||||
from ucloud_common.request import RequestPool
|
from ucloud_common.request import RequestPool
|
||||||
from decouple import config
|
from decouple import config
|
||||||
|
|
||||||
WITHOUT_CEPH = config("WITHOUT_CEPH", False)
|
WITHOUT_CEPH = config("WITHOUT_CEPH", False, cast=bool)
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.DEBUG,
|
level=logging.DEBUG,
|
||||||
|
|
|
@ -39,10 +39,10 @@ class VM:
|
||||||
|
|
||||||
|
|
||||||
def get_start_command_args(vm_entry, vnc_sock_filename: str, migration=False, migration_port=4444):
|
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_memory = int(bitmath.Byte(int(vm_entry.specs["ram"])).to_MB())
|
||||||
vm_cpus = int(vm_entry.specs["cpu"])
|
vm_cpus = int(vm_entry.specs["cpu"])
|
||||||
vm_uuid = vm_entry.uuid
|
vm_uuid = vm_entry.uuid
|
||||||
threads_per_core = 1
|
|
||||||
|
|
||||||
if WITHOUT_CEPH:
|
if WITHOUT_CEPH:
|
||||||
command = f"-drive file={os.path.join('/var/vm', vm_uuid)},format=raw,if=virtio,cache=none"
|
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
|
# REQUIREMENT: Use Unix Socket instead of TCP Port for VNC
|
||||||
vnc_sock_file = tempfile.NamedTemporaryFile()
|
vnc_sock_file = tempfile.NamedTemporaryFile()
|
||||||
qemu_machine = qmp.QEMUMachine("/usr/bin/qemu-system-x86_64",
|
|
||||||
args=get_start_command_args(vm_entry,
|
qemu_args = get_start_command_args(vm_entry=vm_entry,
|
||||||
vnc_sock_file.name,
|
vnc_sock_filename=vnc_sock_file.name,
|
||||||
migration=migration,
|
migration=migration,
|
||||||
migration_port=migration_port
|
migration_port=migration_port)
|
||||||
)
|
qemu_machine = qmp.QEMUMachine("/usr/bin/qemu-system-x86_64",
|
||||||
)
|
args=qemu_args)
|
||||||
return VM(vm_entry.key, qemu_machine, vnc_sock_file)
|
return VM(vm_entry.key, qemu_machine, vnc_sock_file)
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,11 +87,11 @@ def need_running_vm(func):
|
||||||
try:
|
try:
|
||||||
status = vm.handle.command("query-status")
|
status = vm.handle.command("query-status")
|
||||||
logging.debug(f"VM Status Check - {status}")
|
logging.debug(f"VM Status Check - {status}")
|
||||||
except OSError:
|
except Exception as exception:
|
||||||
logging.info(
|
logging.info(
|
||||||
f"{func.__name__} failed - VM {e.key} - Unknown Error"
|
f"{func.__name__} failed - VM {e} {exception} - Unknown Error"
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
return func(e)
|
return func(e)
|
||||||
else:
|
else:
|
||||||
logging.info(
|
logging.info(
|
||||||
|
@ -129,6 +129,8 @@ def create(vm_entry: VMEntry):
|
||||||
# This exception catches all other exceptions
|
# This exception catches all other exceptions
|
||||||
# i.e FileNotFound (BaseImage), pool Does Not Exists etc.
|
# i.e FileNotFound (BaseImage), pool Does Not Exists etc.
|
||||||
logging.exception(e)
|
logging.exception(e)
|
||||||
|
|
||||||
|
vm_entry.status = "ERROR"
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(_command_to_extend)
|
subprocess.check_output(_command_to_extend)
|
||||||
|
|
Loading…
Add table
Reference in a new issue