File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -188,6 +188,20 @@ def run(self):
188
188
self .nb_object = cables [0 ]
189
189
else :
190
190
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
+ ]
191
205
else :
192
206
object_query_params = self ._build_query_params (
193
207
endpoint_name , data , user_query_params
Original file line number Diff line number Diff line change @@ -1315,6 +1315,31 @@ def _update_netbox_object(self, data):
1315
1315
else :
1316
1316
updated_obj ["vcpus" ] = float (data ["vcpus" ])
1317
1317
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
+
1318
1343
if serialized_nb_obj == updated_obj :
1319
1344
return serialized_nb_obj , None
1320
1345
else :
You can’t perform that action at this time.
0 commit comments