After some research I was able to get data via RESTful API from a networking device:
if sys.version_info >= (2,7,9):
import ssl
conn = httplib.HTTPSConnection('192.168.158.136', 443, context=ssl._create_unverified_context())
else:
conn = httplib.HTTPSConnection('192.168.158.136', 443)
headers = {"Authorization" : "Basic %s" % base64.b64encode('user:pass'),
"Content-Type" : "application/json"}
url="https://192.168.158.136/wapi/v1.2/network?_return_fields%2b=extattrs"
conn.request('GET', url, headers=headers)
response = conn.getresponse()
print response.read()
conn.close()
This prints me a json formatted list of the objects I need:
[
{
"_ref": "network/ZG5zLm5ldHdvcmskMTAuMC4wLjAvMjQvMA:10.0.0.0/24/default",
"extattrs": {
"Location": {
"value": "NAU"
}
},
"network": "10.0.0.0/24",
"network_view": "default"
},
{
"_ref": "network/ZG5zLm5ldHdvcmskMTAuMS4xLjAvMjQvMA:10.1.1.0/24/default",
"extattrs": {
"Location": {
"value": "BTN"
}
},
"network": "10.1.1.0/24",
"network_view": "default"
},
{
"_ref": "network/ZG5zLm5ldHdvcmskMTAuMi4yLjAvMjQvMA:10.2.2.0/24/default",
"extattrs": {
"Location": {
"value": "TRT"
}
},
"network": "10.2.2.0/24",
"network_view": "default"
},
{
"_ref": "network/ZG5zLm5ldHdvcmskMTkyLjE2OC4wLjAvMTYvMA:192.168.0.0/16/default",
"extattrs": {
"Location": {
"value": "MCW"
}
},
"network": "192.168.0.0/16",
"network_view": "default"
}
]
Now I need to "somehow" format that as a list which just contains the "network" and the content of the extattrs
"Location" (and only Location, there will be others to, but I need Location only) in the format of:
Network Location, i.e.
10.0.0.0/24 NAU 10.1.1.0/24 BTN 10.2.2.0/24 TRT 192.168.0.0/16 MCW
I'm struggling in getting this done, i.e. reformatting the JSON code I get back from the query.