HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/proxy/__pycache__/cimc.cpython-310.pyc
o

�N�g$�@s�dZddlZddlZddlmmZddlZdgZ	ddiZ
iZe�e
�ZdZdd�Zd!dd	�Zd
d�Zd"d
d�Zd#dd�Zdd�Zd!dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �ZdS)$a
Proxy Minion interface module for managing Cisco Integrated Management Controller devices
=========================================================================================

.. versionadded:: 2018.3.0

:codeauthor: ``Spencer Ervin <spencer_ervin@hotmail.com>``
:maturity:   new
:depends:    none
:platform:   unix

This proxy minion enables Cisco Integrated Management Controller devices (hereafter referred to
as simply 'cimc' devices to be treated individually like a Salt Minion.

The cimc proxy leverages the XML API functionality on the Cisco Integrated Management Controller.
The Salt proxy must have access to the cimc on HTTPS (tcp/443).

More in-depth conceptual reading on Proxy Minions can be found in the
:ref:`Proxy Minion <proxy-minion>` section of Salt's
documentation.


Configuration
=============

To use this integration proxy module, please configure the following:

Pillar
------

Proxy minions get their configuration from Salt's Pillar. Every proxy must
have a stanza in Pillar and a reference in the Pillar top-file that matches
the ID.

.. code-block:: yaml

    proxy:
      proxytype: cimc
      host: <ip or dns name of cimc host>
      username: <cimc username>
      password: <cimc password>
      verify_ssl: True

proxytype
^^^^^^^^^

The ``proxytype`` key and value pair is critical, as it tells Salt which
interface to load from the ``proxy`` directory in Salt's install hierarchy,
or from ``/srv/salt/_proxy`` on the Salt Master (if you have created your
own proxy module, for example). To use this cimc Proxy Module, set this to
``cimc``.

host
^^^^

The location, or ip/dns, of the cimc host. Required.

username
^^^^^^^^

The username used to login to the cimc host. Required.

password
^^^^^^^^

The password used to login to the cimc host. Required.
�NZcimc�vendorZCiscocCstS)z7
    Only return if all the modules are available.
    )�__virtualname__�rr�C/opt/saltstack/salt/lib/python3.10/site-packages/salt/proxy/cimc.py�__virtual__YsrcCs8t|�}|dvr|rt|�t�d|�tj�d��dS)N)Z200Z201Z202Z204z#Received error HTTP status code: %sz+Did not receive a valid response from host.)�str�logout�log�error�salt�
exceptions�CommandExecutionError)Zresponse_code_to_checkZcookie_to_logoutZformatted_response_coderrr�_validate_response_code`s��rcCs�t�d|�d|dvrt�d�dSd|dvr t�d�dSd|dvr-t�d	�dSd
�|dd�td<dd
dd�td<|ddtd<|d�d�td<|d�d�td<|d�d�}|durgd}|td<t�d�td�t�d�dtd<dS)z=
    This function gets called when the proxy starts up.
    z=== opts %s ===�host�proxyz-No 'host' key found in pillar for this proxy.F�usernamez1No 'username' key found in pillar for this proxy.�passwordz2No 'passwords' key found in pillar for this proxy.zhttps://{}/nuova�urlz!application/x-www-form-urlencoded�>zlwp-request/2.06)zContent-TypezContent-Lengthz
USER-Agent�headers�
verify_sslNTz)Attempting to connect to cimc proxy host.�computeRackUnitz*Successfully connected to cimc proxy host.�initialized)r	�debug�critical�format�DETAILS�get�get_config_resolver_class)�optsrrrr�initks4



�

r FcCs�i}t�}d}|dur
d}d�||||�}tdtd|dddtd	ddtd
d�	}t|d|�t�d
|d�d}t�|�}	t	|�|	D]	}
t
|
�||
j<qF|S)zp
    The configConfMo method configures the specified managed object in a single subtree (for example, DN).
    �falseT�truez\<configConfMo cookie="{}" inHierarchical="{}" dn="{}"><inConfig>{}</inConfig></configConfMo>�
http.queryr�POST�plainrr��data�method�decode_type�decoder�raise_error�statusrr,�(<[\s\S.]*>)�textr��logonr�	__utils__rr�re�findall�ET�
fromstringr�prepare_return�tag)�dnZinconfig�hierarchical�ret�cookie�h�payload�r�answer�items�itemrrr�set_config_modify�s4��
rBc
Cs�i}t�}d}|dur
d}d�|||�}tdtd|dddtd	ddtd
d�	}t|d|�t�d
|d�d}t�|�}t	|�|D]	}	t
|	�||	j<qE|S)zZ
    The configResolveClass method returns requested managed object in a given class.
    r!Tr"zB<configResolveClass cookie="{}" inHierarchical="{}" classId="{}"/>r#rr$r%rrr&r,r-r.rr/)
Zcidr9r:r;r<r=r>r?r@rArrrr�s6���
rcCs�i}d�tdtd�}tdtd|dddtd	d
dtdd�	}t|d
�t�d|d�d}t�|�}|jD]	}|j|||<q9d|vrMt	j
�d��|dS)zC
    Logs into the cimc device and returns the session cookie.
    z1<aaaLogin inName='{}' inPassword='{}'></aaaLogin>rrr#rr$r%TrFrr&r,r-r.rZ	outCookiez Unable to log into proxy device.)rrr1rr2r3r4r5�attribrrr
)�contentr=r>r?r@rArrrr0�s.��

r0c
Cs6d�|�}tdtd|dddtddtdd	�d
S)z-
    Closes the session with the device.
    z3<aaaLogout cookie="{0}" inCookie="{0}"></aaaLogout>r#rr$r%Trr)r'r(r)r*rr+rN)rr1r)r;r=rrrrs
�
rcCsXi}t|�D]}|j|vrg||j<||j�t|��q|jD]	}|j|||<q |S)z$
    Converts the etree to dict
    )�listr7�appendr6rC)�xr:�arrrr6s


r6cCst�dd�S)z�
    Since grains are loaded in many different places and some of those
    places occur before the proxy can be initialized, return whether
    our init() function has been called
    rF)rrrrrrr!src
Cs�t�di�sDttd<ztdd�}|ddtd<WtdStjjy*YtdStyC}zt�	|�WYd}~tdSd}~wwtdS)z0
    Get the grains from the proxied device
    �grains_cacherFZ
outConfigsN)
rr�GRAINS_CACHErrrr
�	Exceptionr	r
)Zcompute_rack�errrrr�grains*s
����rMcCsdtd<t�S)z4
    Refresh the grains from the proxied device
    NrI)rrMrrrr�grains_refresh:srNc
Cs\z
t�}t|�WdStjjyYdSty-}zt�|�WYd}~dSd}~ww)z>
    Returns true if the device is reachable, else false.
    FNT)r0rrrr
rKr	r)r;rLrrr�pingBs
�
��rOcCst�d�dS)z_
    Shutdown the connection to the proxy device. For this proxy,
    shutdown is a no-op.
    zCIMC proxy shutdown() called.N)r	rrrrr�shutdownQsrP)N)NNF)NF)�__doc__�loggingr2Zxml.etree.ElementTreeZetreeZElementTreer4Zsalt.exceptionsrZ__proxyenabled__rJr�	getLogger�__file__r	rrrr rBrr0rr6rrMrNrOrPrrrr�<module>s.D


'
&(
!