Skip to content

Commit 0cf47c8

Browse files
authored
Fix cable creation in NetBox v3.3 (#927) (#938)
1 parent cc3816e commit 0cf47c8

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

plugins/module_utils/netbox_dcim.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,20 @@ def run(self):
188188
self.nb_object = cables[0]
189189
else:
190190
self._handle_errors(msg="More than one result returned for %s" % (name))
191+
192+
if Version(self.full_version) >= Version("3.3.0"):
193+
data["a_terminations"] = [
194+
{
195+
"object_id": data.pop("termination_a_id"),
196+
"object_type": data.pop("termination_a_type"),
197+
}
198+
]
199+
data["b_terminations"] = [
200+
{
201+
"object_id": data.pop("termination_b_id"),
202+
"object_type": data.pop("termination_b_type"),
203+
}
204+
]
191205
else:
192206
object_query_params = self._build_query_params(
193207
endpoint_name, data, user_query_params

plugins/module_utils/netbox_utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,31 @@ def _update_netbox_object(self, data):
13151315
else:
13161316
updated_obj["vcpus"] = float(data["vcpus"])
13171317

1318+
# Ensure idempotency for cable on netbox versions later than 3.3
1319+
version_post_33 = self._version_check_greater(self.version, "3.3", True)
1320+
if (
1321+
serialized_nb_obj.get("a_terminations")
1322+
and serialized_nb_obj.get("b_terminations")
1323+
and data.get("a_terminations")
1324+
and data.get("b_terminations")
1325+
and version_post_33
1326+
):
1327+
1328+
def _convert_termination(termination):
1329+
object_app = self._find_app(termination.endpoint.name)
1330+
object_name = ENDPOINT_NAME_MAPPING[termination.endpoint.name]
1331+
return {
1332+
"object_id": termination.id,
1333+
"object_type": f"{object_app}.{object_name}",
1334+
}
1335+
1336+
serialized_nb_obj["a_terminations"] = list(
1337+
map(_convert_termination, self.nb_object.a_terminations)
1338+
)
1339+
serialized_nb_obj["b_terminations"] = list(
1340+
map(_convert_termination, self.nb_object.b_terminations)
1341+
)
1342+
13181343
if serialized_nb_obj == updated_obj:
13191344
return serialized_nb_obj, None
13201345
else:

0 commit comments

Comments
 (0)