From 01b85f7476aec3807fc37505ad74e430d8eee7fc Mon Sep 17 00:00:00 2001 From: Robert Latta <robert.latta@geant.org> Date: Thu, 5 Nov 2020 16:49:09 +0000 Subject: [PATCH] Added df data retrieval --- inventory_provider/db/ims_data.py | 54 ++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/inventory_provider/db/ims_data.py b/inventory_provider/db/ims_data.py index 4effd671..cea3a9f6 100644 --- a/inventory_provider/db/ims_data.py +++ b/inventory_provider/db/ims_data.py @@ -1,6 +1,6 @@ import logging import re -from collections import OrderedDict +from collections import OrderedDict, defaultdict from inventory_provider import environment from inventory_provider.db import ims @@ -25,6 +25,55 @@ interface_generators = { } +def get_fibre_info(ds: IMS): + # get all the wdm ots circuits where each node is in a different location + + circuit_nav_props = [ + ims.CIRCUIT_PROPERTIES['SubCircuits'], + ims.CIRCUIT_PROPERTIES['CalculatedNode'], + ims.CIRCUIT_PROPERTIES['PortA'], + ims.CIRCUIT_PROPERTIES['PortB'], + ] + + ne_details = {} + for c in ds.get_filtered_entities( + 'Circuit', + 'product.name == "wdm" | speed.name == "ots" | ' + 'vendor == "infinera"', + circuit_nav_props, + step_count=1000): + if c["nodeaid"] and c["nodebid"] and \ + c["siteaid"] and c["sitebid"] and c["siteaid"] != c["sitebid"]: + if c['subcircuits']: + subs = [s['subcircuit'] for s in c['subcircuits']] + if len(subs) > 1: + # not sure if this is possible in IMS + logger.info('There is more than one Sub-Circuit for' + f'{c["name"]}') + + for s in subs: + shelf = c['porta']['shelf']['sequencenumber'] + t = { + 'ne': c['nodea']['name'] + f'-{shelf}', + 'circuit_id': c['id'], + 'df_route': s['name'], + 'df_route_id': s['id'], + 'df_status': IMS_OPSDB_STATUS_MAP.get( + InventoryStatus(s['inventorystatusid']), 'unknown') + } + ne_details[f"{c['nodea']['name']}_{s['id']}"] = t + t = t.copy() + shelf = c['portb']['shelf']['sequencenumber'] + t['ne'] = c['nodeb']['name'] + f'-{shelf}' + ne_details[f"{c['nodeb']['name']}_{s['id']}"] = t + + by_ne = defaultdict(lambda: []) + for d in ne_details.values(): + by_ne[d['ne']].append(d) + + yield from by_ne.items() + + def get_interface_services(ds: IMS): # get subset of circuits - # start with just the ams fra lag, then expand to @@ -141,6 +190,9 @@ def get_circuit_hierarchy(ds: IMS): [c['carriercircuitid'] for c in circuit['carriercircuits']] yield { 'id': circuit['id'], + 'name': circuit['name'], + 'status': IMS_OPSDB_STATUS_MAP.get( + InventoryStatus(circuit['inventorystatusid']), 'unknown'), 'product': circuit['product']['name'], 'project': circuit['customer']['name'], 'sub-circuits': sub_circuits, -- GitLab