salt.modules.xapi¶
This module (mostly) uses the XenAPI to manage Xen virtual machines.
Big fat warning: the XenAPI used in this file is the one bundled with Xen Source, NOT XenServer nor Xen Cloud Platform. As a matter of fact it will fail under those platforms. From what I've read, little work is needed to adapt this code to XS/XCP, mostly playing with XenAPI version, but as XCP is not taking precedence on Xen Source on many platforms, please keep compatibility in mind.
Useful documentation:
. http://downloads.xen.org/Wiki/XenAPI/xenapi-1.0.6.pdf . http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/api/ . https://github.com/xen-org/xen-api/tree/master/scripts/examples/python . http://xenbits.xen.org/gitweb/?p=xen.git;a=tree;f=tools/python/xen/xm;hb=HEAD
-
salt.modules.xapi.create(config_)¶ Start a defined domain
CLI Example:
salt '*' virt.create <path to Xen cfg file>
-
salt.modules.xapi.destroy(vm_)¶ Hard power down the virtual machine, this is equivalent to pulling the power
CLI Example:
salt '*' virt.destroy <vm name>
-
salt.modules.xapi.freecpu()¶ Return an int representing the number of unallocated cpus on this hypervisor
CLI Example:
salt '*' virt.freecpu
-
salt.modules.xapi.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
-
salt.modules.xapi.full_info()¶ Return the node_info, vm_info and freemem
CLI Example:
salt '*' virt.full_info
-
salt.modules.xapi.get_disks(vm_)¶ Return the disks of a named vm
CLI Example:
salt '*' virt.get_disks <vm name>
-
salt.modules.xapi.get_macs(vm_)¶ Return a list off MAC addresses from the named vm
CLI Example:
salt '*' virt.get_macs <vm name>
-
salt.modules.xapi.get_nics(vm_)¶ Return info about the network interfaces of a named vm
CLI Example:
salt '*' virt.get_nics <vm name>
-
salt.modules.xapi.is_hyper()¶ Returns a bool whether or not this node is a hypervisor of any kind
CLI Example:
salt '*' virt.is_hyper
-
salt.modules.xapi.list_vms()¶ Return a list of virtual machine names on the minion
CLI Example:
salt '*' virt.list_vms
-
salt.modules.xapi.migrate(vm_, target, live=1, port=0, node=-1, ssl=None, change_home_server=0)¶ Migrates the virtual machine to another hypervisor
CLI Example:
salt '*' virt.migrate <vm name> <target hypervisor> [live] [port] [node] [ssl] [change_home_server]
Optional values:
- live
- Use live migration
- port
- Use a specified port
- node
- Use specified NUMA node on target
- ssl
- use ssl connection for migration
- change_home_server
- change home server for managed domains
-
salt.modules.xapi.node_info()¶ Return a dict with information about this node
CLI Example:
salt '*' virt.node_info
-
salt.modules.xapi.pause(vm_)¶ Pause the named vm
CLI Example:
salt '*' virt.pause <vm name>
-
salt.modules.xapi.reboot(vm_)¶ Reboot a domain via ACPI request
CLI Example:
salt '*' virt.reboot <vm name>
-
salt.modules.xapi.reset(vm_)¶ Reset a VM by emulating the reset button on a physical machine
CLI Example:
salt '*' virt.reset <vm name>
-
salt.modules.xapi.resume(vm_)¶ Resume the named vm
CLI Example:
salt '*' virt.resume <vm name>
-
salt.modules.xapi.setmem(vm_, memory)¶ Changes the amount of memory allocated to VM.
Memory is to be specified in MB
CLI Example:
salt '*' virt.setmem myvm 768
-
salt.modules.xapi.setvcpus(vm_, vcpus)¶ Changes the amount of vcpus allocated to VM.
vcpus is an int representing the number to be assigned
CLI Example:
salt '*' virt.setvcpus myvm 2
-
salt.modules.xapi.shutdown(vm_)¶ Send a soft shutdown signal to the named vm
CLI Example:
salt '*' virt.shutdown <vm name>
-
salt.modules.xapi.start(config_)¶ Alias for the obscurely named 'create' function
CLI Example:
salt '*' virt.start <path to Xen cfg file>
-
salt.modules.xapi.vcpu_pin(vm_, vcpu, cpus)¶ Set which CPUs a VCPU can use.
CLI Example:
salt 'foo' virt.vcpu_pin domU-id 2 1 salt 'foo' virt.vcpu_pin domU-id 2 2-6
-
salt.modules.xapi.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.xapi.vm_diskstats(vm_=None)¶ Return disk usage counters used by the vms on this hyper in a list of dicts:
[ 'your-vm': { 'io_read_kbs' : 0, 'io_write_kbs' : 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_diskstats
-
salt.modules.xapi.vm_info(vm_=None)¶ Return detailed information about the vms.
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.xapi.vm_netstats(vm_=None)¶ Return combined network counters used by the vms on this hyper in a list of dicts:
[ 'your-vm': { 'io_read_kbs' : 0, 'io_total_read_kbs' : 0, 'io_total_write_kbs' : 0, 'io_write_kbs' : 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.xapi.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>