def basic_config( self, vcpu_count: int = 2, ht_enabled: bool = False, mem_size_mib: int = 256, add_root_device: bool = True, boot_args: str = None, use_initrd: bool = False ): """Shortcut for quickly configuring a microVM. It handles: - CPU and memory. - Kernel image (will load the one in the microVM allocated path). - Root File System (will use the one in the microVM allocated path). - Does not start the microvm. The function checks the response status code and asserts that the response is within the interval [200, 300). """ response = self.machine_cfg.put( vcpu_count=vcpu_count, ht_enabled=ht_enabled, mem_size_mib=mem_size_mib ) assert self._api_session.is_status_no_content(response.status_code) if self.memory_events_queue: mem_tools.threaded_memory_monitor( mem_size_mib, self.jailer_clone_pid, self._memory_events_queue ) boot_source_args = { 'kernel_image_path': self.create_jailed_resource(self.kernel_file), 'boot_args': boot_args } if use_initrd and self.initrd_file != '': boot_source_args.update( initrd_path=self.create_jailed_resource(self.initrd_file)) response = self.boot.put(**boot_source_args) assert self._api_session.is_status_no_content(response.status_code) if add_root_device and self.rootfs_file != '': # Add the root file system with rw permissions. response = self.drive.put( drive_id='rootfs', path_on_host=self.create_jailed_resource(self.rootfs_file), is_root_device=True, is_read_only=False ) assert self._api_session.is_status_no_content(response.status_code)
def basic_config( self, vcpu_count: int = 2, ht_enabled: bool = False, mem_size_mib: int = 256, add_root_device: bool = True ): """Shortcut for quickly configuring a microVM. It handles: - CPU and memory. - Kernel image (will load the one in the microVM allocated path). - Root File System (will use the one in the microVM allocated path). - Does not start the microvm. The function checks the response status code and asserts that the response is within the interval [200, 300). """ response = self.machine_cfg.put( vcpu_count=vcpu_count, ht_enabled=ht_enabled, mem_size_mib=mem_size_mib ) assert self._api_session.is_good_response(response.status_code) if self.memory_events_queue: mem_tools.threaded_memory_monitor( mem_size_mib, self.jailer_clone_pid, self._memory_events_queue ) # Add a kernel to start booting from. response = self.boot.put( kernel_image_path=self.create_jailed_resource(self.kernel_file) ) assert self._api_session.is_good_response(response.status_code) if add_root_device: # Add the root file system with rw permissions. response = self.drive.put( drive_id='rootfs', path_on_host=self.create_jailed_resource(self.rootfs_file), is_root_device=True, is_read_only=False ) assert self._api_session.is_good_response(response.status_code)
def basic_config(self, vcpu_count: int = 2, ht_enabled: bool = False, mem_size_mib: int = 256, add_root_device: bool = True): """Shortcut for quickly configuring a microVM. It handles: - CPU and memory. - Kernel image (will load the one in the microVM allocated path). - Root File System (will use the one in the microVM allocated path). - Does not start the microvm. The function checks the response status code and asserts that the response is within the interval [200, 300). """ response = self.machine_cfg.put(vcpu_count=vcpu_count, ht_enabled=ht_enabled, mem_size_mib=mem_size_mib) assert self._api_session.is_good_response(response.status_code) if self.monitor_memory: mem_tools.threaded_memory_monitor(mem_size_mib, self._jailer_clone_pid) # Add a kernel to start booting from. response = self.boot.put( kernel_image_path=self.create_jailed_resource(self.kernel_file)) assert self._api_session.is_good_response(response.status_code) if add_root_device: # Add the root file system with rw permissions. response = self.drive.put(drive_id='rootfs', path_on_host=self.create_jailed_resource( self.rootfs_file), is_root_device=True, is_read_only=False) assert self._api_session.is_good_response(response.status_code)