VMInfo is a Pydantic model that provides comprehensive runtime information about a VM. It includes the current lifecycle state, configuration, networking details, and process identifiers.
The VM configuration used to create this VM. Contains all settings including CPU count, memory, kernel path, rootfs path, boot args, and environment variables.
Network configuration for the VM. Contains guest IP, gateway, TAP device name, MAC address, and optional SSH port forwarding.None if the VM has not been configured with networking.
from smolvm import SmolVM, VMStatewith SmolVM() as vm: info = vm.info if info.status == VMState.RUNNING: print("VM is running") result = vm.run("hostname") print(f"Hostname: {result.output}") elif info.status == VMState.STOPPED: print("VM is stopped") vm.start() elif info.status == VMState.ERROR: print("VM encountered an error")
from smolvm import SmolVMwith SmolVM() as vm: info = vm.info if info.network: print(f"Guest IP: {info.network.guest_ip}") print(f"Gateway: {info.network.gateway_ip}") print(f"Netmask: {info.network.netmask}") print(f"MAC: {info.network.guest_mac}") if info.network.ssh_host_port: print(f"SSH available at: localhost:{info.network.ssh_host_port}") else: print("VM has no network configuration")
from smolvm import SmolVMwith SmolVM() as vm: config = vm.info.config print(f"Kernel: {config.kernel_path}") print(f"Rootfs: {config.rootfs_path}") print(f"Boot args: {config.boot_args}") print(f"Backend: {config.backend or 'auto'}") print(f"Disk mode: {config.disk_mode}") if config.env_vars: print("Environment variables:") for key, value in config.env_vars.items(): print(f" {key}={value}")
from smolvm import SmolVMwith SmolVM() as vm: info = vm.info if info.socket_path: print(f"Firecracker socket: {info.socket_path}") # You could use this to make direct API calls # to the Firecracker API if needed
from smolvm import SmolVMimport jsonwith SmolVM() as vm: info = vm.info # Convert to dict for serialization info_dict = { "vm_id": info.vm_id, "status": info.status.value, "vcpu_count": info.config.vcpu_count, "mem_size_mib": info.config.mem_size_mib, "guest_ip": info.network.guest_ip if info.network else None, "pid": info.pid, } # Save to file with open(f"/tmp/{info.vm_id}.json", "w") as f: json.dump(info_dict, f, indent=2) print(f"VM info saved to /tmp/{info.vm_id}.json")
from smolvm import SmolVM# First session: create and use VMwith SmolVM() as vm: vm_id = vm.info.vm_id print(f"Created VM: {vm_id}") vm.run("echo 'First session'")# Second session: reconnect to the same VM# (Note: The VM was deleted by the context manager above,# so this is just for illustration)reconnected_vm = SmolVM.from_id(vm_id)info = reconnected_vm.infoprint(f"Reconnected to: {info.vm_id}")print(f"Status: {info.status.value}")reconnected_vm.close()
VMInfo instances are frozen and cannot be modified:
Copy
with SmolVM() as vm: info = vm.info # This raises an error info.status = VMState.STOPPED # ValidationError: "VMInfo" is frozen # To get updated info, call refresh() vm.refresh() updated_info = vm.info