%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3.9/site-packages/ansible/plugins/netconf/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3.9/site-packages/ansible/plugins/netconf/__pycache__/__init__.cpython-39.pyc

a

�)g�B�
@s ddlmZmZmZeZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZddlmZz,ddlmZdd	lmZmZmZd
ZdZWn,ey�ZzdZeZWYdZ[n
dZ[00zdd
lmZmZmZm Z Wn,e!�ydd
l"mZmZmZm Z Yn0dd�Z#Gdd�de
�Z$dS)�)�absolute_import�division�print_function)�abstractmethod��wraps)�AnsibleError)�
AnsiblePlugin)�	to_native)�missing_required_lib)�RPCError)�to_xml�to_ele�	NCElementTNF)�Element�
SubElement�tostring�
fromstringcst���fdd��}|S)Ncs2tstdtd�tt�f���|g|�Ri|��S)Nz%s: %sZncclient)�HAS_NCCLIENTrrr
�NCCLIENT_IMP_ERR)�self�args�kwargs��func��D/usr/lib/python3.9/site-packages/ansible/plugins/netconf/__init__.py�wrapped1sz ensure_ncclient.<locals>.wrappedr)rrrrr�ensure_ncclient0srcs�eZdZdZgd�Z�fdd�Zedd��Zdd�Zd3d
d�Z	d4dd
�Z
d5dd�Zd6dd�Zdd�Z
d7dd�Zd8dd�Zd9dd�Zdd�Zd:dd �Zd;d!d"�Zd#d$�Zd%d&�Zed'd(��Zed)d*��Zd+d,�Zd-d.�Zd/d0�Zd1d2�Z�ZS)<�NetconfBasea]	
    A base class for implementing Netconf connections

    .. note:: Unlike most of Ansible, nearly all strings in
        :class:`TerminalBase` plugins are byte strings.  This is because of
        how close to the underlying platform these plugins operate.  Remember
        to mark literal strings as byte string (``b"string"``) and to use
        :func:`~ansible.module_utils._text.to_bytes` and
        :func:`~ansible.module_utils._text.to_text` to avoid unexpected
        problems.

        List of supported rpc's:
            :get: Retrieves running configuration and device state information
            :get_config: Retrieves the specified configuration from the device
            :edit_config: Loads the specified commands into the remote device
            :commit: Load configuration from candidate to running
            :discard_changes: Discard changes to candidate datastore
            :validate: Validate the contents of the specified configuration.
            :lock: Allows the client to lock the configuration system of a device.
            :unlock: Release a configuration lock, previously obtained with the lock operation.
            :copy_config: create or replace an entire configuration datastore with the contents of another complete
                          configuration datastore.
            :get-schema: Retrieves the required schema from the device
            :get_capabilities: Retrieves device information and supported rpc methods

            For JUNOS:
            :execute_rpc: RPC to be execute on remote device
            :load_configuration: Loads given configuration on device

        Note: rpc support depends on the capabilities of remote device.

        :returns: Returns output received from remote device as byte string
        Note: the 'result' or 'error' from response should to be converted to object
              of ElementTree using 'fromstring' to parse output as xml doc

              'get_capabilities()' returns 'result' as a json string.

            Usage:
            from ansible.module_utils.connection import Connection

            conn = Connection()
            data = conn.execute_rpc(rpc)
            reply = fromstring(reply)

            data = conn.get_capabilities()
            json.loads(data)

            conn.load_configuration(config=[''set system ntp server 1.1.1.1''], action='set', format='text')
    )�rpc�
get_config�get�edit_config�validate�copy_config�dispatch�lock�unlock�discard_changes�commit�
get_schema�
delete_config�get_device_operationscstt|���||_dS�N)�superr�__init__�_connection)rZ
connection��	__class__rrr0oszNetconfBase.__init__cCs|jjSr.)r1Zmanager�rrrr�mssz
NetconfBase.mc
Cshz,t|�}|j�|�}t|d�r&|jn|jWStyb}z|j}tt|���WYd}~n
d}~00dS)z�
        RPC to be execute on remote device
        :param name: Name of rpc in string format
        :return: Received rpc response from remote host
        �data_xmlN)	rr5r �hasattrr6�xmlr�	Exceptionr
)r�name�obj�resp�exc�msgrrrr wszNetconfBase.rpcNcCs@t|t�rt|�}|sd}|jj||d�}t|d�r:|jS|jS)a�
        Retrieve all or part of a specified configuration
        (by default entire configuration is retrieved).
        :param source: Name of the configuration datastore being queried, defaults to running datastore
        :param filter: This argument specifies the portion of the configuration data to retrieve
        :return: Returns xml string containing the RPC response received from remote host
        �running��source�filterr6)�
isinstance�list�tupler5r!r7r6r8)rrArBr<rrrr!�s
zNetconfBase.get_configcCs<t|t�rt|�}|jj||d�}t|d�r2|jn|j}|S)a�
        Retrieve device configuration and state information.
        :param filter: This argument specifies the portion of the state data to retrieve
                       (by default entire state data is retrieved)
        :param with_defaults: defines an explicit method of retrieving default values
                              from the configuration
        :return: Returns xml string containing the RPC response received from remote host
        )rB�
with_defaultsr6)rCrDrEr5r"r7r6r8)rrBrFr<Zresponserrrr"�s
	
zNetconfBase.getr8�	candidatecCs>|durtd��|jj||||||d�}t|d�r8|jS|jS)a�
        Loads all or part of the specified *config* to the *target* configuration datastore.
        :param config: Is the configuration, which must be rooted in the `config` element.
                       It can be specified either as a string or an :class:`~xml.etree.ElementTree.Element`.
        :param format: The format of configuration eg. xml, text
        :param target: Is the name of the configuration datastore being edited
        :param default_operation: If specified must be one of { `"merge"`, `"replace"`, or `"none"` }
        :param test_option: If specified must be one of { `"test_then_set"`, `"set"` }
        :param error_option: If specified must be one of { `"stop-on-error"`, `"continue-on-error"`, `"rollback-on-error"` }
                             The `"rollback-on-error"` *error_option* depends on the `:rollback-on-error` capability.
        :return: Returns xml string containing the RPC response received from remote host
        Nzconfig value must be provided)�format�target�default_operation�test_option�error_optionr6)�
ValueErrorr5r#r7r6r8)rZconfigrHrIrJrKrLr<rrrr#�s
�zNetconfBase.edit_configcCs$|jj|d�}t|d�r|jS|jS)aS
        Validate the contents of the specified configuration.
        :param source: Is the name of the configuration datastore being validated or `config` element
                       containing the configuration subtree to be validated
        :return: Returns xml string containing the RPC response received from remote host
        )rAr6)r5r$r7r6r8)rrAr<rrrr$�szNetconfBase.validatecCs$|j�||�}t|d�r|jS|jS)a
        Create or replace an entire configuration datastore with the contents of another complete configuration datastore.
        :param source: Is the name of the configuration datastore to use as the source of the copy operation or `config`
                       element containing the configuration subtree to copy
        :param target: Is the name of the configuration datastore to use as the destination of the copy operation
        :return: Returns xml string containing the RPC response received from remote host
        r6)r5r%r7r6r8)rrArIr<rrrr%�szNetconfBase.copy_configcCsZ|durtd��|jjt|�||d�}t|t�r8|j}nt|d�rP|jrP|j}n|j	}|S)a�
        Execute rpc on the remote device eg. dispatch('clear-arp-table')
        :param rpc_command: specifies rpc command to be dispatched either in plain text or in xml element format (depending on command)
        :param source: name of the configuration datastore being queried
        :param filter: specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)
        :return: Returns xml string containing the RPC response received from remote host
        Nz"rpc_command value must be providedr@�data_ele)
rMr5r&rrCrr6r7rNr8)rZrpc_commandrArBr<�resultrrrr&�s
zNetconfBase.dispatchcCs$|jj|d�}t|d�r|jS|jS)a.
        Allows the client to lock the configuration system of a device.
        :param target: is the name of the configuration datastore to lock,
                        defaults to candidate datastore
        :return: Returns xml string containing the RPC response received from remote host
        �rIr6)r5r'r7r6r8�rrIr<rrrr'�szNetconfBase.lockcCs$|jj|d�}t|d�r|jS|jS)a:
        Release a configuration lock, previously obtained with the lock operation.
        :param target: is the name of the configuration datastore to unlock,
                       defaults to candidate datastore
        :return: Returns xml string containing the RPC response received from remote host
        rPr6)r5r(r7r6r8rQrrrr(�szNetconfBase.unlockcCs |j��}t|d�r|jS|jS)z�
        Revert the candidate configuration to the currently running configuration.
        Any uncommitted changes are discarded.
        :return: Returns xml string containing the RPC response received from remote host
        r6)r5r)r7r6r8)rr<rrrr)�s
zNetconfBase.discard_changesFcCs(|jj|||d�}t|d�r"|jS|jS)az
        Commit the candidate configuration as the device's new current configuration.
        Depends on the `:candidate` capability.
        A confirmed commit (i.e. if *confirmed* is `True`) is reverted if there is no
        followup commit within the *timeout* interval. If no timeout is specified the
        confirm timeout defaults to 600 seconds (10 minutes).
        A confirming commit may have the *confirmed* parameter but this is not required.
        Depends on the `:confirmed-commit` capability.
        :param confirmed: whether this is a confirmed commit
        :param timeout: specifies the confirm timeout in seconds
        :param persist: make the confirmed commit survive a session termination,
                        and set a token on the ongoing confirmed commit
        :return: Returns xml string containing the RPC response received from remote host
        )�	confirmed�timeout�persistr6)r5r*r7r6r8)rrRrSrTr<rrrr*szNetconfBase.commitcCs(|jj|||d�}t|d�r"|jS|jS)ae
        Retrieve a named schema, with optional revision and type.
        :param identifier: name of the schema to be retrieved
        :param version: version of schema to get
        :param format: format of the schema to be retrieved, yang is the default
        :return: Returns xml string containing the RPC response received from remote host
        )�versionrHr6)r5r+r7r6r8)rZ
identifierrUrHr<rrrr+szNetconfBase.get_schemacCs"|j�|�}t|d�r|jS|jS)z�
        delete a configuration datastore
        :param target: specifies the  name or URL of configuration datastore to delete
        :return: Returns xml string containing the RPC response received from remote host
        r6)r5r,r7r6r8rQrrrr,!szNetconfBase.delete_configcCs|j�|�Sr.)r5�locked)rrIrrrrV*szNetconfBase.lockedcCsdS)z�
        Retrieves device information and supported
        rpc methods by device platform and return result
        as a string
        :return: Netconf session capability
        Nrr4rrr�get_capabilities-szNetconfBase.get_capabilitiescCsdS)z�
        Identifies the operating system of network device.
        :param obj: ncclient manager connection instance
        :return: The name of network operating system.
        Nr)r;rrr�guess_network_os7szNetconfBase.guess_network_oscCs|jS)zs
        Returns list of base rpc method supported by remote device
        :return: List of RPC supported
        )�__rpc__r4rrr�get_base_rpc@szNetconfBase.get_base_rpccCsdS)z�
        Copies file to remote host
        :param source: Source location of file
        :param destination: Destination file path
        :return: Returns xml string containing the RPC response received from remote host
        Nr�rrAZdestinationrrr�put_fileGszNetconfBase.put_filecCsdS)z�
        Fetch file from remote host
        :param source: Source location of file
        :param destination: Source location of file
        :return: Returns xml string containing the RPC response received from remote host
        Nrr[rrr�
fetch_filePszNetconfBase.fetch_filecCs�i}d�|�}d|v|d<d|v|d<d|v|d<d|v|d	<d
|v|d<d|v|d
<d|v|d<g|d<|d
r�|d�d�|dr�|d�d�|d	r�|d�d�t|d�|d<|S)z�
        Retrieve remote host capability from Netconf server hello message.
        :param server_capabilities: Server capabilities received during Netconf session initialization
        :return: Remote host capabilities in dictionary format
        �
z
:candidateZsupports_commitz:with-defaultsZsupports_defaultsz:confirmed-commitZsupports_confirm_commitz:startupZsupports_startupz:xpathZsupports_xpathz:writable-runningZsupports_writable_runningz	:validateZsupports_validateZlock_datastorer?rGZstartupZ
supports_lock)�join�append�bool)rZserver_capabilitiesZ
operationsZcapabilitiesrrrr-Ys$
z!NetconfBase.get_device_operations)NN)NN)Nr8rGNNN)rG)NNN)rG)rG)FNN)NNN)�__name__�
__module__�__qualname__�__doc__rYr0�propertyr5r r!r"r#r$r%r&r'r(r)r*r+r,rVrrW�staticmethodrXrZr\r]r-�
__classcell__rrr2rr9s62










	

	
	
		r)%Z
__future__rrr�typeZ
__metaclass__�abcr�	functoolsrZansible.errorsrZansible.pluginsr	Zansible.module_utils._textr
Zansible.module_utils.basicrZncclient.operationsrZ
ncclient.xml_r
rrrrr9�errZ
lxml.etreerrrr�ImportErrorZxml.etree.ElementTreerrrrrr�<module>s*	

Zerion Mini Shell 1.0