salt.modules.virt

Work with virtual machines managed by libvirt

Required python modules: libvirt

Members

create

salt.modules.virt.create(vm_)

Start a defined domain

CLI Example:

salt '*' virt.create <vm name>

create_xml_path

salt.modules.virt.create_xml_path(path)

Start a defined domain

CLI Example:

salt '*' virt.create_xml_path <path to xml file on the node>

create_xml_str

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>

destroy

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>

freecpu

salt.modules.virt.freecpu()

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

CLI Example:

salt '*' virt.freecpu

freemem

salt.modules.virt.freemem()

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

CLI Example:

salt '*' virt.freemem

full_info

salt.modules.virt.full_info()

Return the node_info, vm_info and freemem

CLI Example:

salt '*' virt.full_info

get_disks

salt.modules.virt.get_disks(vm_)

Return the disks of a named vm

CLI Example:

salt '*' virt.get_disks <vm name>

get_graphics

salt.modules.virt.get_graphics(vm_)

Returns the information on vnc for a given vm

CLI Example:

salt '*' virt.get_graphics <vm name>

get_macs

salt.modules.virt.get_macs(vm_)

Return a list off MAC addresses from the named vm

CLI Example:

salt '*' virt.get_macs <vm name>

get_nics

salt.modules.virt.get_nics(vm_)

Return info about the network interfaces of a named vm

CLI Example:

salt '*' virt.get_nics <vm name>

get_xml

salt.modules.virt.get_xml(vm_)

Returns the xml for a given vm

CLI Example:

salt '*' virt.get_xml <vm name>

is_hyper

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

is_kvm_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

is_xen_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

list_active_vms

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

list_inactive_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

list_vms

salt.modules.virt.list_vms()

Return a list of virtual machine names on the minion

CLI Example:

salt '*' virt.list_vms

migrate

salt.modules.virt.migrate(vm_, target)

Shared storage migration

CLI Example:

salt '*' virt.migrate <vm name> <target hypervisor>

migrate_non_shared

salt.modules.virt.migrate_non_shared(vm_, target)

Attempt to execute non-shared storage "all" migration

CLI Example:

salt '*' virt.migrate_non_shared <vm name> <target hypervisor>

migrate_non_shared_inc

salt.modules.virt.migrate_non_shared_inc(vm_, target)

Attempt to execute non-shared storage "all" migration

CLI Example:

salt '*' virt.migrate_non_shared_inc <vm name> <target hypervisor>

node_info

salt.modules.virt.node_info()

Return a dict with information about this node

CLI Example:

salt '*' virt.node_info

pause

salt.modules.virt.pause(vm_)

Pause the named vm

CLI Example:

salt '*' virt.pause <vm name>

purge

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>

resume

salt.modules.virt.resume(vm_)

Resume the named vm

CLI Example:

salt '*' virt.resume <vm name>

seed_non_shared_migrate

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>

set_autostart

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>

shutdown

salt.modules.virt.shutdown(vm_)

Send a soft shutdown signal to the named vm

CLI Example:

salt '*' virt.shutdown <vm name>

start

salt.modules.virt.start(vm_)

Alias for the obscurely named 'create' function

CLI Example:

salt '*' virt.start <vm name>

undefine

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>

virt_type

salt.modules.virt.virt_type()

Returns the virtual machine type as a string

CLI Example:

salt '*' virt.virt_type

vm_info

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

vm_state

salt.modules.virt.vm_state(vm_)

Return the status of the named VM.

CLI Example:

salt '*' virt.vm_state <vm name>