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

initial raft /msr/services updated with redundant asn

parent 98fd8212
Branches
Tags
No related merge requests found
...@@ -260,7 +260,8 @@ SYSTEM_CORRELATION_SERVICES_LIST_SCHEMA = { ...@@ -260,7 +260,8 @@ SYSTEM_CORRELATION_SERVICES_LIST_SCHEMA = {
'service_type': {'type': 'string'}, # TODO: enum? 'service_type': {'type': 'string'}, # TODO: enum?
'project': {'type': 'string'}, # TODO: remove this? 'project': {'type': 'string'}, # TODO: remove this?
'customer': {'type': 'string'}, 'customer': {'type': 'string'},
'endpoints': {'$ref': '#/definitions/endpoints'} 'endpoints': {'$ref': '#/definitions/endpoints'},
'redundant_asn': {'type': 'integer'}
}, },
'required': [ 'required': [
'circuit_id', 'sid', 'name', 'speed', 'status', 'monitored', 'circuit_id', 'sid', 'name', 'speed', 'status', 'monitored',
...@@ -905,39 +906,51 @@ def get_system_correlation_services(): ...@@ -905,39 +906,51 @@ def get_system_correlation_services():
r = common.get_current_redis() r = common.get_current_redis()
response = _ignore_cache_or_retrieve(request, cache_key, r) response = _ignore_cache_or_retrieve(request, cache_key, r)
if not response: if not response:
peering_info = defaultdict(defaultdict)
key_pattern = 'netconf-interfaces:*' # dict of dicts:
# peering_info[hostname][interface_name] = dict of ifc details
peering_info = defaultdict(dict)
host_if_extraction_re = re.compile( host_if_extraction_re = re.compile(r'^netconf-interfaces:(.+?):')
r'^netconf-interfaces:(.+?):')
for doc in common.load_json_docs( for doc in common.load_json_docs(
config_params=current_app.config['INVENTORY_PROVIDER_CONFIG'], config_params=current_app.config['INVENTORY_PROVIDER_CONFIG'],
key_pattern=key_pattern, key_pattern='netconf-interfaces:*',
num_threads=20): num_threads=20):
matches = host_if_extraction_re.match(doc['key']) matches = host_if_extraction_re.match(doc['key'])
if matches: if matches:
peering_info[matches[1]][doc['value']['name']] = doc['value'] peering_info[matches[1]][doc['value']['name']] = doc['value']
def _load_redundant_peers():
# REPORTING-312: limited to eGEANT group,
# but this can be expanded here in future
redundant_access_groups = ['eGEANT']
for g in redundant_access_groups:
doc = r.get(f'juniper-peerings:group:{g}')
for peer in json.loads(doc.decode('utf-8')):
yield peer['address'], peer['remote-asn']
# dict of peers & asn's: [peer address] -> asn
redundant_access_group_peers = dict(_load_redundant_peers())
def _ip_endpoint_extractor(endpoint_details: Dict): def _ip_endpoint_extractor(endpoint_details: Dict):
hostname = ims_equipment_to_hostname( hostname = ims_equipment_to_hostname(endpoint_details['equipment'])
endpoint_details['equipment'])
interface = endpoint_details['port'].lower() interface = endpoint_details['port'].lower()
ip_endpoint = { ip_endpoint = {
'hostname': hostname, 'hostname': hostname,
'interface': interface, 'interface': interface,
} }
addresses = {} host_info = peering_info[hostname]
host_info = peering_info.get(hostname, {})
interface_info = host_info.get(interface, {}) interface_info = host_info.get(interface, {})
addresses = {}
ipv4 = interface_info.get('ipv4') ipv4 = interface_info.get('ipv4')
ipv6 = interface_info.get('ipv6') ipv6 = interface_info.get('ipv6')
if ipv4: if ipv4:
addresses['v4'] = ipv4[0] addresses['v4'] = ipv4[0]
if ipv6: if ipv6:
addresses['v6'] = ipv6[0] addresses['v6'] = ipv6[0]
if ipv4 or ipv6: if addresses:
ip_endpoint['addresses'] = addresses ip_endpoint['addresses'] = addresses
return ip_endpoint return ip_endpoint
...@@ -952,12 +965,23 @@ def get_system_correlation_services(): ...@@ -952,12 +965,23 @@ def get_system_correlation_services():
if not endpoint_details['geant_equipment']: if not endpoint_details['geant_equipment']:
return return
potential_hostname = ims_equipment_to_hostname( potential_hostname = ims_equipment_to_hostname(
endpoint_details['equipment']) endpoint_details['equipment'])
if potential_hostname in peering_info.keys(): if potential_hostname in peering_info.keys():
return _ip_endpoint_extractor(endpoint_details) return _ip_endpoint_extractor(endpoint_details)
else: else:
return _optical_endpoint_extractor(endpoint_details) return _optical_endpoint_extractor(endpoint_details)
def _get_redundancy_asn(service):
for ep in service['endpoints']:
addresses = ep.get('addresses', {})
for ifc_address in addresses.values():
for p, asn in redundant_access_group_peers.items():
peer = ipaddress.ip_address(p)
ifc = ipaddress.ip_interface(ifc_address)
if peer in ifc.network:
return asn
return None
sid_services = json.loads(r.get('ims:sid_services').decode('utf-8')) sid_services = json.loads(r.get('ims:sid_services').decode('utf-8'))
response = [] response = []
...@@ -977,11 +1001,15 @@ def get_system_correlation_services(): ...@@ -977,11 +1001,15 @@ def get_system_correlation_services():
endpoint = _endpoint_extractor(d) endpoint = _endpoint_extractor(d)
if endpoint: if endpoint:
service_info['endpoints'].append(endpoint) service_info['endpoints'].append(endpoint)
if service_info.get('endpoints'): if service_info.get('endpoints'):
asn = _get_redundancy_asn(service_info)
if asn:
service_info['redundant_asn'] = asn
response.append(service_info) response.append(service_info)
jsonschema.validate(response, jsonschema.validate(
SYSTEM_CORRELATION_SERVICES_LIST_SCHEMA) response, SYSTEM_CORRELATION_SERVICES_LIST_SCHEMA)
if response: if response:
response = json.dumps(response, indent=2) response = json.dumps(response, indent=2)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment