Giter Site home page Giter Site logo

ttp_sros_parser's Introduction

codecov

TTP SrosParser

A library to parse a Nokia SROS 7750 full hierarchical configuration text file into structured data. Show commands are also able to be parsed, if included in the file alongside the configuration. This library is still under development, but a lot of parsers are readily available (see below for supported features). Configurations used for testing have all been on release version higher than TiMOS 16. At the moment, there is no capability to specify release version to accommodate different parsing templates.

What TTP SrosParser is not

A library that connects and extracts information from a remote device. You, as the end-user must obtain a text file of the configuration. This file will be passed into the SrosParser class and you are able to convert a flat text configuration file into structure data using the built-in TTP parser templates. At this point, it's recommended to use a new instance of the srosparser with an individual show command as the text to parse to get the best results when parsing a show commands.

Example

"""SrosParser - Example."""
from ttp_sros_parser.srosparser import SrosParser

EXAMPLE_CONFIG = "some/dir/path/to/7750-config.txt"

# Instantiate class
router = SrosParser(EXAMPLE_CONFIG)

# Call `get_system_cards` method
router.get_system_cards()

Results:

[
   {
      "configure":{
         "card":{
            "card-type":{
               "card-type":"iom-1",
               "subscription-level":"cr"
            },
            "fail-on-error":true,
            "mda":{
               "admin-state":true,
               "egress-xpl":{
                  "window":"10"
               },
               "fail-on-error":true,
               "ingress-xpl":{
                  "window":"10"
               },
               "mda-slot":"1",
               "mda-type":"me6-100gb-qsfp28"
            },
            "slot-number":"1"
         }
      }
   }
]

Available Methods (Parsers)

Current methods available (Automatically updated at build):

Methods

Full Config

SrosParser allows you to parse the full configuration with a single method call, get_full_config() and receive the full JSON output of the device.

Custom Templates

SrosParser allows you to simply specify a custom template after you initialize a new class object.

router = SrosParser("path/to/config.txt")

cool_ttp_template = router.get_custom_template("path/to/template")

print(cool_ttp_template)

Contributing

Any contribution to the project must include unit tests and pass all linting.

Simply run:

  • docker-compose build
  • docker-compose run test

ttp_sros_parser's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ttp_sros_parser's Issues

show lag port | show system lldp neib templates

Link Layer Discovery Protocol (LLDP) System Information{{ignore}}

=============================================================================== {{ignore}}
NB = nearest-bridge   NTPMR = nearest-non-tpmr   NC = nearest-customer {{ignore}}
=============================================================================== {{_start_}}
Lcl Port      Scope Remote Chassis ID  Index  Remote Port     Remote Sys Name {{ignore}}
------------------------------------------------------------------------------- {{ignore}}
<group name="entry*" method="table" >
{{port}}         {{lldp_type}}    {{mac | MAC}}  {{lldp_index}}      {{remote | re(r".*")}}
</group>
=============================================================================== {{_end_}}
* indicates that the corresponding row element may have been truncated.{{ignore}}
Number of neighbors : 40 {{ignore}}
</group>



<vars>
tmp_lagid=""
</vars>

<group name="lag_port">
=============================================================================== {{ignore}}
Lag Port States {{ignore}}
LACP Status: e - Enabled, d - Disabled {{ignore}}
=============================================================================== {{_start_}}
Lag-id Port-id   Adm   Act/Stdby Opr   Primary  Sub-group     Forced  Priority {{ignore}}
------------------------------------------------------------------------------- {{ignore}}
<group name="entry*" method="table" >
{{lagid | default(tmp_lagid)}}   {{interface}}    {{adm}}    {{act}}    {{opr}}    {{primary|default("")}}      {{subgroup | DIGIT}}             {{forced}}       {{priority}}
       {{interface}}    {{adm}}    {{act}}    {{opr}}        {{subgroup | DIGIT}}             {{forced}}       {{priority}}
{{lagid | default(tmp_lagid)}}   {{interface}}    {{adm}}    {{act}}   {{opr}}           {{subgroup | DIGIT}}             {{forced}}       {{priority}}
       {{interface}}    {{adm}}    {{act}}    {{opr}}    {{primary|default("")}}      {{subgroup | DIGIT}}             {{forced}}       {{priority}}
</group>
=============================================================================== {{_end_}}
</group>

router.get_lags() not showing all LAGs

Hi!

I've noticed that the method get_lags() only retrieves some lags. Is there a chance that I'm doing something wrong? In my config file I have 2 network LAGs and 5 Access Lags, but only the first three ones are being shown.

For example:

$ grep -E 'lag ' config.cfg 
    lag 1
    lag 8
    lag 2
    lag 3
    lag 40
    lag 41
    lag 42

However, when trying to get the lags from the config file, only lags 1, 8 and 2 are being shown.

In [43]: lags = router.get_lags()[0]['configure']['lag']                                                                                                                                                                                                                
WARNING:ttp.ttp:ttp.lazy_import_functions: failed to save ttp_dict_cache.pickle '[Errno 13] Permission denied: '/usr/local/lib/python3.8/dist-packages/ttp/ttp_dict_cache.pickle''

In [44]: len(lags)                                                                                                                                                                                                                                                      
Out[44]: 3

In [45]: for lag in lags: 
    ...:     try: 
    ...:         print(lag['lag-index'], lag['mode']) 
    ...:     except: 
    ...:         print(lag['lag-index']) 
    ...:          
    ...:                                                                                                                                                                                                                                                                
1
8
2 access

Any hint? Thanks!
Lucas

ps: don't know if the WARNING error has something to do with this. I just installed this lib using the standard pip method.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.