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/utils/__pycache__/nxos.cpython-310.pyc
o

�N�g�3�@s�dZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlZddl
mZmZmZmZddlmZe�e�ZGdd�dejj�ZGdd	�d	�Zddd�Zd
d�Zdd�Zdd�Zdd�Zdd�Z dd�Z!dd�Z"dS)z&
Util functions for the NXOS modules.
�N)�Iterable)�CommandExecutionError�NxosClientError�	NxosError�NxosRequestNotSupported)�clean_kwargsc@s eZdZdZdd�Zdd�ZdS)�UHTTPConnectionzS
    Subclass of Python library HTTPConnection that uses a unix-domain socket.
    cCstjj�|d�||_dS)NZ	localhost)�http�client�HTTPConnection�__init__�path)�selfr
�r�C/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/nxos.pyr-s
zUHTTPConnection.__init__cCs&t�tjtj�}|�|j�||_dS)N)�socket�AF_UNIX�SOCK_STREAM�connectr
�sock)rrrrrr1s
zUHTTPConnection.connectN)�__name__�
__module__�__qualname__�__doc__rrrrrrr(src@sPeZdZdZdZdZdZdZdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dS)�NxapiClientzi
    Class representing an NX-API client that connects over http(s) or
    unix domain socket (UDS).
    z&/tmp/nginx_local/nginx_1_be_nxapi.sockz/insz
/ins_localz1.0cKs�|�td	i|���|_|jdr4tj�|j�s td|j�d���t�	d|j�t�	d�t
|j�|_dSt�	d|j�t�	d|jd�tj
jj|_dS)
a�
        Initialize NxapiClient() connection object.  By default this connects
        to the local unix domain socket (UDS).  If http(s) is required to
        connect to a remote device then
            nxos_kwargs['host'],
            nxos_kwargs['username'],
            nxos_kwargs['password'],
            nxos_kwargs['transport'],
            nxos_kwargs['port'],
        parameters must be provided.
        �connect_over_udsz&No host specified and no UDS found at �
zNxapi connection arguments: %sz"Connecting over unix domain socketzConnecting over %s�	transportNr)�_prepare_conn_argsr�nxargs�osr
�exists�	NXAPI_UDSr�log�infor�
connection�salt�utilsr	�query)rZnxos_kwargsrrrrEs
�
zNxapiClient.__init__cCsV|�d�|d<|�d�|d<|�d�|d<|ddus'|ddus'|ddur)dSdS)z<
        Determine if connection is local or remote
        �host�username�passwordNFT)�get�r�kwargsrrr�_use_remote_connectioncsz"NxapiClient._use_remote_connectioncCs�d|d<|�dd�|d<|�dd�|d<|�|�rX|�dd�|d<|ddkr0|�d	d
�|d	<n|�d	d�|d	<|�dd�|d<t|dt�rN|d|d
<n|d|d<d|d<|S)zJ
        Set connection arguments for remote or local connection.
        Tr�timeout�<�cookieZadminr�https�porti��PZverifyZ
verify_sslZ	ca_bundleF)r,r/�
isinstance�boolr-rrrrss
zNxapiClient._prepare_conn_argscCsi}ddi}|jdr|jd}d|d|d<|j|d<ndj|jd	|jd
|jd|jd�|d<t|tttf�r@d
�|�}i}t	�
�|d<|j|dd<||dd<d|dd<d|dd<||dd<d|dd<||d<t�
|�|d<d|jdi|d<t�d|�|S)z,
        Build NX-API JSON request.
        zcontent-typezapplication/jsonrr2znxapi_auth=z:local�urlz {transport}://{host}:{port}{uri}rr)r4)rr)r4Zuriz ; �ins_api�version�type�0�chunk�1Zsid�input�jsonZ
output_format�headers�payloadZhttp_request_timeoutr0�optszrequest: %s)r�NXAPI_UDS_URI_PATH�format�NXAPI_REMOTE_URI_PATHr6�list�set�tuple�join�collections�OrderedDict�
NXAPI_VERSIONr@�dumpsr#r$)rr;�commands�requestrA�userrBrrr�_build_request�s8�


�
zNxapiClient._build_requestc	Cs~|�||�}|jdr |j�d|d|d|d�|j��}n|j|dfd|d|d|dddd	�|j��}|�||�S)
z?
        Send NX-API JSON request to the NX-OS device.
        r�POSTr8rBrArCTr@)�methodrC�dataZheader_dict�decodeZdecode_type)rRrr%rP�getresponse�parse_response)rr;�command_listZreq�responserrrrP�s"
���zNxapiClient.requestcCs�t|t�rd|vrt|d�dkrt|���td|����t|t�r'|d}n|}|jdr8t�|���d��}|�	d�}|durHt
d	|����|�	d
�rQ|d
}|�	d�rZ|d}g}g}t|t�sf|g}t|t�sn|g}t|�dkr�d
|dvr�dd�|d�
d
�D�}t||�D]Q\}}|�	d�}	|�	d�}
t�d|�t�d|	|
�|	dkr�t||	|
|�	d�|d���|	dkr�td|
����|	dkr�td|
�d|	����|�|�|�|d�q�|S)zC
        Parse NX-API JSON response from the NX-OS device.
        �statusi�zNX-API Request Not Supported: �dictrzutf-8r9NzUnexpected JSON output
Zoutputs�output��;rcSsg|]}|���qSr)�strip)�.0�cmdrrr�
<listcomp>�sz.NxapiClient.parse_response.<locals>.<listcomp>�code�msgzcommand %s:zPARSE_RESPONSE: %s %sZ400Zclierror)Zrejected_inputrd�messageZ	cli_error�previous_commandsZ413zError 413: Z200zUnknown Error: z, Code: �body)r6r�intrrr@�loads�readrVr,rrG�len�split�zipr#r$rr�append)rrZrYrhr]�resultrgZ
cmd_resultrbrdrerrrrX�sZ










��	
zNxapiClient.parse_responseN)rrrrr"rFrDrMrr/rrRrPrXrrrrr7s(r�cli_showcKstdi|��}|�||�S)aX
    Send exec and config commands to the NX-OS device over NX-API.

    commands
        The exec or config commands to be sent.

    method:
        ``cli_show_ascii``: Return raw test or unstructured output.
        ``cli_show``: Return structured output.
        ``cli_conf``: Send configuration commands to the device.
        Defaults to ``cli_show``.

    transport: ``https``
        Specifies the type of connection transport to use. Valid values for the
        connection are ``http``, and  ``https``.

    host: ``localhost``
        The IP address or DNS host name of the device.

    username: ``admin``
        The username to pass to the device to authenticate the NX-API connection.

    password
        The password to pass to the device to authenticate the NX-API connection.

    port
        The TCP port of the endpoint for the NX-API connection. If this keyword is
        not specified, the default value is automatically determined by the
        transport type (``80`` for ``http``, or ``443`` for ``https``).

    timeout: ``60``
        Time in seconds to wait for the device to respond. Default: 60 seconds.

    verify: ``True``
        Either a boolean, in which case it controls whether we verify the NX-API
        TLS certificate, or a string, in which case it must be a path to a CA bundle
        to use. Defaults to ``True``.
    Nr�rrP)rOrTr.r
rrr�
nxapi_requests'rscKstdi|��jdS)z9
    Verify connection to the NX-OS device over UDS.
    rNr)rr)r.rrr�ping9srtcCst�d|�d�tj�S)N�^z
(?:^[ 
].*$
?)+)�re�compile�	MULTILINE)�blockrrr�_parserCsrzcC�Zdii}td��|��d�}t�dtj�}|�|�D]}|��\}}||d|<q|dS)zF
    Internal helper function to parse sotware grain information.
    �softwareZSoftwarerz^  ([^:]+): *([^
]+)�rz�search�grouprvrwrx�finditer�groups)rU�retr|�matcher�line�key�valrrr�_parse_softwareG�r�cCr{)zG
    Internal helper function to parse hardware grain information.
    �hardwareZHardwarerz^  ([^:
]+): *([^
]+)r})rUr�r�r�r�r�r�rrr�_parse_hardwareTr�r�cCsTdgi}td��|��d�}t�dtj�}|�|�D]}|d�|���q|dS)zE
    Internal helper function to parse plugin grain information.
    �pluginsZpluginrz^  (?:([^,]+), )+([^
]+))	rzr~rrvrwrxr��extendr�)rUr�r�r�r�rrr�_parse_pluginsasr�cCst�}|�dd�dS)NZcli_show_asciizshow versionrrr)r
rrr�version_infomsr�cCs(|siSt|�t|�t|�d�}d|iS)zY
    Helper method to return parsed system_info
    from the 'show version' command.
    )r|r�r�Znxos)r�r�r�)rUr$rrr�system_infors�r�)rq)#rrK�http.clientr	r@�loggingr rvr�collections.abcrZsalt.utils.httpr&Zsalt.exceptionsrrrrZsalt.utils.argsr�	getLoggerrr#r
rrrrsrtrzr�r�r�r�r�rrrr�<module>s0

X+