%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/napalm_yang_mod.pyc

�
���^c@@s�dZddlmZmZmZddlZyddlZeZWne	k
r]e
ZnXddlZddlm
Z
dZdgZeje�Zd�Zd�Zd	�Ze
d
��Ze
d��Ze
d��Ze
d
��ZdS(uT
NAPALM YANG
===========

NAPALM YANG basic operations.

.. versionadded:: 2017.7.0
i(tabsolute_importtunicode_literalstprint_functionN(tproxy_napalm_wrapunapalm_yangu*cC@s)tstdfStjjjttt�S(u�
    NAPALM library must be installed for this module to work and run in a (proxy) minion.
    This module in particular requires also napalm-yang.
    uHUnable to load napalm_yang execution module: please install napalm-yang!(	tHAS_NAPALM_YANGtFalsetsalttutilstnapalmtvirtualt__opts__t__virtualname__t__file__(((s@/usr/lib/python2.7/site-packages/salt/modules/napalm_yang_mod.pyt__virtual__)s
cC@s`tjj�}xJ|D]B}t}x&|jd�D]}t||�}q2W|j|�qW|S(uU
    Read list of models and returns a Root object with the proper models added.
    u.(tnapalm_yangtbasetRoottsplittgetattrt	add_model(tmodelstroottmodeltcurrenttpart((s@/usr/lib/python2.7/site-packages/salt/modules/napalm_yang_mod.pyt_get_root_object7s
cG@stt|t�r/t|dt�r/|d}nt|�}|j|�t|�}|j|�tjj||�S(u�
    Returns the difference between two configuration entities structured
    according to the YANG model.

    .. note::
        This function is recommended to be used mostly as a state helper.

    candidate
        First model to compare.

    running
        Second model to compare.

    models
        A list of models to be used when comparing.

    CLI Example:

    .. code-block:: bash

        salt '*' napalm_yang.diff {} {} models.openconfig_interfaces

    Output Example:

    .. code-block:: python

        {
            "interfaces": {
                "interface": {
                    "both": {
                        "Port-Channel1": {
                            "config": {
                                "mtu": {
                                    "first": "0",
                                    "second": "9000"
                                }
                            }
                        }
                    },
                    "first_only": [
                        "Loopback0"
                    ],
                    "second_only": [
                        "Loopback1"
                    ]
                }
            }
        }
    i(t
isinstancettupletlistRt	load_dictRRtdiff(t	candidatetrunningRtfirsttsecond((s@/usr/lib/python2.7/site-packages/salt/modules/napalm_yang_mod.pyRHs2"


cO@st|t�r/t|dt�r/|d}n|jdt�}|jdt�}|jdg�}|r�ttd�r�tj}n|s�tj	d�g}nt
|�}itj	d�d6|d6}|r�|j|�n|r�|j|�n|j
d	t�S(
u!
    Parse configuration from the device.

    models
        A list of models to be used when parsing.

    config: ``False``
        Parse config.

    state: ``False``
        Parse state.

    profiles: ``None``
        Use certain profiles to parse. If not specified, will use the device
        default profile(s).

    CLI Example:

    .. code-block:: bash

        salt '*' napalm_yang.parse models.openconfig_interfaces

    Output Example:

    .. code-block:: python

        {
            "interfaces": {
                "interface": {
                    ".local.": {
                        "name": ".local.",
                        "state": {
                            "admin-status": "UP",
                            "counters": {
                                "in-discards": 0,
                                "in-errors": 0,
                                "out-errors": 0
                            },
                            "enabled": True,
                            "ifindex": 0,
                            "last-change": 0,
                            "oper-status": "UP",
                            "type": "softwareLoopback"
                        },
                        "subinterfaces": {
                            "subinterface": {
                                ".local..0": {
                                    "index": ".local..0",
                                    "state": {
                                        "ifindex": 0,
                                        "name": ".local..0"
                                    }
                                }
                            }
                        }
                    },
                    "ae0": {
                        "name": "ae0",
                        "state": {
                            "admin-status": "UP",
                            "counters": {
                                "in-discards": 0,
                                "in-errors": 0,
                                "out-errors": 0
                            },
                            "enabled": True,
                            "ifindex": 531,
                            "last-change": 255203,
                            "mtu": 1518,
                            "oper-status": "DOWN"
                        },
                        "subinterfaces": {
                            "subinterface": {
                                "ae0.0": {
                                    "index": "ae0.0",
                                    "state": {
                                        "description": "ASDASDASD",
                                        "ifindex": 532,
                                        "name": "ae0.0"
                                    }
                                }
                                "ae0.32767": {
                                    "index": "ae0.32767",
                                    "state": {
                                        "ifindex": 535,
                                        "name": "ae0.32767"
                                    }
                                }
                            }
                        }
                    },
                    "dsc": {
                        "name": "dsc",
                        "state": {
                            "admin-status": "UP",
                            "counters": {
                                "in-discards": 0,
                                "in-errors": 0,
                                "out-errors": 0
                            },
                            "enabled": True,
                            "ifindex": 5,
                            "last-change": 0,
                            "oper-status": "UP"
                        }
                    },
                    "ge-0/0/0": {
                        "name": "ge-0/0/0",
                        "state": {
                            "admin-status": "UP",
                            "counters": {
                                "in-broadcast-pkts": 0,
                                "in-discards": 0,
                                "in-errors": 0,
                                "in-multicast-pkts": 0,
                                "in-unicast-pkts": 16877,
                                "out-broadcast-pkts": 0,
                                "out-errors": 0,
                                "out-multicast-pkts": 0,
                                "out-unicast-pkts": 15742
                            },
                            "description": "management interface",
                            "enabled": True,
                            "ifindex": 507,
                            "last-change": 258467,
                            "mtu": 1400,
                            "oper-status": "UP"
                        },
                        "subinterfaces": {
                            "subinterface": {
                                "ge-0/0/0.0": {
                                    "index": "ge-0/0/0.0",
                                    "state": {
                                        "description": "ge-0/0/0.0",
                                        "ifindex": 521,
                                        "name": "ge-0/0/0.0"
                                    }
                                }
                            }
                        }
                    }
                    "irb": {
                        "name": "irb",
                        "state": {
                            "admin-status": "UP",
                            "counters": {
                                "in-discards": 0,
                                "in-errors": 0,
                                "out-errors": 0
                            },
                            "enabled": True,
                            "ifindex": 502,
                            "last-change": 0,
                            "mtu": 1514,
                            "oper-status": "UP",
                            "type": "ethernetCsmacd"
                        }
                    },
                    "lo0": {
                        "name": "lo0",
                        "state": {
                            "admin-status": "UP",
                            "counters": {
                                "in-discards": 0,
                                "in-errors": 0,
                                "out-errors": 0
                            },
                            "description": "lo0",
                            "enabled": True,
                            "ifindex": 6,
                            "last-change": 0,
                            "oper-status": "UP",
                            "type": "softwareLoopback"
                        },
                        "subinterfaces": {
                            "subinterface": {
                                "lo0.0": {
                                    "index": "lo0.0",
                                    "state": {
                                        "description": "lo0.0",
                                        "ifindex": 16,
                                        "name": "lo0.0"
                                    }
                                },
                                "lo0.16384": {
                                    "index": "lo0.16384",
                                    "state": {
                                        "ifindex": 21,
                                        "name": "lo0.16384"
                                    }
                                },
                                "lo0.16385": {
                                    "index": "lo0.16385",
                                    "state": {
                                        "ifindex": 22,
                                        "name": "lo0.16385"
                                    }
                                },
                                "lo0.32768": {
                                    "index": "lo0.32768",
                                    "state": {
                                        "ifindex": 248,
                                        "name": "lo0.32768"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    iuconfigustateuprofilesuprofileuosuDRIVERudevicetfilter(RRRtpopRthasattrt
napalm_devicetprofilet
__grains__tgetRtparse_configtparse_statetto_dicttTrue(RtkwargstconfigtstatetprofilesRt
parser_kwargs((s@/usr/lib/python2.7/site-packages/salt/modules/napalm_yang_mod.pytparse�s$�"

cO@s�t|t�r/t|dt�r/|d}n|jdg�}|rcttd�rctj}n|s~tjd�g}ni|d6}t	|�}|j
|�|j|�}tj
d�tj
|�|S(u�
    Return the native config.

    data
        Dictionary structured with respect to the models referenced.

    models
        A list of models to be used when generating the config.

    profiles: ``None``
        Use certain profiles to generate the config.
        If not specified, will use the platform default profile(s).

    CLI Example:

    .. code-block:: bash

        salt '*' napalm_yang.get_config {} models.openconfig_interfaces

    Output Example:

    .. code-block:: text

        interface et1
            ip address 192.168.1.1/24
            description Uplink1
            mtu 9000
        interface et2
            ip address 192.168.2.1/24
            description Uplink2
            mtu 9000
    iuprofilesuprofileuosuGenerated config(RRRR$R%R&R'R(R)RRttranslate_configtlogtdebug(tdataRR.R1R2Rt
native_config((s@/usr/lib/python2.7/site-packages/salt/modules/napalm_yang_mod.pyt
get_configos""




cO@s�t|t�r/t|dt�r/|d}nt|||�}|jdt�}|jdt�}|jdt�}|jdt�}tdd|d|d	|d
|d|dt�S(
u
    Generate and load the config on the device using the OpenConfig or IETF
    models and device profiles.

    data
        Dictionary structured with respect to the models referenced.

    models
        A list of models to be used when generating the config.

    profiles: ``None``
        Use certain profiles to generate the config.
        If not specified, will use the platform default profile(s).

    test: ``False``
        Dry run? If set as ``True``, will apply the config, discard
        and return the changes. Default: ``False`` and will commit
        the changes on the device.

    commit: ``True``
        Commit? Default: ``True``.

    debug: ``False``
        Debug mode. Will insert a new key under the output dictionary,
        as ``loaded_config`` containing the raw configuration loaded on the device.

    replace: ``False``
        Should replace the config with the new generate one?

    CLI Example:

    .. code-block:: bash

        salt '*' napalm_yang.load_config {} models.openconfig_interfaces test=True debug=True

    Output Example:

    .. code-block:: jinja

        device1:
            ----------
            already_configured:
                False
            comment:
            diff:
                [edit interfaces ge-0/0/0]
                -   mtu 1400;
                [edit interfaces ge-0/0/0 unit 0 family inet]
                -       dhcp;
                [edit interfaces lo0]
                -    unit 0 {
                -        description lo0.0;
                -    }
                +    unit 1 {
                +        description "new loopback";
                +    }
            loaded_config:
                <configuration>
                  <interfaces replace="replace">
                    <interface>
                      <name>ge-0/0/0</name>
                      <unit>
                        <name>0</name>
                        <family>
                          <inet/>
                        </family>
                        <description>ge-0/0/0.0</description>
                      </unit>
                      <description>management interface</description>
                    </interface>
                    <interface>
                      <name>ge-0/0/1</name>
                      <disable/>
                      <description>ge-0/0/1</description>
                    </interface>
                    <interface>
                      <name>ae0</name>
                      <unit>
                        <name>0</name>
                        <vlan-id>100</vlan-id>
                        <family>
                          <inet>
                            <address>
                              <name>192.168.100.1/24</name>
                            </address>
                            <address>
                              <name>172.20.100.1/24</name>
                            </address>
                          </inet>
                        </family>
                        <description>a description</description>
                      </unit>
                      <vlan-tagging/>
                      <unit>
                        <name>1</name>
                        <vlan-id>1</vlan-id>
                        <family>
                          <inet>
                            <address>
                              <name>192.168.101.1/24</name>
                            </address>
                          </inet>
                        </family>
                        <disable/>
                        <description>ae0.1</description>
                      </unit>
                      <vlan-tagging/>
                      <unit>
                        <name>2</name>
                        <vlan-id>2</vlan-id>
                        <family>
                          <inet>
                            <address>
                              <name>192.168.102.1/24</name>
                            </address>
                          </inet>
                        </family>
                        <description>ae0.2</description>
                      </unit>
                      <vlan-tagging/>
                    </interface>
                    <interface>
                      <name>lo0</name>
                      <unit>
                        <name>1</name>
                        <description>new loopback</description>
                      </unit>
                      <description>lo0</description>
                    </interface>
                  </interfaces>
                </configuration>
            result:
                True
    iutestudebugucommitureplaceunet.load_configttextttestR6tcommittreplacetinherit_napalm_device(	RRRR9R$RR-t__salt__R&(R7RR.R/R;R6R<R=((s@/usr/lib/python2.7/site-packages/salt/modules/napalm_yang_mod.pytload_config�s�"
cO@sgt|t�r/t|dt�r/|d}n|jdd�}t|�}|j|�|j|�S(u7
    Return the compliance report using YANG objects.

    data
        Dictionary structured with respect to the models referenced.

    models
        A list of models to be used when generating the config.

    filepath
        The absolute path to the validation file.

    CLI Example:

    .. code-block:: bash

        salt '*' napalm_yang.compliance_report {} models.openconfig_interfaces filepath=~/validate.yml

    Output Example:

    .. code-block:: json

        {
          "skipped": [],
          "complies": true,
          "get_interfaces_ip": {
            "missing": [],
            "complies": true,
            "present": {
              "ge-0/0/0.0": {
                "complies": true,
                "nested": true
              }
            },
            "extra": []
          }
        }
    iufilepathu(RRRR$RRtcompliance_report(R7RR.tfilepathR((s@/usr/lib/python2.7/site-packages/salt/modules/napalm_yang_mod.pyRA:s("

(t__doc__t
__future__RRRtloggingRR-RtImportErrorRtsalt.utils.napalmRRRt__proxyenabled__t	getLoggerRR5R
RRR3R9R@RA(((s@/usr/lib/python2.7/site-packages/salt/modules/napalm_yang_mod.pyt<module>	s&


				<�4�

Zerion Mini Shell 1.0