%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@s�dZddlmZmZmZddlZddljjZddl	Z
ddlmZy*ddl
mZddlmZeZWnek
r�eZnXdZeje�Zd�Zd	�Zd
�Zd�Zd�ZdS(
ui
Pillar data from vCenter or an ESXi host

.. versionadded:: 2017.7.0

:depends: - pyVmomi

This external pillar can pull attributes from objects in vCenter or an ESXi host and provide those attributes
as pillar data to minions.  This can allow for pillar based targeting of minions on ESXi host, Datastore, VM
configuration, etc.  This setup requires only the salt master have access to the vCenter server/ESXi hosts.

The pillar will return an empty dict if the 'os' or 'virtual' grain are not 'VMWare', 'ESXi', or 'VMWare ESXi'.

Defaults
========

- The external pillar will search for Virtual Machines with the VM name matching the minion id.
- Data will be returned into the 'vmware' pillar key.
- The external pillar has a default set of properties to return for both VirtualMachine and HostSystem types.


Configuring the VMWare pillar
=============================

The required minimal configuration in the salt master ext_pillar setup:

.. code-block:: yaml

    ext_pillar:
        - vmware:
            host: <vcenter/esx host>
            username: <user to connect with>
            password: <password>

Optionally, the following keyword arguments can be passed to the ext_pillar for customized configuration:

    pillar_key
        Optionally set the pillar key to return the data into.  Default is ``vmware``.

    protocol
        Optionally set to alternate protocol if the vCenter server or ESX/ESXi host is not
        using the default protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the vCenter server or ESX/ESXi host is not
        using the default port. Default port is ``443``.

    property_name
        Property name to match the minion id against.  Defaults to ``name``.

    property_types
        Optionally specify a list of pyVmomi vim types to search for the minion id in 'property_name'.
        Default is ``['VirtualMachine']``.

        For example, to search both vim.VirtualMachine and vim.HostSystem object types:

        .. code-block:: yaml

           ext_pillar:
               - vmware:
                   host: myesx
                   username: root
                   password: complex_password
                   property_types:
                     - VirtualMachine
                     - HostSystem

        Additionally, the list of property types can be dicts, the item of the dict being a list specifying
        the attribute to return for that vim object type.

        The pillar will attempt to recurse the attribute and return all child attributes.

        To explicitly specify deeper attributes without attempting to recurse an attribute, convert the list
        item to a dict with the item of the dict being the child attributes to return.  Follow this pattern
        to return attributes as deep within the object as necessary.

        .. note::
            Be careful when specifying custom attributes!  Many attributes have objects as attributes which
            have the parent object as an attribute and which will cause the pillar to fail due to the attempt
            to convert all sub-objects recursively (i.e. infinite attribute loops).  Specifying only the
            sub-attributes you would like returned will keep the infinite recursion from occurring.

            A maximum recursion exception will occur in this case and the pillar will not return as desired.

        .. code-block:: yaml

            ext_pillar:
                - vmware:
                    host: myvcenter
                    username: my_user
                    password: my_pass
                    replace_default_attributes: True
                    property_types:
                      - VirtualMachine:
                          - config:
                             - bootOptions:
                                 - bootDelay
                                 - bootRetryDelay
                      - HostSystem:
                          - datastore:
                             - name

        The above ext_pillar example would return a pillar like the following for a VirtualMachine object that's
        name matched the minion id:

        .. code-block:: yaml

            vmware:
              config:
                bootOptions:
                  bootDelay: 1000
                  bootRetryDelay: 1000

        If you were to retrieve these virtual machine attributes via pyVmomi directly, this would be the same as

        .. code-block:: python

            vmObject.config.bootOptions.bootDelay
            vmObject.config.bootOptionis.bootRetryDelay

        The above ext_pillar example would return a pillar like the following for a HostySystem object that's name
        matched the minion id:

        .. code-block:: yaml

            vmware:
              datastore:
                 - name: Datastore1
                 - name: Datastore2

        The 'datastore' property of a HostSystem object is a list of datastores, thus a list is returned.

    replace_default_attributes
        If custom attributes are specified by the property_types parameter, replace_default_attributes determines
        if those will be added to default attributes (False) or replace the default attributes completely (True).
        The default setting is 'False'.

        .. note::

            vCenter "Custom Attributes" (i.e. Annotations) will always be returned if it exists on the object as
            part of the pillar regardless of this setting.

i(tabsolute_importtprint_functiontunicode_literalsN(tsix(tvim(t
DisconnectuvmwarecC@str
tStS(u1
    Only return if python-etcd is installed
    (tHAS_LIBSt__virtualname__tFalse(((s=/usr/lib/python2.7/site-packages/salt/pillar/vmware_pillar.pyt__virtual__�scK@sBi}d^}d^}d^}g}d}d^}	d^}
d}t}iiddddddd	d
ddd
dddgd6iiididd6gd6dgd6iddddgd6iddgd6idddgd 6id!gd"6gd#6iiidd$6dddgd%6gd 6gd&6idd'id(d)d*d+d,d-id.d/d0d1dd2id3d4gd56d6d7d8g
d96gd#6idd:6gd$6idd'iid;d6gd#6gd:6gd<6}
id'gd#6idiidd=6d6gd>6idgd$6idgd6g}d?|kr|d?}ni||<d|kr9tjd@�|S|d}tjdA|�dB|krptjdC�|S|dB}tjdD|�dE|kr�tjdF�|S|dE}tjdG|�dH|kr�|dH}|r�g}i}
q�ndI|kr�x�|dID]�}t|t�r�|jtt	|j
�dJ��t||j
�dJt�rs|||j
�dJ}q�tjdK�q|jtt	|��qWnt	j
g}tjdL|�dM|kr�|dM}nd}tjdN|�dO|kr|dO}	tjdP|	�ndQ|kr=|dQ}
tjdR|
�nd^}d^}dStkrhtdSj�}ndTtkr�tdTj�}n|dks�|dUks�|dVkr:i||<y`tjjj||||	|
�}|rd^}x|D]}tjjj|||dW|�}|r�t|�jjdXdY�}t|dZ�r�i||d[<xU|jD]G}x>|jD]3}|j|jkrk|j||d[|j<qkqkWq[Wng}||
kr�|
|}ntj||t |||��||<Pq�q�Wt!|�ntjd\|�Wnt"k
r5tjd]�nX|SiSd^S(_u+
    Check vmware/vcenter for all data
    unameuvmwareuversionuguestIdufilesutoolsuflagsumemoryHotAddEnableducpuHotAddEnableducpuHotRemoveEnabledudatastoreUrlu
swapPlacementubootOptionsuscheduledHardwareUpgradeInfoumemoryAllocationu
cpuAllocationuconfiguparentuhostubootTimeuruntimeutoolsStatusutoolsVersionStatusutoolsVersionStatus2utoolsRunningStatusuguestucpuReservationumemoryReservationu	committeduuncommitteduunsharedustorageudasProtectedudasVmProtectionusummaryu	datastoreuperDatastoreUsageuVirtualMachineu
overallStatusuurlu	freeSpaceumaxFileSizeumaxVirtualDiskCapacityumaxPhysicalRDMFileSizeumaxVirtualRDMFileSizeucapacityublockSizeMbu	maxBlocksumajorVersionuuuidudiskNameu	partitionuextentuvmfsUpgradeableussdulocaluvmfsuvmu
powerStateu
HostSystemudistributedVirtualSwitchunetworku
pillar_keyuXVMWare external pillar configured but host is not specified in ext_pillar configuration.uvmware_pillar -- host = %suusernameu[VMWare external pillar requested but username is not specified in ext_pillar configuration.uvmware_pillar -- username = %supasswordu[VMWare external pillar requested but password is not specified in ext_pillar configuration.uvmware_pillar -- password = %sureplace_default_attributesuproperty_typesiu?A property_type dict was specified, but its value is not a listu$vmware_pillar -- property_types = %su
property_nameu#vmware_pillar -- property_name = %suprotocoluvmware_pillar -- protocol = %suportuvmware_pillar -- port = %suvirtualuosuvmware esxiuesxit
property_nameuvim.uuavailableFielduannotationsuYUnable to obtain a connection with %s, please verify your vmware ext_pillar configurationu�A runtime error occurred in the vmware_pillar, this is likely caused by an infinite recursion in a requested attribute.  Verify your requested attributes and reconfigure the pillar.N(#tNoneRtlogterrortdebugt
isinstancetdicttappendtgetattrRtkeystlisttwarningtVirtualMachinet
__grains__tlowertsalttutilstvmwaretget_service_instancetget_mor_by_propertyttypet__name__treplacethasattrtavailableFieldtcustomValuetkeytvaluetnamet
dictupdatetupdatet_crawl_attributeRtRuntimeError(t	minion_idtpillartkwargst
vmware_pillarthosttusernametpasswordtproperty_typesR
tprotocoltportt
pillar_keytreplace_default_attributesttype_specific_pillar_attributestpillar_attributest	prop_typetvirtualgraintosgraint_conntdatat	type_nameR"R#ttype_specific_pillar_attribute((s=/usr/lib/python2.7/site-packages/salt/pillar/vmware_pillar.pyt
ext_pillar�sd





"










 


$
	
	&



cC@s�t|td��s�t|t�rRg}x!|D]}|jt|��q1W|St|t�r�i}x-tj|�D]\}}t|�||<qwW|St	|d�r�t|j
�St|�SndS(ua
    helper function to recurse through a vim object and attempt to return all child objects
    u__dict__N(RRRRRt_recurse_config_to_dictRRt	iteritemsR!t__dict__t_serializer(tt_datatt_listtitt_dicttktv((s=/usr/lib/python2.7/site-packages/salt/pillar/vmware_pillar.pyRA�s

cC@st|t�r@g}x$|D]}|jt||��qW|St|t�r�i}xC|D];}t||�r\tt||d�||�||<q\q\W|St|t�r�i}x)|D]!}tj	|t||��}q�W|Sit
t||d��|6SdS(uG
    helper function to crawl an attribute specified for retrieval
    N(RRRR)RR!RRR'R(RA(t	this_datat	this_attrRFtdRHRIt	this_dicttl((s=/usr/lib/python2.7/site-packages/salt/pillar/vmware_pillar.pyR)�s"

*
cC@sQddl}t||j�rM|j�dk	rC||j�}n|j�S|S(uG
    helper function to serialize some objects for prettier return
    iN(tdatetimeRt	utcoffsetRt__str__(tobjRP((s=/usr/lib/python2.7/site-packages/salt/pillar/vmware_pillar.pyRDs
(t__doc__t
__future__RRRtloggingtsalt.utils.dictupdateRR'tsalt.utils.vmwareRtsalt.extRtpyVmomiRt
pyVim.connectRtTrueRtImportErrorRRt	getLoggerRRR	R@RAR)RD(((s=/usr/lib/python2.7/site-packages/salt/pillar/vmware_pillar.pyt<module>�s&


		�)		

Zerion Mini Shell 1.0