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
Use the run_cmds
script to start a session with the local ncs
daemon and test the various state gathering commands
[grundler@ncs-1 umnet-pyncs]$ ./run_cmds -h
usage: run_cmds [-h] -c CMD -d DEV
optional arguments:
-h, --help show this help message and exit
-c CMD, --cmd CMD
-d DEV, --device DEV
[grundler@ncs-1 umnet-pyncs]$
[grundler@ncs-1 umnet-pyncs]$
[grundler@ncs-1 umnet-pyncs]$ ./run_cmds -d s-ehall-2012p-1 -c get-interface-details
INFO:root:connecting to ncs...
INFO:root:transaction started...
INFO:root:submitting commands to worker pool (1)
DEBUG:root:pid: 19275: invoking get-interface-details against s-ehall-2012p-1
DEBUG:root:sending 'show interfaces' to s-ehall-2012p-1
...
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file umnet_pyncs-0.1.34.tar.gz
.
File metadata
- Download URL: umnet_pyncs-0.1.34.tar.gz
- Upload date:
- Size: 16.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.1 CPython/3.9.1 Linux/3.10.0-1160.108.1.el7.x86_64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c028f568859e0e63af117554ea6ef47c2afef1f02db12e3c5536707183d7d619 |
|
MD5 | b217c46278e635fd4e4a534c8fc6eca5 |
|
BLAKE2b-256 | 7efb8683a0690cc0af577edb29ea7317a06b00da28fa7f1f6dd208aa69105ff4 |
File details
Details for the file umnet_pyncs-0.1.34-py3-none-any.whl
.
File metadata
- Download URL: umnet_pyncs-0.1.34-py3-none-any.whl
- Upload date:
- Size: 21.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.1 CPython/3.9.1 Linux/3.10.0-1160.108.1.el7.x86_64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0351d1626ba8d93f509823ff99da349b32f52fcb8b1ccb27a71387081d4d50c0 |
|
MD5 | 7dbc495c0972e354e82a21bfb36ca242 |
|
BLAKE2b-256 | da547d953085ceda0d5e5cefcd400039487c967c4feee0c1a214d106f7d573db |