use crate::types::{CpuArch, default_vm_cpu_count, default_vm_memory_size};
#[derive(Debug, Clone)]
pub struct VmConfig {
pub vcpu_count: u32,
pub memory_size: u64,
pub arch: CpuArch,
pub kernel_path: Option<String>,
pub kernel_cmdline: Option<String>,
pub initrd_path: Option<String>,
pub enable_rosetta: bool,
}
impl Default for VmConfig {
fn default() -> Self {
Self {
vcpu_count: default_vm_cpu_count(),
memory_size: default_vm_memory_size(),
arch: CpuArch::native(),
kernel_path: None,
kernel_cmdline: None,
initrd_path: None,
enable_rosetta: false,
}
}
}
impl VmConfig {
#[must_use]
pub fn builder() -> VmConfigBuilder {
VmConfigBuilder::default()
}
}
#[derive(Debug, Default)]
pub struct VmConfigBuilder {
config: VmConfig,
}
impl VmConfigBuilder {
#[must_use]
pub const fn vcpu_count(mut self, count: u32) -> Self {
self.config.vcpu_count = count;
self
}
#[must_use]
pub const fn memory_size(mut self, size: u64) -> Self {
self.config.memory_size = size;
self
}
#[must_use]
pub const fn arch(mut self, arch: CpuArch) -> Self {
self.config.arch = arch;
self
}
#[must_use]
pub fn kernel_path(mut self, path: impl Into<String>) -> Self {
self.config.kernel_path = Some(path.into());
self
}
#[must_use]
pub fn kernel_cmdline(mut self, cmdline: impl Into<String>) -> Self {
self.config.kernel_cmdline = Some(cmdline.into());
self
}
#[must_use]
pub fn initrd_path(mut self, path: impl Into<String>) -> Self {
self.config.initrd_path = Some(path.into());
self
}
#[must_use]
pub const fn enable_rosetta(mut self, enable: bool) -> Self {
self.config.enable_rosetta = enable;
self
}
#[must_use]
pub fn build(self) -> VmConfig {
self.config
}
}