网络运营商的命令行黑客工具包

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中定义。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java能否使用OpenJPA将一个实体持久化到多个持久化单元?   java如何访问当前按下的键   java singleton是否意味着哈希代码总是返回相同的值?   inputstream无法在Java中同时使用STDIN和STDERR读取程序输出   java运行时有多贵。getRuntime()与获取内存度量相结合   java AndroidStudio ListView适配器更新   java小程序请求未扩展实时会话   java是设置布尔值所必需的关键部分?   java比较两个字符串,并突出显示发现的不匹配项   java带抽屉布局,无论哪个屏幕处于活动状态,如何在按下后退键时关闭应用程序?   爪哇:颜色有什么区别。黑色和彩色。黑色   Velocity模板中子类的java访问方法   java如何快速学习Drools或其他规则引擎   从Java应用程序访问时缓存数据库查询结果   java cassandra nodetool JPLISAgent。c错误   java我正在解析一个没有pubDate的RSS提要,有没有其他方法可以确定一个项目是何时发布的?