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/xapi-project/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
(domain)¶Nitrogen 版后已移除: Use start()
instead.
Start a defined domain
CLI 范例:
salt '*' virt.create <domain>
salt.modules.xapi.
destroy
(domain)¶Nitrogen 版后已移除: Use stop()
instead.
Power off a defined domain
CLI 范例:
salt '*' virt.destroy <domain>
salt.modules.xapi.
freecpu
()¶Return an int representing the number of unallocated cpus on this hypervisor
CLI 范例:
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 范例:
salt '*' virt.freemem
salt.modules.xapi.
full_info
()¶Return the node_info, vm_info and freemem
CLI 范例:
salt '*' virt.full_info
salt.modules.xapi.
get_disks
(vm_)¶Return the disks of a named vm
CLI 范例:
salt '*' virt.get_disks <vm name>
salt.modules.xapi.
get_macs
(vm_)¶Return a list off MAC addresses from the named vm
CLI 范例:
salt '*' virt.get_macs <vm name>
salt.modules.xapi.
get_nics
(vm_)¶Return info about the network interfaces of a named vm
CLI 范例:
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 范例:
salt '*' virt.is_hyper
salt.modules.xapi.
list_domains
()¶Return a list of virtual machine names on the minion
CLI 范例:
salt '*' virt.list_domains
salt.modules.xapi.
list_vms
()¶Nitrogen 版后已移除: Use list_domains()
instead.
List all virtual machines.
CLI 范例:
salt '*' virt.list_vms <domain>
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 范例:
salt '*' virt.migrate <vm name> <target hypervisor> [live] [port] [node] [ssl] [change_home_server]
Optional values:
salt.modules.xapi.
node_info
()¶Return a dict with information about this node
CLI 范例:
salt '*' virt.node_info
salt.modules.xapi.
pause
(vm_)¶Pause the named vm
CLI 范例:
salt '*' virt.pause <vm name>
salt.modules.xapi.
reboot
(vm_)¶Reboot a domain via ACPI request
CLI 范例:
salt '*' virt.reboot <vm name>
salt.modules.xapi.
reset
(vm_)¶Reset a VM by emulating the reset button on a physical machine
CLI 范例:
salt '*' virt.reset <vm name>
salt.modules.xapi.
resume
(vm_)¶Resume the named vm
CLI 范例:
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 范例:
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 范例:
salt '*' virt.setvcpus myvm 2
salt.modules.xapi.
shutdown
(vm_)¶Send a soft shutdown signal to the named vm
CLI 范例:
salt '*' virt.shutdown <vm name>
salt.modules.xapi.
start
(config_)¶Start a defined domain
CLI 范例:
salt '*' virt.start <path to Xen cfg file>
salt.modules.xapi.
stop
(vm_)¶Hard power down the virtual machine, this is equivalent to pulling the power
CLI 范例:
salt '*' virt.stop <vm name>
salt.modules.xapi.
vcpu_pin
(vm_, vcpu, cpus)¶Set which CPUs a VCPU can use.
CLI 范例:
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 范例:
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 范例:
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 范例:
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 范例:
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 范例:
salt '*' virt.vm_state <vm name>