主备机房出口切换 python脚本
16lz
2021-02-24
在前东家的时候,A 机房出口偶发会挂掉,需要切换到备机房B-IDC 出口。全自动化脚本是不可能的,只能半自动化脚本进行切换。基本上就是在核心上把A机房的路由干掉,转化指向B机房。如果A机房出口恢复再反向切换回来。A机房使用的是华为核心交换、B机房使用的是思科的核心交换,比较有代表性。脚本做过实际测试,并且在大促的时候成功的切换过流量,减少了损失。个人感觉还是非常有价值的一件事情 。现在把脚本分享出来仅供语法格式参考,所有ip已做更改。
#! /usr/bin/env pythonimport pexpectimport syschild = pexpect.spawn('telnet 10.1.1.250') fout = file('huawei.txt','w')child.logfile = foutchild.expect("Username:")child.sendline('admin')child.expect('Password:')child.sendline('输入密码')child.expect('>')# for testchild.sendline('sys')child.expect(']')child.sendline('')#child.sendline('sys')child.expect(']')child.sendline('undo ip route-static 0.0.0.0 0.0.0.0 10.11.12.254')child.expect(']')child.sendline('ip route-static 0.0.0.0 0.0.0.0 172.32.4.2')child.expect(']')child.sendline('ip route-static 0.0.0.0 0.0.0.0 172.32.5.2')child.expect(']')child.sendline('quit')print "YJ-IDC changed finished"child = pexpect.spawn('telnet 10.12.2.1')fout = file('cisco.txt','w')child.logfile = foutchild.expect("Username:")child.sendline('admin')child.expect('Password:')child.sendline('cisco@123')child.expect('>')child.sendline('en')child.expect('Password:')child.sendline('输入密码')child.expect('#')child.sendline('conf t')child.expect('#')child.sendline('')child.expect('#')child.sendline('')child.expect('#')child.sendline('ip route 172.17.0.0 255.255.0.0 172.32.2.1')child.expect('#')child.sendline('ip route 172.17.0.0 255.255.0.0 172.32.3.1')child.expect('#')child.sendline('ip route 0.0.0.0 0.0.0.0 10.1.1.254')child.expect('#')child.sendline('no ip route 0.0.0.0 0.0.0.0 172.32.2.1')child.expect('#')child.sendline('no ip route 0.0.0.0 0.0.0.0 172.32.3.1')child.expect('#')child.sendline('exit')child.expect('#')child.sendline('exit')print "ALL OF changed outside route finished"
©著作权归作者所有:来自51CTO博客作者X糊涂仙儿的原创作品,如需转载,请注明出处,否则将追究法律责任我们一起来让这个世界有趣一点
赞赏
0人进行了赞赏支持
更多相关文章
- 支持向量机SVM原理(参数解读和python脚本)
- 破解助手、资源下载,2019年九月最新实用油猴脚本推荐,一定要看到最
- IDM下载神器全新详解教程:如何安装以及不限速下载某网盘资源
- 半自动化多站点屏蔽恶意用户的IP(脚本)
- 在Nginx使用Lua扩展功能
- 如何用自己的数据制作Pascal VOC格式数据集(详细教程,附带所有代码
- Repo on Ubuntu
- 快速提高Android开发调试的使用技巧
- JNI实战-Android深度学习模型部署