-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlab3-01-get-host.py
More file actions
25 lines (18 loc) · 897 Bytes
/
lab3-01-get-host.py
File metadata and controls
25 lines (18 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from apicem_config import * # apicem_config.py is the central place to change the apic-em IP, username, password ...etc
# Get token - function is in apicem_config.py
ticket = get_X_auth_token()
headers = {"X-Auth-Token": ticket}
url = "https://"+apicem_ip+"/api/"+version+"/host" # API base url
try:
resp= requests.get(url,headers=headers,verify = False)
response_json = resp.json() # Get the json-encoded content from response
print ("Status: ",resp.status_code) # This is the http request status
print (json.dumps(response_json,indent=4)) # Convert "response_json" object to a JSON formatted string and print it out
except:
print ("Something wrong !")
sys.exit()
# Now create a list of host IP address
host_ip_list=[]
for item in response_json["response"]:
host_ip_list.append(item["hostIp"])
print ("\nThis is the list of host ip:\n",host_ip_list)