salt.modules.virt

Work with virtual machines managed by libvirt

depends:libvirt Python module
salt.modules.virt.create(vm_)

Start a defined domain

CLI Example:

salt '*' virt.create <vm name>
salt.modules.virt.create_xml_path(path)

Start a domain based on the XML-file path passed to the function

CLI Example:

salt '*' virt.create_xml_path <path to XML file on the node>
salt.modules.virt.create_xml_str(xml)

Start a domain based on the XML passed to the function

CLI Example:

salt '*' virt.create_xml_str <XML in string format>
salt.modules.virt.ctrl_alt_del(vm_)

Sends CTRL+ALT+DEL to a VM

CLI Example:

salt '*' virt.ctrl_alt_del <vm name>
salt.modules.virt.define_vol_xml_path(path)

Define a volume based on the XML-file path passed to the function

CLI Example:

salt '*' virt.define_vol_xml_path <path to XML file on the node>
salt.modules.virt.define_vol_xml_str(xml)

Define a volume based on the XML passed to the function

CLI Example:

salt '*' virt.define_vol_xml_str <XML in string format>
salt.modules.virt.define_xml_path(path)

Define a domain based on the XML-file path passed to the function

CLI Example:

salt '*' virt.define_xml_path <path to XML file on the node>
salt.modules.virt.define_xml_str(xml)

Define a domain based on the XML passed to the function

CLI Example:

salt '*' virt.define_xml_str <XML in string format>
salt.modules.virt.destroy(vm_)

Hard power down the virtual machine, this is equivalent to pulling the power

CLI Example:

salt '*' virt.destroy <vm name>
salt.modules.virt.freecpu()

Return an int representing the number of unallocated cpus on this hypervisor

CLI Example:

salt '*' virt.freecpu
salt.modules.virt.freemem()

Return an int representing the amount of memory (in MB) that has not been given to virtual machines on this node

CLI Example:

salt '*' virt.freemem
salt.modules.virt.full_info()

Return the node_info, vm_info and freemem

CLI Example:

salt '*' virt.full_info
salt.modules.virt.get_disks(vm_)

Return the disks of a named vm

CLI Example:

salt '*' virt.get_disks <vm name>
salt.modules.virt.get_graphics(vm_)

Returns the information on vnc for a given vm

CLI Example:

salt '*' virt.get_graphics <vm name>
salt.modules.virt.get_macs(vm_)

Return a list off MAC addresses from the named vm

CLI Example:

salt '*' virt.get_macs <vm name>
salt.modules.virt.get_nics(vm_)

Return info about the network interfaces of a named vm

CLI Example:

salt '*' virt.get_nics <vm name>
salt.modules.virt.get_profiles(hypervisor=None)

Return the virt profiles for hypervisor.

Currently there are profiles for:

  • nic
  • disk

CLI Example:

salt '*' virt.get_profiles
salt '*' virt.get_profiles hypervisor=esxi
salt.modules.virt.get_xml(vm_)

Returns the XML for a given vm

CLI Example:

salt '*' virt.get_xml <vm name>
salt.modules.virt.init(name, cpu, mem, image=None, nic='default', hypervisor='kvm', start=True, disk='default', saltenv='base', **kwargs)

Initialize a new vm

CLI Example:

salt 'hypervisor' virt.init vm_name 4 512 salt://path/to/image.raw
salt 'hypervisor' virt.init vm_name 4 512 nic=profile disk=profile
salt.modules.virt.is_hyper()

Returns a bool whether or not this node is a hypervisor of any kind

CLI Example:

salt '*' virt.is_hyper
salt.modules.virt.is_kvm_hyper()

Returns a bool whether or not this node is a KVM hypervisor

CLI Example:

salt '*' virt.is_kvm_hyper
salt.modules.virt.is_xen_hyper()

Returns a bool whether or not this node is a XEN hypervisor

CLI Example:

salt '*' virt.is_xen_hyper
salt.modules.virt.list_active_vms()

Return a list of names for active virtual machine on the minion

CLI Example:

salt '*' virt.list_active_vms
salt.modules.virt.list_inactive_vms()

Return a list of names for inactive virtual machine on the minion

CLI Example:

salt '*' virt.list_inactive_vms
salt.modules.virt.list_vms()

Return a list of virtual machine names on the minion

CLI Example:

salt '*' virt.list_vms
salt.modules.virt.migrate(vm_, target, ssh=False)

Shared storage migration

CLI Example:

salt '*' virt.migrate <vm name> <target hypervisor>
salt.modules.virt.migrate_non_shared(vm_, target, ssh=False)

Attempt to execute non-shared storage "all" migration

CLI Example:

salt '*' virt.migrate_non_shared <vm name> <target hypervisor>
salt.modules.virt.migrate_non_shared_inc(vm_, target, ssh=False)

Attempt to execute non-shared storage "all" migration

CLI Example:

salt '*' virt.migrate_non_shared_inc <vm name> <target hypervisor>
salt.modules.virt.node_info()

Return a dict with information about this node

CLI Example:

salt '*' virt.node_info
salt.modules.virt.pause(vm_)

Pause the named vm

CLI Example:

salt '*' virt.pause <vm name>
salt.modules.virt.purge(vm_, dirs=False)

Recursively destroy and delete a virtual machine, pass True for dir's to also delete the directories containing the virtual machine disk images - USE WITH EXTREME CAUTION!

CLI Example:

salt '*' virt.purge <vm name>
salt.modules.virt.reboot(vm_)

Reboot a domain via ACPI request

CLI Example:

salt '*' virt.reboot <vm name>
salt.modules.virt.reset(vm_)

Reset a VM by emulating the reset button on a physical machine

CLI Example:

salt '*' virt.reset <vm name>
salt.modules.virt.resume(vm_)

Resume the named vm

CLI Example:

salt '*' virt.resume <vm name>
salt.modules.virt.seed_non_shared_migrate(disks, force=False)

Non shared migration requires that the disks be present on the migration destination, pass the disks information via this function, to the migration destination before executing the migration.

CLI Example:

salt '*' virt.seed_non_shared_migrate <disks>
salt.modules.virt.set_autostart(vm_, state='on')

Set the autostart flag on a VM so that the VM will start with the host system on reboot.

CLI Example:

salt "*" virt.set_autostart <vm name> <on | off>
salt.modules.virt.setmem(vm_, memory, config=False)

Changes the amount of memory allocated to VM. The VM must be shutdown for this to work.

memory is to be specified in MB If config is True then we ask libvirt to modify the config as well

CLI Example:

salt '*' virt.setmem myvm 768
salt.modules.virt.setvcpus(vm_, vcpus, config=False)

Changes the amount of vcpus allocated to VM. The VM must be shutdown for this to work.

vcpus is an int representing the number to be assigned If config is True then we ask libvirt to modify the config as well

CLI Example:

salt '*' virt.setvcpus myvm 2
salt.modules.virt.shutdown(vm_)

Send a soft shutdown signal to the named vm

CLI Example:

salt '*' virt.shutdown <vm name>
salt.modules.virt.start(vm_)

Alias for the obscurely named 'create' function

CLI Example:

salt '*' virt.start <vm name>
salt.modules.virt.stop(vm_)

Alias for the obscurely named 'destroy' function

CLI Example:

salt '*' virt.stop <vm name>
salt.modules.virt.undefine(vm_)

Remove a defined vm, this does not purge the virtual machine image, and this only works if the vm is powered down

CLI Example:

salt '*' virt.undefine <vm name>
salt.modules.virt.virt_type()

Returns the virtual machine type as a string

CLI Example:

salt '*' virt.virt_type
salt.modules.virt.vm_cputime(vm_=None)

Return cputime used by the vms on this hyper in a list of dicts:

[
    'your-vm': {
        'cputime' <int>
        'cputime_percent' <int>
        },
    ...
    ]

If you pass a VM name in as an argument then it will return info for just the named VM, otherwise it will return all VMs.

CLI Example:

salt '*' virt.vm_cputime
salt.modules.virt.vm_diskstats(vm_=None)

Return disk usage counters used by the vms on this hyper in a list of dicts:

[
    'your-vm': {
        'rd_req'   : 0,
        'rd_bytes' : 0,
        'wr_req'   : 0,
        'wr_bytes' : 0,
        'errs'     : 0
        },
    ...
    ]

If you pass a VM name in as an argument then it will return info for just the named VM, otherwise it will return all VMs.

CLI Example:

salt '*' virt.vm_blockstats
salt.modules.virt.vm_info(vm_=None)

Return detailed information about the vms on this hyper in a list of dicts:

[
    'your-vm': {
        'cpu': <int>,
        'maxMem': <int>,
        'mem': <int>,
        'state': '<state>',
        'cputime' <int>
        },
    ...
    ]

If you pass a VM name in as an argument then it will return info for just the named VM, otherwise it will return all VMs.

CLI Example:

salt '*' virt.vm_info
salt.modules.virt.vm_netstats(vm_=None)

Return combined network counters used by the vms on this hyper in a list of dicts:

[
    'your-vm': {
        'rx_bytes'   : 0,
        'rx_packets' : 0,
        'rx_errs'    : 0,
        'rx_drop'    : 0,
        'tx_bytes'   : 0,
        'tx_packets' : 0,
        'tx_errs'    : 0,
        'tx_drop'    : 0
        },
    ...
    ]

If you pass a VM name in as an argument then it will return info for just the named VM, otherwise it will return all VMs.

CLI Example:

salt '*' virt.vm_netstats
salt.modules.virt.vm_state(vm_=None)

Return list of all the vms and their state.

If you pass a VM name in as an argument then it will return info for just the named VM, otherwise it will return all VMs.

CLI Example:

salt '*' virt.vm_state <vm name>