Skip to main content

custom python module for NCS helpers

Project description

Overview

This module is intended to be installed on the production NCS nodes and imported in other services/actions that need to gather state from the network. It uses the NCS device manager and the standard python multiprocessing library to connect to devices in-parallel and issue commands, returning results as structured data.

Usage information

Basic usage example in an NCS callback:

from umnet_pyncs.state import StateManager
...


class DemoAction(Action):
    @Action.action
    def cb_action(self, uinfo, name, kp, input, output, trans):
        ...
        with StateManager() as m:
            interfaces = m.get_state(al_devices, ["get-interface-details"])
            arp = m.get_state(dl_devices, ["get-arp-table"])
            ...

Supported commands

Currently supported commands are:

  • get-mac-table
  • get-arp-table
  • get-interface-details
  • get-transciever-details
  • get-lldp-neighbors
  • get-bfd-neighbors
  • get-ospf-neighbors

Developer testing

Install the ncs-pycli package into your local NSO development environment. Run ncs_pycli to get an ipython shell with an open transaction:

import logging
from umnet_pyncs.state import StateManager

log = logging.getLogger()
log.setLevel(logging.DEBUG)

devices = [d for d in root.devices.device]

m = StateManager()

interfaces = m.get_state(devices, ["get-interface-details"])
    
print(interfaces)

m.__exit__()

For any given command, the various platform-specific models are responsible for implementing how the data is fetched and parsed from the remote device. Each command corresponds to a method that can be invoked to retrieve the data, e.g. get-interface-details maps to the get_interface_details() instance method of the model(s).

For Cisco IOS and NXOS devices (which use CLI-based NEDs), the built-in NCS live-status action(s) are used to send raw CLI commands to the device. For example, the get_mac_address() method will send a show mac address-table CLI command. For both IOS and NXOS we use ntc_templates to parse the raw text output into structured data.

For Juniper devices, since the NED uses NETCONF for all device communications, we instead call the <get-ethernet-switching-table-information> RPC directly. Since this RPC is modelled in YANG, we can then parse the results directly using the maagic API.

All the nitty-gritty details of parsing the data retrieved directly from the remote device is handled by the platform-specific model implementation for that device. Each model normalizes the data using the dataclasses defined in base.py. The intention is to makes it simpler for NCS actions/services to use this module, as well as making it easier to develop/maintain.

NB: this implementation currently relies on an additional template for NXOS that handles parsing show ip arp detail vrf all -- see PR# 1204.

Developer testing

Install the ipython-superuser package into your local NSO development environment. Use the REPL e.g:

import logging
from umnet_pyncs.state import StateManager

logging.basicConfig(level=logging.DEBUG)

devices = [d for d in root.devices.device]

m = StateManager()

# NB: m.get_state() expects a list of devices
interfaces = m.get_state(devices, ["get-interface-details"])
    
print(interfaces)

m.__exit__()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

umnet_pyncs-0.1.13.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

umnet_pyncs-0.1.13-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file umnet_pyncs-0.1.13.tar.gz.

File metadata

  • Download URL: umnet_pyncs-0.1.13.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.8 Linux/6.0.8-arch1-1

File hashes

Hashes for umnet_pyncs-0.1.13.tar.gz
Algorithm Hash digest
SHA256 23580c67b55ae8b36740e34ae7709f24cc33090bd8bdf5e172f9800945debf0f
MD5 e02e51d7833cd4f72679ca3cb96d339d
BLAKE2b-256 e7a994e9de3d4a6610e56a869e12a86e09e9a2418f95e82046e34c7be114f326

See more details on using hashes here.

File details

Details for the file umnet_pyncs-0.1.13-py3-none-any.whl.

File metadata

  • Download URL: umnet_pyncs-0.1.13-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.8 Linux/6.0.8-arch1-1

File hashes

Hashes for umnet_pyncs-0.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 f7dba8664ac9955d80998159819792ba6d90a9c1647c7897b89c4b4446cb9a9f
MD5 91012e41fd0b39d510d560307cee5f0f
BLAKE2b-256 863a254adf550a47a6ec986bdf4e792dea6bd8bf0c01a76c99f8127f9645e7a9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page