在路由器配置中替换字符串使用python

时间:2017-12-02 05:10:54

标签: python

我尝试在securecrt中为juniper路由器运行python脚本,我在其上显示配置然后对其中的字符串进行更改/替换,我想获取show configuration的输出然后将其放入列表然后进行更改然后将其更改为字符串然后应用它。

示例如下:

@路由器> ... tch ARI |显示集

#set policy-options policy-statement STM64-L1 term ARI from route-filter 1.1.1.1/32 exact 
#set policy-options policy-statement STM64-L1 term ARI then accept
#set policy-options policy-statement STM64-L1 term rej then reject 

在其中我想用10G-L100替换字符串STM64-L1然后再将配置作为字符串应用于路由器

我的代码如下:

crt.Screen.Synchronous = True
JGR= crt.Dialog.Prompt("enter term name that will applied: ")    
rep= crt.Dialog.Prompt("enter term name that will removed ")     
pol= crt.Dialog.Prompt("enter policy that will remove term from it ")    
npt= crt.Dialog.Prompt("enter policy that will add term to it ")    
crt.Screen.Send("show configuration | display set | match " +JGR+ "\n")
crt.Screen.WaitForString("/n")
x=crt.Screen.ReadString("exact")
x.split(",")
term_name=x
term_name=list()
for word in term_name:
    h=term_name.index(pol)
    term_name.pop(h)
    term_name.insert(h,npt)
yyy= ' '.join(term_name)
crt.Screen.Send("edit private "+ "\n")
crt.Screen.WaitForString("router#")
crt.Screen.Send(yyy+ "\n")
crt.Screen.WaitForString("router#")
crt.Screen.Send("show | compare " + "\n")
crt.Screen.Synchronous = False

main()的

但是我面临的问题是脚本运行时没有错误但没有应用配置,因为yyy的值只是空格?

由于

0 个答案:

没有答案