|
14 | 14 | ValidationError, |
15 | 15 | AzureResponseError |
16 | 16 | ) |
| 17 | +from azure.core.exceptions import ResourceNotFoundError |
17 | 18 | from ._resource_config import ( |
18 | 19 | CLIENT_TYPE, |
19 | 20 | SUPPORTED_AUTH_TYPE, |
|
31 | 32 | ) |
32 | 33 | from ._addon_factory import AddonFactory |
33 | 34 | from ._utils import ( |
| 35 | + compare_properties_changed, |
34 | 36 | set_user_token_by_source_and_target, |
35 | 37 | set_user_token_header, |
36 | 38 | auto_register, |
|
43 | 45 | get_secret_type_for_update |
44 | 46 | ) |
45 | 47 | from ._credential_free import is_passwordless_command |
46 | | -# pylint: disable=unused-argument,unsubscriptable-object,unsupported-membership-test,too-many-statements,too-many-locals |
| 48 | +# pylint: disable=unused-argument,unsubscriptable-object,unsupported-membership-test,too-many-statements,too-many-locals,broad-exception-caught |
47 | 49 |
|
48 | 50 |
|
49 | 51 | logger = get_logger(__name__) |
@@ -317,7 +319,8 @@ def connection_create(cmd, client, # pylint: disable=too-many-locals,too-many-s |
317 | 319 | target_app_name=None, # Resource.ContainerApp |
318 | 320 | connstr_props=None, # Resource.FabricSql |
319 | 321 | fabric_workspace_uuid=None, |
320 | | - fabric_sql_db_uuid=None |
| 322 | + fabric_sql_db_uuid=None, |
| 323 | + no_recreate=False, |
321 | 324 | ): |
322 | 325 | auth_action = 'optOutAllAuth' if (opt_out_list is not None and |
323 | 326 | OPT_OUT_OPTION.AUTHENTICATION.value in opt_out_list) else None |
@@ -370,12 +373,13 @@ def connection_create(cmd, client, # pylint: disable=too-many-locals,too-many-s |
370 | 373 | app_config_id=app_config_id, |
371 | 374 | enable_appconfig_extension=enable_appconfig_extension, |
372 | 375 | server=server, database=database, |
373 | | - connstr_props=connstr_props |
| 376 | + connstr_props=connstr_props, |
| 377 | + no_recreate=no_recreate, |
374 | 378 | ) |
375 | 379 |
|
376 | 380 |
|
377 | 381 | # The function is used in extension, new feature must be added in the end for backward compatibility |
378 | | -def connection_create_func(cmd, client, # pylint: disable=too-many-locals,too-many-statements |
| 382 | +def connection_create_func(cmd, client, # pylint: disable=too-many-locals,too-many-statements,too-many-branches |
379 | 383 | connection_name=None, client_type=None, |
380 | 384 | source_resource_group=None, source_id=None, |
381 | 385 | target_resource_group=None, target_id=None, |
@@ -406,6 +410,7 @@ def connection_create_func(cmd, client, # pylint: disable=too-many-locals,too-m |
406 | 410 | target_app_name=None, # Resource.ContainerApp |
407 | 411 | enable_appconfig_extension=False, |
408 | 412 | connstr_props=None, # Resource.FabricSql |
| 413 | + no_recreate=False, |
409 | 414 | **kwargs, |
410 | 415 | ): |
411 | 416 | if not source_id: |
@@ -530,6 +535,20 @@ def connection_create_func(cmd, client, # pylint: disable=too-many-locals,too-m |
530 | 535 | 'manually and then create the connection.'.format(str(e))) |
531 | 536 |
|
532 | 537 | validate_service_state(parameters) |
| 538 | + if no_recreate: |
| 539 | + try: |
| 540 | + linker = todict(client.get(resource_uri=source_id, linker_name=connection_name)) |
| 541 | + if linker is not None and linker.get('provisioningState') == 'Accepted': |
| 542 | + logger.warning('Connection provisioningState is Accepted, please retry later to avoid conflict.') |
| 543 | + return linker |
| 544 | + if linker is not None and linker.get('provisioningState') == 'Succeeded' and \ |
| 545 | + not compare_properties_changed(parameters, linker): |
| 546 | + logger.warning( |
| 547 | + 'Connection exists and no property to be updated, skip the update operation.') |
| 548 | + return linker |
| 549 | + except ResourceNotFoundError: |
| 550 | + logger.debug('No existing connection, continue to create it.') |
| 551 | + |
533 | 552 | if enable_mi_for_db_linker and auth_action != 'optOutAllAuth': |
534 | 553 | new_auth_info = enable_mi_for_db_linker( |
535 | 554 | cmd, source_id, target_id, auth_info, client_type, connection_name, connstr_props) |
|
0 commit comments