diff --git a/inventory_provider/db/opsdb.py b/inventory_provider/db/opsdb.py index ee0aabc8b3bd614c8f37987cd09ffddc1b0f45ff..a9d4d6ea9aa904a01cfbbeb86ce6a3c74ef70ce3 100644 --- a/inventory_provider/db/opsdb.py +++ b/inventory_provider/db/opsdb.py @@ -165,6 +165,25 @@ def _infinera_field_update(record): record["interface_name"] += "-" + record["port"] record["interface_name"] = record["interface_name"] \ .replace("--", "-").upper() + + # + + equipment_parts = record["other_end_equipment"].rsplit("-", 1) + card_parts = record["other_end_card_id"].split("-", 1) + record["other_end_interface_name"] = "" + record["other_end_equipment"] = equipment_parts[0] + try: + record["other_end_interface_name"] = equipment_parts[1] + "-" + except IndexError: + pass # Nothing to see here + try: + record["other_end_interface_name"] += card_parts[1] + except IndexError: + record["other_end_interface_name"] += card_parts[0] + if record["other_end_port"] is not None and record["other_end_port"] != "": + record["other_end_interface_name"] += "-" + record["other_end_port"] + record["other_end_interface_name"] = record["other_end_interface_name"] \ + .replace("--", "-").upper() return record diff --git a/test/test_opsdb.py b/test/test_opsdb.py index cf46fd99ea4e88e9c739f555d590cd9e468ba6e9..f86eb67204a9d4e55d1087cf0832b5eb34c0abb7 100644 --- a/test/test_opsdb.py +++ b/test/test_opsdb.py @@ -25,28 +25,42 @@ def test_infinera_field_update(): i = { "equipment": "AMS01-DTNX10-1-1", "card_id": "tim-b-5-7", - "port": "1" + "port": "1", + "other_end_equipment": "LON01-DTNX10-1-1", + "other_end_card_id": "tim-b-5-8", + "other_end_port": "2" } r = inventory_provider.db.opsdb._infinera_field_update(i) assert r["equipment"] == "AMS01-DTNX10-1" assert r["interface_name"] == "1-B-5-7-1" + assert r["other_end_equipment"] == "LON01-DTNX10-1" + assert r["other_end_interface_name"] == "1-B-5-8-2" i = { "equipment": "BUD01_CX_01", "card_id": "tim-1/2", - "port": "1" + "port": "1", + "other_end_equipment": "LON01_CX_01", + "other_end_card_id": "tim-2/3", + "other_end_port": "4" } r = inventory_provider.db.opsdb._infinera_field_update(i) assert r["equipment"] == "BUD01_CX_01" assert r["interface_name"] == "1/2-1" + assert r["other_end_equipment"] == "LON01_CX_01" + assert r["other_end_interface_name"] == "2/3-4" i = { "equipment": "irrelevant", "card_id": "tim_1/2", - "port": "1" + "port": "1", + "other_end_equipment": "irrelevant", + "other_end_card_id": "tim_2/3", + "other_end_port": "4" } r = inventory_provider.db.opsdb._infinera_field_update(i) assert r["interface_name"] == "TIM_1/2-1" + assert r["other_end_interface_name"] == "TIM_2/3-4" def test_juniper_field_update():