Git Product home page Git Product logo

network-configuration-parser's Introduction

network-configuration-parser

This package is to help network engineers have a easy interface to parse device config. Currently the goal is to say a function(device stats, configuration, bgp neighbors(although that kinda fits into device stats hhhhmmmm..... ), ping up down(maybe))

goal for project

  • Allow users to run commands or run services on their devices.
  • Make adding to repo easy.
  • User inputs device and services they want to run they get command and parsed output back to them.

Important for me

  • Create tests for code

Why am I doing this?

  • To help me learn programming better.
  • Because creating a pyats parsers are hard to develop for and hard to add features
  • Selfishly I want to have a repo that is known out in the community but one that also benefits me
  • Not all data parsing is cli sometimes its controller based. and I want to be able to get data back from both controller based network devices and cli devices

Components

  • Nornir
    • Needed to help create my workflow
    • also help with creating inventory
  • TextFSM
    • This is to take a TextFSM template and a CLI command and give back structured data
  • ntc-templates
    • This is a library of textfsm templates
  • nornir_netmiko
    • Used as a connection plugin for nornir to use netmiko
    • I decided to use this plugin because many many tools that are used in network automation uses netmiko under the hood.
    • Netmiko was developed based off paramiko and designed for network devices.
  • Poetry
    • I wanted to try it out and help maintain my environment

Standards

  • .yaml is my yaml file extension

Future features

  • maybe have the inventory be a configuration file. Maybe that would be easier to use.

Steps I follow

  • Set up environment
    • set up github repo
    • install poetry
    • poetry init new-python-package-name
    • poetry add python-packages
  • Create nornir config file
  • Create nornir inventory for first testing
  • play around with nornir a bit and see if my config file works and my inventory works.
  • create script file to play around with.
  • figure out how to run script with poetry
    • poetry shell to get into venv
    • poetry run python network-config-parser/init_script.py
    • I did have to fix my folder structure in order to make sure I grabbed the correct files.
  • found out that my poetry is running python 3.8 but i want to use 3.12. now i need to figure out how to update my python in my poetry
  • run poetry config --list to find what your poetry is configured to use.
  • took me a while but here is what worked
    • update-alternatives --install /usr/bin/python python /usr/bin/python3.12 1
    • This set python3.12 as my system default
    • I had a lot A LOT of issues here.
    • What worked for me was to uninstall python 3.8
    • run these commands
      • update-alternatives --install /usr/bin/python python /usr/bin/python3.12 1
      • update-alternatives --install /usr/bin/python python3 /usr/bin/python3.12 1
      • curl -O https://bootstrap.pypa.io/get-pip.py
      • python get-pip.py
      • finally after all that poety was working with python 3.12
  • also forgot to enable autocompletion in bash to i added that.
    • poetry completions bash >> ~/.bash_completion
  • as I am trying to figure out how to use nornir_netmiko, I look at the nornir_netmiko github repo a lot to see how the project is laid out. one example is figuring out how to import the task I want to use quickly. I see that the task I want to use i in nornir_netmiko then in tasks finally I see the module I care about.
  • I took a look at the multicommand task, but that appears to be more for configuration where you might get prompted to run a command, type y on your keyboard then you need to hit enter on your keyboard for confirm. another example would be configuring a interface. and first you say the interface, then you enter the interface command mode and update the ip address or the description.
  • Long story short that command doesnt work for what I want to do.
  • instead of printing out a bunch of statements trying to get the data you need its better to use the vscode debug. that gives you a nice gui to look through the data and find what you need.
  • Next I decided to test out how ntc and textfsm work together.
  • started by creating a new module.
  • I found a example on the ntc-template docs I was able to use that.
  • Init commit of project inbound. This is more or less a working solution basic solution for what I want.
  • I went down a rabbit hole about OOP a little bit. I understand teh concepts of oop and abstract base classes. But when to use those exact concepts at not as clear to me.
  • I was listening to a audio book on a long drive the other day and the audio book said to use OOP When I want to hide the implementation details or when I need to group a large number of tasks together. I think that will become clear to me as I embark down this program.
  • I created my first basic task. then I created a little bit more complex task.
  • Next I need to figure out how to get the output from the first task and enter it into the second task.

first nornir task def command_to_parse(task: Task, command: str): return Result( host=task.host, result= f" command to run {command}" )

converted into

def command_to_parse(task: Task, user_command: str, data: str = None): data = '*22:58:52.913 UTC Sat Jul 6 2024' version_parsed = parse_output(platform=task.host.platform, command=user_command, data=data) return_result = Result(host=task.host, result = version_parsed) return return_result

network-configuration-parser's People

Contributors

networkingb2a avatar

Watchers

 avatar

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.