-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_duplicate_ip.py
More file actions
74 lines (61 loc) · 2.08 KB
/
delete_duplicate_ip.py
File metadata and controls
74 lines (61 loc) · 2.08 KB
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
"""
Simple application that recover duplicate IP test
"""
import requests
import json
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def main():
"""
recover duplicate IP test
:return: None
"""
# Login to APIC
description = ('Simple application that logs on to the APIC'
' and change speed of an interface.')
cookie = login("https://[IP ADDRESS]:443/api/aaaLogin.json")
if not cookie:
print('%% Could not login to APIC')
# Below logic, changes the speed
http_link="https://[IP ADDRESS]/api/node/mo/uni/tn-Terraform_Tenant/ap-test-app/epg-APP_EPG.xml"
request_api(http_link, cookie)
def login(url):
payload = {
"aaaUser": {
"attributes": {
"name": "admin",
"pwd": "PASSWORD"
}
}
}
headers = {'Content-Type': "application/json"}
response = requests.post(url, data=json.dumps(payload), headers=headers, verify=False).json()
# PARSE TOKEN AND SET COOKIE
token = response['imdata'][0]['aaaLogin']['attributes']['token']
cookie = {}
cookie['APIC-cookie'] = token
return cookie
def request_api(add_url, TOKEN):
header ={'Content-Type': "text/xml",
# "Accept": "application/json"
# "X-Aci-Username":"admin",
# 'X-Aci-Rbac': json.dumps({'domain': 'all', "rolesR": 0, "rolesW": 1}),
# 'Cookie':json.dumps({'Set-Cookie': TOKEN})
}
body = """<fvAEPg name="APP_EPG"><fvRsPathAtt encap="vlan-971" instrImedcy="immediate" mode="regular" primaryEncap="unknown" tDn="topology/pod-1/paths-102/pathep-[eth1/7]"/></fvAEPg>"""
req = requests.post(url=add_url, data=body, headers=header, cookies=TOKEN, verify=False)
res = ""
try:
resp = json.dumps(req.json(), indent=1)
# res = json.loads(resp)
except ValueError as e:
resp = req.content
if resp:
print(resp)
else:
print("Could not get data!!!")
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass