salt.states.virt module
Manage virt
For the key certificate this state uses the external pillar in the master to call for the generation and signing of certificates for systems running libvirt:
libvirt_keys:
virt.keys
salt.states.virt.keys(name, basepath='/etc/pki', **kwargs)
-
Manage libvirt keys.
- name
- The name variable used to track the execution
- basepath
- Defaults to
/etc/pki
, this is the root location used for libvirt keys on the hypervisor
The following parameters are optional:
- country
- The country that the certificate should use. Defaults to US.
- state
- The state that the certificate should use. Defaults to Utah.
- locality
- The locality that the certificate should use. Defaults to Salt Lake City.
- organization
- The organization that the certificate should use. Defaults to Salted.
- expiration_days
- The number of days that the certificate should be valid for. Defaults to 365 days (1 year)
salt.states.virt.network_running(name, bridge, forward, vport=None, tag=None, autostart=True, connection=None, username=None, password=None)
-
Defines and starts a new network with specified arguments.
Parameters: |
-
connection --
libvirt connection URI, overriding defaults -
username --
username to connect with, overriding defaults -
password --
password to connect with, overriding defaults |
domain_name:
virt.network_define
network_name:
virt.network_define:
- bridge: main
- forward: bridge
- vport: openvswitch
- tag: 180
- autostart: True
salt.states.virt.pool_running(name, ptype=None, target=None, permissions=None, source=None, transient=False, autostart=True, connection=None, username=None, password=None)
-
Defines and starts a new pool with specified arguments.
Parameters: |
-
ptype -- libvirt pool type
-
target -- full path to the target device or folder. (Default:
None ) -
permissions -- target permissions. See Permissions definition for more details on this structure.
-
source -- dictionary containing keys matching the
source_* parameters in function salt.modules.virt.pool_define() . -
transient -- when set to
True , the pool will be automatically undefined after being stopped. (Default: False ) -
autostart -- Whether to start the pool when booting the host. (Default:
True ) -
start -- When
True , define and start the pool, otherwise the pool will be left stopped. -
connection -- libvirt connection URI, overriding defaults
-
username -- username to connect with, overriding defaults
-
password -- password to connect with, overriding defaults
|
pool_name:
virt.pool_define
pool_name:
virt.pool_define:
- ptype: netfs
- target: /mnt/cifs
- permissions:
- mode: 0770
- owner: 1000
- group: 100
- source:
- dir: samba_share
- hosts:
one.example.com
two.example.com
- format: cifs
- autostart: True
salt.states.virt.powered_off(name, connection=None, username=None, password=None)
-
Stops a VM by power off.
Parameters: |
-
connection --
libvirt connection URI, overriding defaults -
username --
username to connect with, overriding defaults -
password --
password to connect with, overriding defaults |
domain_name:
virt.stopped
salt.states.virt.rebooted(name, connection=None, username=None, password=None)
-
Reboots VMs
Parameters: |
-
name --
-
connection --
libvirt connection URI, overriding defaults -
username --
username to connect with, overriding defaults -
password --
password to connect with, overriding defaults |
salt.states.virt.reverted(name, snapshot=None, cleanup=False)
-
Deprecated since version 2016.3.0.
Reverts to the particular snapshot.
domain_name:
virt.reverted:
- cleanup: True
domain_name_1:
virt.reverted:
- snapshot: snapshot_name
- cleanup: False
salt.states.virt.running(name, cpu=None, mem=None, image=None, vm_type=None, disk_profile=None, disks=None, nic_profile=None, interfaces=None, graphics=None, seed=True, install=True, pub_key=None, priv_key=None, update=False, connection=None, username=None, password=None, os_type=None, arch=None)
-
Starts an existing guest, or defines and starts a new VM with specified arguments.
Parameters: |
-
name -- name of the virtual machine to run
-
cpu -- number of CPUs for the virtual machine to create
-
mem -- amount of memory in MiB for the new virtual machine
-
image --
disk image to use for the first disk of the new VM Deprecated since version 2019.2.0. -
vm_type --
force virtual machine type for the new VM. The default value is taken from the host capabilities. This could be useful for example to use 'qemu' type instead of the 'kvm' one. -
disk_profile --
Name of the disk profile to use for the new virtual machine -
disks --
List of disk to create for the new virtual machine. See Disks Definitions for more details on the items on this list. -
nic_profile --
Name of the network interfaces profile to use for the new virtual machine -
interfaces --
List of network interfaces to create for the new virtual machine. See Network Interfaces Definitions for more details on the items on this list. -
graphics --
Graphics device to create for the new virtual machine. See Graphics Definition for more details on this dictionary -
saltenv --
Fileserver environment (Default: 'base' ). See cp module for more details -
seed --
-
True to seed the disk image. Only used when the image parameter is provided. - (Default:
True ) -
install --
install salt minion if absent (Default: True ) -
pub_key --
public key to seed with (Default: None ) -
priv_key --
public key to seed with (Default: None ) -
seed_cmd --
Salt command to execute to seed the image. (Default: 'seed.apply' ) -
update --
set to True to update a defined module. (Default: False ) -
connection --
libvirt connection URI, overriding defaults -
username --
username to connect with, overriding defaults -
password --
password to connect with, overriding defaults -
os_type --
type of virtualization as found in the //os/type element of the libvirt definition. The default value is taken from the host capabilities, with a preference for hvm . Only used when creating a new virtual machine. -
arch --
architecture of the virtual machine. The default value is taken from the host capabilities, but x86_64 is prefed over i686 . Only used when creating a new virtual machine. |
Example States
Make sure an already-defined virtual machine called domain_name
is running:
domain_name:
virt.running
Do the same, but define the virtual machine if needed:
domain_name:
virt.running:
- cpu: 2
- mem: 2048
- disk_profile: prod
- disks:
- name: system
size: 8192
overlay_image: True
pool: default
image: /path/to/image.qcow2
- name: data
size: 16834
- nic_profile: prod
- interfaces:
- name: eth0
mac: 01:23:45:67:89:AB
- name: eth1
type: network
source: admin
- graphics:
- type: spice
listen:
- type: address
address: 192.168.0.125
salt.states.virt.saved(name, suffix=None)
-
Deprecated since version 2016.3.0: Use snapshot()
instead.
Takes a snapshot of a particular VM or by a UNIX-style wildcard.
domain_name:
virt.saved:
- suffix: periodic
domain*:
virt.saved:
- suffix: periodic
salt.states.virt.snapshot(name, suffix=None, connection=None, username=None, password=None)
-
Takes a snapshot of a particular VM or by a UNIX-style wildcard.
Parameters: |
-
connection --
libvirt connection URI, overriding defaults -
username --
username to connect with, overriding defaults -
password --
password to connect with, overriding defaults |
domain_name:
virt.snapshot:
- suffix: periodic
domain*:
virt.snapshot:
- suffix: periodic
salt.states.virt.stopped(name, connection=None, username=None, password=None)
-
Stops a VM by shutting it down nicely.
Parameters: |
-
connection --
libvirt connection URI, overriding defaults -
username --
username to connect with, overriding defaults -
password --
password to connect with, overriding defaults |
domain_name:
virt.stopped
salt.states.virt.unpowered(name)
-
Deprecated since version 2016.3.0: Use powered_off()
instead.
Stops a VM by power off.
domain_name:
virt.stopped