VM Management
The vms manager creates, lists, updates, deletes, clones, and snapshots VMs directly.
List VMs
from instavm import InstaVM
client = InstaVM('your_api_key')
vms = client.vms.list()
for vm in vms:
print(f"{vm['vm_id']}: {vm.get('status', 'unknown')}")
Create VM
vm = client.vms.create(
wait=True,
vm_lifetime_seconds=3600,
memory_mb=2048,
vcpu_count=4,
metadata={"project": "data-processing"},
egress_policy={
"allow_https": True,
"allow_http": False,
"allowed_domains": ["api.example.com"]
}
)
print(f"VM: {vm['vm_id']}")
print(f"SSH: {vm.get('ssh_host')}")
Set wait=True to block until the VM is ready.
Update VM
result = client.vms.update(
vm_id="vm_abc123",
memory_mb=4096,
egress_policy={
"allow_https": True,
"allowed_domains": ["api.example.com", "cdn.example.com"]
},
snapshot_on_terminate=True,
snapshot_name="final-state"
)
Delete VM
success = client.vms.delete(vm_id="vm_abc123")
Clone VM
Create a copy of a running VM:
cloned = client.vms.clone(
vm_id="vm_abc123",
wait=True,
snapshot_name="cloned-from-abc123"
)
print(f"Clone: {cloned['vm_id']}")
Snapshot VM
Capture the current state of a VM:
snapshot = client.vms.snapshot(
vm_id="vm_abc123",
wait=True,
name="my-snapshot"
)
print(f"Snapshot: {snapshot['snapshot_id']}")
Mount and unmount volumes
Attach persistent storage to a VM:
client.vms.mount_volume(
vm_id="vm_abc123",
volume_id="vol_def456",
mount_path="/data",
mode="rw",
wait=True,
)
List mounted volumes:
mounted = client.vms.list_volumes(vm_id="vm_abc123")
for item in mounted:
print(item["volume_id"], item["mount_path"], item["mode"], item["status"])
Unmount a volume (requires mount_path):
client.vms.unmount_volume(
vm_id="vm_abc123",
volume_id="vol_def456",
mount_path="/data",
wait=True,
)
Metadata filtering
Attach metadata to VMs and filter by it:
# Create with metadata
vm = client.vms.create(
wait=True,
metadata={"project": "data-analysis", "team": "data-science"}
)
# List filtered by metadata
vms = InstaVM.list(api_key='your_api_key', metadata={"project": "data-analysis"})
for v in vms:
print(f"{v.vm_id}: {v.metadata}")
Next steps
- Volumes -- full volume lifecycle and file/checkpoint operations
- Snapshots -- managing snapshots
- Concepts: Sandboxes -- VM resource configuration
- REST API: VMs -- API endpoints