Virtual machines

!

Subsections of Virtual machines

List virtual machines

Options

optiondescriptionAllowed values
filter-nameapply a regex filter on virtual machines nameregex string
output-formatoutput the result of the list command in the selected format (default to table)table or yaml or json
proxmox-nodecoma separated list of proxmox nodes where we will search for virtual machinesnode1,node2,node3
statusvirtual machine statusrunning or stopped

Examples

  • This command will output an unfiltered list of virtual machines available on the cluster
proxcli vms list
  • This command will output a list of virtual machines on selected nodes
proxcli vms list --proxmox-nodes pve1,pve2
  • This commands will output a list of virtual machines filterd by a regular expression applied on virtual machine name
proxcli vms list --filter-name "^b4p-"
  • This command will output a list of virtual machines with the specified status (comma separated list possible)
proxcli vms list --status running
  • You can combine the different filters together. This command show running vms matching a filter on virtual machine name on a specified node
proxcli vms list --status running --proxmox-node pve2 --filter-name ".*powerdns.*"

output formating

Info

In the previous exemples, the result is formated as a nice table. you can specify other output formating such as json or yaml. just add the output-format argument. This argument take one of table, yaml or json value.

tablejsonyaml

Clone a virtual machine template

Options

optiondescriptionAllowed values
vmidvirtual machine template id to be clonedinteger
namevirtual machine clone nameregex string
vm-descriptionvirtual machine clone descriptionstring
full-cloneA full clone VM is a complete copy and is fully independant to the original VM or VM Template, but requires the same disk space as the original.N/A
storagestorage name (local or remote) where the virtual machine disk image will be clonedstring
targetthe target proxmox node name where the cloned virtual machine will be assignedstring
blockwill the clone process will block until it end ? It make sense on slow remote storage (like on NAS), we wait for the clone task to finish before doing the next clone. This prevent IO saturation on storageN/A
duplicatehow many duplicate do we need ? each duplicate will get his name suffixed by an index.integer
Info

vmid and name are mutualy exclusive

Examples

  • Clone a virtual machine template
proxcli vms clone --vmid 111 --name test --vm-description test --full-clone --block --target pve2 --storage b4papp 
  • Clone a virtual machine template with cloud enabled template

This is the same command as for a normal clone but you need additional steps to set user, password, ssh public key and network configuration. Try the following commands after cloning finishes.

proxcli vms set --vmid 112 --ciuser myuser --cipassword mypassword --ipconfig "ip=dhcp" --sshkey "$(cat ~/.ssh/id_rsa.pub)"
proxcli vms set --vmid 112 --cores 4 --memory 4096
proxcli vms resize --vmid 112 --disk virtio0 --size "50G"
Info

Make sure you already have a cloud init enabled template on your proxmox nodes. You can find in the next section an example of creating an ubuntu server cloud init enabled image.

Customize the cloudimg with embeded qemu-guest-agent

you will need virt-customize tool on your proxmox nodes in order to install qemu-guest-agent (install it with apt install libguestfs-tools) you also need an ubuntu cloud-init enabled image. You can find one here

virt-customize -a lunar-server-cloudimg-amd64.img --install qemu-guest-agent 
virt-customize -a lunar-server-cloudimg-amd64.img --run-command "echo -n > /etc/machine-id"
Create a cloud init enabled template on selected proxmox nodes

Those commands will help you create an ubuntu cloud init enabled virtual machine template. Adjust the variables at the begining of the script so it match your needs.

vmid=$(pvesh get /cluster/nextid)
isopath="/mnt/pve/isos/template/iso/lunar-server-cloudimg-amd64.img"
templatename="lunar-server-cloudinit"
memory=2048
storage="b4papp"
scsihw="virtio-scsi-pci"
devname="virtio"
disksize="5G"
qm create $vmid  --memory ${memory} --name ${templatename} --net0 virtio,bridge=vmbr0
qm set $vmid --agent enabled=1
qm importdisk $vmid $isopath $storage
qm set $vmid --scsihw $scsihw --${devname}0 ${storage}:${vmid}/vm-${vmid}-disk-0.raw
qm set $vmid --ide2 ${storage}:cloudinit
qm set $vmid --boot c --bootdisk ${devname}0
qm resize $vmid ${devname}0 ${disksize}    
qm set ${vmid} --serial0 socket --vga serial0  
qm template ${vmid}
Note

On some shared storages (like Synology NFS share), you may encounter the following error with qm template command:

/usr/bin/chattr: Operation not supported while reading flags on /mnt/pve/b4papp/images/111/base-111-disk-0.raw

You don’t have to do anything, it is just a limitation in synology hardening. But it does not affect the creation of a template.

Set virtual machine parameters

Options

optiondescriptionAllowed values
vmidThe (unique) ID of the VM.integer
vmnameVirtual Machine exact namestring
coresThe number of cores per socket.integer
socketsThe number of CPU sockets.integer
cpulimitLimit of CPU usage. NOTE: If the computer has 2 CPUs, it has total of ‘2’ CPU time. Value ‘0’ indicates no CPU limit.integer
memoryAmount of RAM for the VM in MiB. This is the maximum available memory when you use the balloon device.integer
ipconfigcloud-init: Specify IP addresses and gateways for the corresponding interface. IP addresses use CIDR notation, gateways are optional but need an IP of the same type specified. The special string ‘dhcp’ can be used for IP addresses to use DHCP, in which case no explicit gateway should be provided. For IPv6 the special string ‘auto’ can be used to use stateless autoconfiguration. This requires cloud-init 19.4 or newer. If cloud-init is enabled and neither an IPv4 nor an IPv6 address is specified, it defaults to using dhcp on IPv4.string
cipasswordcloud-init: Password to assign the user. Using this is generally not recommended. Use ssh keys instead. Also note that older cloud-init versions do not support hashed passwords.string
ciusercloud-init: User name to change ssh keys and password for instead of the image’s configured default user.string
citypeSpecifies the cloud-init configuration format. The default depends on the configured operating system type ostype. We use the nocloud format for Linux, and configdrive2 for windows.string
bootSpecify guest boot order. Use the ‘order=’ sub-property as usage with no key or ’legacy=’ is deprecated.string
sshkeycloud-init: Setup public SSH keystring
Info

Set parameters is a small subset of what is available in the proxmox API. I (maybe) will had more parameters later.

Examples

Info

assert we have already cloned a cloud init enabled ubuntu virtual machine with the following command:

proxcli vms clone --vmid 100 --full-clone --block --name ubuntu-cloud-init-clone --vm-description exemple_clone --target pve1 --storage b4papp

the cloned vm is not started yet

  • cloud init configuration of a vm cloned from a cloud init enabled ubuntu virtual machine
proxcli vms set --vmid 110 --ciuser myuser --cipassword mypassword --ipconfig "ip=dhcp" --sshkey "$(cat ~/.ssh/id_rsa.pub)"
  • adjust resources of a cloned virtual machine
proxcli vms set --vmid 110 --cores 4 --memory 4096
  • start the cloned virtual machine
proxcli vms start --vmid 111

Resize virtual machine disk

Options

optiondescriptionAllowed values
vmidthe virtual machine id from which you want to resize the diskstring
vmnamethe virtual machine name from which you want to resize the diskstring
filter-nameregex selector applied on virtual machines names you want to resize the diskstring
diskthe disk name in virtual machine config (usualy the one associated with bootdisk)string
sizeThe desired size of the disk (Ex: 50G)string
Info

vmid, vmname and filter-name are mutualy exclusive

Examples

  • resize the boot disk
proxcli vms resize --vmid 111 --disk virtio0 --size "60G"

Delete virtual machine

Options

optiondescriptionAllowed values
vmidthe virtual machine id you want to deletestring
filter-namea regex applied on virtual machine namestring
confirmdoes not ask for confirmationN/A
blockblock the command until it finishedN/A

Examples

  • delete a virtual machine by its id
proxcli vms delete --vmid 111
  • delete all virtual machines matching the specified regex
proxcli vms delete --filter-name "^b4p"
  • delete all virtual machines matching the specified regex without any confirmation and wait for all deletion to be finished before exiting
proxcli vms delete --filter-name "^b4p" --confirm --block

Dump virtual machine config

Arguments

argumentdescriptionAllowed values
vmidvirtual machine from which we want to dump the configinteger

Examples

  • dump config of a virtual machine
proxcli vms dump_config 111

Migrate a virtual machine

Options

optiondescriptionAllowed values
vmidThe virtual machine id to migrateinteger
filter-nameA regex string to select multiple virtual machines to be migratedstring regex
target-nodethe proxmox target node namestring
Info

vmid and filter-name are mutualy exclusive

Examples

Note

You can’t migrate a running virtual machine. The only way to do live migration is through cluster ha resource migrate. See cluster ha section

  • migrate a virtual machine from one proxmox node to other
proxcli vms migrate --vmid 111 --target-node pve2 
  • migrate multiples virtual machines by selecting the with a regex filter on their name
proxcli vms migrate --filter-name "^b4p" --target-node pve2

Display the next available vm id

Options

optiondescriptionAllowed values

Examples

  • Display the next available virtual machine id
proxcli vms nextId

virtual machine tags

Subsections of virtual machine tags

List virtual machine tags

Options

optiondescriptionAllowed values

Examples

  • list all virtual machine tags
proxcli vms tags list

Set virtual machine tags

Options

optiondescriptionAllowed values
vm-tagscoma separated list of tagsstring
filter-nameregex applied to match virtual machine namesstring
set-modewhether we can append or replace tags. default to replacestring

Examples

  • Set tags for all vms name matching the specified regex
proxcli vms tags set --vm-tags "template,ubuntu" --filter-name "^ubuntu-cloud"
  • append tags for all vms name matching the specified regex
proxcli vms tags set --vm-tags "newtag" --filter-name "^ubuntu-cloud" --set-mode append

Set virtual machine status

Description

Virtual machine status commands use the same options interface for every desired status. The following options table apply to all status commands such as start, stop, suspend or reset.

Options

optiondescriptionAllowed values
vmidthe virtual machine id you want to deletestring
filter-namea regex applied on virtual machine namestring

Examples

  • Start virtual machine
proxcli vms start --vmid 101
  • Stop virtual machine
proxcli vms stop --vmid 101
  • Suspend all virtual machines with name matching specified regex
proxcli vms suspend --filter-name "^b4p"
  • Reset virtual machine
proxcli vms reset --vmid 101

Wait for virtual machine status

Description

wait for virtual machines to reach the desired status (stopped, running …)

Options

optiondescriptionAllowed values
vmidthe virtual machine id you want to wait for reaching the desired statusstring
namethe virtual machine name you want to wait for reaching the desired statusstring
filter-namea regex applied on virtual machine name you want to wait for reaching the desired statusstring
statusthe desired statusstring
Info

vmid, name and filter-name are mutualy exclusive

Examples

  • wait for every virtual machine with name start with test to be stopped
proxcli vms wait_for_status --filter-name "^test" --status "stopped"