File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/vmware.cpython-310.pyc
o
�N�g� � @ s� d Z ddlZddlZddlZddlZddlZddlmZ ddlZ ddl
Z ddlZ ddlZ ddl
Z zddlmZmZmZmZmZ ddlmZmZmZ dZW n eyW dZY nw zddlmZ dd lmZ dZW n eys dZY nw zddlZddl Z dZ!W n ey� dZ!Y nw e�"e#�Z$d
d� Z% d�dd
�Z& d�dd�Z' d�dd�Z(dd� Z)dd� Z* d�dd�Z+d�dd�Z,d�dd�Z-dd� Z.d d!� Z/d"d#� Z0d$d%� Z1d&d'� Z2d(d)� Z3d*d+� Z4d,d-� Z5d.d/� Z6d0d1� Z7d2d3� Z8d4d5� Z9d6d7� Z: d�d8d9�Z; : d�d;d<�Z< d�d=d>�Z=d?d@� Z>dAdB� Z?dCdD� Z@dEdF� ZAd�dGdH�ZBdIdJ� ZCd�dKdL�ZDdMdN� ZEdOdP� ZFd�dQdR�ZGdSdT� ZHdUdV� ZIdWdX� ZJdYdZ� ZKd�d[d\�ZLd�d]d^�ZMd_d`� ZNdadb� ZOd�dcdd�ZPd�dedf�ZQ d�dgdh�ZR d�didj�ZSdkdl� ZTd�dmdn�ZUdodp� ZVdqdr� ZWdsdt� ZXdudv� ZYdwdx� ZZdydz� Z[d{d|� Z\d}d~� Z]dd�� Z^ d�d�d��Z_d�d�� Z`d�d�d��Zad�d�� Zbd�d�� Zc d�d�d��Zdd�d�d��Zed�d�� Zf d�d�d��Zg d�d�d��Zhd�d�d��Zid�d�d��Zjd�d�d��Zkd�d�d��Zl d�d�d��Zmd�d�d��Znd�d�� Zod�d�d��Zp d�d�d��Zqd�d�� Zr d�d�d��Zsd�d�� Ztd�d�� Zud�d�� Zvd�d�� Zwd�d�� Zxd�d�� Zyd�d�� Zzd�d�d��Z{ d�d�d��Z|d�d�d��Z}d�d�dZ~d�dĄ Zd�d�dDŽZ� d�d�dɄZ�d�d�d˄Z�d�d̈́ Z�d�dτ Z�d�dф Z�dS )�an
Connection library for VMware
.. versionadded:: 2015.8.2
This is a base library used by a number of VMware services such as VMware
ESX, ESXi, and vCenter servers.
:codeauthor: Nitin Madhok <nmadhok@g.clemson.edu>
:codeauthor: Alexandru Bleotu <alexandru.bleotu@morganstanley.com>
Dependencies
~~~~~~~~~~~~
- pyVmomi Python Module
- ESXCLI: This dependency is only needed to use the ``esxcli`` function. No other
functions in this module rely on ESXCLI.
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==5.5.0.2014.1.1
The 5.5.0.2014.1.1 is a known stable version that this original VMware utils file
was developed against.
ESXCLI
------
This dependency is only needed to use the ``esxcli`` function. At the time of this
writing, no other functions in this module rely on ESXCLI.
The ESXCLI package is also referred to as the VMware vSphere CLI, or vCLI. VMware
provides vCLI package installation instructions for `vSphere 5.5`_ and
`vSphere 6.0`_.
.. _vSphere 5.5: http://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.vcli.getstart.doc/cli_install.4.2.html
.. _vSphere 6.0: http://pubs.vmware.com/vsphere-60/index.jsp#com.vmware.vcli.getstart.doc/cli_install.4.2.html
Once all of the required dependencies are in place and the vCLI package is
installed, you can check to see if you can connect to your ESXi host or vCenter
server by running the following command:
.. code-block:: bash
esxcli -s <host-location> -u <username> -p <password> system syslog config get
If the connection was successful, ESXCLI was successfully installed on your system.
You should see output related to the ESXi host's syslog configuration.
� N)�
BadStatusLine)�
Disconnect�GetSi�GetStub�SmartConnect�SoapStubAdapter)�VmomiSupport�vim�vmodlTF)�Unauthenticated)�create_vsphere_clientc C s t rdS dS )z,
Only load if PyVmomi is installed.
T)FzBMissing dependency: The salt.utils.vmware module requires pyVmomi.)�HAS_PYVMOMI� r r �E/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/vmware.py�__virtual__w s r c
C s� t jj�d�}|st�d� dS |du rd}|du rd}|r&|d|� d�7 }|s5|d �| |||||�7 }n
|d
�| ||||||�7 }t jjj |dd�} | S )
a(
Shell out and call the specified esxcli command, parse the result
and return something sane.
:param host: ESXi or vCenter host to connect to
:param user: User to connect as, usually root
:param pwd: Password to connect with
:param port: TCP port
:param cmd: esxcli command and arguments
:param esxi_host: If `host` is a vCenter host, then esxi_host is the
ESXi machine on which to execute this command
:param credstore: Optional path to the credential store file
:return: Dictionary
�esxclizJMissing dependency: The salt.utils.vmware.esxcli function requires ESXCLI.FN� �httpsz --credstore '�'z5 -s {} -u {} -p '{}' --protocol={} --portnumber={} {}z; -s {} -h {} -u {} -p '{}' --protocol={} --portnumber={} {}�quiet)Zoutput_loglevel)
�salt�utils�path�which�log�error�format�modulesZcmdmodZrun_all)
�host�user�pwd�cmd�protocol�portZ esxi_hostZ credstoreZesx_cmd�retr r r r � s* ���r c
C sb |st jjj||d�}d}zt| |||d�}W |S ty0 } zt�|� W Y d}~|S d}~ww )a�
Internal helper method to create an instance of the vSphere API client.
Please provide username and password to authenticate.
:param basestring server:
vCenter host name or IP address
:param basestring username:
Name of the user
:param basestring password:
Password of the user
:param Session session:
Request HTTP session instance. If not specified, one
is automatically created and used
:param boolean verify_ssl:
Verify the SSL certificate. Default: True
:param basestring ca_bundle:
Path to the ca bundle to use when verifying SSL certificates.
:returns:
Vsphere Client instance
:rtype:
:class:`vmware.vapi.vmc.client.VsphereClient`
)�
verify_ssl� ca_bundleN)�server�username�password�session)r r �httpr* r r r �trace)r'