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=u'/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.

New in version 2018.3.0.

state
The state that the certificate should use. Defaults to Utah.

New in version 2018.3.0.

locality
The locality that the certificate should use. Defaults to Salt Lake City.

New in version 2018.3.0.

organization
The organization that the certificate should use. Defaults to Salted.

New in version 2018.3.0.

expiration_days
The number of days that the certificate should be valid for. Defaults to 365 days (1 year)

New in version 2018.3.0.

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

    New in version 2019.2.0.

  • username --

    username to connect with, overriding defaults

    New in version 2019.2.0.

  • password --

    password to connect with, overriding defaults

    New in version 2019.2.0.

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.

New in version 2019.2.0.

Parameters:
  • ptype -- libvirt pool type
  • target -- full path to the target device or folder. (Default: None)
  • permissions -- target permissions. See the Permissions definition section of the virt.pool_define documentation for more details on this structure.
  • source -- dictionary containing keys matching the source_* parameters in function 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.

New in version 2016.3.0.

Parameters:
  • connection --

    libvirt connection URI, overriding defaults

    New in version 2019.2.0.

  • username --

    username to connect with, overriding defaults

    New in version 2019.2.0.

  • password --

    password to connect with, overriding defaults

    New in version 2019.2.0.

domain_name:
  virt.stopped
salt.states.virt.rebooted(name, connection=None, username=None, password=None)

Reboots VMs

New in version 2016.3.0.

Parameters:
  • name --
  • connection --

    libvirt connection URI, overriding defaults

    New in version 2019.2.0.

  • username --

    username to connect with, overriding defaults

    New in version 2019.2.0.

  • password --

    password to connect with, overriding defaults

    New in version 2019.2.0.

salt.states.virt.reverted(name, snapshot=None, cleanup=False)

Deprecated since version 2016.3.0.

Reverts to the particular snapshot.

New in version 2016.3.0.

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, loader=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.

New in version 2016.3.0.

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.

    New in version 2019.2.0.

  • disk_profile --

    Name of the disk profile to use for the new virtual machine

    New in version 2019.2.0.

  • disks --

    List of disk to create for the new virtual machine. See the Disk Definitions section of the virt.init function for more details on the items on this list.

    New in version 2019.2.0.

  • nic_profile --

    Name of the network interfaces profile to use for the new virtual machine

    New in version 2019.2.0.

  • interfaces --

    List of network interfaces to create for the new virtual machine. See the Network Interface Definitions section of the virt.init function for more details on the items on this list.

    New in version 2019.2.0.

  • graphics --

    Graphics device to create for the new virtual machine. See the Graphics Definition section of the virt.init function for more details on this dictionary.

    New in version Fluorine.

  • loader --

    Firmware loader for the new virtual machine. See the Loader Definition section of the virt.init function for more details on this dictionary.

    New in version 2019.2.0.

  • saltenv --

    Fileserver environment (Default: 'base'). See cp module for more details

    New in version 2019.2.0.

  • seed --
    True to seed the disk image. Only used when the image parameter is provided.
    (Default: True)

    New in version 2019.2.0.

  • install --

    install salt minion if absent (Default: True)

    New in version 2019.2.0.

  • pub_key --

    public key to seed with (Default: None)

    New in version 2019.2.0.

  • priv_key --

    public key to seed with (Default: None)

    New in version 2019.2.0.

  • seed_cmd --

    Salt command to execute to seed the image. (Default: 'seed.apply')

    New in version 2019.2.0.

  • update --

    set to True to update a defined module. (Default: False)

    New in version 2019.2.0.

  • connection --

    libvirt connection URI, overriding defaults

    New in version 2019.2.0.

  • username --

    username to connect with, overriding defaults

    New in version 2019.2.0.

  • password --

    password to connect with, overriding defaults

    New in version 2019.2.0.

  • 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.

    New in version Neon.

  • 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.

    New in version Neon.

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.

New in version 2016.3.0.

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.

New in version 2016.3.0.

Parameters:
  • connection --

    libvirt connection URI, overriding defaults

    New in version 2019.2.0.

  • username --

    username to connect with, overriding defaults

    New in version 2019.2.0.

  • password --

    password to connect with, overriding defaults

    New in version 2019.2.0.

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.

New in version 2016.3.0.

Parameters:
  • connection --

    libvirt connection URI, overriding defaults

    New in version 2019.2.0.

  • username --

    username to connect with, overriding defaults

    New in version 2019.2.0.

  • password --

    password to connect with, overriding defaults

    New in version 2019.2.0.

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.

New in version 2016.3.0.

domain_name:
  virt.stopped