-
Notifications
You must be signed in to change notification settings - Fork 3
/
lsp_ero.py
42 lines (34 loc) · 1.38 KB
/
lsp_ero.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
'''
Created on Feb 21, 2016
@author: azaringh
'''
import requests
requests.packages.urllib3.disable_warnings()
import json
url = "https://10.10.2.25:8443/oauth2/token"
payload = {'grant_type': 'password', 'username': 'some_name', 'password': 'some_password'}
response = requests.post (url, data=payload, auth=('some_name','some_password'), verify=False)
json_data = json.loads(response.text)
authHeader= {"Authorization":"{token_type} {access_token}".format(**json_data)}
r = requests.get('https://10.10.2.25:8443/NorthStar/API/v1/tenant/1/topology/1/te-lsps/', headers=authHeader, verify=False)
p = json.dumps(r.json())
lsp_list = json.loads(p)
# Find target LSP to use lspIndex
for lsp in lsp_list:
if lsp['name'] == 'GROUP_FIVE_SF_NY_LSP3':
break
# Fill only the required fields
ero= [
{ 'topoObjectType': 'ipv4', 'address': '10.210.15.2'},
{ 'topoObjectType': 'ipv4', 'address': '10.210.13.2'},
{ 'topoObjectType': 'ipv4', 'address': '10.210.17.1'}
]
new_lsp = {}
for key in ('from', 'to', 'name', 'lspIndex', 'pathType'):
new_lsp[key] = lsp[key]
new_lsp['plannedProperties'] = {
'ero': ero
}
response = requests.put('https://10.10.2.25:8443/NorthStar/API/v1/tenant/1/topology/1/te-lsps/' + str(new_lsp['lspIndex']),
json = new_lsp, headers=authHeader, verify=False)
print response.text