diff --git a/inventory_provider/db/opsdb.py b/inventory_provider/db/opsdb.py index fcf6197c777ce300c1bcad69bdc01625d0450124..8e33fb20daa70519b900dba60f5658a942cd1e94 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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391