2019-03-08在思科交换机上运行Python

20190308 0950pm zcl

看了一篇文章,介绍网络设备的自动化运维。

On-Box Python for Cisco Devices – the Why, What, and How
https://blogs.cisco.com/developer/on-box-python-for-devices

https://github.com/aradford123/on-box-python

The EEM cron job runs the Python script at 15 minutes past the hour, Monday to Friday.

event manager applet PCI-check
event timer cron cron-entry "15 * * * 1-5"
action 1.0 cli command "enable"
action 1.1 cli command "guestshell run python bootflash:gs_script/src/pci-tool/pci_check.py --apply"

看懂了,每个15分钟,执行一次 pci_check.py Python程序。周六日休息。
pci_check.py 源代码在这里:
https://github.com/aradford123/on-box-python/blob/master/src/pci-tool/pci_check.py


pci_check.py

程序里面, import 了很多模块。例如: jtextfsm , 这是啥?

template = open("/flash/gs_script/src/pci-tool/show_int.textfsm")

A quick example of using TextFSM to parse data from Cisco show commands
http://gratuitousarp.info/a-quick-example-of-using-textfsm-to-parse-data-from-cisco-show-commands/

TextFSM is a powerful parsing tool (python module) developed by Google.
Programmatic Access to CLI Devices with TextFSM FEBRUARY 26, 2015
http://jedelman.com/home/programmatic-access-to-cli-devices-with-textfsm/
Netmiko and TextFSM
https://pynet.twb-tech.com/blog/automation/netmiko-textfsm.html
TextFSM and Structured DataBy Kirk Byers 2015-10-22
https://pynet.twb-tech.com/blog/python/textfsm.html

https://pynet.twb-tech.com/class-pyauto.html
https://www.cnblogs.com/zz27zz/p/9686496.html
https://www.cnblogs.com/zz27zz/category/1073510.html

https://www.cisco.com/c/dam/assets/global/CN/pdfs/innovation/en_dnadeveloperbestpracticesharing_ppt_sc.pdf

TextFSM

今天是3月8号,是三八父女节。哈哈。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • # Awesome Python [![Awesome](https://cdn.rawgit.com/sindr...
    emily_007阅读 2,242评论 0 3
  • 很多朋友来问我怎么减肥的时候 我一般不会给他正面的回答 我会问他,你为什么要减肥? 答案真可谓是五花八门 我 我要...
    翡翠蝴蝶阅读 214评论 0 0
  • 1.保持内心的平静,从容,享受每一天的遇见。 2.我们原本是富足的,不要被恐惧和担心毁掉美好的生活,我们是宇宙完美...
    素锦_b3dd阅读 164评论 0 0
  • 不愿在午门前站岗, 只想到后宫里喝酒。 幻想常使人陶醉, 现实不容尔出头。 没力气不必硬挣, 有夲事何须自夸。
    坦人阅读 829评论 11 29