diff --git a/inventory_provider/juniper.py b/inventory_provider/juniper.py index 468eef553af60b98d553a4c9b756b1db5069536f..575388892d6fd24292436ab21e8624c2a52adc2d 100644 --- a/inventory_provider/juniper.py +++ b/inventory_provider/juniper.py @@ -213,12 +213,16 @@ def list_interfaces(netconf_config): assert name is not None, "expected interface 'name' child element" ifc = { 'name': name.text, - 'description': '' + 'description': '', + 'bundle': [] } description = e.find('description') if description is not None: ifc['description'] = description.text + for b in i.iterfind(".//bundle"): + ifc['bundle'].append(b.text) + ifc['ipv4'] = e.xpath('./family/inet/address/name/text()') ifc['ipv6'] = e.xpath('./family/inet6/address/name/text()') diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index 13d394e5a02d35156a0281088612a34dd4d804a1..ab2974a12c0943318a7d99761f054df8b833ab5a 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -337,10 +337,23 @@ def refresh_juniper_interface_list(hostname, netconf): for k in r.keys('netconf-interfaces:%s:*' % hostname): r.delete(k) + for k in r.keys('netconf-interface-bundles:%s:*' % hostname): + r.delete(k) + + all_bundles = defaultdict(list) for ifc in juniper.list_interfaces(netconf): + bundles = ifc.get('bundle', None) + for bundle in bundles: + if bundle: + all_bundles[bundle].append(ifc['name']) + r.set( 'netconf-interfaces:%s:%s' % (hostname, ifc['name']), json.dumps(ifc)) + for k, v in all_bundles.items(): + r.set( + 'netconf-interface-bundles:%s:%s' % (hostname, k), + json.dumps(v)) @app.task(base=InventoryTask, bind=True)