-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSDWAN_inv.py
47 lines (33 loc) · 1.31 KB
/
SDWAN_inv.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
#!/usr/bin/env python
from ansible.module_utils.basic import *
import requests
import urllib3
serveraddress = "1.4.28.28"
username = "admin"
password = "admin"
systemip = "172.1.30.3"
def initalize_connection(serveraddress,username,password):
# Disable warnings like unsigned certificates, etc.
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
url="https://"+serveraddress+"/j_security_check"
payload = "j_username="+username+"&j_password="+password
headers = {
'Content-Type': "application/x-www-form-urlencoded",
}
sess=requests.session()
# Handle exceptions if we cannot connect to the vManage
try:
response = sess.request("POST", url, data=payload, headers=headers,verify=False,timeout=10)
except requests.exceptions.ConnectionError:
print ("Unable to Connect to "+ipaddress)
return False
return sess
def get_inventory(serveraddress,session):
module = AnsibleModule(argument_spec={})
url = "https://" + serveraddress + "/dataservice/device"
response = session.request("GET",url,verify=False,timeout=10)
json_string = response.json()
module.exit_json(changed=False, meta=json_string)
session=initalize_connection(serveraddress,username,password)
if session != False:
get_inventory(serveraddress,session)