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

added snmp community & index to juniper-link-info rsp

parent 860b52d6
No related branches found
No related tags found
No related merge requests found
......@@ -105,8 +105,8 @@ def after_request(resp):
def related_interfaces(hostname, interface):
r = common.get_current_redis()
prefix = 'netconf-interfaces:%s:' % hostname
for k in r.keys(prefix + interface + '.*'):
prefix = f'netconf-interfaces:{hostname}:'
for k in r.keys(f'{prefix}{interface}.*'):
k = k.decode('utf-8')
assert k.startswith(prefix) # sanity
assert len(k) > len(prefix) # sanity (contains at least an interface)
......@@ -133,6 +133,52 @@ def get_top_level_services(circuit_id, r):
return tls
def _link_interface_info(r, hostname, interface):
"""
Generates the 'interface' field for
the juniper-link-info response payload.
only called from get_juniper_link_info
:param r: redis connection
:param hostname: router hostname
:param interface: interface name
:return: payload dict
"""
ifc_info = r.get(f'netconf-interfaces:{hostname}:{interface}')
if not ifc_info:
# warning: this should match the structure returned by
# juniper:list_interfaces:_ifc_info
ifc_info = {
'name': interface,
'description': '',
'bundle': [],
'ipv4': [],
'ipv6': []
}
else:
ifc_info =json.loads(ifc_info.decode('utf-8'))
bundle_members = r.get(
f'netconf-interface-bundles:{hostname}:{interface}')
if bundle_members:
ifc_info['bundle_members'] \
= json.loads(bundle_members.decode('utf-8'))
else:
ifc_info['bundle_members'] = []
snmp_info = r.get(
f'snmp-interfaces-single:{hostname}:{interface}')
if snmp_info:
snmp_info = json.loads(snmp_info.decode('utf-8'))
ifc_info['snmp'] = {
'community': snmp_info['community'],
'index': snmp_info['index']
}
return ifc_info
@routes.route("/juniper-link-info/<source_equipment>/<path:interface>",
methods=['GET', 'POST'])
@common.require_accepts_json
......@@ -162,27 +208,8 @@ def get_juniper_link_info(source_equipment, interface):
result['locations'] += [
_location_from_service_dict(s) for s in result['services']]
ifc_info = r.get(
'netconf-interfaces:%s:%s' % (source_equipment, interface))
if ifc_info:
result['interface'] = json.loads(ifc_info.decode('utf-8'))
else:
# warning: this should match the structure returned by
# juniper:list_interfaces:_ifc_info
result['interface'] = {
'name': interface,
'description': '',
'bundle': [],
'ipv4': [],
'ipv6': []
}
bundle_members = r.get(
'netconf-interface-bundles:%s:%s' % (source_equipment, interface))
if bundle_members:
result['interface']['bundle_members'] = \
json.loads(bundle_members.decode('utf-8'))
else:
result['interface']['bundle_members'] = []
result['interface'] = _link_interface_info(
r, source_equipment, interface)
def _related_services():
for related in related_interfaces(source_equipment, interface):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment