Skip to content

Commit 899cb51

Browse files
Rear port normalize (#272)
1 parent d20a949 commit 899cb51

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

plugins/module_utils/netbox_dcim.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,6 @@
5252

5353
class NetboxDcimModule(NetboxModule):
5454
def __init__(self, module, endpoint):
55-
# Front ports can only be connected to rear ports of the same device
56-
# This will prepare the rear port dict if only a string is given
57-
if endpoint == "front_ports":
58-
if isinstance(module.params.get("data").get("rear_port"), str):
59-
rear_port = {
60-
"device": module.params.get("data").get("device"),
61-
"name": module.params.get("data").get("rear_port"),
62-
}
63-
module.params["data"].update({"rear_port": rear_port})
64-
elif endpoint == "front_port_templates":
65-
if isinstance(module.params.get("data").get("rear_port_template"), str):
66-
rear_port_template = {
67-
"device_type": module.params.get("data").get("device_type"),
68-
"name": module.params.get("data").get("rear_port_template"),
69-
}
70-
module.params["data"].update({"rear_port_template": rear_port_template})
71-
7255
super().__init__(module, endpoint)
7356

7457
def run(self):

plugins/module_utils/netbox_utils.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,22 @@ def _build_query_params(
657657
elif parent == "virtual_chassis":
658658
query_dict = {"q": self.module.params["data"].get("master")}
659659

660+
elif parent == "rear_port" and self.endpoint == "front_ports":
661+
if isinstance(module_data.get("rear_port"), str):
662+
rear_port = {
663+
"device_id": module_data.get("device"),
664+
"name": module_data.get("rear_port"),
665+
}
666+
query_dict.update(rear_port)
667+
668+
elif parent == "rear_port_template" and self.endpoint == "front_port_templates":
669+
if isinstance(module_data.get("rear_port_template"), str):
670+
rear_port_template = {
671+
"devicetype_id": module_data.get("device_type"),
672+
"name": module_data.get("rear_port_template"),
673+
}
674+
query_dict.update(rear_port_template)
675+
660676
query_dict = self._convert_identical_keys(query_dict)
661677
return query_dict
662678

@@ -747,7 +763,7 @@ def _find_ids(self, data, user_query_params):
747763
else:
748764
self._handle_errors(msg="%s not found" % (list_item))
749765
else:
750-
if k in ["lag"]:
766+
if k in ["lag", "rear_port", "rear_port_template"]:
751767
query_params = self._build_query_params(
752768
k, data, user_query_params
753769
)

0 commit comments

Comments
 (0)