This repository has been archived by the owner on Apr 19, 2018. It is now read-only.
forked from michaelhenkel/tcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
changemmp.py
executable file
·66 lines (60 loc) · 2.27 KB
/
changemmp.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
#!/usr/bin/python
import sys
from jnpr.junos import Device
from jnpr.junos.utils.config import Config
mmpList = [{'mmp1':'192.168.1.11'},{'mmp2':'192.168.1.12'}]
serviceList = ['svc1','svc2','svc3']
sasList = [{'sas1':'192.168.1.130','sas2':'192.168.1.131'}]
creds = {'user':'root','password':'contrail123'}
if len(sys.argv) < 3:
print 'missing args'
sys.exit()
mmp = str(sys.argv[2])
sas = str(sys.argv[1])
nonpreferredDeviceList = []
for mmpItem in mmpList:
if mmpItem.keys()[0] == mmp:
preferredDevice = mmpItem.values()[0]
else:
nonpreferredDeviceList.append(mmpItem.values()[0])
preferredSvcList = []
for svcItem in range(3, len(sys.argv)):
preferredSvcList.append(sys.argv[svcItem])
print 'sas: %s, mmp: %s, svc: %s' % (sas, mmp, preferredSvcList)
print preferredDevice
print nonpreferredDeviceList
print creds['user']
dev = Device(host=preferredDevice, user=creds['user'], password=creds['password'])
dev.open()
for sasItem in sasList:
if sasItem.keys()[0] == sas:
sasPeer = sasItem.values()[0]
for prefSvc in preferredSvcList:
print 'device %s' % preferredDevice
varPolicy = "set policy-options policy-statement " + sas + "_" + prefSvc +"_to_var term " + prefSvc + " then metric 10"
sasPolicy = "set policy-options policy-statement " + sas + "_" + prefSvc +"_to_sas term " + prefSvc + " then local-preference 110"
print varPolicy
print sasPolicy
cfg = Config(dev)
cfg.lock()
cfg.load(varPolicy, format="set", merge=True)
cfg.load(sasPolicy, format="set", merge=True)
cfg.commit()
cfg.unlock()
dev.close()
for nonprefDev in nonpreferredDeviceList:
print 'device %s' % nonprefDev
dev = Device(host=nonprefDev, user=creds['user'], password=creds['password'])
dev.open()
cfg = Config(dev)
cfg.lock()
for prefSvc in preferredSvcList:
varPolicy = "set policy-options policy-statement " + sas + "_" + prefSvc +"_to_var term " + prefSvc + " then metric 20"
sasPolicy = "set policy-options policy-statement " + sas + "_" + prefSvc +"_to_sas term " + prefSvc + " then local-preference 100"
print varPolicy
print sasPolicy
cfg.load(varPolicy, format="set", merge=True)
cfg.load(sasPolicy, format="set", merge=True)
cfg.commit()
cfg.unlock()
dev.close()