Metadata-Version: 2.1
Name: nornir-pyntc
Version: 1.0.0
Summary: pyntc plugin for Nornir
Home-page: https://github.com/networktocode-llc/nornir_pyntc
License: Apache-2.0
Author: Network to Code, LLC
Author-email: info@networktocode.com
Requires-Python: >=3.7,<4.0
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Requires-Dist: nornir (>=3.2.0,<4.0.0)
Requires-Dist: pyntc (>=0.20.1,<0.21.0)
Project-URL: Repository, https://github.com/networktocode-llc/nornir_pyntc
Description-Content-Type: text/markdown

# nornir-pyntc

nornir-pyntc is a [Nornir Plugin](https://nornir.readthedocs.io/en/latest/plugins/index.html). It extends the main functionality that Nornir provides by adding a plugin wrapping around [pyntc](https://github.com/networktocode/pyntc) library. nornir-pyntc comes with a `connection` plugin and `task` definitions that can be used via the Nornir core library.

## Installation

nornir-pyntc is available as a Python package in PyPI and can be installed with pip:

Initial install:

```
pip install nornir-pyntc
```

To upgrade:

```
pip install nornir-pyntc --upgrade
```

## Supported Platforms

- Cisco AireOS - uses netmiko (SSH)
- Cisco ASA - uses netmiko (SSH)
- Cisco IOS platforms - uses netmiko (SSH)
- Cisco NX-OS - uses pynxos (NX-API)
- Arista EOS - uses pyeapi (eAPI)
- Juniper Junos - uses PyEz (NETCONF)
- F5 Networks - uses f5-sdk (ReST)

## Plugins

Nornir allows plugins to extend different functionality.

These include:
- Connections
- Tasks
- Inventory
- Processors
- Runners

`nornir-pyntc` is a collection of connection and tasks plugins.

### Connections

- `pyntc_connection` - Manages device connections.

### Tasks

The plugin comes with tasks that expose the basic pyntc functionality.

- [pyntc_config](https://github.com/networktocode/pyntc#config-commands) - Pass configuration commands to a network device.
- [pyntc_file_copy](https://github.com/networktocode/pyntc#copying-files) - Copy a file to a network device.
- [pyntc_install_os](https://github.com/networktocode/pyntc#installing-operating-systems) - Install an operating system.
- [pyntc_reboot](https://github.com/networktocode/pyntc#reboot) - Reboot a network device.
- [pyntc_save](https://github.com/networktocode/pyntc#save-configs) - Save the running configuration of a network device.
- [pyntc_show](https://github.com/networktocode/pyntc#sending-show-commands) - Send a single `show` command to a network device.
- [pyntc_show_list](https://github.com/networktocode/pyntc#sending-multiple-commands) - Send multiple `show` commands to a network device.


## Basic Usage

Below examples demonstrate basic usage patterns for the plugin's connection and tasks.

### Connection Examples

This example demonstrates how to use a manual connection handler. The code executes the `open_connection` and `close_connection` method calls manually.

```python
# Base import that is required to Initialize the core Nornir handler.
from nornir import InitNornir

# Specific nornir-pytnc imports.
# Connection plugin import
from nornir_pyntc.connections.pyntc_connection import Pyntc
# Task plugin import for running show commands.
from nornir_pyntc.tasks.pyntc_show import pyntc_show

# Nornir utility function to print results in a simplified way.
from nornir_utils.plugins.functions import print_result

nr = InitNornir(config_file="config.yml")

def task_manages_connection_manually(task):
    task.host.open_connection("pyntc", configuration=task.nornir.config)
    result = nr.run(task=pyntc_show, command="show version")
    task.host.close_connection("pyntc")

manual_result = nr.run(
    task=task_manages_connection_manually,
)

print_result(manual_result)

```

For more details see the section on manual connection handling in the [Nornir Documentation](https://nornir.readthedocs.io/en/latest/howto/handling_connections.html#Manually).

### Task Examples

This example illustrates how to use a task plugin and allow the task plugin to utilize the native nornir-pyntc connection:

```python
# Base import that is required to Initialize the core Nornir handler.
from nornir import InitNornir

# Specific nornir-pytnc imports.
# Task plugin import for running show commands.
from nornir_pyntc.tasks.pyntc_show import pyntc_show

# Nornir utility function to print results in a simplified way.
from nornir_utils.plugins.functions import print_result

nr = InitNornir(config_file="config.yml")

result = nr.run(task=pyntc_show, command="show version")

print_result(result)
```

```raw
pyntc_show**********************************************************************
* n5k1 ** changed : False ******************************************************
vvvv pyntc_show ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO
{ 'bios_cmpl_time': '05/09/2012',
  'bios_ver_str': '3.6.0',
  'bootflash_size': 2007040,
  'chassis_id': 'Nexus5548 Chassis',
  'cpu_name': 'Intel(R) Xeon(R) CPU        ',
  'header_str': 'Cisco Nexus Operating System (NX-OS) Software\n'
                'TAC support: http://www.cisco.com/tac\n'
                'Documents: '
                'http://www.cisco.com/en/US/products/ps9372/tsd_products_support_series_home.html\n'
                'Copyright (c) 2002-2022, Cisco Systems, Inc. All rights '
                'reserved.\n'
                'The copyrights to certain works contained herein are owned '
                'by\n'
                'other third parties and are used and distributed under '
                'license.\n'
                'Some parts of this software are covered under the GNU Public\n'
                'License. A copy of the license is available at\n'
                'http://www.gnu.org/licenses/gpl.html.\n',
  'host_name': 'Nexus5K-1',
  'isan_cmpl_time': ' 2/8/2022 3:00:00',
  'isan_file_name': 'bootflash:///n5000-uk9.7.3.11.N1.1.bin',
  'isan_tmstmp': '02/08/2022 14:26:50',
  'kern_uptm_days': 0,
  'kern_uptm_hrs': 1,
  'kern_uptm_mins': 3,
  'kern_uptm_secs': 49,
  'kick_cmpl_time': ' 2/8/2022 3:00:00',
  'kick_file_name': 'bootflash:///n5000-uk9-kickstart.7.3.11.N1.1.bin',
  'kick_tmstmp': '02/08/2022 12:31:24',
  'kickstart_ver_str': '7.3(11)N1(1)',
  'mem_type': 'kB',
  'memory': 8253792,
  'module_id': 'O2 32X10GE/Modular Universal Platform Supervisor',
  'power_seq_ver_str': [ '             Module 1: v3.0',
                         '             Module 2: v2.0',
                         '             Module not detected',
                         '             Module not detected'],
  'proc_board_id': 'FOC190386H4',
  'rr_ctime': ' Tue Jan 26 14:22:12 2016\n',
  'rr_reason': 'Reset due to upgrade',
  'rr_service': '',
  'rr_sys_ver': '7.3(8)N1(1)',
  'rr_usecs': 628308,
  'sys_ver_str': '7.3(11)N1(1)',
  'ucontroller_ver_str': 'v1.2.0.1'}
^^^^ END pyntc_show ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* n5k2 ** changed : False ******************************************************
vvvv pyntc_show ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO
{ 'bios_cmpl_time': '05/09/2012',
  'bios_ver_str': '3.6.0',
  'bootflash_size': 2007040,
  'chassis_id': 'Nexus5548 Chassis',
  'cpu_name': 'Intel(R) Xeon(R) CPU        ',
  'header_str': 'Cisco Nexus Operating System (NX-OS) Software\n'
                'TAC support: http://www.cisco.com/tac\n'
                'Documents: '
                'http://www.cisco.com/en/US/products/ps9372/tsd_products_support_series_home.html\n'
                'Copyright (c) 2002-2022, Cisco Systems, Inc. All rights '
                'reserved.\n'
                'The copyrights to certain works contained herein are owned '
                'by\n'
                'other third parties and are used and distributed under '
                'license.\n'
                'Some parts of this software are covered under the GNU Public\n'
                'License. A copy of the license is available at\n'
                'http://www.gnu.org/licenses/gpl.html.\n',
  'host_name': 'Nexus5K-2',
  'isan_cmpl_time': ' 2/8/2022 3:00:00',
  'isan_file_name': 'bootflash:///n5000-uk9.7.3.11.N1.1.bin',
  'isan_tmstmp': '02/08/2022 14:26:50',
  'kern_uptm_days': 0,
  'kern_uptm_hrs': 1,
  'kern_uptm_mins': 37,
  'kern_uptm_secs': 48,
  'kick_cmpl_time': ' 2/8/2022 3:00:00',
  'kick_file_name': 'bootflash:///n5000-uk9-kickstart.7.3.11.N1.1.bin',
  'kick_tmstmp': '02/08/2022 12:31:24',
  'kickstart_ver_str': '7.3(11)N1(1)',
  'mem_type': 'kB',
  'memory': 8253792,
  'module_id': 'O2 32X10GE/Modular Universal Platform Supervisor',
  'power_seq_ver_str': [ '             Module 1: v3.0',
                         '             Module 2: v2.0',
                         '             Module not detected',
                         '             Module not detected'],
  'proc_board_id': 'FOC190386H2',
  'rr_ctime': ' Tue Jan 26 14:33:19 2016\n',
  'rr_reason': 'Reset due to upgrade',
  'rr_service': '',
  'rr_sys_ver': '7.3(8)N1(1)',
  'rr_usecs': 68494,
  'sys_ver_str': '7.3(11)N1(1)',
  'ucontroller_ver_str': 'v1.2.0.1'}
^^^^ END pyntc_show ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

## Questions

For any questions or comments, please feel free to swing by the [networktocode slack channel](https://networktocode.slack.com).

Sign up [here](http://slack.networktocode.com/)

