Skip to content
Snippets Groups Projects
Commit 32af0a13 authored by Erik Reid's avatar Erik Reid
Browse files

load junosspace devices

parent af6eefe7
No related branches found
No related tags found
No related merge requests found
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment