%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/states/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/states/esxvm.pyc

�
���^c@@sHdZddlmZmZmZddlZddlZddlZddl	j
jZddlm
Z
yddlZeZWnek
r�eZnXyddlmZeZWnek
r�eZnXeje�Zd�Zddddeeed�Zd�Zddded	�Zdddded
�Zed�ZdS(u�
Salt state to create, update VMware ESXi Virtual Machines.

Dependencies
============

- pyVmomi
- jsonschema

States
======

vm_configured
-------------

Enforces correct virtual machine configuration. Creates, updates and registers
a virtual machine.

This state identifies the action which should be taken for the virtual machine
and applies that action via the create, update, register state functions.

Supported proxies: esxvm


Example:

1. Get the virtual machine ``my_vm`` status with an ``esxvm`` proxy:

Proxy minion configuration for ``esxvm`` proxy:

.. code-block:: yaml

    proxy:
      proxytype: esxvm
      datacenter: my_dc
      vcenter: vcenter.fake.com
      mechanism: sspi
      domain: fake.com
      principal: host

State configuration:

.. code-block:: yaml

      myvm_state:
        esxvm.vm_configured:
        - vm_name: my_vm
        - cpu: {{ {'count': 4, 'cores_per_socket': 2} }}
        - memory: {{ {'size': 16384, 'unit': 'MB'} }}
        - image: rhel7_64Guest
        - version: vmx-12
        - interfaces: {{ [{
                           'adapter': 'Network adapter 1',
                           'name': 'my_pg1',
                           'switch_type': 'distributed',
                           'adapter_type': 'vmxnet3',
                           'mac': '00:50:56:00:01:02,
                           'connectable': { 'start_connected': true,
                                            'allow_guest_control': true,
                                            'connected': true}},
                           {
                           'adapter': 'Network adapter 2',
                           'name': 'my_pg2',
                           'switch_type': 'distributed',
                           'adapter_type': 'vmxnet3',
                           'mac': '00:50:56:00:01:03',
                           'connectable': { 'start_connected': true,
                                            'allow_guest_control': true,
                                            'connected': true}}
                      ] }}
        - disks: {{ [{
                      'adapter': 'Hard disk 1',
                      'unit': 'MB',
                      'size': 51200,
                      'filename': 'my_vm/sda.vmdk',
                      'datastore': 'my_datastore',
                      'address': '0:0',
                      'thin_provision': true,
                      'eagerly_scrub': false,
                      'controller': 'SCSI controller 0'},
                      {
                      'adapter': 'Hard disk 2',
                      'unit': 'MB',
                      'size': 10240,
                      'filename': 'my_vm/sdb.vmdk',
                      'datastore': 'my_datastore',
                      'address': '0:1',
                      'thin_provision': true,
                      'eagerly_scrub': false,
                      'controller': 'SCSI controller 0'}
                ] }}
        - scsi_devices: {{ [{
                             'adapter': 'SCSI controller 0',
                             'type': 'paravirtual',
                             'bus_sharing': 'no_sharing',
                             'bus_number': 0}
                            ] }}
        - serial_ports: {{ [{
                             'adapter': 'Serial port 1',
                             'type': 'network',
                             'yield': false,
                             'backing': {
                                         'uri': 'my_uri',
                                         'direction': 'server',
                                         'filename': 'my_file'},
                              'connectable': {
                                              'start_connected': true,
                                              'allow_guest_control': true,
                                              'connected': true}}
                             ] }}
        - datacenter: {{ 'my_dc' }}
        - datastore: 'my_datastore'
        - placement: {{ {'cluster': 'my_cluster'} }}
        - cd_dvd_drives: {{ [] }}
        - advanced_configs: {{ {'my_param': '1'} }}
        - template: false
        - tools: false
        - power_on: false
        - deploy: false


vm_updated
----------

Updates a virtual machine to a given configuration.

vm_created
----------

Creates a virtual machine with a given configuration.

vm_registered
-------------

Registers a virtual machine with it's configuration file path.

Dependencies
============

pyVmomi
-------

PyVmomi can be installed via pip:

.. code-block:: bash

    pip install pyVmomi

.. note::

    Version 6.0 of pyVmomi has some problems with SSL error handling on
    certain versions of Python. If using version 6.0 of pyVmomi, Python 2.6,
    Python 2.7.9, or newer must be present. This is due to an upstream
    dependency in pyVmomi 6.0 that is not supported in Python versions
    2.7 to 2.7.8. If the version of Python is not in the supported range,
    you will need to install an earlier version of pyVmomi.
    See `Issue #29537`_ for more information.

.. _Issue #29537: https://github.com/saltstack/salt/issues/29537

Based on the note above, to install an earlier version of pyVmomi than the
version currently listed in PyPi, run the following:

.. code-block:: bash

    pip install pyVmomi==6.0.0.2016.4

The 5.5.0.2014.1.1 is a known stable version that this original ESXi State
Module was developed against. To be able to connect through SSPI you must
use pyvmomi 6.0.0.2016.4 or above. The ESXVM State Module was tested with
this version.

About
-----

This state module was written to be used in conjunction with Salt's
:mod:`ESXi Proxy Minion <salt.proxy.esxi>` For a tutorial on how to use Salt's
ESXi Proxy Minion, please refer to the
:ref:`ESXi Proxy Minion Tutorial <tutorial-esxi-proxy>` for
configuration examples, dependency installation instructions, how to run remote
execution functions against ESXi hosts via a Salt Proxy Minion, and a larger state
example.
i(tabsolute_importtprint_functiontunicode_literalsN(tESXVirtualMachineConfigSchema(tVmomiSupportcC@s[tstdfSts tdfSdtjkrWtjdkrWtjd	krWtdfStS(
Nu/State module did not load: jsonschema not foundu,State module did not load: pyVmomi not foundu	vim25/6.0iii	uaState module did not load: Incompatible versions of Python and pyVmomi present. See Issue #29537.(ii(iii	(tHAS_JSONSCHEMAtFalsetHAS_PYVMOMIRt
versionMaptsystversion_infotTrue(((s5/usr/lib/python2.7/site-packages/salt/states/esxvm.pyt__virtual__�s


cC@s�i|d6d'd6id6dd6}tjd�tj�}tjd|�y�tji|d6|d	6|d
6|d6|d6|d
6|d6|d6|	d6|
d6|d6|
d6|d6|d6|d6|d6|d6|d6|�Wn+tjjk
r
}t	jj
|��nXtd�}y!td|ddgd|�Wn(t	jjk
rctd||
||d|�}|r�t
dr�|jid j|�d6�td!|�|St||
||d"|�}|St
dr|jid#j|�d6�td!|�|S|rt|�}nBt||||||||||	|
||d$|
d%|d"|�
}|SnXt||||||||||	|
|d$|
d&|d%|d"|�}td!|�tj|�|S((u�
    Selects the correct operation to be executed on a virtual machine, non
    existing machines will be created, existing ones will be updated if the
    config differs.
    unameuresultuchangesuucommentu(Validating virtual machine configurationuschema = %suvm_nameucpuumemoryuimageuversionu
interfacesudisksuscsi_devicesuserial_portsu
cd_dvd_drivesusata_controllersu
datacenteru	datastoreu	placementutemplateutoolsupower_onudeployu&vsphere.get_service_instance_via_proxyuvsphere.get_vmt
vm_propertiestservice_instanceuvsphere.get_vm_config_fileutestu+The virtual machine {0} will be registered.uvsphere.disconnecttpower_onu(The virtual machine {0} will be created.t
cd_dvd_drivestadvanced_configstsata_controllersN(tNonetlogttraceRt	serializet
jsonschematvalidatet
exceptionstValidationErrortsalttInvalidConfigErrort__salt__tVMwareObjectRetrievalErrort__opts__tupdatetformatt
vm_registeredt	vm_clonedt
vm_createdt
vm_updated(tnametvm_nametcputmemorytimagetversiont
interfacestdiskstscsi_devicestserial_portst
datacentert	datastoret	placementRRRttemplatettoolsRtdeploytresulttschematexcRtvm_file((s5/usr/lib/python2.7/site-packages/salt/states/esxvm.pyt
vm_configured�s�




		

					
cC@s&i|d6td6id6dd6}|S(uu
    Clones a virtual machine from a template virtual machine if it doesn't
    exist and a template is defined.
    unameuresultuchangesuucomment(R(R&R6((s5/usr/lib/python2.7/site-packages/salt/states/esxvm.pyR#;s


cC@s
i|d6d'd6id6dd6}td�}td|d|
d	td
|�}tdi|d6|d6|d
6|d6|d6|d6|d6|d6|	d6|
d6|d6|d6|
d6|d6|�}|s�|jitd6id6dj|�d6�|Stdr�dj||
djgtj	|�D]$\}}dj||j
g�^q'��}|jid'd6|d6�td|�|SyJtd|||||||||	|
|d |d!|
d"|d
|�}Wnetjj
k
r5}tjd#|�|r
td|�n|jitd6tj|�d6�|SX|r�ytd$||
�Wnetjjk
r�}tjd#|�|r�td|�n|jitd6tj|�d6�|SX|jitd%6�ntd|�i|d6td6|d6d&j|�d6}|S((u|
    Updates a virtual machine configuration if there is a difference between
    the given and deployed configuration.
    unameuresultuchangesuucommentu&vsphere.get_service_instance_via_proxyuvsphere.get_vm_configR0tobjectsRuvsphere.compare_vm_configsucpuumemoryuimageuversionu
interfacesudisksuscsi_devicesuserial_portsu
datacenteru	datastoreu	cd_drivesusata_controllersuadvanced_configsu)Virtual machine {0} is already up to dateutestuKState vm_updated will update virtual machine '{0}' in datacenter '{1}':
{2}u
u:
uvsphere.disconnectuvsphere.update_vmRRRu	Error: %suvsphere.power_on_vmupower_onu,Virtual machine {0} was updated successfullyN(RRRR RR!Rtjointsixt	iteritemstchanges_strRRtCommandExecutionErrorRterrort	text_typetVMwarePowerOnError(R&R'R(R)R*R+R,R-R.R/R0R1RRRRR6Rtcurrent_configtdiffstkeyt
differencetcommenttchangesR8((s5/usr/lib/python2.7/site-packages/salt/states/esxvm.pyR%Hs�


	
		
	=		
		

cC@s�i|d6dd6id6dd6}tdrCdj|�|d<|Std�}yVtd	||||||
|||||d
|	d|
d|d
|d|d|�}Wnetjjk
r
}tjd|�|r�td|�n|j	it
d6tj|�d6�|SX|r�ytd||
d|�Wnetjj
k
r�}tjd|�|rntd|�n|j	it
d6tj|�d6�|SX||d<ni|d6|d6}td|�i|d6td6|d6dj|�d6}|S(uR
    Creates a virtual machine with the given properties if it doesn't exist.
    unameuresultuchangesuucommentutestu#Virtual machine {0} will be createdu&vsphere.get_service_instance_via_proxyuvsphere.create_vmR/tide_controllersRt	cd_drivesRRu	Error: %suvsphere.disconnectuvsphere.power_on_vmupower_onuinfou(Virtual machine {0} created successfullyN(RRR!RRRR@RRAR RR=RBRCR(R&R'R(R)R*R+R,R-R.R/R0R1R2RJRRRRR6RtinfoR8RI((s5/usr/lib/python2.7/site-packages/salt/states/esxvm.pyR$�sb




		
		


c	C@s(i|d6dd6id6dd6}dj|j|jdj�}tjdj|��td	�}y!td
||||d|�Wn�tj	j
k
r�}tjd|�|r�td
|�n|jit
d6tj|�d6�|Stj	jk
rP}tjd|�|r(td
|�n|jit
d6tj|�d6�|SX|r�ytd||d|�Wq�tj	jk
r�}tjd|�|r�td
|�n|jit
d6tj|�d6�|SXntd
|�|jitd6i|d6|d6d6dj|�d6�|S(uc
    Registers a virtual machine if the machine files are available on
    the main datastore.
    unameuresultuchangesuucommentu{0}{1}iu.Registering virtual machine with vmx file: {0}u&vsphere.get_service_instance_via_proxyuvsphere.register_vmRu	Error: %suvsphere.disconnectuvsphere.power_on_vmupower_onu+Virtual machine {0} registered successfullyN(RR!t
folderPathtfiletpathRRRRRtVMwareMultipleObjectsErrorRAR RR=RBtVMwareVmRegisterErrorRCR(	R'R0R2R9RR6tvmx_pathRR8((s5/usr/lib/python2.7/site-packages/salt/states/esxvm.pyR"�sV



		( t__doc__t
__future__RRRR	tloggingtsalt.exceptionsRtsalt.ext.sixtextR=tsalt.config.schemas.esxvmRRRRtImportErrorRtpyVmomiRRt	getLoggert__name__RRRR:R#R%R$R"(((s5/usr/lib/python2.7/site-packages/salt/states/esxvm.pyt<module>�s6





		T	_<

Zerion Mini Shell 1.0