@@ -335,16 +335,14 @@ def get_template_object_by_uuid(self, object_type, uuid, fail_module=True):
335
335
self .mso .fail_json (msg = msg )
336
336
return response_object
337
337
338
- def update_config_with_template_and_references (self , config_data , reference_dict = None ):
338
+ def update_config_with_template_and_references (self , config_data , reference_collections = None ):
339
339
"""
340
- Return the updated config_data with the template values and reference_dict if provided
341
-
340
+ Return the updated config_data with the template values and reference_collections if provided
342
341
:param config_data: The original config_data that requires to be updated -> Dict
343
- :param reference_dict : A dict containing the object type, references and the corresponding names -> Dict
342
+ :param reference_collections : A dict containing the object type, references and the corresponding names -> Dict
344
343
:return: Updated config_data with names for references -> Dict
345
-
346
344
Example 1:
347
- reference_dict = {
345
+ reference_collections = {
348
346
"qos": {
349
347
"name": "qosName",
350
348
"reference": "qosRef",
@@ -360,28 +358,25 @@ def update_config_with_template_and_references(self, config_data, reference_dict
360
358
"templateId": "interfaceRoutingPolicyTemplateId",
361
359
},
362
360
}
363
-
364
361
config_data = {
365
362
"qosRef": "unique-qos-id",
366
363
"interfaceRoutingPolicyRef": "unique-interface-id"
367
364
}
368
-
369
- updated_config_data = MSOHandler.set_names_for_references(mso_instance, config_data, reference_dict)
370
- # Expected Output:
371
- # { "templateName": "template_name",
372
- # "templateId": "unique-template-id",
373
- # "qosRef": "unique-qos-id",
374
- # "interfaceRoutingPolicyRef": "unique-interface-id",
375
- # "qosName": "Resolved QoS Name",
376
- # "qosTemplateName": "Resolved QoS Template Name",
377
- # "qosTemplateId": "Resolved QoS Template ID",
378
- # "interfaceRoutingPolicyName": "Resolved Interface Routing Policy Name",
379
- # "interfaceRoutingPolicyTemplateName": "Resolved Interface Routing Policy Template Name",
380
- # "interfaceRoutingPolicyTemplateId": "Resolved Interface Routing Policy Template ID"
381
- # }
382
-
365
+ updated_config_data = mso_template_object.set_names_for_references(mso_instance, config_data, reference_collections)
366
+ Expected Output:
367
+ { "templateName": "template_name",
368
+ "templateId": "unique-template-id",
369
+ "qosRef": "unique-qos-id",
370
+ "interfaceRoutingPolicyRef": "unique-interface-id",
371
+ "qosName": "Resolved QoS Name",
372
+ "qosTemplateName": "Resolved QoS Template Name",
373
+ "qosTemplateId": "Resolved QoS Template ID",
374
+ "interfaceRoutingPolicyName": "Resolved Interface Routing Policy Name",
375
+ "interfaceRoutingPolicyTemplateName": "Resolved Interface Routing Policy Template Name",
376
+ "interfaceRoutingPolicyTemplateId": "Resolved Interface Routing Policy Template ID"
377
+ }
383
378
Example 2:
384
- reference_dict = {
379
+ reference_collections = {
385
380
"stateLimitRouteMap": {
386
381
"name": "stateLimitRouteMapName",
387
382
"reference": "stateLimitRouteMapRef",
@@ -398,21 +393,19 @@ def update_config_with_template_and_references(self, config_data, reference_dict
398
393
"type": "mcastRouteMap"
399
394
},
400
395
}
401
-
402
396
config_data = {
403
397
"stateLimitRouteMapRef": "unique-state-limit-id",
404
398
"reportPolicyRouteMapRef": "unique-report-policy-id"
405
399
}
406
-
407
- updated_config_data = MSOHandler.set_names_for_references(mso_instance, config_data, reference_dict)
408
- # Expected Output:
409
- # { "templateName": "template_name",
410
- # "templateId": "unique-template-id",
411
- # "stateLimitRouteMapRef": "unique-state-limit-id",
412
- # "reportPolicyRouteMapRef": "unique-report-policy-id",
413
- # "stateLimitRouteMapName": "Resolved State Limit Route Map Name",
414
- # "reportPolicyRouteMapName": "Resolved Report Policy Route Map Name"
415
- # }
400
+ updated_config_data = mso_template_object.set_names_for_references(mso_instance, config_data, reference_collections)
401
+ Expected Output:
402
+ { "templateName": "template_name",
403
+ "templateId": "unique-template-id",
404
+ "stateLimitRouteMapRef": "unique-state-limit-id",
405
+ "reportPolicyRouteMapRef": "unique-report-policy-id",
406
+ "stateLimitRouteMapName": "Resolved State Limit Route Map Name",
407
+ "reportPolicyRouteMapName": "Resolved Report Policy Route Map Name"
408
+ }
416
409
"""
417
410
418
411
# Set template ID and template name if available
@@ -421,16 +414,16 @@ def update_config_with_template_and_references(self, config_data, reference_dict
421
414
if self .template_name :
422
415
config_data ["templateName" ] = self .template_name
423
416
424
- # Update config data with reference names if reference_dict is provided
425
- if reference_dict :
426
- for object_values in reference_dict .values ():
427
- if config_data .get (object_values .get ("reference" )):
428
- template_object = self .get_template_object_by_uuid (object_values .get ("type" ), config_data .get (object_values .get ("reference" )))
429
- config_data [object_values .get ("name" )] = template_object .get ("name" )
430
- if object_values .get ("template" ):
431
- config_data [object_values .get ("template" )] = template_object .get ("templateName" )
432
- if object_values .get ("templateId" ):
433
- config_data [object_values .get ("templateId" )] = template_object .get ("templateId" )
417
+ # Update config data with reference names if reference_collections is provided
418
+ if reference_collections :
419
+ for reference_details in reference_collections .values ():
420
+ if config_data .get (reference_details .get ("reference" )):
421
+ template_object = self .get_template_object_by_uuid (reference_details .get ("type" ), config_data .get (reference_details .get ("reference" )))
422
+ config_data [reference_details .get ("name" )] = template_object .get ("name" )
423
+ if reference_details .get ("template" ):
424
+ config_data [reference_details .get ("template" )] = template_object .get ("templateName" )
425
+ if reference_details .get ("templateId" ):
426
+ config_data [reference_details .get ("templateId" )] = template_object .get ("templateId" )
434
427
return config_data
435
428
436
429
def check_template_when_name_is_provided (self , parameter ):
0 commit comments