%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/modules/virt.pyo

�
���^c@@ssdZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlmZddlZddlZy&ddlZddlmZeZWnek
reZnXddlZddlZddlZddlZddlZddlZddl Zddl!Zddl"Zddl#m$Z$m%Z%ddl&m'Z'ddl(m)Z)ej*e+�Z,ej-d	ej.ej/j0ej1j2j3d
���Z4idd6dd6dd
6dd6dd6dd6dd6Z5d�Z6d�Z7d�Z8d�Z9d�Z:d�Z;d�Z<d�Z=d�Z>d�Z?d�Z@d �ZAd!�ZBd"�ZCd#�ZDeEd$�ZFd%�ZGeEd&�ZHeEeEeEeEeEeEeEeEeEd'�	ZId(�ZJed)d*�ZKeEeEeEeEd+�ZLd,�ZMeEd-�ZNeEd.�ZOeEeEd/�ZPeEd0eEeEed0eEd)eeeEeEd1eeeEeEeEd2�ZQd3�ZRd4�ZSd5�ZTd6�ZUd7�ZVd8�ZWd9�ZXddeEeEeEeEeEed:�ZYd;�ZZd<�Z[d=�Z\eEd>�Z]eEd?�Z^d@�Z_dA�Z`dB�ZadC�ZbdD�ZcdE�ZdedF�ZeedG�ZfdH�ZgdI�ZhdJ�ZidK�ZjdL�ZkdM�ZleEdN�ZmdO�ZndP�ZodQ�ZpdR�ZqdS�ZrdT�ZsdU�ZtdV�ZudW�ZvdX�ZwdY�ZxdZ�Zyd[�Zzd\�Z{ed]�Z|ed^�Z}ed_�Z~ed`�Zdadb�Z�dc�Z�eeEdd�Z�de�Z�df�Z�dg�Z�dh�Z�di�Z�dj�Z�dk�Z�eEdl�Z�eEdm�Z�eEdn�Z�edo�Z�eEdp�Z�eEeEdq�Z�dr�Z�eEeds�Z�dt�Z�du�Z�dv�Z�dw�Z�dx�Z�dy�Z�dz�Z�d{�Z�d|�Z�d}�Z�eEeEeEeEd~�Z�eedd��Z�d��Z�d��Z�eEd��Z�d��Z�d��Z�d��Z�dad��Z�eEeEeEeEeEeEeEeEeEeed��Z�d��Z�eEd��Z�d��Z�d��Z�d��Z�d��Z�ed��Z�d��Z�dad��Z�d��Z�dS(�u�
Work with virtual machines managed by libvirt

:depends: libvirt Python module

Connection
==========

The connection to the virtualization host can be either setup in the minion configuration,
pillar data or overridden for each individual call.

By default, the libvirt connection URL will be guessed: the first available libvirt
hypervisor driver will be used. This can be overridden like this:

.. code-block:: yaml

    virt:
      connection:
        uri: lxc:///

If the connection requires an authentication like for ESXi, this can be defined in the
minion pillar data like this:

.. code-block:: yaml

    virt:
      connection:
        uri: esx://10.1.1.101/?no_verify=1&auto_answer=1
        auth:
          username: user
          password: secret

Connecting with SSH protocol
----------------------------

Libvirt can connect to remote hosts using SSH using one of the ``ssh``, ``libssh`` and
``libssh2`` transports. Note that ``libssh2`` is likely to fail as it doesn't read the
``known_hosts`` file. Libvirt may also have been built without ``libssh`` or ``libssh2``
support.

To use the SSH transport, on the minion setup an SSH agent with a key authorized on
the remote libvirt machine.

Per call connection setup
-------------------------

.. versionadded:: 2019.2.0

All the calls requiring the libvirt connection configuration as mentioned above can
override this configuration using ``connection``, ``username`` and ``password`` parameters.

This means that the following will list the domains on the local LXC libvirt driver,
whatever the ``virt:connection`` is.

.. code-block:: bash

    salt 'hypervisor' virt.list_domains connection=lxc:///

The calls not using the libvirt connection setup are:

- ``seed_non_shared_migrate``
- ``virt_type``
- ``is_*hyper``
- all migration functions

- `libvirt ESX URI format <http://libvirt.org/drvesx.html#uriformat>`_
- `libvirt URI format <http://libvirt.org/uri.html#URI_config>`_
- `libvirt authentication configuration <http://libvirt.org/auth.html#Auth_client_config>`_

i(tabsolute_importtprint_functiontunicode_literalsN(tElementTree(tlibvirtError(tCommandExecutionErrortSaltInvocationError(tsix(trangetloaderuvirturunningiiupausediushutdowniiucrashedicC@ststdfSdS(Nu2Unable to locate or import python libvirt library.uvirt(tHAS_LIBVIRTtFalse(((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt__virtual__�s
c@s��fd�}dS(um
    Get libvirt.openAuth callback with username, password values overriding
    the configuration ones.
    c@s�x�|D]�}|dtjkrJ�r,�ntdd|d�|d<q|dtjkr��ri�ntdd|d�|d<qtjd|d�qWdS(u0Callback method passed to libvirt.openAuth().

        The credentials argument is a list of credentials that libvirt
        would like to request. An element of this list is a list containing
        5 items (4 inputs, 1 output):
          - the credential type, e.g. libvirt.VIR_CRED_AUTHNAME
          - a prompt to be displayed to the user
          - a challenge
          - a default result for the request
          - a place to store the actual result for the request

        The user_data argument is currently not set in the openAuth call.
        iu
config.getuvirt:connection:auth:usernameiiuvirt:connection:auth:passworduUnhandled credential type: %s(tlibvirttVIR_CRED_AUTHNAMEt__salt__tVIR_CRED_NOECHOPROMPTtlogtinfo(tcredentialst	user_datat
credential(tpasswordtusername(s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt__request_auth�s
N((RRR((RRs5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt__get_request_auth�scK@s�|jdd�}|jdd�}|jdd�}|s�tddd�}|dk	rttjjjdd�n8tddd�}|dk	r�tjjjdd	�ntdd
|�}ntddd�}|dk	r�tjjjdd�n|d
kr1|dkr1tjjjdd�d}nyOtjtj	tj
tjtjg}tj
||t||�dgd�}Wn-tk
r�tdjtd|���nX|S(u=
    Detects what type of dom this node is and attempts to connect to the
    correct hypervisor via libvirt.

    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    uusernameupasswordu
connectionu
config.getuvirt.connectuSodiumu�'virt.connect' configuration property has been deprecated in favor of 'virt:connection:uri'. 'virt.connect' will stop being used in {version}.ulibvirt:connectionu�'libvirt.connection' configuration property has been deprecated in favor of 'virt:connection:uri'. 'libvirt.connection' will stop being used in {version}.uvirt:connection:uriulibvirt:hypervisoru�'libvirt.hypervisor' configuration property has been deprecated. Rather use the 'virt:connection:uri' to properly define the libvirt URI or alias of the host to connect to. 'libvirt:hypervisor' will stop being used in {version}.uesxiu�esxi hypervisor default with no default connection URI detected, please set 'virt:connection:uri' to 'esx' for keep the legacy behavior. Will default to libvirt guess once 'libvirt:hypervisor' configuration is removed in {version}.uesxiuHSorry, {0} failed to open a connection to the hypervisor software at {1}ufqdnN(tgettNoneRtsalttutilstversionst
warn_untilR
RRtVIR_CRED_ECHOPROMPTtVIR_CRED_PASSPHRASEtVIR_CRED_EXTERNALtopenAuthRt	ExceptionRtformatt
__grains__(tkwargsRRtconn_strt
hypervisort
auth_typestconn((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt
__get_conn�sL



	+
cO@s_t�}t�}g}|jdt�r`x3|j�D]"}|j|j|�j��q7Wn|jdt�r�x$|j�D]}|j|�qWn|s�td��n|r�xQ|D]:}||kr�tdj	d|���q�|j|�q�Wnt|�}x$|D]}|j|j
|��qWt|�dkr[|jd�r[|dp^|S(	u�
    Return a domain object for the named VM or return domain object for all VMs.

    :params conn: libvirt connection object
    :param vms: list of domain names to look for
    :param iterable: True to return an array in all cases
    uactiveuinactiveuNo virtual machines found.uThe VM "{name}" is not presenttnameiuiterablei(tlistRtTruet
listDomainsIDtappendt
lookupByIDR-tlistDefinedDomainsRR%tlookupByNametlen(R+tvmsR'trett
lookup_vmstall_vmstid_R-((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_get_domain�s(		#

c
C@s�tjjj|�}g}xV|D]N}i|dd6|dd6|dd6|dd6d	|krm|d	ndd
6}d|j�kr�t|d�|d<nd
|j�krcg|d
D]�}i|dd6|dd6|dd6tjjt	dj|d|d���j
�d6tjjt	dj|d|d���j�j
�d6^q�|d
<n|j
|�q"Wxy|D]q}d|j�kr{g|D]2}d|j�kr�|d|dkr�|^q�}|r�|d|d<q�q{q{W|dS(uD
    Parse qemu-img info JSON output into disk infos dictionary
    ufilenameufileuformatufile formatuactual-sizeu	disk sizeuvirtual-sizeuvirtual sizeucluster-sizeucluster sizeufull-backing-filenameubacking fileu	snapshotsuidunameutagu
vm-state-sizeuvmsizeu{}.{}udate-secu	date-nsecudateuvm-clock-secu
vm-clock-nsecuvmclockiN(RRtjsontloadsRtkeysR%tdatetimet
fromtimestamptfloatt	isoformattutcfromtimestampttimeR1(Rt	raw_infostdiskst
disk_infostdisktsnapshott
candidates((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_parse_qemu_img_infos*
 	�
?cC@stjt|��jd�jS(u~
    Return a uuid from the named vm

    CLI Example:

    .. code-block:: bash

        salt '*' virt.get_uuid <domain>
    uuuid(Rt
fromstringtget_xmltfindttext(tdom((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt	_get_uuidDs
cC@s5tjt|��jd�}|dk	r1|jSdS(u�
    Return `on_poweroff` setting from the named vm

    CLI Example:

    .. code-block:: bash

        salt '*' virt.get_on_restart <domain>
    uon_poweroffuN(RRLRMRNRRO(RPtnode((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_get_on_poweroffQs
cC@s5tjt|��jd�}|dk	r1|jSdS(u�
    Return `on_reboot` setting from the named vm

    CLI Example:

    .. code-block:: bash

        salt '*' virt.get_on_reboot <domain>
    u	on_rebootuN(RRLRMRNRRO(RPRR((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_get_on_reboot_s
cC@s5tjt|��jd�}|dk	r1|jSdS(u�
    Return `on_crash` setting from the named vm

    CLI Example:

    .. code-block:: bash

        salt '*' virt.get_on_crash <domain>
    uon_crashuN(RRLRMRNRRO(RPRR((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt
_get_on_crashms
c	C@s�i}tj|jd��}x�|jd�D]y}i}|jd�|d<x7|D]/}|jdkr|jd�|d<n|jdkr�|jd�|d<n|jdkr�|jd�|d<ntjd	|j�r!i}x*tj	|j
�D]\}}|||<q�W|||j<n|jd
krTi}|jd�|d<x*tj	|j
�D]\}}|||<q\W||d
<qTqTWd|kr�q.n|||d<q.W|S(uE
    Get domain network interfaces from a libvirt domain object.
    iudevices/interfaceutypeumacuaddressumodelutargetudevu(driver|source|address)uvirtualport(RRLtXMLDesctfindallRttagtretmatchRt	iteritemstattrib(	RPtnicstdoct
iface_nodetnictv_nodettemptkeytvalue((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt	_get_nics{s6
cC@s�idd6dd6dd6dd6dd6}tj|jd��}xD|jd�D]3}x*tj|j�D]\}}|||<qjWqQW|S(	u;
    Get domain graphics from a libvirt domain object.
    uNoneuautoportukeymapulistenuportutypeiudevices/graphics(RRLRVRWRR[R\(RPtoutR^tg_nodeRcRd((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt
_get_graphics�s

cC@si}tj|jd��}x�|jd�D]�}|jd�}|dkrUq.n|jd�}|dkrvq.nd|jkr.|jdd�}|s�|jdd�}n|r�d|jkr�d	|jkr�d
j|jd�|jd	��}n|s
q.ni|d6|jd�d6}|jd
�}|dk	r�|jd�dkr�ypt	j
ddddd|dgdtdt	j�j
�d}	tjjj|	�}
t|
�}|j|�Wq�tk
r�|jidd6�q�Xn|||jd�<q.q.W|S(u8
    Get domain disks from a libvirt domain object.
    iudevices/diskusourceutargetudevufileuuprotocolunameu{0}:{1}udeviceutypeudriveruqcow2uqemu-imguinfou--outputujsonu--backing-chaintshelltstdoutuDoes not existN(RRLRVRWRNRR\RR%t
subprocesstPopenRtPIPEtcommunicateRRtstringutilstto_strRKtupdatet	TypeError(RPRFR^telemtsourcettargettqemu_targetRHtdriverRjtqemu_outputtoutput((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt
_get_disks�sD%!
cC@s�d}d}yNtj|dtdtj�j�d}tjjj|�j	d�d}Wnt
k
rsd}nXyNtj|dtdtj�j�d}tjjj|�j	d�d}Wnt
k
r�d}nXi|d	6|d
6S(uL
    Returns the user and group that the disk images should be owned by
    u%grep ^\s*group /etc/libvirt/qemu.confu$grep ^\s*user /etc/libvirt/qemu.confRiRjiu"iurootuuserugroup(RkRlR/RmRnRRRoRptsplitt
IndexError(tg_cmdtu_cmdRjtgrouptuser((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_libvirt_creds�s"&

&

cC@sMtdd�}|r/tjjjdd�ntdd�}|rIdSdS(	uE
    Returns the command shared by the different migration types
    u
config.optionuvirt.tunneluSodiumum'virt.tunnel' has been deprecated in favor of 'virt:tunnel'. 'virt.tunnel' will stop being used in {version}.u
config.getuvirt:tunneluEvirsh migrate --p2p --tunnelled --live --persistent --undefinesource u3virsh migrate --live --persistent --undefinesource (RRRRR(ttunnel((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_get_migrate_command�s
cC@s,d}|r|d7}ndj||d�S(u8
    Compute libvirt URL for target migration host.
    uqemuu+sshu {0}://{1}/{2}usystem(R%(Rutsshtproto((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_get_targets
c		K@s�t|�d}i|d6|d6tj|�d6tj|�d6}
|d7kr]t|
d<n|d	krvd
|
d<n|r�d|kr�idd
6dd6|d<n5d|dkr�|dd
dkr�d|dd<n|jd
d�dkr�d8}q�n||
d<d|	krKg|
d<x9|	dj�D]}|
dj|�q-Wn
dg|
d<|dkr�tddkr�d|
d<g|
d<q�nd|	kr�|	d|
d<nd|
kr�|
ddkr�d|	kr�|	d|
d<q�d|
d<nd|
kr'd|	kr|	d|
d<q't	|
d<ng|
d<idd6d d6d!d"6dd#6}xt
|�D]�\}
}|j|d$d%�}i|jd&d'�d&6d(j|tj
|
�d)6|d$d*6|d+d
6tj|
�d,6}d-r�|d-r�|d-|d-<n|d9krt|d<t	|d/<n#|d:krBt	|d<t|d/<n|
dj|�q`W||
d1<||
d2<||
d3<d4}ytj|�}Wn(tjjk
r�tjd5|�d6SX|j|
�S(;u8
    Generate the XML string to define a libvirt VM
    iu
hypervisorunameucpuumemuqemuukvmucontroller_modeluvmwareulsilogiculistenuaddressutypeu0.0.0.0unoneugraphicsuboot_devuhduxenu	os_familyuSuseu"/usr/lib/grub2/x86_64-xen/grub.xenukerneluserial_typeutcputelnet_porti�Yuconsoleudisksuvduvirtiouxvdufdufdcuideumodelusdudeviceudisku{0}{1}u
target_devudisk_busuformatuindexusource_fileubhyveudriveruesxiunicsuos_typeuarchulibvirt_domain.jinjauCould not load template %su(uqemuukvmN(uqemuukvmubhyveuxen(uesxiuvmware(tintRt	text_typeRRRR{R1R&R/t	enumerateR%tstringtascii_lowercasetJINJAtget_templatetjinja2t
exceptionstTemplateNotFoundRterrortrender(R-tcputmemtdiskptnicpR)tos_typetarchtgraphicsR'tcontexttdevtdisk_bus_maptiRHtprefixtdisk_contexttfn_ttemplate((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_gen_xmls�


$






"






cC@s�t|�d}i|d6dj||�d6|d6|d6tj|�d6|d6}d	}ytj|�}Wn(tjjk
r�t	j
d
|�dSX|j|�S(uD
    Generate the XML string to define a libvirt storage volume
    iunameu{0}.{1}ufilenameuvolnameudisktypeusizeupoolulibvirt_volume.jinjauCould not load template %su(R�R%RR�R�R�R�R�R�RR�R�(tvmnametdisknametdisktypetsizetpoolR�R�R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_gen_vol_xmlrs
cC@szi|d6|d6|d6|d6|d6}d}ytj|�}Wn(tjjk
rltjd|�dSX|j|�S(	u=
    Generate the XML string to define a libvirt network
    unameubridgeuforwarduvportutagulibvirt_network.jinjauCould not load template %su(R�R�R�R�R�RR�R�(R-tbridgetforwardtvportRXR�R�R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_gen_net_xml�s
c	C@s!g|pgD]}|jd�^q
}i|d6|d6i|d6|d6d6i|pZgd6|d6|d	6g|D]:}i|d
d6t|�dkr�|dndd6^qsd
6|d6|	d6|
d6d6}
d}ytj|�}Wn(tjjk
rtj	d|�dSX|j
|
�S(uB
    Generate the XML string to define a libvirt storage pool
    u:unameuptypeupathupermissionsutargetudevicesudiruadapteriiuportuhostsuauthuformatusourceulibvirt_pool.jinjauCould not load template %suN(R{R5RR�R�R�R�R�RR�R�(R-tptypeRutpermissionstsource_devicest
source_dirtsource_adaptertsource_hoststsource_authtsource_namet
source_formatthostthostsR�R�R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt
_gen_pool_xml�s((
HcC@sStdd�}|r/tjjjdd�ntdd�}tjd|�|S(u
    Extract the images dir from the configuration. First attempts to
    find legacy virt.images, then tries virt:images.
    u
config.optionuvirt.imagesuSodiumum'virt.images' has been deprecated in favor of 'virt:images'. 'virt.images' will stop being used in {version}.u
config.getuvirt:imagesu6Image directory from config option `virt:images` is %s(RRRRRRtdebug(timg_dir((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_get_images_dir�s
	ubasecC@s|jdd�}|jdd�}|rN|rNtdj|d���n|d}tjd|�tjj|�}tjd|�tjj	|�s�tj
|�n|rJtjd|�td	||�}t}t
jjjd
�r1tddj|��}	t
jjj|	�}
|
d
dk}ny�|rs|rstjd|�tddj||�j��n)tjd||�t
jjj||�t
jjj�}|r�|r�tjd|�tddj||��ntjd�d|Ad@}tj||�Wqttfk
rF}
tdj||
���qXn�y�t
jjj�}|r�tjd|�tddj|jdd�||��ntdj|���tjd�d|Ad@}tj||�Wn1ttfk
r}
tdj||
���nX|S(uv
    Create the image file using specified disk_size or/and disk_image

    Return path to the created image file
    usizeuimageuRUnable to create new disk {0}, please specify disk size and/or disk image argumentufilenameusource_fileuImage destination will be %su!Image destination directory is %su#Create disk from specified image %su
cp.cache_fileuqemu-imgucmd.runuqemu-img info "{}"ufile formatuqcow2u*Cloning qcow2 image %s using copy on writeu4qemu-img create -f qcow2 -o backing_file="{0}" "{1}"uCopying %s to %suResize qcow2 image to %sMuqemu-img resize "{0}" {1}MuApply umask and remove exec biti�i�u&Problem while copying image. {0} - {1}u Create empty image with size %sMu!qemu-img create -f {0} "{1}" {2}Muformatu=Unable to create new disk {0}, please specify <size> argumentu'Problem while creating volume {0} - {1}N(RRRR%RR�tostpathtdirnametexiststmakedirsRRRRtwhichtyamlt	safe_loadRR{tfilestcopyfilet	get_umasktchmodtIOErrortOSError(RHtcreate_overlaytsaltenvt	disk_sizet
disk_imagetimg_destR�tsfntqcow2trest	imageinfotmasktmodeterr((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_qemu_image_create�sv


cK@s�iidd6d6g}|dkr]idd6dd6d	d
6dj|rM|nd�d
6}nZ|dkr�idd6d	d
6dd6}n0|dkr�idd6d	d
6dd6}ni}g}	|rqtjtddi�j||��}	g|	D]1}
|
j�D]\}}t|d|�^qq�}	|rqtjd||	dd|	djdd��||	dd<qqn|r�xt|D]i}
d|
kr~g|	D] }
|
d|
dkr�|
^q�}|r�|dj	|
�q�|	j
|
�q~q~Wnx�|	D]�}
x6tj|�D]%\}}||
kr||
|<qqWd|
krg|
drgt
jj|
d�|
d<q�d|
kr�t||
||�q�q�W|	S(u�
    Gather the disk profile from the config or apply the default based
    on the active hypervisor

    This is the ``default`` profile for KVM/QEMU, which can be
    overridden in the configuration:

    .. code-block:: yaml

        virt:
          disk:
            default:
              - system:
                  size: 8192
                  format: qcow2
                  model: virtio

    Example profile for KVM/QEMU with two disks, first is created
    from specified image, the second is empty:

    .. code-block:: yaml

        virt:
          disk:
            two_disks:
              - system:
                  size: 8192
                  format: qcow2
                  model: virtio
                  image: http://path/to/image.qcow2
              - lvm:
                  size: 32768
                  format: qcow2
                  model: virtio

    The ``format`` and ``model`` parameters are optional, and will
    default to whatever is best suitable for the active hypervisor.
    i usizeusystemuvmwareuvmdkuformatuscsiumodeludiskudeviceu[{0}] u0upooluqemuukvmuqcow2uvirtiouxenu
config.getu	virt:diskR-uG%s image from module arguments will be used for disk "%s" instead of %siunameuimageuusource_fileufilename(uqemuukvm(R%tcopytdeepcopyRRtitemstdictRR�RqR1RR[R�R�tbasenamet_fill_disk_filename(tprofileR)RFtvm_nametimageR�R'tdefaulttoverlaytdisklistRHR-tdtudisktfoundRctval((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt
_disk_profile:sR'
"



">	%
-
cK@s	|jdd�}|dkr�|s0t�}q�|jd�s�t||�}||krd||nd}|s�|ds�|djd�r�tdj|d	|���n|d}q�n|rd
j||d	|d�|d<tjj	||d�|d
<ndS(uE
    Compute the disk file name and update it in the disk value.
    upooluqemuukvmuxenu/utarget_pathu/devuRUnable to create new disk {0}, specified pool {1} does not exist or is unsupportedunameu{0}_{1}.{2}uformatufilenameusource_fileN(uqemuukvmuxen(
RRR�t
startswitht	pool_infoRR%R�R�tjoin(R�RHR)R'tbase_dirtinfosR�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyR��s%!c
@s�idd6dd6dd6}idd6dd6dd6}idd6dd6dd6}i|d	6|d
6|d6|d6�d
�}��fd�}�fd�}xY|D]Q}	||	�|	jdd�dkr�||	��n��kr�||	�q�q�W|S(u7
    Complete missing data for network interfaces.
    ubridgeutypeuDEFAULTusourceue1000umodelubr0uvirtiouxenukvmuqemuuvmwarecS@ssx@ddgD]2}||kr
||d<|j|�|d<q
q
W|jdd�|d<|jdd�|d<dS(u�
        Guess which style of definition:

            bridge: br0

             or

            network: net0

             or

            type: network
            source: net0
        ubridgeunetworkutypeusourceN(tpopRR(t
attributesttype_((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_normalize_net_types�s
c@sLxEtj���D]0\}}||ks7||r|||<qqWdS(u9
        Apply the default overlay to attributes
        N(RR[(R�RcRd(R)toverlays(s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_apply_default_overlay�s c@s��dk	r_tjd��tjjjj��rA�|d<q�dj��}t	|��nA|d	kr�tjj
jdd�|d<ntjj
j�|d<dS(
uE
        Compute mac address for NIC depending on hypervisor
        uDefault MAC address is %sumacuMalformed MAC address: {0}uqemuukvmR�u52:54:00N(uqemuukvm(RRR�RRtvalidatetnettmacR%Rtnetworktgen_mac(R�R)tmsg(tdmac(s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_assign_mac�s
umacN(RR(
t
interfacesR)R�tvmware_overlaytkvm_overlaytxen_overlayR�R�R�t	interface((R�R)R�s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_complete_nics�s$
	

c@siid6g}tddi�j|d�}|dk	rTtjjjdd�ntddi�j||�}g��fd�}t|t�r�||�nat|t	�rxO|D]D}t|t�r�t
|�d	kr�||�q��j|�q�q�Wnt�|d
|�S(u+
    Compute NIC data based on profile
    ueth0u
config.optionuvirt.nicuSodiumud'virt.nic' has been deprecated in favor of 'virt:nic'. 'virt.nic' will stop being used in {version}.u
config.getuvirt:nicc@s;x4tj|�D]#\}}||d<�j|�qWdS(uC
        Append dictionary profile data to interfaces list
        unameN(RR[R1(tprofile_dicttinterface_nameR�(R�(s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt%append_dict_profile_to_interface_lists
iR�N(
RRRRRRRt
isinstanceR�R.R5R1R(tprofile_nameR)R�R�tconfig_dataRR�((R�s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_nic_profiles(



c	C@s�|rt||d|�ng}tjd|�|r�t||�}xb|D]Z}g|D] }|d|dkrZ|^qZ}|r�|dj|�qM|j|�qMWtjd|�n|S(uT
    Get network devices from the profile and merge uer defined ones with them.
    R�uNIC profile is %sunameiuMerged NICs: %s(RRR�RRqR1(	R)R�R�R�R�t
users_nicstunicR`R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_get_merged_nicsLs!
-udefaultu
seed.applyc&K@s�t|�}td�|dD��}td�|dD��}|r�tdd|�}|tk	rtjjjdd�nWtd�g|dD]}|d	d
j�^q�D��}d|kr�dn|d}n|d
kr�dn|}t	j
d|�|jdt�}|r2tjjjdd�nt|||d|�}|jdt�}|r{tjjjdd�n|r�tjjjdd�nt
|||	|d|d||�}x�|D]�}t	j
d||�|dkrJd|krtd��nBt	j
d|�t||d|d|d|d�} t| �n|ddd gkrG|}!|!r�tjjjdd!�n|jd"t�}!|d#r�tjj|d#�r�|d#}"nt||!|
�}"nt}"|o�|"o�|jdt�rDt	j
d$|�t||"d%|d&|jd'�d(|d)|
d*|�nntd+j|���q�Wt	j
d,�|r�tjjjdd-�id.d/6}n|tkr�d0|kr�d0n|d}n|tkr�d1|kr�d1n|d}nt||||||||||�	}#t|�}$y|$j|#�WnQtk
r�}%d2j|�tj|%�krst	j|%�n|$j�|%�nX|r�t	j
d3|�t|$|�j �n|$j�t!S(4u�$
    Initialize a new vm

    :param name: name of the virtual machine to create
    :param cpu: Number of virtual CPUs to assign to the virtual machine
    :param mem: Amount of memory to allocate to the virtual machine in MiB.
    :param image: Path to a disk image to use as the first disk (Default: ``None``).
                  Deprecated in favor of the ``disks`` parameter. To set (or change) the image of a
                  disk, add the following to the disks definitions:

                  .. code-block:: python

                      {
                          'name': 'name_of_disk_to_change',
                          'image': '/path/to/the/image'
                      }

    :param nic: NIC profile to use (Default: ``'default'``).
                The profile interfaces can be customized / extended with the interfaces parameter.
                If set to ``None``, no profile will be used.
    :param interfaces:
        List of dictionaries providing details on the network interfaces to create.
        These data are merged with the ones from the nic profile. The structure of
        each dictionary is documented in :ref:`init-nic-def`.

        .. versionadded:: 2019.2.0
    :param hypervisor: the virtual machine type. By default the value will be computed according
                       to the virtual host capabilities.
    :param start: ``True`` to start the virtual machine after having defined it (Default: ``True``)
    :param disk: Disk profile to use (Default: ``'default'``). If set to ``None``, no profile will be used.
    :param disks: List of dictionaries providing details on the disk devices to create.
                  These data are merged with the ones from the disk profile. The structure of
                  each dictionary is documented in :ref:`init-disk-def`.

                  .. versionadded:: 2019.2.0
    :param saltenv: Fileserver environment (Default: ``'base'``).
                    See :mod:`cp module for more details <salt.modules.cp>`
    :param seed: ``True`` to seed the disk image. Only used when the ``image`` parameter is provided.
                 (Default: ``True``)
    :param install: install salt minion if absent (Default: ``True``)
    :param pub_key: public key to seed with (Default: ``None``)
    :param priv_key: public key to seed with (Default: ``None``)
    :param seed_cmd: Salt command to execute to seed the image. (Default: ``'seed.apply'``)
    :param enable_vnc:
        ``True`` to setup a vnc display for the VM (Default: ``False``)

        Deprecated in favor of the ``graphics`` parameter. Could be replaced with
        the following:

        .. code-block:: python

            graphics={'type': 'vnc'}

        .. deprecated:: 2019.2.0
    :param graphics:
        Dictionary providing details on the graphics device to create. (Default: ``None``)
        See :ref:`init-graphics-def` for more details on the possible values.

        .. versionadded:: 2019.2.0
    :param 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``.

        .. versionadded:: 2019.2.0
    :param arch:
        architecture of the virtual machine. The default value is taken from the host capabilities,
        but ``x86_64`` is prefed over ``i686``.

        .. versionadded:: 2019.2.0
    :param enable_qcow:
        ``True`` to create a QCOW2 overlay image, rather than copying the image
        (Default: ``False``).

        Deprecated in favor of ``disks`` parameter. Add the following to the disks
        definitions to create an overlay image of a template disk image with an
        image set:

        .. code-block:: python

            {
                'name': 'name_of_disk_to_change',
                'overlay_image': True
            }

        .. deprecated:: 2019.2.0
    :param pool:
        Path of the folder where the image files are located for vmware/esx hypervisors.

        Deprecated in favor of ``disks`` parameter. Add the following to the disks
        definitions to set the vmware datastore of a disk image:

        .. code-block:: python

            {
                'name': 'name_of_disk_to_change',
                'pool': 'mydatastore'
            }

        .. deprecated:: Flurorine
    :param dmac:
        Default MAC address to use for the network interfaces. By default MAC addresses are
        automatically generated.

        Deprecated in favor of ``interfaces`` parameter. Add the following to the interfaces
        definitions to force the mac address of a NIC:

        .. code-block:: python

            {
                'name': 'name_of_nic_to_change',
                'mac': 'MY:MA:CC:ADD:RE:SS'
            }

        .. deprecated:: 2019.2.0
    :param config: minion configuration to use when seeding.
                   See :mod:`seed module for more details <salt.modules.seed>`
    :param boot_dev: String of space-separated devices to boot from (Default: ``'hd'``)
    :param serial_type: Serial device type. One of ``'pty'``, ``'tcp'`` (Default: ``None``)
    :param telnet_port: Telnet port to use for serial device of type ``tcp``.
    :param console: ``True`` to add a console device along with serial one (Default: ``True``)
    :param connection: libvirt connection URI, overriding defaults

                       .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

                     .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

                     .. versionadded:: 2019.2.0

    .. _init-nic-def:

    .. rubric:: Network Interfaces Definitions

    Network interfaces dictionaries can contain the following properties:

    name
        Name of the network interface. This is only used as a key to merge with the profile data

    type
        Network type. One of ``'bridge'``, ``'network'``

    source
        The network source, typically the bridge or network name

    mac
        The desired mac address, computed if ``None`` (Default: ``None``).

    model
        The network card model (Default: depends on the hypervisor)

    .. _init-disk-def:

    .. rubric:: Disks Definitions

    Disk dictionaries can contain the following properties:

    name
        Name of the disk. This is mostly used in the name of the disk image and as a key to merge
        with the profile data.

    format
        Format of the disk image, like ``'qcow2'``, ``'raw'``, ``'vmdk'``.
        (Default: depends on the hypervisor)

    size
        Disk size in MiB

    pool
        Path to the folder or name of the pool where disks should be created.
        (Default: depends on hypervisor)

    model
        One of the disk busses allowed by libvirt (Default: depends on hypervisor)

        See the libvirt `disk element`_ documentation for the allowed bus types.

    image
        Path to the image to use for the disk. If no image is provided, an empty disk will be created
        (Default: ``None``)

    overlay_image
        ``True`` to create a QCOW2 disk image with ``image`` as backing file. If ``False``
        the file pointed to by the ``image`` property will simply be copied. (Default: ``False``)

    source_file
        Absolute path to the disk image to use. Not to be confused with ``image`` parameter. This
        parameter is useful to use disk images that are created outside of this module. Can also
        be ``None`` for devices that have no associated image like cdroms.

    device
        Type of device of the disk. Can be one of 'disk', 'cdrom', 'floppy' or 'lun'.
        (Default: ``'disk'``)

    .. _init-graphics-def:

    .. rubric:: Graphics Definition

    The graphics dictionnary can have the following properties:

    type
        Graphics type. The possible values are ``none``, ``'spice'``, ``'vnc'`` and other values
        allowed as a libvirt graphics type (Default: ``None``)

        See the libvirt `graphics element`_ documentation for more details on the possible types.

    port
        Port to export the graphics on for ``vnc``, ``spice`` and ``rdp`` types.

    tls_port
        Port to export the graphics over a secured connection for ``spice`` type.

    listen
        Dictionary defining on what address to listen on for ``vnc``, ``spice`` and ``rdp``.
        It has a ``type`` property with ``address`` and ``None`` as possible values, and an
        ``address`` property holding the IP or hostname to listen on.

        By default, not setting the ``listen`` part of the dictionary will default to
        listen on all addresses.

    .. rubric:: CLI Example

    .. code-block:: bash

        salt 'hypervisor' virt.init vm_name 4 512 salt://path/to/image.raw
        salt 'hypervisor' virt.init vm_name 4 512 /var/lib/libvirt/images/img.raw
        salt 'hypervisor' virt.init vm_name 4 512 nic=profile disk=profile

    The disk images will be created in an image folder within the directory
    defined by the ``virt:images`` option. Its default value is
    ``/srv/salt-images/`` but this can changed with such a configuration:

    .. code-block:: yaml

        virt:
            images: /data/my/vm/images/

    .. _disk element: https://libvirt.org/formatdomain.html#elementsDisks
    .. _graphics element: https://libvirt.org/formatdomain.html#elementsGraphics
    cS@sh|]}|d�qS(uos_type((t.0tguest((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pys	<setcomp>es	uguestscS@sh|]}|dd�qS(uarchuname((RR((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pys	<setcomp>fs	u
config.getulibvirt:hypervisoruSodiumu�'libvirt:hypervisor' configuration property has been deprecated. Rather use the 'virt:connection:uri' to properly define the libvirt URI or alias of the host to connect to. 'libvirt:hypervisor' will stop being used in {version}.cS@s#h|]}|D]}|�qqS(((Rtytx((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pys	<setcomp>ts	uarchudomainsukvmiuesxiuvmwareuUsing hypervisor %sudmacu�'dmac' parameter has been deprecated. Rather use the 'interfaces' parameter to properly define the desired MAC address. 'dmac' will be removed in {version}.R�upoolu�'pool' parameter has been deprecated. Rather use the 'disks' parameter to properly define the vmware datastore of disks. 'pool' will be removed in {version}.u�'image' parameter has been deprecated. Rather use the 'disks' parameter to override or define the image. 'image' will be removed in {version}.R�R�uCreating disk for VM [ %s ]: %suimageuMvirt.init does not support image template in conjunction with esxi hypervisoruGenerating libvirt XML for %sunameuformatusizeuqemuuxenu�'enable_qcow' parameter has been deprecated. Rather use the 'disks' parameter to override or define the image. 'enable_qcow' will be removed in {version}.u
overlay_imageusource_fileuSeed command is %sR:tconfiguconfigtinstalltpub_keytpriv_keyu4Unsupported hypervisor when handling disk image: {0}uGenerating VM XMLu�'enable_vnc' parameter has been deprecated in favor of 'graphics'. Use graphics={'type': 'vnc'} for the same behavior. 'enable_vnc' will be removed in {version}. uvncutypeuhvmux86_64udomain '{}' already existsuStarting VM %s("tcapabilitiestsortedRRRRRRR>RR�RR
R�RR�tdefine_vol_xml_strRR�R�R�R�R%R�R,t	defineXMLRRR�twarningtcloseR;tcreateR/(&R-R�R�R�R`R�R)tstartRHRFR�tseedRRRtseed_cmdt
enable_vnctenable_qcowR�R�R�R'tcapstos_typestarchesRthypervisorsR�R�R�R�t_disktvol_xmlR�R�tvm_xmlR+R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytinit^s��
;


$







'


cC@s|jd�}|jd�}|jd�dk	rKtj|jd��nd}|jd�dk	r~tj|jd��nd}||ko|dk	o|dk	o|jd�|jd�ko|jdd�|jdd�ko|jd�|jd�kS(uM
    Test if two disk elements should be considered like the same device
    utargetusourceubusudeviceudiskudevN(RNRRttostringR(tdisk1tdisk2ttarget1ttarget2tsource1tsource2((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_disks_equals33$cC@sd�}||�||�kS(uR
    Test if two interface elements should be considered like the same device
    cS@s�i|jdd6|jd�dk	rC|jd�j|jdndd6|jd�dk	r{|jd�jdj�ndd6|jd�dk	r�|jd�jdndd6S(uC
        Filter out elements to ignore when comparing nics
        utypeusourceumacuaddressumodelN(R\RNRtlower(R`((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_filter_nics
98((tnic1tnic2R0((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_nics_equals	
cC@s1d�}tj||��tj||��kS(uK
    Test if two graphics devices should be considered the same device
    cS@s�tj|�}idd6dd6ddgd6idd6dd6d	gd6id
d6dd6d	gd6g}xx|D]p}|j|d�}|d}|dk	rp||jks�|j||dkrp|j||dd�qpqpW|S(
u�
        When the domain is running, the graphics element may contain additional properties
        with the default values. This function will strip down the default values.
        u.unodeuportuattribu5900u-1uvaluesuaddressu	127.0.0.1ulisteniN(R�R�RNRR\tset(tgfxtgfx_copytdefaultsR�RRR\((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_filter_graphics's!

2(RR'(tgfx1tgfx2R8((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_graphics_equal#s	c	C@s�d�}igd6gd6gd6gd6}tj|�}x�|D]�}g|D]'}|||�||��rN|^qN}|r�|j|d�|dj|d�|dj|d�qA|dj|�|dj|�qAW||d<|S(u,
    Compare lists to extract the changes

    :param old: old list
    :param new: new list
    :return: a dictionary with ``unchanged``, ``new``, ``deleted`` and ``sorted`` keys

    The sorted list is the union of unchanged and new lists, but keeping the original
    order from the new list.
    cS@s<tj|�}d|_x|j�D]}d|_q%W|S(uM
        Remove the XML indentation to compare XML trees more easily
        N(R�R�RROtiterttail(RRt	node_copytitem((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_remove_indentGs
	
u	unchangedunewudeletedusortedi(R�R�tremoveR1(	toldtnewt
comparatorR@tdifftold_devicestnew_itemR?R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_diff_lists<s	
"
4
cC@sg}ddddddg}x�|D]�}|jd�}|jd�}g|D]}|j|�rP|^qPd	}gtt|��D]>}	d
j|tj|	�|kr�d
j|tj|	�^q�d	}
|jd|
�|j	|
�q%Wt
||t�S(u�
    Compare disk definitions to extract the changes and fix target devices

    :param old: list of ElementTree nodes representing the old disks
    :param new: list of ElementTree nodes representing the new disks
    ufduhduvdusduxvduubdutargetudeviu{0}{1}(RNRR�RR5R%R�R�R4R1RHR.(RBRCttargetstprefixesRHttarget_nodeRuR?R�R�t
new_target((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_diff_disk_listsas

,BcC@s�t||t�}g|dD]}|jd�jd�^q}xF|dD]:}|jd�}|jd�|krL|j|�qLqLW|S(u�
    Compare network interface definitions to extract the changes

    :param old: list of ElementTree nodes representing the old interfaces
    :param new: list of ElementTree nodes representing the new interfaces
    u	unchangedumacuaddressunew(RHR3RNRRA(RBRCRER`tmacsR�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_diff_interface_listsys/cC@st||t�S(u�
    Compare graphic devices definitions to extract the changes

    :param old: list of ElementTree nodes representing the old graphic devices
    :param new: list of ElementTree nodes representing the new graphic devices
    (RHR;(RBRC((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_diff_graphics_lists�sc	(K@s"itd6igd6gd6d6igd6gd6d6}
t|	�}t||�}tj|jd��}
t}|
jd�}t|||||	�}tjt||||t	|||�||j
�|
jd�jd	�||	�	�}|
jd
�}|rIt|j
�|krItj|�|_
|jdtj|��t}nxmdd
gD]_}|
j|�}|rVt|j
�|dkrVtj|�|_
|jdd�t}qVqVW|
jd�}iddgd6ddgd6dgd6}i}x�|D]�}i||<t�}g||D]$}|j|d'�d'k	r#|^q#r�|j|�}|jdj|��}t�dj|�||�||<||ds�||dr�x|D]}|j|�q�W|j||d�t}q�q�q�W|r|drzxqt|dd�D]X\}}||d}||ddkr|rtjj|�rt||�qqWny3|jtj j!j"tj#|
���t|
d<Wn&t$j%k
r�} |j&�| �nXg}!|j'�r0|r0|r"|!j(idd6dd 6|t$j)gd!6�n|rZ|!j(id"d6d#d 6|dt$j)gd!6�nx�ddgD]�}x[||jdg�D]C}"|!j(i|d6d$d 6tj j!j"tj#|"��gd!6�q�Wx[||jdg�D]C}#|!j(i|d6d%d 6tj j!j"tj#|#��gd!6�q�WqgWnx�|!D]�}$y�t*||$d �|$d!�}%|$d}&|&d(kr�t+|%�|
|&<n9idd$6dd%6}'|
|&|'|$d j(|$d!d�Wq7t$j%k
r} d&|
kr�g|
d&<n|
d&j(tj| ��q7Xq7Wn|j&�|
S()up	
    Update the definition of an existing domain.

    :param name: Name of the domain to update
    :param cpu: Number of virtual CPUs to assign to the virtual machine
    :param mem: Amount of memory to allocate to the virtual machine in MiB.
    :param disk_profile: disk profile to use
    :param disks:
        Disk definitions as documented in the :func:`init` function.
        If neither the profile nor this parameter are defined, the disk devices
        will not be changed. However to clear disks set this parameter to empty list.

    :param nic_profile: network interfaces profile to use
    :param interfaces:
        Network interface definitions as documented in the :func:`init` function.
        If neither the profile nor this parameter are defined, the interface devices
        will not be changed. However to clear network interfaces set this parameter
        to empty list.

    :param graphics:
        The new graphics definition as defined in :ref:`init-graphics-def`. If not set,
        the graphics will not be changed. To remove a graphics device, set this parameter
        to ``{'type': 'none'}``.

    :param live:
        ``False`` to avoid trying to live update the definition. In such a case, the
        new definition is applied at the next start of the virtual machine. If ``True``,
        not all aspects of the definition can be live updated, but as much as possible
        will be attempted. (Default: ``True``)

    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    :return:

        Returns a dictionary indicating the status of what has been done. It is structured in
        the following way:

        .. code-block:: python

            {
              'definition': True,
              'cpu': True,
              'mem': True,
              'disks': {'attached': [list of actually attached disks],
                        'detached': [list of actually detached disks]},
              'nics': {'attached': [list of actually attached nics],
                       'detached': [list of actually detached nics]},
              'errors': ['error messages for failures']
            }

    .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.update domain cpu=2 mem=1024

    u
definitionuattachedudetachedudisku	interfaceiutypeu
.//os/typeuarchuvcpuucurrentumemoryu
currentMemoryiuunituMiBudevicesudisksudisk_profileu
interfacesunic_profileugraphicsudevices/{0}u_diff_{0}_listsudeletedunewusortedusource_fileucpuudeviceu
setVcpusFlagsucmduargsumemusetMemoryFlagsuattachDeviceudetachDeviceuerrorsN(ucpuumem(,RR,R;RRLRVRR�R�R
tOSTypeRNR�RORR�R4R/tlocalsRRWR%tglobalsRAtextendR�R�R�tisfileR�RRRRoRpR'R
RRtisActiveR1tVIR_DOMAIN_AFFECT_LIVEtgetattrtbool((R-R�R�tdisk_profileRFtnic_profileR�R�tliveR'tstatusR+tdomaintdesctneed_updateR)t	all_diskstnew_desctcpu_nodet
mem_node_nametmem_nodetdevices_nodet
parameterstchangestdev_typetfunc_localstparamRBRCR?tidxtsource_fileR�tcommandstaddedtremovedtcmdR7tdevice_typetactions((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyRq�s�G		




	5#

!-%

*1

)
%
cK@sPg}t|�}x-t|dt�D]}|j|j��q%W|j�|S(u�
    Return a list of available domains.

    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.list_domains
    titerable(R,R;R/R1R-R(R'R6R+RP((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytlist_domainsSs
cK@sVg}t|�}x3t|dtdt�D]}|j|j��q+W|j�|S(u�
    Return a list of names for active virtual machine on the minion

    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.list_active_vms
    Rttinactive(R,R;R/RR1R-R(R'R6R+RP((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytlist_active_vmsos
cK@sVg}t|�}x3t|dtdt�D]}|j|j��q+W|j�|S(u�
    Return a list of names for inactive virtual machine on the minion

    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.list_inactive_vms
    Rttactive(R,R;R/RR1R-R(R'R6R+RP((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytlist_inactive_vms�s
cK@s~d�}i}t|�}|r=|t||��||<n3x0t|dt�D]}||�||j�<qPW|j�|S(u�
    Return detailed information about the vms on this hyper in a
    list of dicts:

    :param vm_: name of the domain
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    .. code-block:: python

        [
            '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:

    .. code-block:: bash

        salt '*' virt.vm_info
    cS@s�|j�}i|dd6t|d�d6t|�d6t|�d6t|�d6t|�d6t|�d	6t|�d
6t|�d6t|d�d
6t|d�d6t	j
|dd�d6S(u/
        Compute the infos of a domain
        iucpuiucputimeudisksugraphicsunicsuuuiduon_crashu	on_rebootuon_poweroffiumaxMemiumemiuunknownustate(RR�RzRhReRQRURTRStVIRT_STATE_NAME_MAPR(RPtraw((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_info�s






Rt(R,R;R/R-R(tvm_R'R|RR+R^((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytvm_info�s&	
cK@s~d�}i}t|�}|r=|t||��||<n3x0t|dt�D]}||�||j�<qPW|j�|S(uf
    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.

    :param vm_: name of the domain
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.vm_state <domain>
    cS@s,d}|j�}tj|dd�}|S(u&
        Compute domain state
        uiuunknown(RRzR(RPtstateR{((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyR|sRt(R,R;R/R-R(R}R'R|RR+R^((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytvm_state�s	
cC@sw|j�}i|dd6|dd6tj|d�d6|dd6|d	d
6|dd6|d
d6|dd6}|S(uP
    Internal variant of node_info taking a libvirt connection as parameter
    iucpucoresiucpumhziucpumodeliucpusiu
cputhreadsiu	numanodesiu	phymemoryiusockets(tgetInfoRR�(R+R{R((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt
_node_infoscK@s&t|�}t|�}|j�|S(u�
    Return a dict with information about this node

    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.node_info
    (R,R�R(R'R+R((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt	node_info$s
cK@s/t|�}tt||��}|j�|S(u�
    Return info about the network interfaces of a named vm

    :param vm_: name of the domain
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.get_nics <domain>
    (R,ReR;R(R}R'R+R]((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytget_nics>s
cK@sAtjt||��}g|jd�D]}|jd�^q(S(u�
    Return a list off MAC addresses from the named vm

    :param vm_: name of the domain
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.get_macs <domain>
    udevices/interface/macuaddress(RRLRMRWR(R}R'R^RR((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytget_macsYscK@s/t|�}tt||��}|j�|S(u�
    Returns the information on vnc for a given vm

    :param vm_: name of the domain
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.get_graphics <domain>
    (R,RhR;R(R}R'R+R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytget_graphicsrs
cK@s/t|�}tt||��}|j�|S(u�
    Return the disks of a named vm

    :param vm_: name of the domain
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.get_disks <domain>
    (R,RzR;R(R}R'R+RF((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt	get_disks�s
c	K@s�t|�}t||�}tj|j�dd�dkrAtStj}|r`|tjB}n|j	|d|�}|j	|dtj
�}|j�||ko�dkSS(u�
    Changes the amount of memory allocated to VM. The VM must be shutdown
    for this to work.

    :param vm_: name of the domain
    :param memory: memory amount to set in MB
    :param config: if True then libvirt will be asked to modify the config as well
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.setmem <domain> <size>
        salt '*' virt.setmem my_domain 768
    iuunknownushutdowni(R,R;RzRRRR
tVIR_DOMAIN_MEM_MAXIMUMtVIR_DOMAIN_AFFECT_CONFIGtsetMemoryFlagstVIR_DOMAIN_AFFECT_CURRENTR(	R}tmemoryRR'R+RPtflagstret1tret2((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytsetmem�s"	
c	K@s�t|�}t||�}tj|j�dd�dkrAtStj}|r`|tjB}n|j	||�}|j	|tj
�}|j�||ko�dkSS(u*
    Changes the amount of vcpus allocated to VM. The VM must be shutdown
    for this to work.

    If config is True then we ask libvirt to modify the config as well

    :param vm_: name of the domain
    :param vcpus: integer representing the number of CPUs to be assigned
    :param config: if True then libvirt will be asked to modify the config as well
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.setvcpus <domain> <amount>
        salt '*' virt.setvcpus my_domain 4
    iuunknownushutdown(R,R;RzRRRR
tVIR_DOMAIN_VCPU_MAXIMUMR�t
setVcpusFlagsR�R(	R}tvcpusRR'R+RPR�R�R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytsetvcpus�s"	
cC@sh|j�d}|d8}xGt|dt�D]3}|j�dkr-||j�dd8}q-q-W|S(uN
    Internal variant of freemem taking a libvirt connection as parameter
    iiRtiii(R�R;R/tIDR(R+R�RP((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_freemem	s
cK@s&t|�}t|�}|j�|S(u�
    Return an int representing the amount of memory (in MB) that has not
    been given to virtual machines on this node

    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.freemem
    (R,R�R(R'R+R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytfreemem	s
cC@sZ|j�d}xCt|dt�D]/}|j�dkr#||j�d8}q#q#W|S(uN
    Internal variant of freecpu taking a libvirt connection as parameter
    iRtii(R�R;R/R�R(R+tcpusRP((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_freecpu-	s
cK@s&t|�}t|�}|j�|S(u�
    Return an int representing the number of unallocated cpus on this
    hypervisor

    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.freecpu
    (R,R�R(R'R+R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytfreecpu8	s
cK@sQt|�}it|�d6t|�d6t|�d6t�d6}|j�|S(u�
    Return the node_info, vm_info and freemem

    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.full_info
    ufreecpuufreememu	node_infouvm_info(R,R�R�R�R~R(R'R+R((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt	full_infoS	s



cK@s2t|�}t||�jd�}|j�|S(u�
    Returns the XML for a given vm

    :param vm_: domain name
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.get_xml <domain>
    i(R,R;RVR(R}R'R+txml_desc((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyRMp	s
cK@s_i}t|�}td�g|dD]}|ddj�^q&D��}d|kr_dn|d}|s�tdd�}|dk	r�tjjjd	d
�q�|}ntddi�}x�dd
gD]�}t	t
jtdj
|��}	i|	d|�d6||<||kr�|j|i�x,||D]}
|	|
|�|||
<q3Wq�q�W|S(ub
    Return the virt profiles for hypervisor.

    Currently there are profiles for:

    - nic
    - disk

    :param hypervisor: override the default machine type.
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.get_profiles
        salt '*' virt.get_profiles hypervisor=esxi
    cS@s#h|]}|D]}|�qqS(((RR
R((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pys	<setcomp>�	s	uguestsuarchudomainsukvmiu
config.getulibvirt:hypervisoruSodiumu�'libvirt:hypervisor' configuration property has been deprecated. Rather use the 'virt:connection:uri' to properly define the libvirt URI or alias of the host to connect to. 'libvirt:hypervisor' will stop being used in {version}.uvirtudiskunicu_{0}_profileudefaultN(RRR>RRRRRRRXtsystmodulest__name__R%t
setdefault(R)R'R7RRR"tdefault_hypervisortvirtconfttypt_functprf((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytget_profiles�	s(;
	"cK@s;t|�}t||�}|j�dk}|j�|S(u�
    Send a soft shutdown signal to the named vm

    :param vm_: domain name
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.shutdown <domain>
    i(R,R;tshutdownR(R}R'R+RPR7((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyR��	s

cK@s;t|�}t||�}|j�dk}|j�|S(u�
    Pause the named vm

    :param vm_: domain name
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.pause <domain>
    i(R,R;tsuspendR(R}R'R+RPR7((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytpause�	s

cK@s;t|�}t||�}|j�dk}|j�|S(u�
    Resume the named vm

    :param vm_: domain name
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.resume <domain>
    i(R,R;tresumeR(R}R'R+RPR7((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyR��	s

cK@s5t|�}t||�j�dk}|j�|S(u�
    Start a defined domain

    :param vm_: domain name
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.start <domain>
    i(R,R;RR(R-R'R+R7((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyR
s
cK@s5t|�}t||�j�dk}|j�|S(u�
    Hard power down the virtual machine, this is equivalent to pulling the power.

    :param vm_: domain name
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.stop <domain>
    i(R,R;tdestroyR(R-R'R+R7((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytstop4
s
cK@s;t|�}t||�jtj�dk}|j�|S(u�
    Reboot a domain via ACPI request

    :param vm_: domain name
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.reboot <domain>
    i(R,R;trebootR
tVIR_DOMAIN_REBOOT_DEFAULTR(R-R'R+R7((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyR�O
s!
cK@s>t|�}t||�}|jd�dk}|j�|S(u�
    Reset a VM by emulating the reset button on a physical machine

    :param vm_: domain name
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.reset <domain>
    i(R,R;tresetR(R}R'R+RPR7((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyR�j
s

cK@sSt|�}t||�}|jdddddgdd�dk}|j�|S(u�
    Sends CTRL+ALT+DEL to a VM

    :param vm_: domain name
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.ctrl_alt_del <domain>
    iii8ioi(R,R;tsendKeyR(R}R'R+RPR7((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytctrl_alt_del�
s
*
cK@s2t|�}|j|d�dk	}|j�|S(u
    Start a domain based on the XML passed to the function

    :param xml: libvirt XML definition of the domain
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.create_xml_str <XML in string format>
    iN(R,t	createXMLRR(txmlR'R+R7((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytcreate_xml_str�
s
cK@sfyGtjjj|d��)}ttjjj|j��|�SWdQXWntt	fk
rat
SXdS(uF
    Start a domain based on the XML-file path passed to the function

    :param path: path to a file containing the libvirt XML definition of the domain
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.create_xml_path <path to XML file on the node>
    urN(RRR�tfopenR�Rot
to_unicodetreadR�R�R(R�R'tfp_((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytcreate_xml_path�
scK@s/t|�}|j|�dk	}|j�|S(u
    Define a domain based on the XML passed to the function

    :param xml: libvirt XML definition of the domain
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.define_xml_str <XML in string format>
    N(R,RRR(R�R'R+R7((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytdefine_xml_str�
s
cK@sfyGtjjj|d��)}ttjjj|j��|�SWdQXWntt	fk
rat
SXdS(uH
    Define a domain based on the XML-file path passed to the function

    :param path: path to a file containing the libvirt XML definition of the domain
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.define_xml_path <path to XML file on the node>

    urN(RRR�R�R�RoR�R�R�R�R(R�R'R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytdefine_xml_path�
scK@s�tddd�}|dk	r8tjjjdd�ntddd�}t|�}|jtj	|��}|j
|d�dk	}|j�|S(	u�
    Define a volume based on the XML passed to the function

    :param xml: libvirt XML definition of the storage volume
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.define_vol_xml_str <XML in string format>

    The storage pool where the disk image will be defined is ``default``
    unless changed with a configuration like this:

    .. code-block:: yaml

        virt:
            storagepool: mine
    u
config.getulibvirt:storagepooluSodiumu�'libvirt:storagepool' has been deprecated in favor of 'virt:storagepool'. 'libvirt:storagepool' will stop being used in {version}.uvirt:storagepooludefaultiN(RRRRRRR,tstoragePoolLookupByNameRR�R�R(R�R'tpoolnameR+R�R7((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyRs

cK@sfyGtjjj|d��)}ttjjj|j��|�SWdQXWntt	fk
rat
SXdS(uL
    Define a volume based on the XML-file path passed to the function

    :param path: path to a file containing the libvirt XML definition of the volume
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.define_vol_xml_path <path to XML file on the node>

    urN(RRR�R�RRoR�R�R�R�R(R�R'R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytdefine_vol_xml_pathJscC@sYt�d|t||�}tj|dtdtj�j�d}tjj	j
|�S(u4
    Attempt to execute non-shared storage "all" migration

    :param vm_: domain name
    :param target: target libvirt host name
    :param ssh: True to connect over ssh

    CLI Example:

    .. code-block:: bash

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

    A tunnel data migration can be performed by setting this in the
    configuration:

    .. code-block:: yaml

        virt:
            tunnel: True

    For more details on tunnelled data migrations, report to
    https://libvirt.org/migration.html#transporttunnel
    u --copy-storage-all RiRji(R�R�RkRlR/RmRnRRRoRp(R}RuR�RqRj((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytmigrate_non_sharedjs
cC@sYt�d|t||�}tj|dtdtj�j�d}tjj	j
|�S(u8
    Attempt to execute non-shared storage "all" migration

    :param vm_: domain name
    :param target: target libvirt host name
    :param ssh: True to connect over ssh

    CLI Example:

    .. code-block:: bash

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

    A tunnel data migration can be performed by setting this in the
    configuration:

    .. code-block:: yaml

        virt:
            tunnel: True

    For more details on tunnelled data migrations, report to
    https://libvirt.org/migration.html#transporttunnel
    u --copy-storage-inc RiRji(R�R�RkRlR/RmRnRRRoRp(R}RuR�RqRj((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytmigrate_non_shared_inc�s
cC@sYt�d|t||�}tj|dtdtj�j�d}tjj	j
|�S(u
    Shared storage migration

    :param vm_: domain name
    :param target: target libvirt host name
    :param ssh: True to connect over ssh

    CLI Example:

    .. code-block:: bash

        salt '*' virt.migrate <domain> <target hypervisor>

    A tunnel data migration can be performed by setting this in the
    configuration:

    .. code-block:: yaml

        virt:
            tunnel: True

    For more details on tunnelled data migrations, report to
    https://libvirt.org/migration.html#transporttunnel
    u RiRji(R�R�RkRlR/RmRnRRRoRp(R}RuR�RqRj((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytmigrate�s
c
	C@s�x�tj|�D]~\}}|d}|d}|dj�dd}tjj|�r�|r�tjjj	t
jddtdt
j
�j�d�}|d|dkr�|d|dkr�tSntjjtjj|��stjtjj|��ntjj|�r#tj|�nd	|d
|d
|}t
j|dt�t�}	d|	dd
|	dd
|}t
j|dt�qWtS(u�
    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.

    :param disks: the list of disk data as provided by virt.get_disks
    :param force: skip checking the compatibility of source and target disk
                  images if True. (default: False)

    CLI Example:

    .. code-block:: bash

        salt '*' virt.seed_non_shared_migrate <disks>
    ufileufile formatuvirtual sizeiuqemu-img info archRiRjiuqemu-img create -f u uchown uuseru:ugroup(RR[R{R�R�RURRR�R�RkRlR/RmRnRtisdirR�R�RAtcallR�(
RFtforcet_tdataR�tformR�tpreRqtcreds((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytseed_non_shared_migrate�s*

	"uoncK@swt|�}t||�}t}|dkrE|jd�dk}n$|dkri|jd�dk}n|j�|S(u�
    Set the autostart flag on a VM so that the VM will start with the host
    system on reboot.

    :param vm_: domain name
    :param state: 'on' to auto start the pool, anything else to mark the
                  pool not to be started when the host boots
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt "*" virt.set_autostart <domain> <on | off>
    uoniiuoff(R,R;RtsetAutostartR(R}RR'R+RPR7((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt
set_autostart�s
cK@sht|�}t||�}ttdt�rH|jtj�dk}n|j�dk}|j�|S(u&
    Remove a defined vm, this does not purge the virtual machine image, and
    this only works if the vm is powered down

    :param vm_: domain name
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.undefine <domain>
    uVIR_DOMAIN_UNDEFINE_NVRAMi(	R,R;RXR
Rt
undefineFlagstVIR_DOMAIN_UNDEFINE_NVRAMtundefineR(R}R'R+RPR7((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyR� s
c
K@s�t|�}t||�}t|�}|dkrRtjjjdd�t}nt	j
|j�dd�dkr�|j�dkr�t
St�}xe|D]]}|r�||ddkr�q�ntj||d	�|jtjj||d	��q�W|r"x|D]}	tj|	�qWnttd
t
�riy|jtj�Wqstk
re|j�qsXn
|j�|j�tS(
u�
    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!

    Pass removables=False to avoid deleting cdrom and floppy images. To avoid
    disruption, the default but dangerous value is True. This will be changed
    to the safer False default value in Sodium.

    :param vm_: domain name
    :param dirs: pass True to remove containing directories
    :param removables: pass True to remove removable devices

        .. versionadded:: 2019.2.0
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.purge <domain> removables=False
    uSodiumu�removables argument default value is True, but will be changed to False by default in {version}. Please set to True to maintain the current behavior in the future.iuunknownushutdownutypeucdromufloppyufileuVIR_DOMAIN_UNDEFINE_NVRAMN(ucdromufloppy(R,R;RzRRRRRR/RzRRR�RR4R�RAtaddR�R�tshutiltrmtreeRXR
R�R�R$R�R(
R}tdirst
removablesR'R+RPRFtdirectoriesRHtdir_((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytpurgeAs6	4	
%



cC@stdS(u�
    Returns the virtual machine type as a string

    CLI Example:

    .. code-block:: bash

        salt '*' virt.virt_type
    uvirtual(R&(((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt	virt_type�s
cC@styGtjjjd��,}dtjjj|j��kr@tSWdQXWntk
r[tSXdt	dt
d�kS(uE
    Returns a bool whether or not this node is a KVM hypervisor
    u
/proc/modulesukvm_Nulibvirtducmd.runups(RRR�R�RoR�R�RR�RR&(R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt
_is_kvm_hyper�s!
cC@stjjjdd�t�S(u�
    Returns a bool whether or not this node is a KVM hypervisor

    CLI Example:

    .. code-block:: bash

        salt '*' virt.is_kvm_hyper

    .. deprecated:: 2019.2.0
    uSodiumu�'is_kvm_hyper' function has been deprecated. Use the 'get_hypervisor' == "kvm" instead. 'is_kvm_hyper' will be removed in {version}.(RRRRR�(((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytis_kvm_hyper�scC@s�ytddkrtSWntk
r,tSXyGtjjjd��,}dtjjj|j	��krmtSWdQXWnt
tfk
r�tSXdtdtd�kS(	uE
    Returns a bool whether or not this node is a XEN hypervisor
    uvirtual_subtypeuXen Dom0u
/proc/modulesuxen_Nulibvirtducmd.runups(
R&RtKeyErrorRRR�R�RoR�R�R�R�R(R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt
_is_xen_hyper�s
!cC@stjjjdd�t�S(u�
    Returns a bool whether or not this node is a XEN hypervisor

    CLI Example:

    .. code-block:: bash

        salt '*' virt.is_xen_hyper

    .. deprecated:: 2019.2.0
    uSodiumu�'is_xen_hyper' function has been deprecated. Use the 'get_hypervisor' == "xen" instead. 'is_xen_hyper' will be removed in {version}.(RRRRR�(((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytis_xen_hyper�scC@sYddg}g|D].}ttjtd�j|��r|^q}|rU|dSdS(u5
    Returns the name of the hypervisor running on this node or ``None``.

    Detected hypervisors:

    - kvm
    - xen

    CLI Example:

    .. code-block:: bash

        salt '*' virt.get_hypervisor

    .. versionadded:: 2019.2.0
        the function and the ``kvm`` and ``xen`` hypervisors support
    ukvmuxenu_is_{}_hyperiN(RXR�R�R�R%R(R"thypertresult((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytget_hypervisor�s;cC@strt�pt�StS(u�
    Returns a bool whether or not this node is a hypervisor of any kind

    CLI Example:

    .. code-block:: bash

        salt '*' virt.is_hyper
    (R
R�R�R(((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytis_hyper�s
c@s�t|�}|j�d��fd�}i}|rS|t||��||<n3x0t|dt�D]}||�||j�<qfW|j�|S(u*
    Return cputime used by the vms on this hyper in a
    list of dicts:

    :param vm_: domain name
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    .. code-block:: python

        [
            '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:

    .. code-block:: bash

        salt '*' virt.vm_cputime
    ic@sx|j�}t|d�}t|d�}d}|rMd|�|}nit|d�d6tdj|��d6S(u2
        Compute cputime info of a domain
        iiigH�����z>ucputimeu{0:.0f}ucputime_percent(RR�R%(RPR{R�tcputimetcputime_percent(t	host_cpus(s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyR|'
sRt(R,R�R;R/R-R(R}R'R+R|RR^((R�s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt
vm_cputime
s#
cK@s~d�}i}t|�}|r=|t||��||<n3x0t|dt�D]}||�||j�<qPW|j�|S(u
    Return combined network counters used by the vms on this hyper in a
    list of dicts:

    :param vm_: domain name
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    .. code-block:: python

        [
            'your-vm': {
                'rx_bytes'   : 0,
                'rx_packets' : 0,
                'rx_errs'    : 0,
                'rx_drop'    : 0,
                'tx_bytes'   : 0,
                'tx_packets' : 0,
                'tx_errs'    : 0,
                'tx_drop'    : 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:

    .. code-block:: bash

        salt '*' virt.vm_netstats
    cS@s0t|�}idd6dd6dd6dd6dd6dd6dd6dd	6}x�tj|�D]�}d
|krZ|d
}|j|�}|dc|d7<|dc|d7<|dc|d7<|dc|d
7<|dc|d7<|dc|d7<|dc|d7<|d	c|d7<qZqZW|S(u3
        Compute network stats of a domain
        iurx_bytesu
rx_packetsurx_errsurx_droputx_bytesu
tx_packetsutx_errsutx_droputargetiiiiiii(ReRt
itervaluestinterfaceStats(RPR]R7tattrsR�tstats((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyR|i
s.

Rt(R,R;R/R-R(R}R'R|RR+R^((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytvm_netstats@
s)	
c@s��fd���fd�}i}t��}|rR|t||��||<n9x6t|dtdt�D]}||�||j�<qkW|j�|S(u�
    Return disk usage counters used by the vms on this hyper in a
    list of dicts:

    :param vm_: domain name
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    .. code-block:: python

        [
            'your-vm': {
                'rd_req'   : 0,
                'rd_bytes' : 0,
                'wr_req'   : 0,
                'wr_bytes' : 0,
                'errs'     : 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:

    .. code-block:: bash

        salt '*' virt.vm_blockstats
    c@sAtjt|���}g|jd�D]}|jd�^q(S(uO
        Extract the disk devices names from the domain XML definition
        udevices/disk/targetudev(RRLRMRWR(RPR^Ru(R'(s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt
get_disk_devs�
sc@s��|�}idd6dd6dd6dd6dd6}x�|D]y}|j|�}|dc|d7<|dc|d7<|dc|d7<|dc|d	7<|dc|d
7<q<W|S(u4
        Compute the disk stats of a domain
        iurd_requrd_bytesuwr_requwr_bytesuerrsiiii(t
blockStats(RPRFR7RHR�(R�(s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyR|�
s


RtRv(R,R;R/RR-R(R}R'R|RR+R^((R�R's5/usr/lib/python2.7/site-packages/salt/modules/virt.pytvm_diskstats�
s&
cC@s�t�}tj|j��}x�|D]�}|jdkrJ|j|d<q%|jdkr�|s�tjjt|j��j	d�nt|j�|d<q%|jdkr%|jdk|d<q%q%W|j
�dk|d<|S(	ub
    Parse XML doc and return a dict with the status values.

    :param xmldoc:
    :return:
    unameucreationTimeu ucreatedustateurunningiucurrent(R�RRLt
getXMLDescRXROR?R@RARBt	isCurrent(tvm_snapshott	unix_timeR7ttreeRR((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_parse_snapshot_description�
s	
@cK@s�t�}t|�}xdt|dt|r3|gp9t��D];}g|j�D]}t|�^qPpkd||j�<q=W|j�|S(u2
    List available snapshots for certain vm or for all.

    :param domain: domain name
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.list_snapshots
        salt '*' virt.list_snapshots <domain>
    RtuN/A(	R�R,R;R/R.tlistAllSnapshotsR�R-R(R^R'R7R+t	vm_domaintsnap((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytlist_snapshots�
s	.9
cK@s|r9|j�|j�kr9tdjd|���n|sldjd|dtjdtj���}n|r�djd|d|�}ntjd	�}tj|d
�}||_	t
|�}t||�jt
jjjtj|���|j�i|d
6S(u
    Create a snapshot of a VM.

    :param domain: domain name
    :param name: Name of the snapshot. If the name is omitted, then will be used original domain
                 name with ISO 8601 time as a suffix.

    :param suffix: Add suffix for the new name. Useful in states, where such snapshots
                   can be distinguished from manually created.
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.snapshot <domain>
    uVVirtual Machine {name} is already defined. Please choose another name for the snapshotR-u{domain}-{tsnap}R^ttsnapu
%Y%m%d-%H%M%Su{name}-{suffix}tsuffixudomainsnapshotuname(R/RR%RDtstrftimet	localtimeRtElementt
SubElementROR,R;tsnapshotCreateXMLRRRoRpR'R(R^R-R�R'R^tn_nameR+((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyRIs-	
cO@s�t�}t|�}t||�}xP|j�D]B}|j�|ksP|r1t|�||j�<|j�q1q1W|j�ig|j�D]}t|�^q�p�d|6}i|d6|d6S(u�
    Delete one or more snapshots of the given VM.

    :param name: domain name
    :param names: names of the snapshots to remove
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.delete_snapshots <domain> all=True
        salt '*' virt.delete_snapshots <domain> <snapshot>
        salt '*' virt.delete_snapshots <domain> <snapshot1> <snapshot2> ...
    uN/Au	availableudeleted(R�R,R;R�tgetNameR�tdeleteR(R-tnamesR'tdeletedR+R^R�t	available((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytdelete_snapshotsJs	
2cK@sft�}t|�}t||�}|j�}t�}x9|D]1}	|jit|	dt�dd6|	d6�q@Wgt|dd�dt�D]}
|
d^q�}~|s�|j	�t
d��n+t|�d	kr�|j	�t
d
��nd}xu|D]m}|sR|j
�rn||j|�d	rn||j|�d	d}Pqnq|j�|kr|}PqqW|s�|j	�t
tr�dj|�p�d
��n%|j
�r�|j	�t
d��n|j|�|j�|d<|rNt�}
xG|D]?}|j�|j�kr<|
j|j��|j�q�Pq�W|
|d<n
d|d<|j	�|S(u�
    Revert snapshot to the previous from current (if available) or to the specific.

    :param name: domain name
    :param vm_snapshot: name of the snapshot to revert
    :param cleanup: Remove all newer than reverted snapshots. Values: True or False (default False).
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.revert <domain>
        salt '*' virt.revert <domain> <snapshot>
    R�ucreateduidxuptrRccS@s|dS(Nuidx((R?((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt<lambda>�streverseuNo snapshots foundiu8Cannot revert to itself: only one snapshot is available.iuSnapshot "{0}" not foundu$No more previous snapshots availableu0Cannot revert to the currently running snapshot.urevertedudeleteduN/AN(R�R,R;R�R.R1R�R/RRRR5RR�tindexRRIR%trevertToSnapshotR(R-R�tcleanupR'R7R+R^t	snapshotst
_snapshotstsnap_objtw_ptrR�tp_snapR((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytrevert_snapshotrsX		
/2


#
!

	




cC@s�|jd�}|jd�}|j}d}|rB|}|}n|j|�}|s�igd6}|r}t|�|d<n|||<n|r�|dj|�ndS(uc
    Parse the <machine> element of the host capabilities and add it
    to the machines list.
    umaxCpusu	canonicaluualternate_namesumaxcpusN(RROR�R1(tmachinesRRtmaxcpust	canonicalR-talternate_nametmachine((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_caps_add_machine�s		

c	C@s�|jd�}i|jd�jd6i|jd�d6id6id6d6}x|D]}|jdkr�t|j�|dd<qT|jdkr�|j|dd<qT|jdkr�t|dd|�qT|jd	krT|jd
�}id
d6id6}|jd�}|d
k	r*|j|d<nx(|jd�D]}t|d|�q:W||dd|<qTqTW|jd�}|d
k	r�d�|D�|d<n|S(uF
    Parse the <guest> element of the connection capabilities XML
    uarchuos_typeunameumachinesudomainsuwordsizeuemulatorumachineudomainutypeufeaturescS@s`i|]V}i|jd�dkr*tntd6|jd�dkrLtntd6|j�qS(utoggleuyesudefaultuno(RR/RRX(Rtchild((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pys
<dictcomp>s	N(RNRORRXR�RRRW(	Rt	arch_nodeR�Rtdomain_typeR^t
emulator_nodeRtfeatures_nodes((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_parse_caps_guest�s<

cC@s�it|jd��d6}|jd�}|dk	rk|jdd�}|j}dj||�|d<ng|jd�D]D}idj|jd�|jdd��d6t|j�d6^q{}|r�||d<nd	�|jd
�D�}|r||d<ng}x�|jd�D]�}	it|	jd��d6}
|	jd
�}|rdt|�|
d
<n|	jd�}|r�t|�|
d<n|	jd�}
|
r�|
|
d<n|j|
�qW|r�||d<n|S(uK
    Parse the <cell> nodes of the connection capabilities XML output.
    uidumemoryuunituKiBu{} {}upagesusizeu	availablecS@s7i|]-}t|jd��t|jd���qS(uvalueuid(R�R(Rtdistance((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pys
<dictcomp>s	udistances/siblingu	distancesucpus/cpuu	socket_iducore_idusiblingsucpusN(R�RRNRROR%RWR1(tcellR�RetunitR�tpagetpagest	distancesR�RcR�t	socket_idtcore_idtsiblings((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_parse_caps_cells@	W



cC@s@it|jd��d6t|jd��d6|jd�d6dj|jd�|jd��d6|jd�d6}g}x�|jd�D]�}|jd�}idj|jd	�|�d	6|jd�d6t|jd
��d
6}|jd�}|rdj||�|d<n|j|�q�W|r<||d<n|S(
uF
    Parse the <bank> element of the connection capabilities XML.
    uidulevelutypeu{} {}usizeuunitucpusucontrolugranularityu	maxAllocsuminucontrols(R�RR%RWR1(tbankR�tcontrolstcontrolRtresult_controltminimum((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_parse_caps_bank:s(%
c

C@s�i}x�|D]�}|jdkr2|j|d<q
|jdkr�i|jd�d&k	rk|jd�jnd&d6|jd�d&k	r�|jd�jnd&d6|jd�d&k	r�|jd�jnd&d6g|jd�D]}|jd�^q�d6g|jd	�D]4}id
j|jd�|jdd
��d6^q
d	6}|jd�}|d&k	ry|jd�|d<n|jd�}|d&k	r�t|jd��|d<t|jd��|d<t|jd��|d<n||d<q
|jdkr!g|D]}|j^q|d<q
|jdkryi|jd�d&k	d6g|jd�D]}|j^qYd6|d<q
|jdkr�ig|jd�D]}	t|	�^q�d6|d<q
|jdkr
ig|jd�D]}
t	|
�^q�d6|d<q
q
Wg|jd�D]�}i|jd�d&k	rG|jd�jnd&d6|jd �d&k	ru|jd �jnd&d 6g|jd!�D]&}i|jd"�d"6|jd#6^q�d$6^q|d%<|S('uF
    Parse the <host> element of the connection capabilities XML.
    uuuiducpuuarchumodeluvendorufeatureunameufeaturesupagesu{} {}usizeuunituKiBu	microcodeuversionutopologyusocketsucoresuthreadsupower_managementumigration_featuresuliveuuri_transports/uri_transportu
transportsu	migrationu
cells/cellucellsucacheubankubanksusecmodeludoiu	baselabelutypeulabelu
baselabelsusecurityN(
RXRORNRRWRR%R�R&R,(
R�R�RtfeatureR R�t	microcodettopologyRRRR'tsecmodeltlabel((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_parse_caps_hostYsH
...,K
#037�cK@snt|�}tj|j��}|j�it|jd��d6g|jd�D]}t|�^qTd6S(ur
    Return the hypervisor connection capabilities.

    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.capabilities
    uhostuguestuguests(	R,RRLtgetCapabilitiesRR2RNRWR(R'R+RR((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyR�s
cC@s2|jd�g|jd�D]}|j^qfS(uP
    Return a tuple containing the name of the enum and the possible values
    unameuvalue(RRWRO(RRRd((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_parse_caps_enum�sc
C@s�i}x�|jd�D]�}|jd�dks7qn|jd�}|dkr_t||<q|dkrfi}|jd�}|dk	r�i|jd6}|jd�}|r�||d<n|jd	�}|r�||d	<n||d<n|jd
�dk	r|jd
�jnd}	|	r-|	|d
<nd�|jd�D�}
|
rY|
|d
<n|||<q|dkri}d�|jd�D�}|r�||d<n|||<qqW|S(u<
    Parse the <cpu> element of the domain capabilities
    umodeu	supporteduyesunameuhost-passthroughu
host-modelumodelu	vendor_idufallbackuvendorcS@s+i|]!}|jd�|jd��qS(upolicyuname(R(RR-((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pys
<dictcomp>�s	ufeatureufeaturesucustomcS@s%i|]}|jd�|j�qS(uusable(RRO(Rtmodel((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pys
<dictcomp>�s	umodelsN(RWRR/RNRRO(
RRR�R�R-t
host_modelt
model_nodeR5t	vendor_idtfallbacktvendortfeaturestcustom_modeltmodels((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_parse_caps_cpu�sD




-



cC@sri}xe|D]]}|jd�dkr
g|jd�D]}t|�^q8}d�|D�||j<q
q
W|S(uG
    Parse the devices or features list of the domain capatilities
    u	supporteduyesuenumcS@s+i|]!}|dr|d|d�qS(ii((RR?((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pys
<dictcomp>�s	(RRWR4RX(RRR�Rtenums((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_parse_caps_devices_features�s
(cC@stg|jd�D]}t|�^q}d�|D�}g|jd�D]}|j^qH}|rp||d<n|S(u@
    Parse the <loader> element of the domain capabilities.
    uenumcS@s+i|]!}|dr|d|d�qS(ii((RR?((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pys
<dictcomp>�s	uvalueuvalues(RWR4RO(RRtenumR?R�Rtvalues((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_parse_caps_loader�s(%
cK@snt|�}tj|j||||d��}|j�i|jd�dk	rd|jd�jndd6|jd�dk	r�|jd�jndd6|jd�dk	r�|jd�jndd6|jd�dk	r�|jd�jndd6}xo|D]g}|jdkr?|j	d�r?t
|j	d��|d	<q�|jd
krj|j	d�dk|d
<q�|jd
kr�i|d
<|jd�}	|	dk	rf|	j	d�dkrft|	�}
|
|d
d<qfq�|jdkrt|�}|rf||d<qfq�|jdkr5t
|�}|rf||d<qfq�|jdkr�t
|�}
|
rf|
|d<qfq�q�W|S(u�
    Return the domain capabilities given an emulator, architecture, machine or virtualization type.

    .. versionadded:: 2019.2.0

    :param emulator: return the capabilities for the given emulator binary
    :param arch: return the capabilities for the given CPU architecture
    :param machine: return the capabilities for the given emulated machine type
    :param domain: return the capabilities for the given virtualization type.
    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    The list of the possible emulator, arch, machine and domain can be found in
    the host capabilities output.

    If none of the parameters is provided the libvirt default domain capabilities
    will be returned.

    CLI Example:

    .. code-block:: bash

        salt '*' virt.domain_capabilities arch='x86_64' domain='kvm'

    iupathuemulatorudomainumachineuarchuvcpuumaxu	max_vcpusu	iothreadsu	supporteduyesuosuloaderucpuudevicesufeaturesN(R,RRLtgetDomainCapabilitiesRRNRRORXRR�RCR>R@(temulatorR�RR^R'R+RR�Rtloader_nodeR	R�tdevicesR;((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytdomain_capabilitiess@$
...1

!ulibvirtc	K@s�t|�}tj|j��}|jd�}tjdtjj	j
tj|���d}|r�tt
dt�r�|t
j7}q�|j�t�n|r�tt
dt�r�|t
j7}ntj|jtjj	j
tj|��g|��}|j�|ritt
dt�ritjjjdd��}tj|�}WdQX|jd	�j}	x
|	re|jd
�}
g|
D]3}|jd�|	kr{tt|��r{|^q{}|s�tdj|	���n*t|�d
kr�tdj|	���n|d}|jd	�}
|
dkr*d}	n|
jd�}	|jg|jd�D]}|^qO�q_Wn|dkr�i|jd	�jd	6|jd�jd6g|jd�D]}|jd�^q�d6S|j�S(u
    Return the optimal 'custom' CPU baseline config for VM's on this minion

    .. versionadded:: 2016.3.0

    :param full: Return all CPU features rather than the ones on top of the closest CPU model
    :param migratable: Exclude CPU features that are unmigratable (libvirt 2.13+)
    :param out: 'libvirt' (default) for usable libvirt XML definition, 'salt' for nice dict
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.cpu_baseline

    uhost/cpuuHost CPU model definition: %siu#VIR_CONNECT_BASELINE_CPU_MIGRATABLEu(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURESu/usr/share/libvirt/cpu_map.xmlurNumodelu
arch/modelunameuModel {0} not found in CPU mapiu$Multiple models {0} found in CPU mapufeatureusaltuvendorufeatures( R,RRLR3RNRR�RRRoRpR'RXR
Rt#VIR_CONNECT_BASELINE_CPU_MIGRATABLERt
ValueErrort(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATUREStbaselineCPUR�R�tparseRORWRRYR5R%RRTttoxml(tfullt
migratableRfR'R+RR�R�tcpu_mapt	cpu_modeltcpu_map_modelstelt	cpu_specsR7R-((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytcpu_baselineJsJ(
	6
	@
	0-cK@s�t|�}|jdd�}|jdd�}|jdt�}|jdt�}t|||||�}	y|j|	�Wn0tk
r�}
tj|
�|j	�|
�nXy|j
|�}Wn0tk
r�}
tj|
�|j	�|
�nX|dkr|j	�tS|tks(|tkrG|j�dkrG|j
�n|tkr{|j�dkr{|jt|��n4|tkr�|j�dkr�|jt|��n|j	�tS(u�
    Create libvirt network.

    :param name: Network name
    :param bridge: Bridge name
    :param forward: Forward mode(bridge, router, nat)
    :param vport: Virtualport type
    :param tag: Vlan tag
    :param autostart: Network autostart (default True)
    :param start: Network start (default True)
    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    CLI Example:

    .. code-block:: bash

        salt '*' virt.network_define network main bridge openvswitch

    .. versionadded:: 2019.2.0
    uvportutagu	autostartustartiN(R,RRR/R�tnetworkDefineXMLRRRRtnetworkLookupByNameRRVRt	autostartR�R�(R-R�R�R'R+R�RXRYtstartingtnet_xmlR�R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytnetwork_define�sD	






*

cK@sEt|�}z'g|j�D]}|j�^qSWd|j�XdS(u^
    List all virtual networks.

    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

       salt '*' virt.list_networks
    N(R,tlistAllNetworksR-R(R'R+R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt
list_networks�s'c@s�i}t|�}d��z�yWg|j�D]*}|dksR|j�|kr.|^q.}�fd�|D�}Wn,tjk
r�}tjdt|��nXWd|j	�X|S(u�
    Return informations on a virtual network provided its name.

    :param name: virtual network name
    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    If no name is provided, return the infos for all defined virtual networks.

    .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.network_info default
    cS@sk|j�}xX|D]P}|dtjkr9d|d<q|dtjkrYd|d<qd|d<qW|S(u3
        Get all DHCP leases for a network
        utypeuipv4uipv6uunknown(t
DHCPLeasesR
tVIR_IP_ADDR_TYPE_IPV4tVIR_IP_ADDR_TYPE_IPV6(R�tleasestlease((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_net_get_leases
s


c@smi|]c}i|j�d6|j�d6|j�d6|j�d6|j�d6�|�d6|j��qS(uuuidubridgeu	autostartuactiveu
persistentuleases(t
UUIDStringt
bridgeNameRYRVtisPersistentR-(RR�(Rd(s5/usr/lib/python2.7/site-packages/salt/modules/virt.pys
<dictcomp>s	uSilenced libvirt error: %sN(
R,R]RR-R
RRR�tstrR(R-R'R�R+R�tnetsR�((Rds5/usr/lib/python2.7/site-packages/salt/modules/virt.pytnetwork_info�s	=cK@sBt|�}z$|j|�}t|j��SWd|j�XdS(u�
    Start a defined virtual network.

    :param name: virtual network name
    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.network_start default
    N(R,RXRYRR(R-R'R+R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt
network_start+s
cK@sBt|�}z$|j|�}t|j��SWd|j�XdS(u�
    Stop a defined virtual network.

    :param name: virtual network name
    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.network_stop default
    N(R,RXRYR�R(R-R'R+R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytnetwork_stopDs
cK@sBt|�}z$|j|�}t|j��SWd|j�XdS(u�
    Remove a defined virtual network. This does not stop the virtual network.

    :param name: virtual network name
    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.network_undefine default
    N(R,RXRYR�R(R-R'R+R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytnetwork_undefine]s
cK@sWt|�}z9|j|�}t|j|dkr9dnd��SWd|j�XdS(u�
    Set the autostart flag on a virtual network so that the network
    will start with the host system on reboot.

    :param name: virtual network name
    :param state: 'on' to auto start the network, anything else to mark the
                  virtual network not to be started when the host boots
    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt "*" virt.network_set_autostart <pool> <on | off>
    uoniiN(R,RXRYR�R(R-RR'R+R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytnetwork_set_autostartvs
*c
K@s�t|
�}t|||d|d|d|d|d|d|d|	d|
�}z^y>|rl|j|�}n"|j|�}|r�|j�nWntk
r�}|�nXWd	|j�XtS(
u�
    Create libvirt pool.

    :param name: Pool name
    :param ptype:
        Pool type. See `libvirt documentation <https://libvirt.org/storage.html>`_  for the
        possible values.
    :param target: Pool full path target
    :param permissions:
        Permissions to set on the target folder. This is mostly used for filesystem-based
        pool types. See :ref:`pool-define-permissions` for more details on this structure.
    :param source_devices:
        List of source devices for pools backed by physical devices. (Default: ``None``)

        Each item in the list is a dictionary with ``path`` and optionally ``part_separator``
        keys. The path is the qualified name for iSCSI devices.

        Report to `this libvirt page <https://libvirt.org/formatstorage.html#StoragePool>`_
        for more informations on the use of ``part_separator``
    :param source_dir:
        Path to the source directory for pools of type ``dir``, ``netfs`` or ``gluster``.
        (Default: ``None``)
    :param source_adapter:
        SCSI source definition. The value is a dictionary with ``type``, ``name``, ``parent``,
        ``managed``, ``parent_wwnn``, ``parent_wwpn``, ``parent_fabric_wwn``, ``wwnn``, ``wwpn``
        and ``parent_address`` keys.

        The ``parent_address`` value is a dictionary with ``unique_id`` and ``address`` keys.
        The address represents a PCI address and is itself a dictionary with ``domain``, ``bus``,
        ``slot`` and ``function`` properties.
        Report to `this libvirt page <https://libvirt.org/formatstorage.html#StoragePool>`_
        for the meaning and possible values of these properties.
    :param source_hosts:
        List of source for pools backed by storage from remote servers. Each item is the hostname
        optionally followed by the port separated by a colon. (Default: ``None``)
    :param source_auth:
        Source authentication details. (Default: ``None``)

        The value is a dictionary with ``type``, ``username`` and ``secret`` keys. The type
        can be one of ``ceph`` for Ceph RBD or ``chap`` for iSCSI sources.

        The ``secret`` value links to a libvirt secret object. It is a dictionary with
        ``type`` and ``value`` keys. The type value can be either ``uuid`` or ``usage``.

        Examples:

        .. code-block:: python

            source_auth={
                'type': 'ceph',
                'username': 'admin',
                'secret': {
                    'type': 'uuid',
                    'uuid': '2ec115d7-3a88-3ceb-bc12-0ac909a6fd87'
                }
            }

        .. code-block:: python

            source_auth={
                'type': 'chap',
                'username': 'myname',
                'secret': {
                    'type': 'usage',
                    'uuid': 'mycluster_myname'
                }
            }

    :param source_name:
        Identifier of name-based sources.
    :param source_format:
        String representing the source format. The possible values are depending on the
        source type. See `libvirt documentation <https://libvirt.org/storage.html>`_ for
        the possible values.
    :param start: Pool start (default True)
    :param transient:
        When ``True``, the pool will be automatically undefined after being stopped.
        Note that a transient pool will force ``start`` to ``True``. (Default: ``False``)
    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    .. _pool-define-permissions:

    .. rubric:: Permissions definition

    The permissions are described by a dictionary containing the following keys:

    mode
        The octal representation of the permissions. (Default: `0711`)

    owner
        the numeric user ID of the owner. (Default: from the parent folder)

    group
        the numeric ID of the group. (Default: from the parent folder)

    label
        the SELinux label. (Default: `None`)


    .. rubric:: CLI Example:

    Local folder pool:

    .. code-block:: bash

        salt '*' virt.pool_define somepool dir target=/srv/mypool                                   permissions="{'mode': '0744' 'ower': 107, 'group': 107 }"

    CIFS backed pool:

    .. code-block:: bash

        salt '*' virt.pool_define myshare netfs source_format=cifs                                   source_dir=samba_share source_hosts="['example.com']" target=/mnt/cifs

    .. versionadded:: 2019.2.0
    R�R�R�R�R�R�R�R�N(R,R�tstoragePoolCreateXMLtstoragePoolDefineXMLRRRR/(R-R�RuR�R�R�R�R�R�R�R�t	transientRR'R+tpool_xmlR�R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytpool_define�s0�	cK@sEt|�}z'g|j�D]}|j�^qSWd|j�XdS(uY
    List all storage pools.

    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.list_pools
    N(R,tlistAllStoragePoolsR-R(R'R+R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt
list_pools5s'c@s�i}t|�}d��z�yWg|j�D]*}|dksR|j�|kr.|^q.}�fd�|D�}Wn,tjk
r�}tjdt|��nXWd|j	�X|S(u�
    Return informations on a storage pool provided its name.

    :param name: libvirt storage pool name
    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    If no name is provided, return the infos for all defined storage pools.

    .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.pool_info default
    cS@s�dddddg}|j�}|dt|�krE||dnd}tj|j��}|jd�}i	|j�d	6|d
6|dd6|d
d6|dd6|j�d6|j�d6|dk	r�|j
ndd6|jd�d6S(u_
        Format the pool info dictionary

        :param pool: the libvirt pool object
        uinactiveubuildingurunningudegradeduinaccessibleiuunknownutarget/pathuuuidustateiucapacityiu
allocationiufreeu	autostartu
persistentutarget_pathutypeN(RR5RRLRVRNReRYRgRROR(R�tstatesR�RR_t	path_node((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt_pool_extract_infosbs*


c@s%i|]}�|�|j��qS((R-(RR�(Rx(s5/usr/lib/python2.7/site-packages/salt/modules/virt.pys
<dictcomp>{s	uSilenced libvirt error: %sN(
R,RtRR-R
RRR�RhR(R-R'R�R+R�tpoolsR�((Rxs5/usr/lib/python2.7/site-packages/salt/modules/virt.pyR�Ls	=cK@sBt|�}z$|j|�}t|j��SWd|j�XdS(u�
    Start a defined libvirt storage pool.

    :param name: libvirt storage pool name
    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.pool_start default
    N(R,R�RYRR(R-R'R+R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt
pool_start�s
cK@sBt|�}z$|j|�}t|j��SWd|j�XdS(u�
    Build a defined libvirt storage pool.

    :param name: libvirt storage pool name
    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.pool_build default
    N(R,R�RYtbuildR(R-R'R+R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt
pool_build�s
cK@sBt|�}z$|j|�}t|j��SWd|j�XdS(u�
    Stop a defined libvirt storage pool.

    :param name: libvirt storage pool name
    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.pool_stop default
    N(R,R�RYR�R(R-R'R+R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt	pool_stop�s
cK@sBt|�}z$|j|�}t|j��SWd|j�XdS(u�
    Remove a defined libvirt storage pool. The pool needs to be stopped before calling.

    :param name: libvirt storage pool name
    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.pool_undefine default
    N(R,R�RYR�R(R-R'R+R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt
pool_undefine�s
cK@s`t|�}zB|j|�}tj}|r9tj}nt|j|��SWd|j�XdS(u
    Delete the resources of a defined libvirt storage pool.

    :param name: libvirt storage pool name
    :param fast: if set to False, zeroes out all the data.
                 Default value is True.
    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.pool_delete default
    N(R,R�R
tVIR_STORAGE_POOL_DELETE_NORMALtVIR_STORAGE_POOL_DELETE_ZEROEDRYRR(R-tfastR'R+R�R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytpool_delete�s	cK@sBt|�}z$|j|�}t|j��SWd|j�XdS(u�
    Refresh a defined libvirt storage pool.

    :param name: libvirt storage pool name
    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.pool_refresh default
    N(R,R�RYtrefreshR(R-R'R+R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytpool_refreshs
cK@sWt|�}z9|j|�}t|j|dkr9dnd��SWd|j�XdS(u�
    Set the autostart flag on a libvirt storage pool so that the storage pool
    will start with the host system on reboot.

    :param name: libvirt storage pool name
    :param state: 'on' to auto start the pool, anything else to mark the
                  pool not to be started when the host boots
    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt "*" virt.pool_set_autostart <pool> <on | off>
    uoniiN(R,R�RYR�R(R-RR'R+R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytpool_set_autostarts
*cK@s;t|�}z|j|�}|j�SWd|j�XdS(u�
    List the volumes contained in a defined libvirt storage pool.

    :param name: libvirt storage pool name
    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt "*" virt.pool_list_volumes <pool>
    N(R,R�tlistVolumesR(R-R'R+R�((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pytpool_list_volumes:s
(�t__doc__t
__future__RRRR�R�RYR�R�RkR�tloggingRDR?t	xml.etreeRR�tjinja2.exceptionsR
RR/R
tImportErrorRtsalt.utils.filesRtsalt.utils.jsontsalt.utils.networktsalt.utils.pathtsalt.utils.stringutilstsalt.utils.templatestsalt.utils.validate.nettsalt.utils.versionstsalt.utils.yamltsalt.exceptionsRRtsalt.extRtsalt.ext.six.movesRt	getLoggerR�RtEnvironmenttFileSystemLoaderR�R�Rt	templatestTEMPLATE_DIRNAMER�RzRRR,R;RKRQRSRTRUReRhRzR�R�R�RR�R�R�R�R�R�R�R�RRR
R&R.R3R;RHRMRORPRqRuRwRyR~R�R�R�R�R�R�R�R�R�R�R�R�R�R�RMR�R�R�R�RR�R�R�R�R�R�R�R�RR�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�RIRRRRR&R,R2RR4R>R@RCRHRVR\R^RjRkRlRmRnRsRuR�RzR|R}R~R�R�R�R�(((s5/usr/lib/python2.7/site-packages/salt/modules/virt.pyt<module>Gs�


	$

		!	K	&	)	
				$		+			\		\c	KH��				%			�			B+						/.	
					:							 					 	/	 """((	!A	
						?QO!2	(R		/	/		=			2		FT	B	4			�	7					

Zerion Mini Shell 1.0