-
Notifications
You must be signed in to change notification settings - Fork 0
/
vprprovision.py
402 lines (309 loc) · 16.9 KB
/
vprprovision.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
import os
import sys
import select
import re
import time
################################
def Ftn_Read_File ():
source = ''
conf1 = ' '
if len(sys.argv) >= 2:
try:
conf1 = sys.argv[-1]
except:
print 'Something is wrong with your arguments. \
Please reference help.'
else:
print 'No arguments was provided. Please use \
"a file to run the script".'
# read the config file
try:
with open(conf1) as f:
source = f.readlines()
except IOError:
print "Can't read running config file."
return (source)
############################
'''
def Ftn_Read_File2():
if len(sys.argv) > 1:
try:
conf1 = sys.argv[-4]
conf2 = sys.argv[-3]
conf3 = sys.argv[-2]
conf4 = sys.argv[-1]
except:
print 'Something is wrong with your arguments. \
Please reference help.'
else:
print 'No arguments was provided. Please use \
"./maint_helper source_running_file destination_running_file".'
try:
with open(conf1) as f:
oldvlans = f.readlines()
with open(conf2) as f:
newvlans = f.readlines()
with open(conf3) as f:
newvprids = f.readlines()
with open(conf4) as f:
newips = f.readlines()
except IOError:
print "Can't read running config file."
return oldvlans,newvlans,newvprids,newips
'''
##########################
def Format_File_Input_To_Array():
Array = []
source = Ftn_Read_File ()
for num, line in enumerate(source , 0):
if len(line) != 0:
Array.append(line)
return Array
def Format_File_Input_To_Array2():
Arrayold = []
Arraynew = []
Arrayvprids =[]
Arrayips = []
oldvlans,newvlans,Newvprids,NewIps = Ftn_Read_File2()
for num, line in enumerate(oldvlans , 0):
if len(line) != 0:
Arrayold.append(line)
for num, line in enumerate(newvlans , 0):
if len(line) != 0:
Arraynew.append(line)
for num, line in enumerate(Newvprids , 0):
if len(line) != 0:
Arrayvprids.append(line)
for num, line in enumerate(NewIps , 0):
if len(line) != 0:
Arrayips.append(line)
return Arrayold,Arraynew,Arrayvprids,Arrayips
oldarrayvlans = []
newarrayvlans = []
newarrayvprids = []
newarrayips = []
vlanLAN = 0
#print newarrayips
#print newarrayvprids
vlan = 0
source = Ftn_Read_File()
#oldarrayvlans,newarrayvlans,newarrayvprids,newarrayips = Format_File_Input_To_Array2()
for num, line in enumerate(source , 1):
if re.search('^@oldvlan',line):
vlan = line.strip('@oldvlan').strip()
oldarrayvlans.append(vlan)
if re.search('^@newvlan',line):
vlan = line.strip('@newvlan').strip()
newarrayvlans.append(vlan)
if re.search('^@newvprid',line):
vlan = line.strip('@newvprid').strip()
newarrayvprids.append(vlan)
if re.search('^@newip',line):
vlan = line.strip('@newip').strip()
newarrayips.append(vlan)
print oldarrayvlans
print newarrayvlans
print newarrayvprids
print newarrayips
#exit()
print '****************************************'
print '****************************************'
print '***config for 903-01SH****'
print '****************************************'
for vlans in range(len(oldarrayvlans)):
print('delete protocols vstp vlan %s' % oldarrayvlans[vlans].strip())
print('delete vlans VLAN%s' % oldarrayvlans[vlans].strip())
print('delete interfaces ae0 unit 0 family ethernet-switching vlan members %s' % oldarrayvlans[vlans].strip())
print('delete interfaces ae1 unit 0 family ethernet-switching vlan members %s' % oldarrayvlans[vlans].strip())
print('delete interfaces ae2 unit 0 family ethernet-switching vlan members %s' % oldarrayvlans[vlans].strip())
print '****************************************'
print '****************************************'
print '***config for 903-01SH****New VPR'
print '****************************************'
for vlans in range(len(newarrayvlans)):
print('set vlans VLAN%s description VPR-%s-WAN' % (newarrayvlans[vlans].strip(),newarrayvprids[vlans].strip()))
print('set vlans VLAN%s vlan-id %s ' % (newarrayvlans[vlans].strip(),newarrayvlans[vlans].strip()))
print('set interfaces ae0 unit 0 family ethernet-switching vlan members %s' % newarrayvlans[vlans].strip())
print('set interfaces ae1 unit 0 family ethernet-switching vlan members %s' % newarrayvlans[vlans].strip())
print('set interfaces ae2 unit 0 family ethernet-switching vlan members %s' % newarrayvlans[vlans].strip())
print('set protocols vstp vlan %s bridge-priority 0 ' % newarrayvlans[vlans].strip())
print '****************************************'
print '****************************************'
print '***config for 903-02SH****New VPR'
print '****************************************'
for vlans in range(len(newarrayvlans)):
vlanLAN = (int)(newarrayvlans[vlans].strip())
vlanLAN = vlanLAN + 1
print('set vlans VLAN%s description VPR-%s-WAN' % (newarrayvlans[vlans].strip(),newarrayvprids[vlans].strip()))
print('set vlans VLAN%s vlan-id %s ' % (newarrayvlans[vlans].strip(),newarrayvlans[vlans].strip()))
print('set vlans VLAN%s description VPR-%s-LAN' % (vlanLAN,newarrayvprids[vlans].strip()))
print('set vlans VLAN%s vlan-id %s ' % (vlanLAN,vlanLAN))
vlanLAN = (int)(newarrayvlans[-1].strip())
vlanLAN = vlanLAN + 1
print('set interfaces ae0 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae1 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae11 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae12 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae13 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae14 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae15 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae16 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae17 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae18 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae19 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae20 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae21 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae22 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae23 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae24 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae25 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae26 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae27 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae28 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae29 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae30 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae31 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae32 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae33 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae34 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae35 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae36 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae37 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae38 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae39 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae40 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae51 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae52 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae53 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae54 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae55 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae56 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae57 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae58 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae59 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae60 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae61 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae62 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae63 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae64 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae65 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae66 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae67 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae68 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae69 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae70 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae71 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae72 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae73 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae74 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae75 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae76 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae77 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae78 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae79 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae80 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae81 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae82 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae83 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae84 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae85 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae86 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae87 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae88 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print('set interfaces ae89 unit 0 family ethernet-switching vlan members %s-%s' % (newarrayvlans[0].strip(),vlanLAN))
print '****************************************'
print '****************************************'
print '***config for DR11****New VPR'
print '****************************************'
print '****************************************'
print '****************************************'
print '******DR11 config******'
print '****************************************'
counter = 0
count1 = 0
count2 = 0
vlancounter =0
for vlans in range(len(newarrayvlans)):
print('vlan %s' %newarrayvlans[vlans].strip())
print('name VPR-%s-WAN' % newarrayvprids[vlans].strip())
print('exit')
print '****************************************'
print ('interface Po201')
for vlans in range(len(newarrayvlans)):
print ('switchport trunk allowed vlan add %s' %newarrayvlans[vlans].strip())
print '****************************************'
for ips in range(len(newarrayips)):
if not(ips % 4):
#print 'find'
#print ips
counter = ips
if (counter +2) < (len(newarrayips) - 1):
count1 = counter + 1
count2 = count1 + 1
#print 'counter %d' %counter
#print 'count1 %d' %count1
#print 'count2 %d' %count2
print('interface vlan %s' % (newarrayvlans[vlancounter].strip()))
print('description VPR-%s-WAN | %s | %s | %s | Vlan%s ' % (newarrayvprids[vlancounter].strip(),newarrayips[counter].strip(),newarrayips[count1].strip(),newarrayips[count2].strip(),newarrayvlans[vlancounter].strip()))
print('ip address %s 255.255.255.224 ' % (newarrayips[count2].strip()))
print('ip verify unicast source reachable-via rx ')
print('no ip redirects')
print('no ip proxy-arp')
print('standby 1 ip %s' % (newarrayips[count1].strip()))
print('standby 1 timers 5 15')
print('standby 1 priority 110')
print('standby 1 preempt delay minimum 60')
print('standby 1 authentication VLAN%s' % (newarrayvlans[vlancounter].strip()))
print('standby 1 track 101 decrement 50')
print('service-policy input 1GbpsLimit')
print('service-policy output 1GbpsLimit')
print('no shut')
print('exit')
count1 = 0
count2 = 0
vlancounter = vlancounter + 1
#else:
#print 'not find'
#print ips
print '****************************************'
print '****************************************'
print '******DR12 config******'
print '****************************************'
counter = 0
count1 = 0
count2 = 0
vlancounter =0
for ips in range(len(newarrayips)):
if not(ips % 4):
#print 'find'
#print ips
counter = ips
if (counter +2) < (len(newarrayips) - 1):
count1 = counter + 1
count2 = count1 + 2
#print 'counter %d' %counter
#print 'count1 %d' %count1
#print 'count2 %d' %count2
#print 'vlanconter %d' %vlancounter
print('interface vlan %s' % (newarrayvlans[vlancounter].strip()))
print('description VPR-%s-WAN | %s | %s | %s | Vlan%s ' % (newarrayvprids[vlancounter].strip(),newarrayips[counter].strip(),newarrayips[count1].strip(),newarrayips[count2].strip(),newarrayvlans[vlancounter].strip()))
print('ip address %s 255.255.255.224 ' % (newarrayips[count2].strip()))
print('ip verify unicast source reachable-via rx ')
print('no ip redirects')
print('no ip proxy-arp')
print('standby 1 ip %s' % (newarrayips[count1].strip()))
print('standby 1 timers 5 15')
print('standby 1 priority 90')
print('standby 1 preempt delay minimum 60')
print('standby 1 authentication VLAN%s' % (newarrayvlans[vlancounter].strip()))
print('standby 1 track 101 decrement 50')
print('service-policy input 1GbpsLimit')
print('service-policy output 1GbpsLimit')
print('no shut')
print('exit')
count1 = 0
count2 = 0
vlancounter = vlancounter + 1
#else:
#print 'not find'
#print ips