|
38 | 38 | HTTP_RESOURCE_ALREADY_EXISTS, |
39 | 39 | NETSCALER_COMMON_ARGUMENTS, |
40 | 40 | NITRO_ATTRIBUTES_ALIASES, |
| 41 | + GETALL_ONLY_RESOURCES, |
41 | 42 | ) |
42 | 43 | from .decorators import trace |
43 | 44 | from .logger import log, loglines |
@@ -321,17 +322,31 @@ def get_existing_resource(self): |
321 | 322 | if is_exist is False: |
322 | 323 | return {} |
323 | 324 | if len(existing_resource) > 1: |
324 | | - msg = ( |
325 | | - "ERROR: For resource `%s` Found more than one resource with the same primary key `%s` and resource_module_params %s" |
326 | | - % ( |
327 | | - self.resource_name, |
328 | | - self.resource_id, |
329 | | - self.resource_module_params, |
| 325 | + if self.resource_name in GETALL_ONLY_RESOURCES: |
| 326 | + for resources in existing_resource: |
| 327 | + # Check if all module params match this resource |
| 328 | + match_found = True |
| 329 | + for key, value in self.resource_module_params.items(): |
| 330 | + if key in resources and resources[key] != value: |
| 331 | + match_found = False |
| 332 | + break |
| 333 | + |
| 334 | + # If all parameters match, use this resource |
| 335 | + if match_found: |
| 336 | + self.existing_resource = resources |
| 337 | + break |
| 338 | + else: |
| 339 | + msg = ( |
| 340 | + "ERROR: For resource `%s` Found more than one resource with the same primary key `%s` and resource_module_params %s" |
| 341 | + % ( |
| 342 | + self.resource_name, |
| 343 | + self.resource_id, |
| 344 | + self.resource_module_params, |
| 345 | + ) |
330 | 346 | ) |
331 | | - ) |
332 | | - self.return_failure(msg) |
333 | | - |
334 | | - self.existing_resource = existing_resource[0] |
| 347 | + self.return_failure(msg) |
| 348 | + else: |
| 349 | + self.existing_resource = existing_resource[0] |
335 | 350 |
|
336 | 351 | if self.resource_name in NITRO_ATTRIBUTES_ALIASES: |
337 | 352 | self.existing_resource = self._add_nitro_attributes_aliases( |
|
0 commit comments