网络运营商的命令行黑客工具包
notch.agent的Python项目详细描述
notch为所有网络设备提供编程接口 像交换机,路由器和防火墙。其代理管理 网络中网络设备的命令行接口,以便 您可以使用 包括python库或使用json-rpc的其他语言 接口。
注意
这个包只提供了notch代理。上的基本安装 单个计算机还需要客户端库,可在 notch.client包。
例如,要从每个Cisco ISH获取版本信息 网络上的设备(通过运行在localhost:8080的notch代理):
#!/usr/bin/env python import notch.client def callback(request): """Called by the Notch Client when a request is complete.""" if request.error: print 'Exception: ', str.error.__class__.__name__ print str(request.error) else: print request.result nc = notch.client.Connection('localhost:8080') # Gets a list of devices from the Notch Agent. try: all_devices = nc.devices_matching('^.*$') except notch.client.Error: print 'Error querying for devices.' all_devices = [] # Send the command to each device, asynchronously receiving results. for device in all_devices: nc.command(device, 'show version', callback=callback) # Wait for all outstanding requests to complete. nc.wait_all()
安装
注意
从0.5版开始,notch被拆分成单独的notch.client 和共享命名空间包的notch.agentpypi包 notch。
<> >从早期版本升级用户必须删除所有现有的缺口 继续安装之前的软件包:$ pip uninstall notch $ pip uninstall notch.client $ pip uninstall notch.agent
还要检查pythonsite-packages目录以确保 没有任何notch*文件或目录。
使用pip安装notch代理或客户端库。
首先需要两个包,但在较大的安装中, 只有充当代理的机器才需要notch.agent包。
$ pip install notch.agent $ pip install notch.client
这将安装除一个依赖项之外的所有依赖项,然后可以使用以下命令安装这些依赖项:
$ pip install -e git+https://github.com/joshmarshall/tornadorpc.git@fda3e0e4#egg=tornadorpc-dev
您也可以使用easy_install,但我们不建议这样做。如果你不知道 拥有pip,首先使用easy_install安装它。
配置
notch代理需要一些配置才能开始 如果你已经使用了腐臭系统,作为陷波剂 将读取其router.db配置文件以填充其资源清册。
然后,您可以使用内置测试服务器启动notch代理:
$ notch-agent --config=/path/to/your/notch.yaml
内置测试服务器不支持并行操作,因此 必须使用与wsgi兼容的服务器进行生产操作。Apache2与 mod_wsgi用于许多安装和示例配置 可在config/notch-mod_wsgi.sample.conf中找到。wsgi应用程序 对象本身在wsgi/notch.wsgi中定义。