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']}")
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
- Snapshots -- managing snapshots
- Concepts: Sandboxes -- VM resource configuration
- REST API: VMs -- API endpoints