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

removed connections with junosspace

parent 03d06d4e
No related branches found
No related tags found
No related merge requests found
...@@ -109,53 +109,6 @@ UNIT_SCHEMA = """<?xml version="1.1" encoding="UTF-8" ?> ...@@ -109,53 +109,6 @@ UNIT_SCHEMA = """<?xml version="1.1" encoding="UTF-8" ?>
""" # noqa: E501 """ # noqa: E501
# elements 'use-nat' and 'fingerprint' were added between
# junosspace versions 15.x and 17.x ... hopefully new versions
# will also add new elements at the end of the sequence so
# that the final xs:any below will suffice to allow validation
JUNOSSPACE_DEVICES_SCHEMA = """<?xml version="1.1" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="junosspace-device">
<xs:sequence>
<xs:element name="deviceFamily" minOccurs="1" maxOccurs="1" type="xs:string" />
<xs:element name="OSVersion" minOccurs="1" maxOccurs="1" type="xs:string" />
<xs:element name="platform" minOccurs="1" maxOccurs="1" type="xs:string" />
<xs:element name="serialNumber" minOccurs="1" maxOccurs="1" type="xs:string" />
<xs:element name="connectionStatus" minOccurs="1" maxOccurs="1" type="xs:string" />
<xs:element name="ipAddr" minOccurs="1" maxOccurs="1" type="xs:string" />
<xs:element name="managedStatus" minOccurs="1" maxOccurs="1" type="xs:string" />
<xs:element name="device-id" minOccurs="1" maxOccurs="1" type="xs:string" />
<xs:element name="web-mgmt" minOccurs="0" maxOccurs="1" type="xs:string" />
<xs:element name="lsys-count" minOccurs="1" maxOccurs="1" type="xs:string" />
<xs:element name="hosting-deviceId" minOccurs="1" maxOccurs="1" type="xs:string" />
<xs:element name="authentication-status" minOccurs="1" maxOccurs="1" type="xs:string" />
<xs:element name="connection-type" minOccurs="1" maxOccurs="1" type="xs:string" />
<xs:element name="name" minOccurs="1" maxOccurs="1" type="xs:string" />
<xs:element name="domain-id" minOccurs="1" maxOccurs="1" type="xs:string" />
<xs:element name="domain-name" minOccurs="1" maxOccurs="1" type="xs:string" />
<xs:element name="config-status" minOccurs="1" maxOccurs="1" type="xs:string" />
<xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="href" type="xs:string" />
<xs:attribute name="uri" type="xs:string" />
<xs:attribute name="key" type="xs:string" />
</xs:complexType>
<xs:element name="devices">
<xs:complexType>
<xs:sequence>
<xs:element name="device" minOccurs="0" maxOccurs="unbounded" type="junosspace-device" />
</xs:sequence>
<xs:attribute name="uri" type="xs:string" />
<xs:attribute name="size" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:schema>
""" # noqa: E501
def _rpc(hostname, ssh): def _rpc(hostname, ssh):
dev = Device( dev = Device(
host=hostname, host=hostname,
...@@ -351,58 +304,20 @@ def interface_addresses(netconf_config): ...@@ -351,58 +304,20 @@ def interface_addresses(netconf_config):
# #
def load_routers_from_junosspace(config): def load_routers_from_netdash(url):
""" """
query junosspace for configured devices query url for a linefeed-delmitted list of managed router hostnames
:param config: junosspace config element from app config :param url: url of alldevices.txt file
:return: list of dictionaries, each element of which describes a router :return: list of router hostnames
""" """
logger = logging.getLogger(__name__) r = requests.get(url=url)
r.raise_for_status()
request_url = config['api']
if not request_url.endswith('/'):
request_url += '/'
request_url += 'device-management/devices'
r = requests.get(
request_url,
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
if r.status_code != 200:
logger.error("error response from %r" % request_url)
assert False # TODO: use proper exception type
devices = etree.fromstring(r.text.encode('utf-8'))
schema_doc = etree.XML(JUNOSSPACE_DEVICES_SCHEMA.encode('utf-8'))
schema = etree.XMLSchema(schema_doc)
if not schema.validate(devices):
for e in schema.error_log:
logger.error('%d.%d: %s' % (e.line, e.column, e.message))
assert False
def _derive_hostname(n): neteng_routers = set([
# TODO: ask ops if this name->hostname operation is valid l.strip() for l in r.text.splitlines() if l.strip()
if n.endswith('geant.net'): ])
return n return list(neteng_routers)
m = re.match(r'^(.*?)(\.re\d+)?$', n)
if m:
return m.group(1) + '.geant.net'
logger.error(f'unrecognized junosspace device name format: "{n}"')
return None
for d in devices.xpath('//devices/device'):
name = d.xpath('./name/text()')[0]
yield {
"OSVersion": d.xpath('./OSVersion/text()')[0],
"platform": d.xpath('./platform/text()')[0],
"address": d.xpath('./ipAddr/text()')[0],
"name": name,
"hostname": _derive_hostname(name)
}
def local_interfaces( def local_interfaces(
......
...@@ -42,11 +42,7 @@ def data_config_filename(): ...@@ -42,11 +42,7 @@ def data_config_filename():
"socket_timeout": 2.8 "socket_timeout": 2.8
}, },
"redis-databases": [0, 7], "redis-databases": [0, 7],
"junosspace": { "managed-routers": "bogus url",
"api": "bogus-url",
"username": "bogus-username",
"password": "bogus-password"
}
} }
f.write(json.dumps(config).encode('utf-8')) f.write(json.dumps(config).encode('utf-8'))
......
...@@ -12,27 +12,22 @@ TEST_DATA_FILENAME = os.path.realpath(os.path.join( ...@@ -12,27 +12,22 @@ TEST_DATA_FILENAME = os.path.realpath(os.path.join(
'..', '..',
'test', 'test',
'data', 'data',
'junosspace-devices.xml')) 'netdash-alldevices.txt'))
@responses.activate @responses.activate
def test_junosspace_devices_parsing(data_config): def test_junosspace_devices_parsing(data_config):
data_config['junosspace']['api'] = 'http://sabababa' data_config['managed-routers'] = 'http://sabababa'
with open(TEST_DATA_FILENAME) as f: with open(TEST_DATA_FILENAME) as f:
responses.add( responses.add(
method=responses.GET, method=responses.GET,
url=data_config['junosspace']['api'] + url=data_config['managed-routers'],
'/device-management/devices',
body=f.read()) body=f.read())
routers = juniper.load_routers_from_junosspace(data_config['junosspace']) hostnames = juniper.load_routers_from_netdash(
data_config['managed-routers'])
hostnames = [r['hostname'] for r in routers]
# test for .re\d+ greediness
assert 'mx1.ams.nl.geant.net' in hostnames assert 'mx1.ams.nl.geant.net' in hostnames
# test that 'qfx1.fra.de' is parsed
assert 'qfx1.fra.de.geant.net' in hostnames
def test_router_hostname_derivation(mocked_redis): def test_router_hostname_derivation(mocked_redis):
......
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