File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/ciscoconfparse_mod.cpython-310.pyc
Back
o ;j"; � @ s� d Z ddlmZ zddlZdZW n ey dZY nw dZdd� Zdd d�Zddd �Z ddd�Z ddd�Z ddd�Z ddd�Z ddd�Z ddd�ZdS )am Execution module for `ciscoconfparse <http://www.pennington.net/py/ciscoconfparse/index.html>`_ .. versionadded:: 2019.2.0 This module can be used for basic configuration parsing, audit or validation for a variety of network platforms having Cisco IOS style configuration (one space indentation), including: Cisco IOS, Cisco Nexus, Cisco IOS-XR, Cisco IOS-XR, Cisco ASA, Arista EOS, Brocade, HP Switches, Dell PowerConnect Switches, or Extreme Networks devices. In newer versions, ``ciscoconfparse`` provides support for brace-delimited configuration style as well, for platforms such as: Juniper Junos, Palo Alto, or F5 Networks. See http://www.pennington.net/py/ciscoconfparse/index.html for further details. :depends: ciscoconfparse This module depends on the Python library with the same name, ``ciscoconfparse`` - to install execute: ``pip install ciscoconfparse``. � )� SaltExceptionNTF�ciscoconfparsec C s t rt S dS )N)Fz!Missing dependency ciscoconfparse)�HAS_CISCOCONFPARSE� r r �S/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/ciscoconfparse_mod.py�__virtual__, s r �basec C sJ |rt d ||d�} | du rt|� d���t| t�r| �� } t�| �}|S )� zcp.get_file_str)�saltenvFz is not available)Z__salt__r � isinstance�str� splitlinesr ZCiscoConfParse)�config�config_pathr �ccpr r r �_get_ccp8 s r c C s t | ||d�}|�|�}|S )a� Return all the line objects that match the expression in the ``regex`` argument. .. warning:: This function is mostly valuable when invoked from other Salt components (i.e., execution modules, states, templates etc.). For CLI usage, please consider using :py:func:`ciscoconfparse.find_lines <salt.ciscoconfparse_mod.find_lines>` config The configuration sent as text. .. note:: This argument is ignored when ``config_path`` is specified. config_path The absolute or remote path to the file with the configuration to be parsed. This argument supports the usual Salt filesystem URIs, e.g., ``salt://``, ``https://``, ``ftp://``, ``s3://``, etc. regex The regular expression to match the lines against. saltenv: ``base`` Salt fileserver environment from which to retrieve the file. This argument is ignored when ``config_path`` is not a ``salt://`` URL. Usage example: .. code-block:: python objects = __salt__['ciscoconfparse.find_objects'](config_path='salt://path/to/config.txt', regex='Gigabit') for obj in objects: print(obj.text) �r r r )r �find_objects)r r �regexr r �linesr r r r I s & r c C s t | |||d�}dd� |D �S )a Return all the lines (as text) that match the expression in the ``regex`` argument. config The configuration sent as text. .. note:: This argument is ignored when ``config_path`` is specified. config_path The absolute or remote path to the file with the configuration to be parsed. This argument supports the usual Salt filesystem URIs, e.g., ``salt://``, ``https://``, ``ftp://``, ``s3://``, etc. regex The regular expression to match the lines against. saltenv: ``base`` Salt fileserver environment from which to retrieve the file. This argument is ignored when ``config_path`` is not a ``salt://`` URL. CLI Example: .. code-block:: bash salt '*' ciscoconfparse.find_lines config_path=https://bit.ly/2mAdq7z regex='ip address' Output example: .. code-block:: text cisco-ios-router: - ip address dhcp - ip address 172.20.0.1 255.255.255.0 - no ip address )r r r r c S � g | ]}|j �qS r ��text��.0�liner r r � <listcomp>� � zfind_lines.<locals>.<listcomp>)r )r r r r r r r r � find_linest s &�r c C �"