我最终试图创建一些基本功能来使用Exscript来控制我的cisco测试实验室设备。到目前为止,Exscript已经为我完美地完成了所有事情,例如,我只是在做一些函数。
我遇到的问题是创建这个执行重新加载命令的reload_start()函数,重新启动我的Cisco设备,并恢复我在测试运行中所做的任何更改。我已经尝试了数十个不同的字符串组合来执行,但无法使它在输入“重新加载”时出现的附加提示中工作。
相反,我的copy_to_running_config()函数工作得很好,只需在字符串的末尾添加'\n‘。
我还没有跳入Exscript的提示函数(get_prompt()、expect_prompt()、with ()等),我猜这是我需要探索的途径,但我找不到这方面的例子来处理我的具体目标。
from Exscript import Account
from Exscript.protocols import Telnet
from Exscript.protocols.drivers import ios
def __init__(self, ip):
self.ip = ip
self.account = Account('admin', 'key')
self.conn = Telnet()
self.conn.set_driver('ios')
self.conn.connect(ip)
self.conn.login(self.account)
self.conn.execute('terminal length 0')
def enable(self):
self.conn.execute('enable')
def copy_to_running_config(self, config):
self.enable()
self.conn.execute('copy flash:{0} running-config \n'.format(config))
res = self.conn.response
self.conn.execute('exit')
return res
def reload_start(self):
self.enable()
self.conn.execute('reload \n no \n')
print self.conn.response任何帮助或投入将是非常感谢的!
发布于 2013-11-18 08:44:27
您的函数reload_start应该如下所示:
def reload_start(self):
self.enable()
self.conn.set_prompt(r'Save\? \[yes/no\]\:')
self.conn.execute('reload')
self.conn.set_prompt(r'Proceed with reload\? \[confirm\]')
self.conn.execute('no')
self.conn.set_prompt()
self.conn.execute('confirm')
print self.conn.response在执行命令之前,必须为提示符设置正则表达式。否则,Exscrpt无法确定何时发送下一个命令。
尽管如此,如果配置没有更改,路由器也没有要求您保存,那么上面的脚本将无法工作,因为它会等待保存问题。
https://stackoverflow.com/questions/18667848
复制相似问题