From 7912126034ba8a77e42c27a0e82b5072210a13d8 Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Fri, 17 Apr 2020 14:12:43 +0200 Subject: [PATCH] reformat interface names for cisco devices --- inventory_provider/db/opsdb.py | 49 ++++++++++++++++++-------------- inventory_provider/tasks/data.py | 0 2 files changed, 28 insertions(+), 21 deletions(-) create mode 100644 inventory_provider/tasks/data.py diff --git a/inventory_provider/db/opsdb.py b/inventory_provider/db/opsdb.py index fcf6197c..8e33fb20 100644 --- a/inventory_provider/db/opsdb.py +++ b/inventory_provider/db/opsdb.py @@ -46,30 +46,37 @@ def _infinera_field_update(record): def _juniper_field_update(record): - if not record["interface_name"]: - record["interface_name"] = record["card_id"] - if record["port"] is not None and record["port"] != "": - separator = "/" if "-" in record["interface_name"] else "" - record["interface_name"] += separator + str(record["port"]) - if record["logical_unit"] is not None and record["logical_unit"] != "": - record["interface_name"] += "." + str(record["logical_unit"]) - - if not record["other_end_interface_name"]: - record["other_end_interface_name"] = record["other_end_card_id"] - if record["other_end_port"] is not None \ - and record["other_end_port"] != "": - separator = "" - if "-" in record["other_end_interface_name"]: - separator = "/" - record["other_end_interface_name"] += \ - separator + str(record["other_end_port"]) - if record["other_end_logical_unit"] is not None \ - and record["other_end_logical_unit"] != "": - record["other_end_interface_name"] += \ - "." + str(record["other_end_logical_unit"]) + + def _separator(ifc_name): + if '-' in ifc_name: + return '/' + if '/' in ifc_name: + return '/' + return '' + + def _empty(s): + return s is None or s == '' + + for end in ['', 'other_end_']: + if not record[end + "interface_name"]: + record[end + "interface_name"] = record[end + "card_id"] + if not _empty(record[end + "port"]): + record[end + "interface_name"] += \ + _separator(record[end + "interface_name"]) \ + + str(record[end + "port"]) + if not _empty(record[end + "logical_unit"]): + record[end + "interface_name"] += \ + "." + str(record[end + "logical_unit"]) + return record +def _cisco_field_update(record): + if record['name'].startswith('EUMET-JEUNO'): + print('here') + return _juniper_field_update(record) + + def _coriant_field_update(record): record["interface_name"] = record["card_id"] if record["port"] is not None and record["port"] != "": diff --git a/inventory_provider/tasks/data.py b/inventory_provider/tasks/data.py new file mode 100644 index 00000000..e69de29b -- GitLab