我最终尝试创建一些基本功能来使用Exscript控制我的思科测试实验室设备。到目前为止,Exscript已经完美地为我做了所有的事情,例如,我只介绍了一些函数。在
我遇到的问题是创建这个reload_start()函数来执行reload命令,重新启动我的Cisco设备并恢复我在测试运行中所做的任何更改。我尝试了几十种不同的字符串组合来执行,但无法使其绕过键入“reload”时出现的其他提示
相比之下,我的copy_to_running_config()函数运行得很好,只需在字符串末尾添加“\n”。在
我还没有进入Exscript的提示函数(get_prompt()、expect_prompt()、waitfor()等),我想这是我需要探索的途径,但我找不到与我的特定目标相关的示例。在
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
任何帮助或意见将不胜感激!在
函数reload_start应如下所示:
在执行命令之前,必须为提示设置正则表达式。否则Exscrpt无法确定何时发送下一个命令。在
然而,如果配置没有改变,路由器也不要求您保存,上面的脚本将无法工作,因为它将等待保存问题。在
相关问题 更多 >
编程相关推荐