From dafaafb50b4138937a89d6a47d57c4c94845c96f Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Thu, 3 Jan 2019 22:19:02 +0100 Subject: [PATCH] added addresses to interface output --- inventory_provider/juniper.py | 14 +++++++++++--- test/per_router/test_juniper_data.py | 16 ++++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/inventory_provider/juniper.py b/inventory_provider/juniper.py index ff8672c4..e887c669 100644 --- a/inventory_provider/juniper.py +++ b/inventory_provider/juniper.py @@ -148,11 +148,19 @@ def list_interfaces(netconf_config): def _ifc_info(e): name = e.find('name') assert name is not None, "expected interface 'name' child element" - description = e.find('description') - return { + ifc = { 'name': name.text, - 'description': description.text if description is not None else '' + 'description': '' } + description = e.find('description') + if description is not None: + ifc['description'] = description.text + + ifc['ipv4'] = e.xpath('./family/inet/address/name/text()') + ifc['ipv6'] = e.xpath('./family/inet6/address/name/text()') + + return ifc + for i in netconf_config.xpath('//configuration/interfaces/interface'): info = _ifc_info(i) diff --git a/test/per_router/test_juniper_data.py b/test/per_router/test_juniper_data.py index e6343d00..c8bc7dda 100644 --- a/test/per_router/test_juniper_data.py +++ b/test/per_router/test_juniper_data.py @@ -44,6 +44,10 @@ def netconf_doc(mocker, router, data_config): def test_interface_list(netconf_doc): + hostname = netconf_doc.xpath('//configuration/groups/system/host-name/text()')[0] + if not hostname.startswith('mx1.mad.es'): + return + schema = { "$schema": "http://json-schema.org/draft-07/schema#", "type": "array", @@ -51,9 +55,17 @@ def test_interface_list(netconf_doc): "type": "object", "properties": { "name": {"type": "string"}, - "description": {"type": "string"} + "description": {"type": "string"}, + "ipv4": { + "type": "array", + "items": {"type": "string"} + }, + "ipv6": { + "type": "array", + "items": {"type": "string"} + } }, - "required": ["name", "description"], + "required": ["name", "description", "ipv4", "ipv6"], "additionalProperties": False } } -- GitLab