diff --git a/inventory_provider/juniper.py b/inventory_provider/juniper.py index 7645ed5a3df9e9ce7fa5bc1712d656d24a1412dc..705509d885918e04576c2ef48bcd4c3683b7a2b4 100644 --- a/inventory_provider/juniper.py +++ b/inventory_provider/juniper.py @@ -2,6 +2,8 @@ import logging from jnpr.junos import Device from lxml import etree +import requests +from requests.auth import HTTPBasicAuth from inventory_provider.constants import JUNIPER_LOGGER_NAME @@ -101,6 +103,7 @@ UNIT_SCHEMA = """<?xml version="1.1" encoding="UTF-8" ?> """ # noqa: E501 + def _rpc(hostname, ssh): dev = Device( host=hostname, @@ -218,3 +221,24 @@ def list_bgp_routes(netconf_config): # # return _loads(output[1]) if output[1] else {} # + +def load_routers_from_junosspace(config): + """ + query junosspace for configured devices + + :param config: junosspace config element from app config + :return: list of dictionaries, each element of which describes a router + """ + api_url = config['api'] + if not api_url.endswith('/'): + api_url += '/' + r = requests.get( + api_url + 'device-management/devices', + auth=HTTPBasicAuth(config['username'], config['password']), + # TODO: seems server doesn't send the full chain + # ... add the terena cert locally & reenable cert validateion + verify=False + ) + # TODO: use a proper exception type + assert r.status_code == 200 + return etree.fromstring(r.text.encode('utf-8')) \ No newline at end of file