-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab4_task2_create_tenant.py
53 lines (45 loc) · 1.24 KB
/
lab4_task2_create_tenant.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
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
# 2. task
TENANT_NAME = 'APILAB-GUI'
TENANT_VRF_NAME = 'APILAB-GUI-VRF'
payload_task = {
'fvTenant' : {
'attributes': {
'dn': f'uni/tn-{TENANT_NAME}',
'name': TENANT_NAME,
'rn': f'tn-{TENANT_NAME}',
'status': 'created',
},
'children': [
{'fvCtx': {
'attributes': {
'dn': f'uni/tn-{TENANT_NAME}/ctx-{TENANT_VRF_NAME}',
'name': TENANT_VRF_NAME,
'rn': f'ctx-{TENANT_VRF_NAME}',
'status': 'created'
},
'children': []
}}
]
}
}
result = requests.post(f'{URL}api/node/mo/uni/tn-{TENANT_NAME}.json', data=json.dumps(payload_task), verify = False, cookies=COOKIES)
print('Return code: {code}'.format(code=result.status_code))
pprint(result.content)