%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/modules/textfsm_mod.pyo

�
���^c@@s6dZddlmZddlZddlZyddlZeZWnek
r]e	ZnXyddl
Z
eZWnek
r�e	ZnXyddlm
Z
Wn!ek
r�ddlm
Z
nXeje�ZdZdgZd�Zd�Zddd	d
�Zdddddddd	e	ddd�ZdS(s�
TextFSM
=======

.. versionadded:: 2018.3.0

Execution module that processes plain text and extracts data
using TextFSM templates. The output is presented in JSON serializable
data, and can be easily re-used in other modules, or directly
inside the renderer (Jinja, Mako, Genshi, etc.).

:depends:   - textfsm Python library

.. note::

    For Python 2/3 compatibility, it is more recommended to
    install the ``jtextfsm`` library: ``pip install jtextfsm``.
i(tabsolute_importN(tfopenttextfsmt*cC@str
tStdfS(sB
    Only load this execution module if TextFSM is installed.
    sJThe textfsm execution module failed to load: requires the textfsm library.(tHAS_TEXTFSMt__virtualname__tFalse(((s</usr/lib/python2.7/site-packages/salt/modules/textfsm_mod.pyt__virtual__2scC@s�g}tjd�tj|�tjd�tj|�xU|D]M}i}x1t|�D]#\}}|||j|j�<qZW|j|�qAWtjd�tj|�|S(sD
    Converts TextFSM cli_table object to list of dictionaries.
    s
Cli Table:sFSM handler:sExtraction result:(tlogtdebugt	enumeratetheadertlowertappend(tobjectstfsm_handlertobjstrowt	temp_dicttindextelement((s</usr/lib/python2.7/site-packages/salt/modules/textfsm_mod.pyt_clitable_to_dict;s






tbasec
C@sitd6dd6dd6}tjdj|��tjdj|��td|d|�}|tkr�d	j|�|d<tj|d�|SyXtjd
j|��t|d�}tj|j��|j	d�t
j|�}Wn@t
jk
r+}tjd
dt
�dj||�|d<|SX|r�|r�tjdj|��td|d|�}|tkr�dj|�|d<tj|d�|Sn|s�d|d<tj|d�|Stjd�tj|�|j|�}	t|	|�|d<t
|d<|S(s�
    Extracts the data entities from the unstructured
    raw text sent as input and returns the data
    mapping, processing using the TextFSM template.

    template_path
        The path to the TextFSM template.
        This can be specified using the absolute path
        to the file, or using one of the following URL schemes:

        - ``salt://``, to fetch the template from the Salt fileserver.
        - ``http://`` or ``https://``
        - ``ftp://``
        - ``s3://``
        - ``swift://``

    raw_text: ``None``
        The unstructured text to be parsed.

    raw_text_file: ``None``
        Text file to read, having the raw text to be parsed using the TextFSM template.
        Supports the same URL schemes as the ``template_path`` argument.

    saltenv: ``base``
        Salt fileserver envrionment from which to retrieve the file.
        Ignored if ``template_path`` is not a ``salt://`` URL.

    CLI Example:

    .. code-block:: bash

        salt '*' textfsm.extract salt://textfsm/juniper_version_template raw_text_file=s3://junos_ver.txt
        salt '*' textfsm.extract http://some-server/textfsm/juniper_version_template raw_text='Hostname: router.abc ... snip ...'

    Jinja template example:

    .. code-block:: jinja

        {%- set raw_text = 'Hostname: router.abc ... snip ...' -%}
        {%- set textfsm_extract = salt.textfsm.extract('https://some-server/textfsm/juniper_version_template', raw_text) -%}

    Raw text example:

    .. code-block:: text

        Hostname: router.abc
        Model: mx960
        JUNOS Base OS boot [9.1S3.5]
        JUNOS Base OS Software Suite [9.1S3.5]
        JUNOS Kernel Software Suite [9.1S3.5]
        JUNOS Crypto Software Suite [9.1S3.5]
        JUNOS Packet Forwarding Engine Support (M/T Common) [9.1S3.5]
        JUNOS Packet Forwarding Engine Support (MX Common) [9.1S3.5]
        JUNOS Online Documentation [9.1S3.5]
        JUNOS Routing Software Suite [9.1S3.5]

    TextFSM Example:

    .. code-block:: text

        Value Chassis (\S+)
        Value Required Model (\S+)
        Value Boot (.*)
        Value Base (.*)
        Value Kernel (.*)
        Value Crypto (.*)
        Value Documentation (.*)
        Value Routing (.*)

        Start
        # Support multiple chassis systems.
          ^\S+:$$ -> Continue.Record
          ^${Chassis}:$$
          ^Model: ${Model}
          ^JUNOS Base OS boot \[${Boot}\]
          ^JUNOS Software Release \[${Base}\]
          ^JUNOS Base OS Software Suite \[${Base}\]
          ^JUNOS Kernel Software Suite \[${Kernel}\]
          ^JUNOS Crypto Software Suite \[${Crypto}\]
          ^JUNOS Online Documentation \[${Documentation}\]
          ^JUNOS Routing Software Suite \[${Routing}\]

    Output example:

    .. code-block:: json

        {
            "comment": "",
            "result": true,
            "out": [
                {
                    "kernel": "9.1S3.5",
                    "documentation": "9.1S3.5",
                    "boot": "9.1S3.5",
                    "crypto": "9.1S3.5",
                    "chassis": "",
                    "routing": "9.1S3.5",
                    "base": "9.1S3.5",
                    "model": "mx960"
                }
            ]
        }
    tresultttcommenttoutsUsing the saltenv: {}s$Caching {} using the Salt fileservers
cp.cache_filetsaltenvs+Unable to read the TextFSM template from {}s,Reading TextFSM template from cache path: {}tris$Unable to parse the TextFSM templatetexc_infosHUnable to parse the TextFSM template from {}: {}. Please check the logs.s$Trying to read the raw input from {}scp.get_file_strsBUnable to read from {}. Please specify a valid input file or text.s*Please specify a valid input file or text.sProcessing the raw text:N(RtNoneRR	tformatt__salt__terrorRtreadtseekRtTextFSMtTextFSMTemplateErrortTruet	ParseTextR(
t
template_pathtraw_textt
raw_text_fileRtretttpl_cached_pathttpl_file_handleRttfteR((s</usr/lib/python2.7/site-packages/salt/modules/textfsm_mod.pytextractNsNh






cC@s�id)d6td6dd6}ts@d|d<tj|d�|S|s�tjd�pdtjd|�}|r�tjdj	|��t
j|�}|s�dj	|�|d<|Stjd	j	|��q�d
|d<tj|d�|Sn|sCtjd�tjd�ptjd�}|sCd
|d<tj|d�|Sntjdj	|��tjdj	|��td|d|d|	d|
d|�}
tjd�tj|
�|
s�dj	|�|d<tj|d�|St
jj|
d�}tjd�ptjdd�}t
jj||�}tjdj	|��tjdj	|��tj||�}i|d6}tjd�p�tjdd�}tjdj	|��|||<tjd j	|��|r=|r=tjd!j	|��td"|d|�}|tkr=d#j	|�|d<tj|d�|Sn|sbd$|d<tj|d�|Stjd%�tj|�y1|j||�t||�|d<t|d<Wn<tjk
r�}tjd&d't�d(j	|�|d<nX|S(*s�
    Dynamically identify the template required to extract the
    information from the unstructured raw text.

    The output has the same structure as the ``extract`` execution
    function, the difference being that ``index`` is capable
    to identify what template to use, based on the platform
    details and the ``command``.

    command
        The command executed on the device, to get the output.

    platform
        The platform name, as defined in the TextFSM index file.

        .. note::
            For ease of use, it is recommended to define the TextFSM
            indexfile with values that can be matches using the grains.

    platform_grain_name
        The name of the grain used to identify the platform name
        in the TextFSM index file.

        .. note::
            This option can be also specified in the minion configuration
            file or pillar as ``textfsm_platform_grain``.

        .. note::
            This option is ignored when ``platform`` is specified.

    platform_column_name: ``Platform``
        The column name used to identify the platform,
        exactly as specified in the TextFSM index file.
        Default: ``Platform``.

        .. note::
            This is field is case sensitive, make sure
            to assign the correct value to this option,
            exactly as defined in the index file.

        .. note::
            This option can be also specified in the minion configuration
            file or pillar as ``textfsm_platform_column_name``.

    output
        The raw output from the device, to be parsed
        and extract the structured data.

    output_file
        The path to a file that contains the raw output from the device,
        used to extract the structured data.
        This option supports the usual Salt-specific schemes: ``file://``,
        ``salt://``, ``http://``, ``https://``, ``ftp://``, ``s3://``, ``swift://``.

    textfsm_path
        The path where the TextFSM templates can be found. This can be either
        absolute path on the server, either specified using the following URL
        schemes: ``file://``, ``salt://``, ``http://``, ``https://``, ``ftp://``,
        ``s3://``, ``swift://``.

        .. note::
            This needs to be a directory with a flat structure, having an
            index file (whose name can be specified using the ``index_file`` option)
            and a number of TextFSM templates.

        .. note::
            This option can be also specified in the minion configuration
            file or pillar as ``textfsm_path``.

    index_file: ``index``
        The name of the TextFSM index file, under the ``textfsm_path``. Default: ``index``.

        .. note::
            This option can be also specified in the minion configuration
            file or pillar as ``textfsm_index_file``.

    saltenv: ``base``
        Salt fileserver envrionment from which to retrieve the file.
        Ignored if ``textfsm_path`` is not a ``salt://`` URL.

    include_empty: ``False``
        Include empty files under the ``textfsm_path``.

    include_pat
        Glob or regex to narrow down the files cached from the given path.
        If matching with a regex, the regex must be prefixed with ``E@``,
        otherwise the expression will be interpreted as a glob.

    exclude_pat
        Glob or regex to exclude certain files from being cached from the given path.
        If matching with a regex, the regex must be prefixed with ``E@``,
        otherwise the expression will be interpreted as a glob.

        .. note::
            If used with ``include_pat``, files matching this pattern will be
            excluded from the subset of files defined by ``include_pat``.

    CLI Example:

    .. code-block:: bash

        salt '*' textfsm.index 'sh ver' platform=Juniper output_file=salt://textfsm/juniper_version_example textfsm_path=salt://textfsm/
        salt '*' textfsm.index 'sh ver' output_file=salt://textfsm/juniper_version_example textfsm_path=ftp://textfsm/ platform_column_name=Vendor
        salt '*' textfsm.index 'sh ver' output_file=salt://textfsm/juniper_version_example textfsm_path=https://some-server/textfsm/ platform_column_name=Vendor platform_grain_name=vendor

    TextFSM index file example:

    ``salt://textfsm/index``

    .. code-block:: text

        Template, Hostname, Vendor, Command
        juniper_version_template, .*, Juniper, sh[[ow]] ve[[rsion]]

    The usage can be simplified,
    by defining (some of) the following options: ``textfsm_platform_grain``,
    ``textfsm_path``, ``textfsm_platform_column_name``, or ``textfsm_index_file``,
    in the (proxy) minion configuration file or pillar.

    Configuration example:

    .. code-block:: yaml

        textfsm_platform_grain: vendor
        textfsm_path: salt://textfsm/
        textfsm_platform_column_name: Vendor

    And the CLI usage becomes as simple as:

    .. code-block:: bash

        salt '*' textfsm.index 'sh ver' output_file=salt://textfsm/juniper_version_example

    Usgae inside a Jinja template:

    .. code-block:: jinja

        {%- set command = 'sh ver' -%}
        {%- set output = salt.net.cli(command) -%}
        {%- set textfsm_extract = salt.textfsm.index(command, output=output) -%}
    RRRRs/TextFSM doesnt seem that has clitable embedded.ttextfsm_platform_grains0Using the {} grain to identify the platform names8Unable to identify the platform name using the {} grain.sUsing platform: {}s?No platform specified, no platform grain identifier configured.sLNo TextFSM templates path specified, trying to look into the opts and pillarttextfsm_pathsSNo TextFSM templates path specified. Please configure in opts/pillar/function args.sUsing the saltenv: {}s$Caching {} using the Salt fileserverscp.cache_dirRt
include_emptytinclude_pattexclude_patsCache fun return:sAUnable to fetch from {}. Is the TextFSM path correctly specified?ittextfsm_index_fileRsUsing the cached index file: {}s"TextFSM templates cached under: {}tCommandttextfsm_platform_column_nametPlatforms,Using the TextFSM platform idenfiticator: {}s:Processing the TextFSM index file using the attributes: {}sProcessing the output from {}scp.get_file_strs<Unable to read from {}. Please specify a valid file or text.s*Please specify a valid output text or filesProcessing the raw text:sUnable to proces the CliTableRs Unable to process the output: {}N(RRtHAS_CLITABLERR!t__opts__tgett
__pillar__R	Rt
__grains__tinfoR tostpathtdirnametjointclitabletCliTabletParseCmdRR&t
CliTableError(tcommandtplatformtplatform_grain_nametplatform_column_nametoutputtoutput_fileR1t
index_fileRR2R3R4R+ttextfsm_cachedir_retttextfsm_cachedirtindex_file_pathttextfsm_objtattrstcterr((s</usr/lib/python2.7/site-packages/salt/modules/textfsm_mod.pyR�s��





	

!





(t__doc__t
__future__RR?tloggingRR&RtImportErrorRRCR9tsalt.utils.filesRt
salt.utilst	getLoggert__name__RRt__proxyenabled__RRRR/R(((s</usr/lib/python2.7/site-packages/salt/modules/textfsm_mod.pyt<module>sD






				�

Zerion Mini Shell 1.0