diff --git a/inventory_provider/routes/data.py b/inventory_provider/routes/data.py index 13d6a9f22439a5f1285827ca443fc7b51e3d0b0d..c364e4d1920e6792fac4a9557fac36592c15fc29 100644 --- a/inventory_provider/routes/data.py +++ b/inventory_provider/routes/data.py @@ -59,22 +59,24 @@ def router_interfaces(hostname): r = redis.StrictRedis( host=redis_config["hostname"], port=redis_config["port"]) - ifc_data_string = r.hget(hostname, 'snmp-interfaces') + ifc_data_string = r.hget(hostname, 'interfaces') if not ifc_data_string: return Response( response="no available info for '%s'" % hostname, status=404, mimetype="text/html") + def _interfaces(d): + for ii in d['interface-information']: + for ifc_list in ii['physical-interface'] + ii['logical-interface']: + for ifc in ifc_list: + yield { + 'name': ifc['name'][0]['data'], + 'description': ifc['description'][0]['data'] + } - def _interfaces(s): - for ifc in json.loads(s): - if 'v4InterfaceName' in ifc: - yield ifc['v4InterfaceName'] - if 'v6InterfaceName' in ifc: - yield ifc['v6InterfaceName'] - - interfaces = list(_interfaces(ifc_data_string.decode('utf-8'))) + ifc_data = json.loads(ifc_data_string.decode('utf-8')) + interfaces = list(_interfaces(ifc_data)) if not interfaces: return Response( response="no interfaces found for '%s'" % hostname, diff --git a/test/test_data_routes.py b/test/test_data_routes.py index a40b7b22aa9f86a570641ac2ef8bcb5086f635cf..9c7e52a0b9f8ccf74e5b81285625b7c84cd7535e 100644 --- a/test/test_data_routes.py +++ b/test/test_data_routes.py @@ -241,7 +241,15 @@ def test_router_interfaces(client_with_mocked_data): interfaces_list_schema = { "$schema": "http://json-schema.org/draft-07/schema#", "type": "array", - "items": {"type": "string"} + "items": { + "type": "object", + "properties": { + "name": {"type": "string"}, + "description": {"type": "string"} + }, + "required": ["name", "description"], + "additionalProperties": False + } } for router in _routers(client_with_mocked_data):