API Reference
Detailed Interface Reference
Top-Level Interface
-
create_image(distro, name)- Create or retrieve a VM image from the specified distribution -
with_machine(image, config, f)- Execute an async closure in a virtual machine with automatic resource cleanup -
with_pool(f)- Execute an async closure in a machine pool with automatic resource cleanup -
MachineConfig- Configuration for virtual machine resources (CPU, memory, disk)pub struct MachineConfig { pub core: u32, // Number of CPU cores pub mem: u32, // Memory size in MB pub disk: Option<u32>, // Disk size in GB (optional) pub clear: bool, // Clear resources after use }
Machine Core Interface
Machine::new(image, config)- Create a new machine instanceMachine::init()- Initialize the machine (first boot with cloud-init)Machine::spawn()- Start the machine (normal boot)Machine::exec(command)- Execute a command in the VM and return the outputMachine::shutdown()- Gracefully shutdown the virtual machineMachine::upload(src, dst)- Upload a file or directory to the VMMachine::download(src, dst)- Download a file or directory from the VMMachine::get_ip()- Get the IP address of the VM
Machine Pool Interface
MachinePool::new()- Create a new, empty machine poolMachinePool::add(name, image, config)- Add a new machine instance to the poolMachinePool::get(name)- Get a machine instance by the nameMachinePool::init_all()- Initialize all machines in the pool concurrentlyMachinePool::spawn_all()- Spawn all machines in the pool concurrentlyMachinePool::shutdown_all()- Shutdown all machines in the pool concurrently
std::fs Compatible Interface
The following methods provide filesystem operations compatible with std::fs semantics:
Machine::copy(from, to)- Copy a file within the VMMachine::create_dir(path)- Create a directoryMachine::create_dir_all(path)- Create a directory and all missing parent directoriesMachine::exists(path)- Check if a path existsMachine::hard_link(src, dst)- Create a hard linkMachine::metadata(path)- Get file/directory metadataMachine::read(path)- Read file contents as bytesMachine::read_dir(path)- Read directory entriesMachine::read_link(path)- Read symbolic link targetMachine::read_to_string(path)- Read file contents as stringMachine::remove_dir_all(path)- Remove a directory after removing all its contentsMachine::remove_file(path)- Remove a fileMachine::rename(from, to)- Rename or move a file/directoryMachine::set_permissions(path, perm)- Set file/directory permissionsMachine::write(path, contents)- Write bytes to a file