我目前正在开发一个 python 代码,该代码使用结构模块连接到远程 brocade 交换机并发出一些配置命令。我面临的问题是涉及需要用户输入的命令(即是/否)。
我阅读了几篇建议使用 Fabric 的本机设置方法以及 wexpect 的帖子,但没有一个成功。
我检查了以下链接,但没有一个能够帮助我的代码:
以下是需要自动化的命令输出示例:
DS300B_Autobook:admin> cfgsave
您即将保存定义的分区配置。这个
操作只会保存已定义配置的更改。
如果更新包括对一个或多个流量隔离的更改
区域,您必须发出“cfgenable”命令进行更改
生效。
是否只想保存定义的分区配置?(是,是,否,n):[否]
我为此编写的代码如下所示(试图使其与命令提供的输出完全相同):
with settings(prompts={"DS300B_Autobook:admin> cfgsave\n"
"You are about to save the Defined zoning configuration. This\n"
"action will only save the changes on Defined configuration.\n"
"If the update includes changes to one or more traffic isolation\n"
"zones, you must issue the 'cfgenable' command for the changes\n"
"to take effect.\n"
"Do you want to save the Defined zoning configuration only? (yes, y, no, n): [no] " : "yes"}):
c.run('cfgsave')
如果有办法让它在屏幕上显示命令的输出并提示我提供输入,这也是合理的解决方案。