Skip to content
Snippets Groups Projects
Commit 9516e5a8 authored by Robert Latta's avatar Robert Latta
Browse files

Merge branch 'feature/add-interface-bundle-data' into develop

parents 3ad21825 6af17bcd
No related branches found
No related tags found
No related merge requests found
...@@ -213,12 +213,16 @@ def list_interfaces(netconf_config): ...@@ -213,12 +213,16 @@ def list_interfaces(netconf_config):
assert name is not None, "expected interface 'name' child element" assert name is not None, "expected interface 'name' child element"
ifc = { ifc = {
'name': name.text, 'name': name.text,
'description': '' 'description': '',
'bundle': []
} }
description = e.find('description') description = e.find('description')
if description is not None: if description is not None:
ifc['description'] = description.text 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['ipv4'] = e.xpath('./family/inet/address/name/text()')
ifc['ipv6'] = e.xpath('./family/inet6/address/name/text()') ifc['ipv6'] = e.xpath('./family/inet6/address/name/text()')
......
...@@ -62,8 +62,14 @@ def poller_interface_oids(hostname): ...@@ -62,8 +62,14 @@ def poller_interface_oids(hostname):
if not snmp_index: if not snmp_index:
continue continue
bundle_parents = r.get('netconf-interface-bundles:%s:%s' % (
hostname, ifc['name'].split('.')[0]))
ifc_data = { ifc_data = {
'name': ifc['name'], 'name': ifc['name'],
'bundle': ifc['bundle'],
'bundle-parents':
json.loads(bundle_parents) if bundle_parents else [],
'snmp-index': snmp_index, 'snmp-index': snmp_index,
'description': ifc['description'], 'description': ifc['description'],
'circuits': [] 'circuits': []
......
...@@ -2,7 +2,7 @@ import json ...@@ -2,7 +2,7 @@ import json
import logging import logging
import re import re
from celery import bootsteps, Task, group, states from celery import bootsteps, Task, states
from celery.result import AsyncResult from celery.result import AsyncResult
from collections import defaultdict from collections import defaultdict
...@@ -337,10 +337,23 @@ def refresh_juniper_interface_list(hostname, netconf): ...@@ -337,10 +337,23 @@ def refresh_juniper_interface_list(hostname, netconf):
for k in r.keys('netconf-interfaces:%s:*' % hostname): for k in r.keys('netconf-interfaces:%s:*' % hostname):
r.delete(k) 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): 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( r.set(
'netconf-interfaces:%s:%s' % (hostname, ifc['name']), 'netconf-interfaces:%s:%s' % (hostname, ifc['name']),
json.dumps(ifc)) 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) @app.task(base=InventoryTask, bind=True)
...@@ -458,27 +471,28 @@ def launch_refresh_cache_all(config): ...@@ -458,27 +471,28 @@ def launch_refresh_cache_all(config):
# first batch of subtasks: refresh cached opsdb data # first batch of subtasks: refresh cached opsdb data
subtasks = [ subtasks = [
update_junosspace_device_list.s(), update_junosspace_device_list.apply_async(),
update_interfaces_to_services.s(), update_interfaces_to_services.apply_async(),
update_geant_lambdas.s(), update_geant_lambdas.apply_async(),
update_circuit_hierarchy.s() update_circuit_hierarchy.apply_async()
] ]
[x.get() for x in subtasks]
results = group(subtasks).apply_async()
results.join()
# second batch of subtasks: # second batch of subtasks:
# alarms db status cache # alarms db status cache
# juniper netconf & snmp data # juniper netconf & snmp data
subtasks = [ subtasks = [
update_equipment_locations.s(), update_equipment_locations.apply_async(),
] ]
for hostname in _derive_router_hostnames(config): for hostname in _derive_router_hostnames(config):
logger.debug( logger.debug(
'queueing router refresh jobs for %r' % hostname) 'queueing router refresh jobs for %r' % hostname)
subtasks.append(reload_router_config.s(hostname)) subtasks.append(reload_router_config.apply_async(args=[hostname]))
break
[x.get() for x in subtasks]
return [r.id for r in group(subtasks).apply_async()] return [x.id for x in subtasks]
def check_task_status(task_id): def check_task_status(task_id):
......
...@@ -18,6 +18,10 @@ def test_router_interfaces(router, client_with_mocked_data): ...@@ -18,6 +18,10 @@ def test_router_interfaces(router, client_with_mocked_data):
"properties": { "properties": {
"name": {"type": "string"}, "name": {"type": "string"},
"description": {"type": "string"}, "description": {"type": "string"},
"bundle": {
"type": "array",
"items": {"type": "string"}
},
"ipv4": { "ipv4": {
"type": "array", "type": "array",
"items": {"type": "string"} "items": {"type": "string"}
......
...@@ -52,6 +52,10 @@ def test_interface_list(netconf_doc): ...@@ -52,6 +52,10 @@ def test_interface_list(netconf_doc):
"properties": { "properties": {
"name": {"type": "string"}, "name": {"type": "string"},
"description": {"type": "string"}, "description": {"type": "string"},
"bundle": {
"type": "array",
"items": {"type": "string"}
},
"ipv4": { "ipv4": {
"type": "array", "type": "array",
"items": {"type": "string"} "items": {"type": "string"}
......
...@@ -34,11 +34,25 @@ def test_router_interfaces(router, client_with_mocked_data): ...@@ -34,11 +34,25 @@ def test_router_interfaces(router, client_with_mocked_data):
"type": "array", "type": "array",
"items": {"$ref": "#/definitions/circuit"} "items": {"$ref": "#/definitions/circuit"}
}, },
"bundle": {
"type": "array",
"items": {"type": "string"}
},
"bundle-parents": {
"type": "array",
"items": {"type": "string"}
},
"description": {"type": "string"}, "description": {"type": "string"},
"name": {"type": "string"}, "name": {"type": "string"},
"snmp-index": {"type": "integer"} "snmp-index": {"type": "integer"}
}, },
"required": ["circuits", "description", "name", "snmp-index"], "required": [
"circuits",
"bundle",
"bundle-parents",
"description",
"name",
"snmp-index"],
"additionalProperties": False "additionalProperties": False
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment