Coder Social home page Coder Social logo

nornir-learning's Introduction

README

Required

Python3.5+

pip install nornir
pip install pandas
pip install xlwt
pip install xlrd

Use

ansible_inventoty.py: An example to parse ansible hosts file.

custom_csv_inventoty.py: A custom inventory plugin to parse csv file.

hp_comware_running_config_backup.py: Backup running config to file

hp_comware_gather_info.py

使用

下载所有文件即可

功能(更新……)

  1. 批量登录设备,执行单条命令,一般用来收集信息
  2. 将收集到的信息按照设备名称保存到gather_info文件夹
  3. 将收集到的信息解析之后保存到 excel 文件中,默认按设备名称区分 sheet ,也可将全部结果放入同一个 sheet

参数

  1. Parse output to Excel?(Y/N): parse=True 会把设备返回的内容格式化,如果模板错误或不存在,则将内容保存到文件中
  2. process_tasks(t,verbose=False) : 修改verbose=True 可以显示任务执行中的详细错误信息
  3. parse_to_excel(t,one_sheet=False): 修改one_sheet=True 可以将收集到的所有信息保存到同一个 excel sheet 页中

设置系统环境变量(自定义需求使用)

如果要解析输出,需要自行脚本中修改系统环境变量。

目前hp_comware相关的 TextFSM 大部分已合并到 ntc-templates,并且pip install ntc-templates后, Netmiko 会为自动在~/ntc-template/templates/index中查找 ntc-templates 索引文件,默认不用手工配置(仅针对 Linux)。
原理上netmikontc-templates都支持的设备型号及对应命令,都可以用本脚本进行解析输出。

如果需要测试或自定义解析模板文件,仍可参考textfsm_hpe_cmw7使用:

下载 textfsm_hpe_cmw7 中的 templates 文件夹保存到本地。

  1. Linux
    直接修改脚本的路径(line 24),或者bash运行:
# 修改为自己的路径
export NET_TEXTFSM=/path/to/textfsm_hpe_cmw7/templates/
  1. Windows
    我的电脑,右键【属性】--->【高级系统设置】--->【环境变量】--->【新建】--->变量名:NET_TEXTFSM 变量值(举例,按实际写):D:\textfsm_hpe_cmw7\templates
    然后取消注释并修改脚本中的路径(line 26),注意路径中的 \\,注释掉 line 24 。

有什么用?

专业网工,业余写脚本,造轮子!!!

小脚本更新记录

2020/06/23: 更新custom_inventory.py,添加groupsgroups->data->cmds 字段,可以根据分组,执行不同的命令 2020/03/15:更新Readme,textfsm_hpe_cmw7已弃用
2020/03/08:优化gather_info保存输出到文件功能,修改为追加模式并写入执行的命令,用来区分多次执行的结果;hp_comware_gather_info.py增加多条命令支持,可一次性收集多条信息
2020/03/04: 更新主机插件,现在可支持 csv 和 excel 文件
2020/03/02: 更新parse_to_excel,可以将所有输出保存在同一个 sheet 页中
2020/03/01:增加parse_to_excel,将设备输出的结果解析后保存到 excel 文件中,解析失败则写入文本文件
2020/02/26:调整plugins/tasks目录结构,分离任务模块;增加gather_info任务,用来收集设备输出信息,并写入到文本文件
2020/02/24:更新process_tasks,调整 verbose 输出
2020/02/20:添加 csv 主机插件,可从 csv 文件解析设备信息
2020/02/16:初次学习Nornir,主要以 HP_Comware 设备为验证对象进行学习

nornir-learning's People

Contributors

xdai555 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.