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

return list of device structures

parent e8e6beb0
Branches
Tags
No related merge requests found
import logging
import re
from jnpr.junos import Device
from lxml import etree
......@@ -294,4 +295,18 @@ def load_routers_from_junosspace(config):
juniper_logger.error("%d.%d: %s" % (e.line, e.column, e.message))
assert False
return True
for d in devices.xpath('//devices/device'):
name = d.xpath('./name/text()')[0]
# TODO: ask ops if this name->hostname operation is valid
m = re.match(r'^(.*)\.re\d+$', name)
if m:
hostname = m.group(1) + '.geant.net'
else:
hostname = None
yield {
"OSVersion": d.xpath('./OSVersion/text()')[0],
"platform": d.xpath('./platform/text()')[0],
"address": d.xpath('./ipAddr/text()')[0],
"name": name,
"hostname": hostname
}
......@@ -22,5 +22,5 @@ def test_junosspace_devices_parsing(data_config):
url = data_config['junosspace']['api'] + '/device-management/devices',
body=f.read())
doc = juniper.load_routers_from_junosspace(data_config['junosspace'])
assert doc
routers = juniper.load_routers_from_junosspace(data_config['junosspace'])
print(list(routers))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment