-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab6_task5_application_profile_vzAny.py
161 lines (142 loc) · 4.71 KB
/
lab6_task5_application_profile_vzAny.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
import requests
import json
from pprint import pprint
requests.packages.urllib3.disable_warnings()
USERNAME = 'admin'
PASSWORD = '1234QWer'
URL = 'https://192.168.10.1/'
# 1. Authentication
payload = {
'aaaUser': {
'attributes': {
'name': USERNAME,
'pwd': PASSWORD
}
}
}
auth = requests.post(f'{URL}api/aaaLogin.json', data=json.dumps(payload), verify=False)
COOKIES = auth.cookies
# create bridge domain for DNSany
BD_NAME = 'APILAB-GUI-DNS-BD'
GATEWAY = '192.168.144.254/24'
TENANT = 'APILAB-GUI'
VRF = 'APILAB-GUI-VRF'
payload_bd = {
'fvBD': {
'attributes': {
'dn': f'uni/tn-{TENANT}/BD-{BD_NAME}',
'mac': '00:22:BD:F8:19:FF',
'arpFlood': 'true',
'name': BD_NAME,
'rn': f'BD-{BD_NAME}',
'status': 'created'
},
'children': [
{'fvSubnet': {
'attributes': {
'dn': f'uni/tn-{TENANT}/BD-{BD_NAME}/subnet-[{GATEWAY}]',
'ctrl': '',
'ip': GATEWAY,
'preferred': 'true',
'rn': f'subnet-[{GATEWAY}]',
'status': 'created'},
'children': []
}
},
{'fvRsCtx': {
'attributes': {
'tnFvCtxName': VRF,
'status': 'created,modified'},
'children': []
}
}
]
}
}
result_bd = requests.post(f'{URL}api/node/mo/uni/tn-{TENANT}/BD-{BD_NAME}.json', data=json.dumps(payload_bd), verify = False, cookies=COOKIES)
print('Return code: {code}'.format(code=result_bd.status_code))
pprint(result_bd.content)
# create contract
FILTER = 'DNS'
CONTRACT_NAME = 'DNSany'
SUBJECT_NAME = 'DNS'
payload_contr = {
'vzBrCP': {
'attributes': {
'dn': f'uni/tn-{TENANT}/brc-{CONTRACT_NAME}',
'name': CONTRACT_NAME,
'rn': f'brc-{CONTRACT_NAME}',
'status': 'created'},
'children': [
{'vzSubj': {
'attributes': {
'dn': f'uni/tn-{TENANT}/brc-{CONTRACT_NAME}/subj-{SUBJECT_NAME}',
'name': SUBJECT_NAME,
'rn': f'subj-{SUBJECT_NAME}',
'status': 'created'},
'children':[
{'vzRsSubjFiltAtt': {
'attributes': {
'status': 'created,modified',
'tnVzFilterName': FILTER,
'directives': 'none'},
'children':[]}}
]}}
]}
}
result_contr = requests.post(f'{URL}api/node/mo/uni/tn-{TENANT}/brc-{CONTRACT_NAME}.json', data=json.dumps(payload_contr), verify = False, cookies=COOKIES)
print('Return code: {code}'.format(code=result_contr.status_code))
pprint(result_contr.content)
# create access profile
AP_NAME = 'DNS'
EPG_NAME = 'DNS_EPG'
payload_ap = {
'fvAp': {
'attributes': {
'dn': f'uni/tn-{TENANT}/ap-{AP_NAME}',
'name': AP_NAME,
'rn': f'ap-{AP_NAME}',
'status': 'created'},
'children': [
{'fvAEPg': {
'attributes': {
'dn': f'uni/tn-{TENANT}/ap-{AP_NAME}/epg-{EPG_NAME}',
'name': EPG_NAME,
'rn': f'epg-{EPG_NAME}',
'status': 'created'},
'children': [
{'fvRsBd': {
'attributes': {
'tnFvBDName': BD_NAME,
'status': 'created,modified'},
'children':[]
}
},
{'fvRsProv': {
'attributes': {
'tnVzBrCPName': CONTRACT_NAME,
'status': 'created,modified'},
'children':[]
}
}
]
}
}
]
}
}
result_ap = requests.post(f'{URL}api/node/mo/uni/tn-{TENANT}/ap-{AP_NAME}.json', data=json.dumps(payload_ap), verify = False, cookies=COOKIES)
print('Return code: {code}'.format(code=result_ap.status_code))
pprint(result_ap.content)
# vzANY
payload_vzany = {
'vzRsAnyToCons': {
'attributes': {
'tnVzBrCPName': CONTRACT_NAME,
'status': 'created'},
'children': []
}
}
result_vzany = requests.post(f'{URL}api/node/mo/uni/tn-{TENANT}/ctx-{VRF}/any.json', data=json.dumps(payload_vzany), verify = False, cookies=COOKIES)
print('Return code: {code}'.format(code=result_vzany.status_code))
pprint(result_vzany.content)