diff --git a/src/aleph/vm/controllers/__main__.py b/src/aleph/vm/controllers/__main__.py index 69fbc3779..3ccc97bda 100644 --- a/src/aleph/vm/controllers/__main__.py +++ b/src/aleph/vm/controllers/__main__.py @@ -75,7 +75,7 @@ async def execute_persistent_vm(config: Configuration): process = await execution.start(config.vm_configuration.config_file_path) elif isinstance(config.vm_configuration, QemuConfidentialVMConfiguration): # FIXME assert isinstance(config.vm_configuration, QemuConfidentialVMConfiguration) - execution = QemuConfidentialVM(config.vm_configuration) + execution = QemuConfidentialVM(config.vm_hash, config.vm_configuration) process = await execution.start() else: assert isinstance(config.vm_configuration, QemuVMConfiguration) diff --git a/src/aleph/vm/controllers/qemu/client.py b/src/aleph/vm/controllers/qemu/client.py index 2b7870994..936f65b5b 100644 --- a/src/aleph/vm/controllers/qemu/client.py +++ b/src/aleph/vm/controllers/qemu/client.py @@ -16,7 +16,7 @@ class QemuVmClient: def __init__(self, vm): self.vm = vm if not (vm.qmp_socket_path and vm.qmp_socket_path.exists()): - raise Exception + raise Exception("VM is not running") client = qmp.QEMUMonitorProtocol(str(vm.qmp_socket_path)) client.connect() diff --git a/src/aleph/vm/controllers/qemu_confidential/instance.py b/src/aleph/vm/controllers/qemu_confidential/instance.py index 765558c16..fd371dfb0 100644 --- a/src/aleph/vm/controllers/qemu_confidential/instance.py +++ b/src/aleph/vm/controllers/qemu_confidential/instance.py @@ -62,9 +62,7 @@ def __init__( hardware_resources: MachineResources = MachineResources(), tap_interface: Optional[TapInterface] = None, ): - super().__init__( - vm_id, vm_hash, resources, enable_networking, enable_console, hardware_resources, tap_interface - ) + super().__init__(vm_id, vm_hash, resources, enable_networking, hardware_resources, tap_interface) async def setup(self): pass @@ -106,7 +104,11 @@ async def configure(self): ) configuration = Configuration( - vm_id=self.vm_id, settings=settings, vm_configuration=vm_configuration, hypervisor=HypervisorType.qemu + vm_id=self.vm_id, + vm_hash=self.vm_hash, + settings=settings, + vm_configuration=vm_configuration, + hypervisor=HypervisorType.qemu, ) logger.debug(configuration) diff --git a/src/aleph/vm/hypervisors/qemu/qemuvm.py b/src/aleph/vm/hypervisors/qemu/qemuvm.py index 59148aee9..79d7c9d12 100644 --- a/src/aleph/vm/hypervisors/qemu/qemuvm.py +++ b/src/aleph/vm/hypervisors/qemu/qemuvm.py @@ -19,7 +19,7 @@ class QemuVM: vcpu_count: int mem_size_mb: int interface_name: str - qemu_process = None + qemu_process: Optional[Process] = None def __repr__(self) -> str: if self.qemu_process: @@ -95,6 +95,7 @@ async def start( if self.cloud_init_drive_path: args += ["-cdrom", f"{self.cloud_init_drive_path}"] print(*args) + self.qemu_process = proc = await asyncio.create_subprocess_exec( *args, stdin=asyncio.subprocess.DEVNULL, diff --git a/src/aleph/vm/hypervisors/qemu_confidential/qemuvm.py b/src/aleph/vm/hypervisors/qemu_confidential/qemuvm.py index 15bc95b45..dd31b2580 100644 --- a/src/aleph/vm/hypervisors/qemu_confidential/qemuvm.py +++ b/src/aleph/vm/hypervisors/qemu_confidential/qemuvm.py @@ -1,8 +1,10 @@ import asyncio from asyncio.subprocess import Process from pathlib import Path +from typing import TextIO from cpuid.features import secure_encryption_info +from systemd import journal from aleph.vm.controllers.configuration import QemuConfidentialVMConfiguration from aleph.vm.controllers.qemu.instance import logger @@ -21,8 +23,8 @@ def __repr__(self) -> str: else: return "" - def __init__(self, config: QemuConfidentialVMConfiguration): - super().__init__(config) + def __init__(self, vm_hash, config: QemuConfidentialVMConfiguration): + super().__init__(vm_hash, config) self.qemu_bin_path = config.qemu_bin_path self.cloud_init_drive_path = config.cloud_init_drive_path self.image_path = config.image_path @@ -47,6 +49,8 @@ async def start( # -net tap,ifname=tap0,script=no,downscript=no -drive file=alpine.qcow2,media=disk,if=virtio -nographic # hardware_resources.published ports -> not implemented at the moment # hardware_resources.seconds -> only for microvm + journal_stdout: TextIO = journal.stream(self._journal_stdout_name) + journal_stderr: TextIO = journal.stream(self._journal_stderr_name) # TODO : ensure this is ok at launch sev_info = secure_encryption_info() @@ -114,9 +118,11 @@ async def start( self.qemu_process = proc = await asyncio.create_subprocess_exec( *args, stdin=asyncio.subprocess.DEVNULL, - stdout=asyncio.subprocess.PIPE, - stderr=asyncio.subprocess.PIPE, + stdout=journal_stdout, + stderr=journal_stderr, ) - logger.debug(f"started QemuConfidentialVM vm {self}, {proc}") + print( + f"Started QemuVm {self}, {proc}. Log available with: journalctl -t {self._journal_stdout_name} -t {self._journal_stderr_name}" + ) return proc diff --git a/src/aleph/vm/orchestrator/run.py b/src/aleph/vm/orchestrator/run.py index 7f7be1812..da29084dd 100644 --- a/src/aleph/vm/orchestrator/run.py +++ b/src/aleph/vm/orchestrator/run.py @@ -254,6 +254,8 @@ async def start_persistent_vm(vm_hash: ItemHash, pubsub: Optional[PubSub], pool: if not execution: logger.info(f"Starting persistent virtual machine with id: {vm_hash}") execution = await create_vm_execution(vm_hash=vm_hash, pool=pool, persistent=True) + else: + logger.info(f"{vm_hash} is already running") await execution.becomes_ready()