Introducing nornir-pyntc
Nornir-Pyntc is a Nornir Plugin. It extends the main functionality that Nornir provides by adding a plugin wrapping around pyntc library. nornir-pyntc comes with a connection
plugin and task
definitions that can be used via the Nornir core library.
What Is pyntc?
pyntc is an open-source multi-vendor Python library that establishes a common framework for working with different network APIs and device types. The main purpose of pyntc is to simplify the execution of common tasks.
What Is nornir-pyntc?
nornir-pyntc
is a collection of connection and tasks plugins.
Connection Plugin
pyntc_connection
– Manages device connections.
Tasks
The plugin comes with tasks that expose the basic pyntc functionality.
- pyntc_config – Pass configuration commands to a network device.
- pyntc_file_copy – Copy a file to a network device.
- pyntc_install_os – Install an operating system.
- pyntc_reboot – Reboot a network device.
- pyntc_save – Save the running configuration of a network device.
- pyntc_show – Send a single
show
command to a network device. - pyntc_show_list – Send multiple
show
commands to a network device.
Task Examples
This example illustrates how to use a task plugin and allow the task plugin to utilize the native nornir-pyntc connection:
# 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)
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 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
For an example of how to use the connection plugin to manually handle the connection to a device see Connection Examples.
Conclusion
nornir-pyntc is a prime candidate to utilize within Nautobot. This plugin can be used in conjunction with nornir-nautobot and nautobot-plugin-nornir to create automated jobs within the Nautobot infrastructure.
-Jeff
Tags :
Contact Us to Learn More
Share details about yourself & someone from our team will reach out to you ASAP!