1 Star 0 Fork 46

xiaozhu1215/qytang_Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
2016.02.09 copy all config 22.17 KB
一键复制 编辑 原始数据 按行查看 历史
现任明教教主-乾颐堂 提交于 2016-02-09 10:28 . new file
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
#!/usr/bin/python3
import multiprocessing
from telnetlib import Telnet
from copyrouter import copyrouter
from copysw import copysw
from copyasafinal import copyasa
from copyips import copyips
from finalqytclearLine import routerclearline
from ftp import putfile
from qytmail import qytmail
#from ftp import ftp_up
import time
import os
import shutil
#veconfig = {'R1':'','R2':'','R3':'','R4':'','R5':'','R6':'','ASA1':'','ASA2':'','ASA3sys':'','ASA3admin':'','ASA3c1':'','ASA3c2':'','ASA4':'','SW1':'','SW2':'','SW3':'','SW4':'','SW5':'','SW6':'','IPS':''}
#vfconfig = {'R1':'','R2':'','R3':'','R4':'','R5':'','R6':'','ASA1sys':'','ASA1admin':'','ASA1c1':'','ASA1c2':'','ASA2sys':'','ASA2admin':'','ASA2c1':'','ASA2c2':'','ASA3':'','ASA4':'','SW1':'','SW2':'','SW3':'','SW4':'','SW5':'','SW6':'','IPS':''}
#v10config = {'R1':'','R2':'','R3':'','R4':'','R5':'','R6':'','ASA1':'','ASA3sys':'','ASA3admin':'','ASA3c1':'','ASA3c2':'','ASA4':'','SW1':'','SW2':'','SW3':'','SW4':'','SW5':'','SW6':'','IPS':''}
#v11config = {'R1':'','R2':'','R3':'','R4':'','R5':'','R6':'','ASA1':'','ASA2':'','ASA3sys':'','ASA3admin':'','ASA3c1':'','ASA3c2':'','ASA4':'','SW1':'','SW2':'','SW3':'','SW4':'','SW5':'','SW6':'','IPS':''}
#v12config = {'R1':'','R2':'','R3':'','R4':'','R5':'','R6':'','ASA1sys':'','ASA1admin':'','ASA1c1':'','ASA1c2':'','ASA2sys':'','ASA2admin':'','ASA2c1':'','ASA2c2':'','ASA3':'','ASA4':'','SW1':'','SW2':'','SW3':'','SW4':'','SW5':'','SW6':'','IPS':''}
def copyallconfig(username, password, rackno, verno):
index = []
for i in range(30):
index.append(1)
processes = []
allDone = 0
#清除所有占用的line,准备配置设备
clearlinemp = multiprocessing.Process(target=routerclearline, args=(username, password, rackno))
clearlinemp.start()
time.sleep(10)
# print(clearlinemp.exitcode)
if clearlinemp.exitcode == 3:
os._exit(0)
else:
pass
devices = []
#配置六台路由器
for i in range(6):
newri = i + 1
strri = str(newri)
copyroutermp = multiprocessing.Process(target=copyrouter, args=(username, password, rackno, verno, strri))
processes.append(copyroutermp)
copyroutermp.start()
devices.append('R%s' % str(newri))
time.sleep(10)
#配置六台交换机
for i in range(6):
newsi = i + 1
strsi = str(newsi)
copyswmp = multiprocessing.Process(target=copysw, args=(username, password, rackno, verno, strsi))
processes.append(copyswmp)
copyswmp.start()
devices.append('SW%s' % strsi)
time.sleep(10)
copyipsmp = multiprocessing.Process(target=copyips, args=(username, password, rackno, verno))
processes.append(copyipsmp)
copyipsmp.start()
devices.append('IPS')
if verno == 've'or verno == 'v11':
copyasa1 = multiprocessing.Process(target=copyasa, args=(username, password, rackno, verno, '1'))
processes.append(copyasa1)
devices.append('ASA1')
copyasa1.start()
copyasa2 = multiprocessing.Process(target=copyasa, args=(username, password, rackno, verno, '2'))
processes.append(copyasa2)
devices.append('ASA2')
copyasa2.start()
if verno == 've':
copyasa3sys = multiprocessing.Process(target=copyasa, args=(username, password, rackno, verno, '3', ['admin', 'c1', 'c2']))
processes.append(copyasa3sys)
devices.append('ASA3')
copyasa3sys.start()
else:
copyasa3sys = multiprocessing.Process(target=copyasa, args=(username, password, rackno, verno, '3', ['Admin', 'C1', 'C2']))
processes.append(copyasa3sys)
devices.append('ASA3')
copyasa3sys.start()
copyasa4 = multiprocessing.Process(target=copyasa, args=(username, password, rackno, verno, '4'))
processes.append(copyasa4)
devices.append('ASA4')
copyasa4.start()
if verno == 'vf'or verno == 'v12':
if verno == 'vf':
copyasa1 = multiprocessing.Process(target=copyasa, args=(username, password, rackno, verno, '1', ['admin', 'c1', 'c2']))
processes.append(copyasa1)
devices.append('ASA1')
copyasa1.start()
copyasa2 = multiprocessing.Process(target=copyasa, args=(username, password, rackno, verno, '2', ['admin', 'c1', 'c2']))
processes.append(copyasa2)
devices.append('ASA2')
copyasa2.start()
else:
copyasa1 = multiprocessing.Process(target=copyasa, args=(username, password, rackno, verno, '1', ['Admin', 'C1', 'C2']))
processes.append(copyasa1)
devices.append('ASA1')
copyasa1.start()
copyasa2 = multiprocessing.Process(target=copyasa, args=(username, password, rackno, verno, '2', ['Admin', 'C1', 'C2']))
processes.append(copyasa2)
devices.append('ASA2')
copyasa2.start()
copyasa3 = multiprocessing.Process(target=copyasa, args=(username, password, rackno, verno, '3'))
processes.append(copyasa3)
devices.append('ASA3')
copyasa3.start()
copyasa4 = multiprocessing.Process(target=copyasa, args=(username, password, rackno, verno, '4'))
processes.append(copyasa4)
devices.append('ASA4')
copyasa4.start()
if verno == 'v10':
copyasa1 = multiprocessing.Process(target=copyasa, args=(username, password, rackno, verno, '1'))
processes.append(copyasa1)
devices.append('ASA1')
copyasa1.start()
copyasa3 = multiprocessing.Process(target=copyasa, args=(username, password, rackno, verno, '3', ['admin', 'c1', 'c2']))
processes.append(copyasa3)
devices.append('ASA3')
copyasa3.start()
copyasa4 = multiprocessing.Process(target=copyasa, args=(username, password, rackno, verno, '4'))
processes.append(copyasa4)
devices.append('ASA4')
copyasa4.start()
#等待配置结束的信息
clock1 = time.clock()
while True:
clock2 = time.clock()
timetouse = int((clock2 - clock1) * 1000)
stringtimetouse = str(timetouse)
print('Use time: ' + stringtimetouse)
if verno == 'v10':
os.system('clear')
allDone = index.count(0)
if allDone == 16: break
for i in range(16):
if processes[i].exitcode == 0:
index[i] = 0
print('%s done' % devices[i])
else:
print('%s copying' % devices[i])
else:
os.system('clear')
allDone = index.count(0)
if allDone == 17: break
for i in range(17):
if processes[i].exitcode == 0:
index[i] = 0
print('%s done' % devices[i])
else:
print('%s copying' % devices[i])
if timetouse > 60:
print('Timeout')
if verno == 'v10':
for i in range(16):
try:
processes[i].terminate()
except:
pass
result = 0
else:
for i in range(17):
try:
processes[i].terminate()
except:
pass
result = 0
break
time.sleep(3)
timelst = time.asctime().split(' ')
finalconfigfile = '/python/cgi-bin/bakconfig/' + rackno + '-' + verno + '-' + yourname + '-' + timelst[5] + '-' + timelst[1] + '-' + timelst[3] + '.txt'
fianlconfig = open(finalconfigfile, 'w')
os.system('clear')
print('Waiting For create finalconfig')
for i in range(6):
i = i + 1
routerno = str(i)
configfile = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'R' + routerno + '.txt'
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'R' + routerno + '=' * 30 + '\n')
config = (open(configfile, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
os.system('clear')
print('Router config joined in finalconfig')
if verno == 've':
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA1' + '=' * 30 + '\n')
configfileasa1 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA1' + '.txt'
config = (open(configfileasa1, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA2' + '=' * 30 + '\n')
configfileasa2 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA2' + '.txt'
config = (open(configfileasa2, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA3/SYS' + '=' * 30 + '\n')
configfileasa3 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA3' + '.txt'
config = (open(configfileasa3, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA3/admin' + '=' * 30 + '\n')
configfileasa3admin = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA3admin' + '.txt'
config = (open(configfileasa3admin, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA3/c1' + '=' * 30 + '\n')
configfileasa3c1 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA3c1' + '.txt'
config = (open(configfileasa3c1, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA3/c2' + '=' * 30 + '\n')
configfileasa3c2 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA3c2' + '.txt'
config = (open(configfileasa3c2, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA4' + '=' * 30 + '\n')
configfileasa4 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA4' + '.txt'
config = (open(configfileasa4, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
if verno == 'v11':
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA1' + '=' * 30 + '\n')
configfileasa1 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA1' + '.txt'
config = (open(configfileasa1, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA2' + '=' * 30 + '\n')
configfileasa2 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA2' + '.txt'
config = (open(configfileasa2, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA3/SYS' + '=' * 30 + '\n')
configfileasa3 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA3' + '.txt'
config = (open(configfileasa3, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA3/admin' + '=' * 30 + '\n')
configfileasa3admin = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA3Admin' + '.txt'
config = (open(configfileasa3admin, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA3/c1' + '=' * 30 + '\n')
configfileasa3c1 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA3C1' + '.txt'
config = (open(configfileasa3c1, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA3/c2' + '=' * 30 + '\n')
configfileasa3c2 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA3C2' + '.txt'
config = (open(configfileasa3c2, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA4' + '=' * 30 + '\n')
configfileasa4 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA4' + '.txt'
config = (open(configfileasa4, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
if verno == 'vf':
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA1/SYS' + '=' * 30 + '\n')
configfileasa1 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA1' + '.txt'
config = (open(configfileasa1, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA1/admin' + '=' * 30 + '\n')
configfileasa1admin = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA1admin' + '.txt'
config = (open(configfileasa1admin, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA1/c1' + '=' * 30 + '\n')
configfileasa1c1 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA1c1' + '.txt'
config = (open(configfileasa1c1, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA1/c2' + '=' * 30 + '\n')
configfileasa1c2 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA1c2' + '.txt'
config = (open(configfileasa1c2, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA2/SYS' + '=' * 30 + '\n')
configfileasa2 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA2' + '.txt'
config = (open(configfileasa2, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA2/admin' + '=' * 30 + '\n')
configfileasa2admin = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA2admin' + '.txt'
config = (open(configfileasa2admin, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA2/c1' + '=' * 30 + '\n')
configfileasa2c1 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA2c1' + '.txt'
config = (open(configfileasa2c1, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA2/c2' + '=' * 30 + '\n')
configfileasa2c2 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA2c2' + '.txt'
config = (open(configfileasa2c2, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA3' + '=' * 30 + '\n')
configfileasa3 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA3' + '.txt'
config = (open(configfileasa3, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA4' + '=' * 30 + '\n')
configfileasa4 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA4' + '.txt'
config = (open(configfileasa4, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
if verno == 'v12':
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA1/SYS' + '=' * 30 + '\n')
configfileasa1 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA1' + '.txt'
config = (open(configfileasa1, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA1/admin' + '=' * 30 + '\n')
configfileasa1admin = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA1Admin' + '.txt'
config = (open(configfileasa1admin, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA1/c1' + '=' * 30 + '\n')
configfileasa1c1 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA1C1' + '.txt'
config = (open(configfileasa1c1, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA1/c2' + '=' * 30 + '\n')
configfileasa1c2 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA1C2' + '.txt'
config = (open(configfileasa1c2, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA2/SYS' + '=' * 30 + '\n')
configfileasa2 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA2' + '.txt'
config = (open(configfileasa2, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA2/admin' + '=' * 30 + '\n')
configfileasa2admin = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA2Admin' + '.txt'
config = (open(configfileasa2admin, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA2/c1' + '=' * 30 + '\n')
configfileasa2c1 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA2C1' + '.txt'
config = (open(configfileasa2c1, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA2/c2' + '=' * 30 + '\n')
configfileasa2c2 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA2C2' + '.txt'
config = (open(configfileasa2c2, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA3' + '=' * 30 + '\n')
configfileasa3 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA3' + '.txt'
config = (open(configfileasa3, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA4' + '=' * 30 + '\n')
configfileasa4 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA4' + '.txt'
config = (open(configfileasa4, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
if verno == 'v10':
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA1'+ '=' * 30 + '\n')
configfileasa1 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA1' + '.txt'
config = (open(configfileasa1, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA3/SYS' + '=' * 30 + '\n')
configfileasa3 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA3' + '.txt'
config = (open(configfileasa3, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA3/admin' + '=' * 30 + '\n')
configfileasa3admin = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA3admin' + '.txt'
config = (open(configfileasa3admin, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA3/c1' + '=' * 30 + '\n')
configfileasa3c1 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA3c1' + '.txt'
config = (open(configfileasa3c1, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA3/c2' + '=' * 30 + '\n')
configfileasa3c2 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA3c2' + '.txt'
config = (open(configfileasa3c2, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'ASA4' + '=' * 30 + '\n')
configfileasa4 = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'ASA4' + '.txt'
config = (open(configfileasa4, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
os.system('clear')
print('ASA config joined in finalconfig')
for i in range(6):
i = i + 1
swno = str(i)
configfile = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'SW' + swno + '.txt'
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'SW' + swno + '=' * 30 + '\n')
config = (open(configfile, 'r')).read()
fianlconfig.write(config)
time.sleep(2)
except:
pass
os.system('clear')
print('SW config joined in finalconfig')
try:
fianlconfig.write('\n')
fianlconfig.write('=' * 30 + 'IPS' + '=' * 30 + '\n')
configfileips = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'IPS' + '.txt'
config = (open(configfileips, 'r')).read()
print(config)
fianlconfig.write(config)
time.sleep(2)
except:
print('IPS config error')
fianlconfig.close()
os.system('clear')
print('IPS config joined in finalconfig')
tmpfiledir = '/python/cgi-bin/tmpconfig/' + verno + '/'
for file in os.listdir(tmpfiledir):
removefile = os.path.join(tmpfiledir, file)
if os.path.isfile(removefile):
os.remove(removefile)
os.system('clear')
print('Clearing tmp config')
# finalconfigfile = '/python/cgi-bin/bakconfig/' + rackno + '-' + verno + '-' + yourname + '-' + timelst[5] + '-' + timelst[1] + '-' + timelst[3] + '.txt'
os.chdir('/python/cgi-bin/bakconfig')
uploadfile = rackno + '-' + verno + '-' + yourname + '-' + timelst[5] + '-' + timelst[1] + '-' + timelst[3] + '.txt'
cmd = 'unix2dos %s' % uploadfile
os.system(cmd)
site = '172.17.100.205'
dir = '.'
os.system('clear')
print('uploading finalconfig file')
putfile(uploadfile, site, dir, user = ('labtest', 'Cisc0123'))
os.system('clear')
# ftp_up(configfileips)
print('ALL DONE!!!!!!')
mailtext = 'copy rack config ' + rackno + ' ' + verno
qytmail(username, mailtext)
if __name__ == "__main__":
import getpass
yourname = input('Your Username: ')
if yourname.strip() == '':
print('!' * 60)
print(' ' * 18 + 'Need Username')
print('!' * 60)
os._exit(0)
yourpw = getpass.getpass('Your Password: ')
if yourpw.strip() == '':
print('!' * 60)
print(' ' * 18 + 'Need Password')
print('!' * 60)
os._exit(0)
print('ve or vf or v10 or v11 or v12')
version = input('Your want to export which version: ')
if version == 've' or version == 'vf' or version == 'v10' or version == 'v11' or version == 'v12':
pass
else:
print('!' * 60)
print(" Version must in 've or vf or v10 or v11 or v12'")
print('!' * 60)
os._exit(0)
print('Serious attention the Rack is in you control')
print('BJRack01 or BJRack02 or BJRack03')
rackno1 = input('The Rack you want to config: ')
rackno2 = input('Reconfirm the Rack: ')
if rackno1 == rackno2:
rackno = rackno1
if rackno == 'BJRack01' or rackno == 'BJRack02' or rackno == 'BJRack03':
copyallconfig(yourname, yourpw, rackno, version)
else:
print('!' * 60)
print(" Rack Name must in 'BJRack01 or BJRack02 or BJRack03'")
print('!' * 60)
else:
print('!' * 60)
print(' Rackno Missmatch, Try again')
print('!' * 60)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/xiaozhu1215/qytang_Python.git
git@gitee.com:xiaozhu1215/qytang_Python.git
xiaozhu1215
qytang_Python
qytang_Python
master

搜索帮助