Cisco Tech Club Webináře
On-line každých 14 dní
Peter Morvay
Nornir, PyATS- automatizace, jak ji potřebujete
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public
”I am not sure why they are reinventing Ansible”
3
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public © 2019 Cisco and/or its affiliates. All rights reserved.
Nornir
Flexible and scalable network automation framework where everything is done in Python
4
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public
• Why use Framework?
• Systematic Inventory Management
• Modular integration to other ligraries (netmiko, …)
• Integrated Concurrency
• Systematizes automation approach
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public
• + Own integrations to IPAMs
• https://nornir.readthedocs.io/en/stable/ref/api/inventory.html#
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public
Internal inventory
Host > Group1 > Group2 > Default
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public
Inventory
---
localhost:
hostname: localhost
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public
nr = InitNornir(config_file="config.yaml")
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public
nr.run(task=my_task)
nr.close_connections()
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public
def my_task(task):
print(f"==== {task.host} ==== \n")
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public
Built-in tasks
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public
from nornir.plugins.functions.text import print_result
print_result(result)
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public
Demo
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public
Network profilingPyATS, Genie
20
State validation before and after changes (aka MTTI)
Parsersconverting/formatting command output into Python data structures
Parsing Function
Open-Source Libraries
• The core of pyATS & Genie is light weight, and platform, feature/protocol agnostic
• All platform, device, and feature implementations are open-source:
• Connection plugins & extensions
• Libraries - feature models, parsers, data-driven testcases are loaded via an abstracted library layer (eg: https://github.com/CiscoTestAutomation/genieparser)
Example:
• IOSXE (eg asr1k, cat9k)• Junos
• NXOS (eg n9k, n7k)• NSO
• IOSXR (eg asr9k)• NGFW (eg, asa)
Solution Layout
• Topology & Test definition
• Execution & ReportingpyATS Core Test InfrastructureToolbox
• Basis for agnostic automation libraries
• Boilerplate library foundation & engineGenie Library Framework
• Parsers, Feature/Protocol Models
• Reusable Testcases: Triggers, VerificationsGenie Libs
SDK & Library
• XPRESSO, Ansible, RobotFramework
• Jenkins, CI/CD pipelines, CLI, other tooling, etcIntegrationBusiness Logic
pyATS | Genie Parsers
https://pubhub.devnetcloud.com/media/pyats-packages/docs/genie/genie_libs/#/parsers
Features:
• 1200+ individual parsers across Cisco network OS and counting
• Agnostic framework: multiple OS/Platform/Release/etc support
• Multi-mgmt. protocol: support for parsing CLI/NETCONF/XML/etc
• Self-testing: each parser features its own schema
Environment
• Linux/macOS/WSL
• Python 3.4-3.7 (3.8 soon)
• Generates HTML+Text and Email Reports
• Plugin-based engine – integrates into anything
bash$ python3 –m venv ~/pyatsbash$ source ~/pyats/bin/activate(pyats) bash$ pip install pyats[full]
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public
Demo
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public
Questions?
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public
By Jarry Pilař
Next TechClub: 21.1.2020
Principy řešení Software DefinedAccess pro podnikové sítě
30
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public
Sources
Nornir training https://pynet.twb-tech.com/class-nornir.html
Devnethttps://developer.cisco.com/netdevops/live/https://developer.cisco.com/netdevops/live/#s01t09https://developer.cisco.com/network-automation/detail/8755580187240324/
Code from presentationhttps://github.com/pmorvay/TechClub20_Nornir