From 08f0efa43189bf595cce9c333c3aaafaac51f7bb Mon Sep 17 00:00:00 2001 From: Yishi Wang Date: Fri, 6 Sep 2024 14:51:59 +0800 Subject: [PATCH 1/4] remove msrestazure code --- .../cli/command_modules/acr/_archive_utils.py | 4 +- .../cli/command_modules/acr/_run_polling.py | 4 +- .../cli/command_modules/acr/_stream_utils.py | 4 +- .../azure/cli/command_modules/acr/_utils.py | 2 +- .../cli/command_modules/acr/check_health.py | 6 +-- .../azure/cli/command_modules/acr/custom.py | 4 +- .../azure/cli/command_modules/acr/import.py | 4 +- .../cli/command_modules/acr/network_rule.py | 4 +- .../cli/command_modules/acs/_completers.py | 4 +- .../azure/cli/command_modules/acs/_helpers.py | 4 +- .../command_modules/acs/_roleassignments.py | 11 ++-- .../cli/command_modules/acs/_validators.py | 20 +++---- .../command_modules/acs/addonconfiguration.py | 2 +- .../acs/azuremonitormetrics/amw/helper.py | 2 +- .../acs/azuremonitormetrics/helper.py | 2 +- .../azure/cli/command_modules/acs/custom.py | 2 +- .../acs/managed_cluster_decorator.py | 9 ++-- .../acs/tests/latest/test_aks_commands.py | 2 +- .../acs/tests/latest/test_helpers.py | 5 +- .../command_modules/acs/tests/test_helper.py | 2 +- .../cli/command_modules/advisor/custom.py | 4 +- .../cli/command_modules/ams/_validators.py | 2 +- .../cli/command_modules/ams/operations/mru.py | 2 +- .../test_ams_account_identity_scenarios.py | 2 +- .../command_modules/appconfig/_validators.py | 4 +- .../command_modules/appservice/_validators.py | 2 +- .../appservice/access_restrictions.py | 2 +- .../appservice/appservice_environment.py | 2 +- .../cli/command_modules/appservice/custom.py | 8 +-- .../appservice/logicapp/custom.py | 2 +- .../appservice/static_sites.py | 2 +- .../tests/latest/test_logicapp_commands.py | 2 +- .../latest/test_webapp_commands_thru_mock.py | 4 +- .../cli/command_modules/appservice/utils.py | 2 +- .../aro/_dynamic_validators.py | 6 +-- .../azure/cli/command_modules/aro/_format.py | 2 +- .../azure/cli/command_modules/aro/_rbac.py | 2 +- .../cli/command_modules/aro/_validators.py | 7 ++- .../azure/cli/command_modules/aro/custom.py | 12 ++--- .../aro/tests/latest/custom_preparers.py | 2 +- .../aro/tests/latest/test_aro_commands.py | 16 +++--- .../batch/_exception_handler.py | 4 +- .../cli/command_modules/batch/_validators.py | 2 +- .../cli/command_modules/batchai/_format.py | 6 +-- .../cli/command_modules/batchai/custom.py | 7 ++- .../botservice/_exception_handler.py | 3 -- .../cli/command_modules/cdn/custom/custom.py | 2 +- .../cdn/custom/custom_rule_util.py | 2 +- .../cognitiveservices/_params.py | 2 +- .../cognitiveservices/custom.py | 2 +- .../command_modules/container/_validators.py | 2 +- .../cli/command_modules/container/custom.py | 6 +-- .../tests/latest/test_container_commands.py | 1 - .../containerapp/_acr_run_polling.py | 4 +- .../containerapp/_archive_utils.py | 4 +- .../command_modules/containerapp/_up_utils.py | 2 +- .../command_modules/containerapp/_utils.py | 2 +- .../containerapp/_validators.py | 6 +-- .../command_modules/containerapp/commands.py | 1 - .../containerapp/containerapp_decorator.py | 2 +- .../containerapp_env_decorator.py | 2 +- .../containerapp_job_decorator.py | 2 +- .../command_modules/containerapp/custom.py | 2 +- .../latest/test_containerapp_commands.py | 2 +- ...est_containerapp_ingress_sticky_session.py | 2 +- .../latest/test_containerapp_scenario.py | 2 +- .../tests/latest/test_containerappjob_crud.py | 2 +- ...st_containerappjob_event_triggered_crud.py | 2 +- .../latest/test_containerappjob_executions.py | 2 +- .../latest/test_containerappjob_registry.py | 2 - .../test_containerappjob_with_identity.py | 2 +- .../test_containerappjob_with_secrets.py | 2 +- .../cli/command_modules/cosmosdb/custom.py | 4 +- .../cli/command_modules/dls/_validators.py | 4 +- .../dls/tests/latest/test_dls_commands.py | 4 +- .../cli/command_modules/eventgrid/custom.py | 2 +- .../command_modules/eventhubs/_validator.py | 4 +- ..._eventhub_commands_privateendpoint_test.py | 1 - .../command_modules/hdinsight/_completers.py | 2 +- .../command_modules/hdinsight/_validators.py | 2 +- .../cli/command_modules/hdinsight/custom.py | 6 +-- .../cli/command_modules/hdinsight/util.py | 8 +-- .../azure/cli/command_modules/iot/custom.py | 4 +- .../tests/latest/test_iot_central_commands.py | 1 - .../command_modules/keyvault/_validators.py | 8 +-- .../cli/command_modules/keyvault/custom.py | 2 +- .../lab/tests/latest/test_lab_validators.py | 2 +- .../cli/command_modules/lab/validators.py | 10 ++-- .../monitor/operations/activity_log_alerts.py | 4 +- .../monitor/operations/autoscale_settings.py | 2 +- .../operations/diagnostics_settings.py | 5 +- .../monitor/operations/metric_alert.py | 2 +- .../monitor/operations/monitor_clone_util.py | 2 +- .../latest/test_monitor_general_operations.py | 2 +- .../test_monitor_log_analytics_workspace.py | 4 +- .../test_monitor_metric_alert_scenarios.py | 8 +-- .../tests/latest/test_monitor_metrics.py | 2 +- ...onitor_subscription_diagnostic_settings.py | 2 +- .../cli/command_modules/monitor/validators.py | 12 ++--- .../cli/command_modules/mysql/_network.py | 2 +- .../azure/cli/command_modules/mysql/_util.py | 5 +- .../cli/command_modules/mysql/_validators.py | 2 +- .../azure/cli/command_modules/mysql/custom.py | 9 ++-- .../cli/command_modules/netappfiles/custom.py | 2 +- .../command_modules/netappfiles/validators.py | 2 +- .../cli/command_modules/network/_format.py | 2 +- .../command_modules/network/_validators.py | 54 +++++++++---------- .../network/azure_stack/_format.py | 2 +- .../network/azure_stack/_validators.py | 20 +++---- .../network/azure_stack/custom.py | 2 +- .../operations/public_ip.py | 2 +- .../cli/command_modules/network/custom.py | 2 +- .../network/operations/load_balancer.py | 2 +- .../network/operations/watcher.py | 2 +- .../test_network_commands.py | 2 +- .../test_network_commands.py | 2 +- .../test_network_commands.py | 2 +- .../tests/latest/test_network_commands.py | 4 +- .../latest/test_private_endpoint_commands.py | 1 - .../test_network_commands.py | 2 +- .../policyinsights/_validators.py | 2 +- .../command_modules/policyinsights/custom.py | 2 +- .../command_modules/privatedns/_validators.py | 2 +- .../rdbms/_flexible_server_util.py | 5 +- .../azure/cli/command_modules/rdbms/custom.py | 7 ++- .../rdbms/flexible_server_custom_postgres.py | 5 +- .../rdbms/flexible_server_virtual_network.py | 2 +- .../rdbms/tests/latest/test_rdbms_commands.py | 1 - ...ms_flexible_commands_postgres_migration.py | 1 - .../cli/command_modules/rdbms/validators.py | 2 +- .../azure/cli/command_modules/redis/custom.py | 4 +- .../command_modules/resource/_validators.py | 2 +- .../cli/command_modules/resource/custom.py | 6 +-- .../resource/tests/latest/test_resource.py | 8 +-- .../azure/cli/command_modules/role/custom.py | 8 +-- .../cli/command_modules/security/custom.py | 6 +-- .../tests/latest/test_tasks_scenario.py | 2 +- .../command_modules/servicebus/_validators.py | 6 +-- ...ervicebus_commands_privateendpoint_test.py | 1 - .../servicefabric/_sf_utils.py | 4 +- .../servicefabric/_validators.py | 6 +-- .../command_modules/servicefabric/custom.py | 8 ++- .../cli/command_modules/sql/_validators.py | 2 +- .../azure/cli/command_modules/sql/custom.py | 12 ++--- .../cli/command_modules/sqlvm/_format.py | 6 +-- .../cli/command_modules/sqlvm/_validators.py | 2 +- .../azure/cli/command_modules/sqlvm/custom.py | 2 +- .../command_modules/storage/_validators.py | 8 +-- .../storage/_validators_azure_stack.py | 6 +-- .../storage/operations/account.py | 8 +-- .../synapse/manual/_validators.py | 6 +-- .../operations/sqlpoolsensitivitylabel.py | 6 +-- .../azure/cli/command_modules/vm/_format.py | 2 +- .../cli/command_modules/vm/_image_builder.py | 2 +- .../command_modules/vm/_template_builder.py | 2 +- .../cli/command_modules/vm/_validators.py | 40 +++++++------- .../azure/cli/command_modules/vm/_vm_utils.py | 4 +- .../azure/cli/command_modules/vm/custom.py | 44 +++++++-------- .../cli/command_modules/vm/disk_encryption.py | 6 +-- .../hybrid_2018_03_01/test_vm_commands.py | 4 +- .../hybrid_2019_03_01/test_vm_commands.py | 4 +- .../hybrid_2020_09_01/test_vm_commands.py | 6 +-- .../latest/test_image_builder_commands.py | 2 +- .../vm/tests/latest/test_vm_commands.py | 8 +-- 164 files changed, 371 insertions(+), 401 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acr/_archive_utils.py b/src/azure-cli/azure/cli/command_modules/acr/_archive_utils.py index 3441eeaaa8b..c2219c8c68c 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_archive_utils.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_archive_utils.py @@ -11,7 +11,7 @@ import requests from knack.log import get_logger from knack.util import CLIError -from msrestazure.azure_exceptions import CloudError +from azure.core.exceptions import HttpResponseError from azure.cli.core.profiles import ResourceType, get_sdk from ._constants import TASK_VALID_VSTS_URLS @@ -46,7 +46,7 @@ def upload_source_code(cmd, client, resource_group_name, registry_name) upload_url = source_upload_location.upload_url relative_path = source_upload_location.relative_path - except (AttributeError, CloudError) as e: + except (AttributeError, HttpResponseError) as e: raise CLIError("Failed to get a SAS URL to upload context. Error: {}".format(e.message)) if not upload_url: diff --git a/src/azure-cli/azure/cli/command_modules/acr/_run_polling.py b/src/azure-cli/azure/cli/command_modules/acr/_run_polling.py index 5804d983a06..7117b21199b 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_run_polling.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_run_polling.py @@ -7,7 +7,7 @@ from azure.core.polling import PollingMethod, LROPoller from msrest import Deserializer -from msrestazure.azure_exceptions import CloudError +from azure.core.exceptions import HttpResponseError from ._constants import get_acr_task_models, get_finished_run_status, get_succeeded_run_status @@ -90,7 +90,7 @@ def _set_operation_status(self, response): self.operation_result = self._deserialize(response) self.operation_status = self.operation_result.status or RunStatus.queued.value return - raise CloudError(response) + raise HttpResponseError(response) def _update_status(self): self._response = self._client._pipeline.run( # pylint: disable=protected-access diff --git a/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py b/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py index 9878d68ae86..c847c6a3ba7 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py @@ -9,7 +9,7 @@ import requests from knack.util import CLIError from knack.log import get_logger -from msrestazure.azure_exceptions import CloudError +from azure.core.exceptions import HttpResponseError from azure.common import AzureHttpError from azure.cli.core.profiles import ResourceType, get_sdk from ._azure_utils import get_blob_info @@ -41,7 +41,7 @@ def stream_logs(cmd, client, else: log_file_sas = response.log_artifact_link artifact = True - except (AttributeError, CloudError) as e: + except (AttributeError, HttpResponseError) as e: logger.debug("%s Exception: %s", error_msg, e) raise CLIError(error_msg) diff --git a/src/azure-cli/azure/cli/command_modules/acr/_utils.py b/src/azure-cli/azure/cli/command_modules/acr/_utils.py index c6f8b438a90..5f0bd739e65 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_utils.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_utils.py @@ -587,7 +587,7 @@ def get_scope_map_from_id(cmd, scope_map_id): def resolve_identity_client_id(cli_ctx, managed_identity_resource_id): from azure.mgmt.msi import ManagedServiceIdentityClient from azure.cli.core.commands.client_factory import get_mgmt_service_client - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id res = parse_resource_id(managed_identity_resource_id) client = get_mgmt_service_client(cli_ctx, ManagedServiceIdentityClient, subscription_id=res['subscription']) diff --git a/src/azure-cli/azure/cli/command_modules/acr/check_health.py b/src/azure-cli/azure/cli/command_modules/acr/check_health.py index 5d99c75ad9f..12748af1c4f 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/check_health.py +++ b/src/azure-cli/azure/cli/command_modules/acr/check_health.py @@ -332,10 +332,10 @@ def _check_registry_health(cmd, registry_name, ignore_errors): if not valid_identity and registry.identity.user_assigned_identities: for k, v in registry.identity.user_assigned_identities.items(): if v.client_id == client_id: - from msrestazure.azure_exceptions import CloudError + from azure.core.exceptions import HttpResponseError try: valid_identity = (resolve_identity_client_id(cmd.cli_ctx, k) == client_id) - except CloudError: + except HttpResponseError: pass if not valid_identity: from ._errors import CMK_MANAGED_IDENTITY_ERROR @@ -344,7 +344,7 @@ def _check_registry_health(cmd, registry_name, ignore_errors): def _check_private_endpoint(cmd, registry_name, vnet_of_private_endpoint): # pylint: disable=too-many-locals, too-many-statements import socket - from msrestazure.tools import parse_resource_id, is_valid_resource_id, resource_id + from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id, resource_id if registry_name is None: raise CLIError("Registry name must be provided to verify DNS routings of its private endpoints") diff --git a/src/azure-cli/azure/cli/command_modules/acr/custom.py b/src/azure-cli/azure/cli/command_modules/acr/custom.py index fcbcb0ad9df..813e8c7ce27 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/custom.py +++ b/src/azure-cli/azure/cli/command_modules/acr/custom.py @@ -90,7 +90,7 @@ def acr_create(cmd, lro_poller = client.begin_create(resource_group_name, registry_name, registry) if workspace: - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id from azure.cli.core.commands import LongRunningOperation from azure.cli.core.commands.client_factory import get_subscription_id acr = LongRunningOperation(cmd.cli_ctx)(lro_poller) @@ -609,7 +609,7 @@ def _analyze_identities(identities): def _ensure_identity_resource_id(subscription_id, resource_group, resource): - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id if is_valid_resource_id(resource): return resource return resource_id(subscription=subscription_id, diff --git a/src/azure-cli/azure/cli/command_modules/acr/import.py b/src/azure-cli/azure/cli/command_modules/acr/import.py index b9a315d69fe..567a2ff1df0 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/import.py +++ b/src/azure-cli/azure/cli/command_modules/acr/import.py @@ -5,7 +5,7 @@ from knack.util import CLIError from knack.log import get_logger -from msrestazure.tools import is_valid_resource_id, parse_resource_id +from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id from azure.cli.command_modules.acr._docker_utils import get_login_server_suffix from azure.cli.core.commands import LongRunningOperation from azure.cli.core.util import sdk_no_wait @@ -118,7 +118,7 @@ def acr_import(cmd, # pylint: disable=too-many-locals def _handle_import_exception(e, cmd, source_registry, source_image, registry): - from msrestazure.azure_exceptions import ClientException + from msrest.exceptions import ClientException try: # if command fails, it might be because user specified registry twice in --source and --registry if source_registry: diff --git a/src/azure-cli/azure/cli/command_modules/acr/network_rule.py b/src/azure-cli/azure/cli/command_modules/acr/network_rule.py index 5152747aff4..51084250d2b 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/network_rule.py +++ b/src/azure-cli/azure/cli/command_modules/acr/network_rule.py @@ -122,13 +122,13 @@ def acr_network_rule_remove(cmd, def _validate_subnet(cli_ctx, subnet, vnet_name, resource_group_name): - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id subnet_is_id = is_valid_resource_id(subnet) if subnet_is_id and not vnet_name: return subnet if subnet and not subnet_is_id and vnet_name: - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id from azure.cli.core.commands.client_factory import get_subscription_id return resource_id( subscription=get_subscription_id(cli_ctx), diff --git a/src/azure-cli/azure/cli/command_modules/acs/_completers.py b/src/azure-cli/azure/cli/command_modules/acs/_completers.py index e3f4deea94a..ad292520d3e 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_completers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_completers.py @@ -72,12 +72,12 @@ def _get_location(cli_ctx, namespace): def _get_location_from_resource_group(cli_ctx, resource_group_name): from azure.cli.command_modules.acs._client_factory import get_resource_groups_client - from msrestazure.azure_exceptions import CloudError + from azure.core.exceptions import HttpResponseError try: rg = get_resource_groups_client(cli_ctx).get(resource_group_name) return rg.location - except CloudError as err: + except HttpResponseError as err: # Print a warning if the user hit [TAB] but the `--resource-group` argument was incorrect. # For example: "Warning: Resource group 'bogus' could not be found." from argcomplete import warn diff --git a/src/azure-cli/azure/cli/command_modules/acs/_helpers.py b/src/azure-cli/azure/cli/command_modules/acs/_helpers.py index a6f0a0b7152..c5c7f4334d1 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_helpers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_helpers.py @@ -23,7 +23,6 @@ UnclassifiedUserFault, ) from azure.core.exceptions import AzureError, HttpResponseError, ServiceRequestError, ServiceResponseError -from msrestazure.azure_exceptions import CloudError # type variables ManagedCluster = TypeVar("ManagedCluster") @@ -208,8 +207,7 @@ def get_user_assigned_identity(cli_ctx, subscription_id, resource_group_name, id identity = msi_client.user_assigned_identities.get( resource_group_name=resource_group_name, resource_name=identity_name ) - # track 1 sdk raise exception from msrestazure.azure_exceptions - except CloudError as ex: + except HttpResponseError as ex: if "was not found" in ex.message: raise ResourceNotFoundError("Identity '{}' not found.".format(identity_name)) raise ServiceError(ex.message) diff --git a/src/azure-cli/azure/cli/command_modules/acs/_roleassignments.py b/src/azure-cli/azure/cli/command_modules/acs/_roleassignments.py index 7242b4def21..70f002e6bbd 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_roleassignments.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_roleassignments.py @@ -24,7 +24,6 @@ from azure.core.exceptions import HttpResponseError, ResourceExistsError from knack.log import get_logger from knack.prompting import prompt_y_n -from msrestazure.azure_exceptions import CloudError logger = get_logger(__name__) @@ -127,7 +126,7 @@ def add_role_assignment(cmd, role, service_principal_msi_id, is_service_principa resolve_assignee=is_service_principal, ) break - except (CloudError, HttpResponseError) as ex: + except HttpResponseError as ex: if isinstance(ex, ResourceExistsError) or "The role assignment already exists." in ex.message: break logger.info(ex.message) @@ -209,7 +208,7 @@ def delete_role_assignments(cli_ctx, role, service_principal, delay=2, scope=Non cli_ctx, role=role, assignee=service_principal, scope=scope, is_service_principal=is_service_principal ) break - except (CloudError, HttpResponseError) as ex: + except HttpResponseError as ex: logger.info(ex.message) except Exception as ex: # pylint: disable=broad-except logger.error(str(ex)) @@ -321,7 +320,7 @@ def ensure_aks_acr_role_assignment(cmd, assignee, registry_id, detach=False, is_ # pylint: disable=unused-argument def ensure_aks_acr(cmd, assignee, acr_name_or_id, subscription_id, detach=False, is_service_principal=True): - from msrestazure.tools import is_valid_resource_id, parse_resource_id + from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id # Check if the ACR exists by resource ID. if is_valid_resource_id(acr_name_or_id): @@ -329,7 +328,7 @@ def ensure_aks_acr(cmd, assignee, acr_name_or_id, subscription_id, detach=False, parsed_registry = parse_resource_id(acr_name_or_id) acr_client = get_container_registry_client(cmd.cli_ctx, subscription_id=parsed_registry["subscription"]) registry = acr_client.registries.get(parsed_registry["resource_group"], parsed_registry["name"]) - except (CloudError, HttpResponseError) as ex: + except HttpResponseError as ex: raise AzCLIError(ex.message) ensure_aks_acr_role_assignment(cmd, assignee, registry.id, detach, is_service_principal) return @@ -339,7 +338,7 @@ def ensure_aks_acr(cmd, assignee, acr_name_or_id, subscription_id, detach=False, registry_resource = "Microsoft.ContainerRegistry/registries" try: registry = get_resource_by_name(cmd.cli_ctx, registry_name, registry_resource) - except (CloudError, HttpResponseError) as ex: + except HttpResponseError as ex: if "was not found" in ex.message: raise AzCLIError("ACR {} not found. Have you provided the right ACR name?".format(registry_name)) raise AzCLIError(ex.message) diff --git a/src/azure-cli/azure/cli/command_modules/acs/_validators.py b/src/azure-cli/azure/cli/command_modules/acs/_validators.py index 6a228a8597b..a12aafe25f1 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acs/_validators.py @@ -365,7 +365,7 @@ def validate_pod_subnet_id(namespace): def _validate_subnet_id(subnet_id, name): if subnet_id is None or subnet_id == '': return - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id if not is_valid_resource_id(subnet_id): raise InvalidArgumentValueError(name + " is not a valid Azure resource ID.") @@ -374,7 +374,7 @@ def validate_ppg(namespace): if namespace.ppg is not None: if namespace.ppg == '': return - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id if not is_valid_resource_id(namespace.ppg): raise CLIError("--ppg is not a valid Azure resource ID.") @@ -478,7 +478,7 @@ def validate_assign_identity(namespace): if namespace.assign_identity is not None: if namespace.assign_identity == '': return - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id if not is_valid_resource_id(namespace.assign_identity): raise InvalidArgumentValueError("--assign-identity is not a valid Azure resource ID.") @@ -487,27 +487,27 @@ def validate_assign_kubelet_identity(namespace): if namespace.assign_kubelet_identity is not None: if namespace.assign_kubelet_identity == '': return - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id if not is_valid_resource_id(namespace.assign_kubelet_identity): raise InvalidArgumentValueError("--assign-kubelet-identity is not a valid Azure resource ID.") def validate_nodepool_id(namespace): - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id if not is_valid_resource_id(namespace.nodepool_id): raise InvalidArgumentValueError("--nodepool-id is not a valid Azure resource ID.") def validate_snapshot_id(namespace): if namespace.snapshot_id: - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id if not is_valid_resource_id(namespace.snapshot_id): raise InvalidArgumentValueError("--snapshot-id is not a valid Azure resource ID.") def validate_host_group_id(namespace): if namespace.host_group_id: - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id if not is_valid_resource_id(namespace.host_group_id): raise InvalidArgumentValueError("--host-group-id is not a valid Azure resource ID.") @@ -515,7 +515,7 @@ def validate_host_group_id(namespace): def validate_crg_id(namespace): if namespace.crg_id is None: return - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id if not is_valid_resource_id(namespace.crg_id): raise InvalidArgumentValueError( "--crg-id is not a valid Azure resource ID.") @@ -630,7 +630,7 @@ def validate_azure_keyvault_kms_key_vault_resource_id(namespace): key_vault_resource_id = namespace.azure_keyvault_kms_key_vault_resource_id if key_vault_resource_id is None or key_vault_resource_id == '': return - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id if not is_valid_resource_id(key_vault_resource_id): raise InvalidArgumentValueError("--azure-keyvault-kms-key-vault-resource-id is not a valid Azure resource ID.") @@ -792,7 +792,7 @@ def validate_application_security_groups(namespace): if not asg_ids: return - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id for asg in asg_ids: if not is_valid_resource_id(asg): raise InvalidArgumentValueError(asg + " is not a valid Azure resource ID.") diff --git a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py index dfdd8a8822c..c21a8a6a250 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py +++ b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py @@ -24,7 +24,7 @@ from azure.cli.core.util import send_raw_request from azure.core.exceptions import HttpResponseError from knack.log import get_logger -from msrestazure.tools import parse_resource_id, resource_id +from azure.mgmt.core.tools import parse_resource_id, resource_id logger = get_logger(__name__) # mapping for azure public cloud diff --git a/src/azure-cli/azure/cli/command_modules/acs/azuremonitormetrics/amw/helper.py b/src/azure-cli/azure/cli/command_modules/acs/azuremonitormetrics/amw/helper.py index db3bce14e77..4c3194f3726 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/azuremonitormetrics/amw/helper.py +++ b/src/azure-cli/azure/cli/command_modules/acs/azuremonitormetrics/amw/helper.py @@ -11,7 +11,7 @@ def get_amw_region(cmd, azure_monitor_workspace_resource_id): import re - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id # Define the allowed characters in the final string allowed_chars = re.compile(r'[^a-zA-Z0-9]') diff --git a/src/azure-cli/azure/cli/command_modules/acs/azuremonitormetrics/helper.py b/src/azure-cli/azure/cli/command_modules/acs/azuremonitormetrics/helper.py index 5e91173d065..46deecf4b2a 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/azuremonitormetrics/helper.py +++ b/src/azure-cli/azure/cli/command_modules/acs/azuremonitormetrics/helper.py @@ -65,7 +65,7 @@ def register_rps(cmd, subscription_id, rp_namespaces, user_agent): def rp_registrations(cmd, cluster_subscription_id, raw_parameters): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id cluster_rp_namespaces = { "microsoft.insights": False, "microsoft.alertsmanagement": False diff --git a/src/azure-cli/azure/cli/command_modules/acs/custom.py b/src/azure-cli/azure/cli/command_modules/acs/custom.py index 7d33d2ab2cd..ad212da9f0f 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/custom.py +++ b/src/azure-cli/azure/cli/command_modules/acs/custom.py @@ -3145,7 +3145,7 @@ def aks_approuting_zone_list( resource_group_name, name ): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id mc = client.get(resource_group_name, name) if mc.ingress_profile and mc.ingress_profile.web_app_routing and mc.ingress_profile.web_app_routing.enabled: diff --git a/src/azure-cli/azure/cli/command_modules/acs/managed_cluster_decorator.py b/src/azure-cli/azure/cli/command_modules/acs/managed_cluster_decorator.py index af2bec43333..ff1b17c6951 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/managed_cluster_decorator.py +++ b/src/azure-cli/azure/cli/command_modules/acs/managed_cluster_decorator.py @@ -110,8 +110,7 @@ from knack.log import get_logger from knack.prompting import NoTTYException, prompt, prompt_pass, prompt_y_n from knack.util import CLIError -from msrestazure.azure_exceptions import CloudError -from msrestazure.tools import is_valid_resource_id, parse_resource_id +from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id logger = get_logger(__name__) @@ -6796,7 +6795,7 @@ def postprocessing_after_mc_created(self, cluster: ManagedCluster) -> None: # mdm metrics is supported only in azure public cloud, so add the role assignment only in this cloud cloud_name = self.cmd.cli_ctx.cloud.name if cloud_name.lower() == "azurecloud": - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id cluster_resource_id = resource_id( subscription=self.context.get_subscription_id(), @@ -6978,7 +6977,7 @@ def create_mc(self, mc: ManagedCluster) -> ManagedCluster: return cluster # CloudError was raised before, but since the adoption of track 2 SDK, # HttpResponseError would be raised instead - except (CloudError, HttpResponseError) as ex: + except HttpResponseError as ex: error_msg = str(ex) if "not found in Active Directory tenant" in ex.message: time.sleep(3) @@ -8559,7 +8558,7 @@ def postprocessing_after_mc_created(self, cluster: ManagedCluster) -> None: # mdm metrics is supported only in azure public cloud, so add the role assignment only in this cloud cloud_name = self.cmd.cli_ctx.cloud.name if cloud_name.lower() == "azurecloud": - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id cluster_resource_id = resource_id( subscription=self.context.get_subscription_id(), diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_commands.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_commands.py index 45f45a72d29..5b805443cbe 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_commands.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_commands.py @@ -3663,7 +3663,7 @@ def test_aks_byo_appgw_with_ingress_appgw_addon(self, resource_group, resource_g self.cmd(create_appgw) # construct group id - from msrestazure.tools import parse_resource_id, resource_id + from azure.mgmt.core.tools import parse_resource_id, resource_id parsed_vnet_id = parse_resource_id(vnet_id) group_id = resource_id(subscription=parsed_vnet_id["subscription"], resource_group=parsed_vnet_id["resource_group"]) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py index 3459a48b3d5..369f91160b0 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py @@ -38,7 +38,6 @@ ) from azure.cli.core.profiles import ResourceType from azure.core.exceptions import AzureError, HttpResponseError, ServiceRequestError, ServiceResponseError -from msrestazure.azure_exceptions import CloudError class DecoratorFunctionsTestCase(unittest.TestCase): @@ -325,7 +324,7 @@ def test_get_user_assigned_identity(self): ) self.assertEqual(user_assigned_identity, mock_user_assigned_identity) - cloud_error_2 = CloudError(Mock(status_code="xxx"), "mock user assigned identity was not found") + cloud_error_2 = HttpResponseError(Mock(status_code="xxx"), "mock user assigned identity was not found") mock_user_assigned_identity_operations_2 = Mock( user_assigned_identities=Mock(get=Mock(side_effect=cloud_error_2)) ) @@ -335,7 +334,7 @@ def test_get_user_assigned_identity(self): ), self.assertRaises(ResourceNotFoundError): get_user_assigned_identity("mock_cli_ctx", "mock_sub_id", "mock_rg", "mock_identity_name") - cloud_error_3 = CloudError(Mock(status_code="xxx"), "test_error_msg") + cloud_error_3 = HttpResponseError(Mock(status_code="xxx"), "test_error_msg") mock_user_assigned_identity_operations_3 = Mock( user_assigned_identities=Mock(get=Mock(side_effect=cloud_error_3)) ) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/test_helper.py b/src/azure-cli/azure/cli/command_modules/acs/tests/test_helper.py index 15cd3a8704a..90cc0a5ff9b 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/test_helper.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/test_helper.py @@ -18,7 +18,7 @@ def test_sanitize_resource_id(self): # Test case where resource_id needs leading slash and trailing slash removed self.assertEqual(sanitize_resource_id("test/resource/"), "/test/resource") - @patch('msrestazure.tools.parse_resource_id') + @patch('azure.mgmt.core.tools.parse_resource_id') @patch('azure.cli.command_modules.acs.azuremonitormetrics.helper.register_rps') def test_subscription_id_selection(self, mock_register_rps, mock_parse_resource_id): # Mocking return value of parse_resource_id diff --git a/src/azure-cli/azure/cli/command_modules/advisor/custom.py b/src/azure-cli/azure/cli/command_modules/advisor/custom.py index 5f8b6705353..22a2886bff1 100644 --- a/src/azure-cli/azure/cli/command_modules/advisor/custom.py +++ b/src/azure-cli/azure/cli/command_modules/advisor/custom.py @@ -147,7 +147,7 @@ def _parse_recommendation_uri(recommendation_uri): def _generate_recommendations(client): - from msrestazure.azure_exceptions import CloudError + from azure.core.exceptions import HttpResponseError response = client.generate(cls=_callback) location = response.headers['Location'] @@ -155,7 +155,7 @@ def _generate_recommendations(client): try: client.get_generate_status(operation_id=operation_id) - except CloudError as ex: + except HttpResponseError as ex: # Advisor API returns 204 which is not aligned with ARM guidelines # so the SDK will throw an exception that we will have to ignore if ex.status_code != 204: diff --git a/src/azure-cli/azure/cli/command_modules/ams/_validators.py b/src/azure-cli/azure/cli/command_modules/ams/_validators.py index a639567265a..de7e193918f 100644 --- a/src/azure-cli/azure/cli/command_modules/ams/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/ams/_validators.py @@ -9,7 +9,7 @@ def validate_storage_account_id(cmd, namespace): """Validate storage account name""" from azure.cli.core.commands.client_factory import get_subscription_id - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id if namespace.storage_account: if not is_valid_resource_id(namespace.storage_account): diff --git a/src/azure-cli/azure/cli/command_modules/ams/operations/mru.py b/src/azure-cli/azure/cli/command_modules/ams/operations/mru.py index 3329d85f258..d781cee9c41 100644 --- a/src/azure-cli/azure/cli/command_modules/ams/operations/mru.py +++ b/src/azure-cli/azure/cli/command_modules/ams/operations/mru.py @@ -73,7 +73,7 @@ def __init__(self, cli_ctx, resource_group_name, account_name): self.access_token = self._get_v2_access_token() def _get_v2_api_endpoint(self, cli_ctx, resource_group_name, account_name): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id from azure.cli.command_modules.ams._sdk_utils import (get_media_namespace, get_media_type) access_token = self.profile.get_raw_token()[0][2].get('accessToken') diff --git a/src/azure-cli/azure/cli/command_modules/ams/tests/latest/test_ams_account_identity_scenarios.py b/src/azure-cli/azure/cli/command_modules/ams/tests/latest/test_ams_account_identity_scenarios.py index 886585db90c..6fd39a04351 100644 --- a/src/azure-cli/azure/cli/command_modules/ams/tests/latest/test_ams_account_identity_scenarios.py +++ b/src/azure-cli/azure/cli/command_modules/ams/tests/latest/test_ams_account_identity_scenarios.py @@ -4,7 +4,7 @@ # -------------------------------------------------------------------------------------------- from azure.cli.testsdk import ScenarioTest, ResourceGroupPreparer, StorageAccountPreparer -from msrestazure.tools import resource_id +from azure.mgmt.core.tools import resource_id class AmsAccountIdentityTests(ScenarioTest): @ResourceGroupPreparer() diff --git a/src/azure-cli/azure/cli/command_modules/appconfig/_validators.py b/src/azure-cli/azure/cli/command_modules/appconfig/_validators.py index 7cc42d26a15..4aa9649571c 100644 --- a/src/azure-cli/azure/cli/command_modules/appconfig/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/appconfig/_validators.py @@ -111,7 +111,7 @@ def validate_export(namespace): def validate_appservice_name_or_id(cmd, namespace): from azure.cli.core.commands.client_factory import get_subscription_id - from msrestazure.tools import is_valid_resource_id, parse_resource_id + from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id if namespace.appservice_account: if not is_valid_resource_id(namespace.appservice_account): config_store_name = "" @@ -217,7 +217,7 @@ def validate_identity(namespace): return for identity in identities: - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id if identity == '[all]' and subcommand == 'remove': continue diff --git a/src/azure-cli/azure/cli/command_modules/appservice/_validators.py b/src/azure-cli/azure/cli/command_modules/appservice/_validators.py index 17f6e8dc4b7..ab2ed4e4bc9 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/_validators.py @@ -12,7 +12,7 @@ from azure.cli.core.commands.validators import validate_tags from knack.log import get_logger -from msrestazure.tools import is_valid_resource_id, parse_resource_id +from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id from ._appservice_utils import _generic_site_operation from ._client_factory import web_client_factory diff --git a/src/azure-cli/azure/cli/command_modules/appservice/access_restrictions.py b/src/azure-cli/azure/cli/command_modules/appservice/access_restrictions.py index 7a882daa7e1..639a81747aa 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/access_restrictions.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/access_restrictions.py @@ -12,7 +12,7 @@ from azure.mgmt.web.models import IpSecurityRestriction from importlib import import_module from knack.log import get_logger -from msrestazure.tools import is_valid_resource_id, resource_id, parse_resource_id +from azure.mgmt.core.tools import is_valid_resource_id, resource_id, parse_resource_id from ._appservice_utils import _generic_site_operation from .custom import get_site_configs diff --git a/src/azure-cli/azure/cli/command_modules/appservice/appservice_environment.py b/src/azure-cli/azure/cli/command_modules/appservice/appservice_environment.py index 6e89210e5bb..3bcb5ac5b6f 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/appservice_environment.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/appservice_environment.py @@ -21,7 +21,7 @@ MutuallyExclusiveArgumentError) from importlib import import_module from knack.log import get_logger -from msrestazure.tools import (parse_resource_id, is_valid_resource_id, resource_id) +from azure.mgmt.core.tools import (parse_resource_id, is_valid_resource_id, resource_id) VERSION_2019_08_01 = "2019-08-01" VERSION_2019_10_01 = "2019-10-01" diff --git a/src/azure-cli/azure/cli/command_modules/appservice/custom.py b/src/azure-cli/azure/cli/command_modules/appservice/custom.py index 5650437c030..9d6f8c302e8 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/custom.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/custom.py @@ -31,8 +31,8 @@ from knack.util import CLIError from knack.log import get_logger -from msrestazure.azure_exceptions import CloudError -from msrestazure.tools import is_valid_resource_id, parse_resource_id, resource_id +from azure.core.exceptions import HttpResponseError +from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id, resource_id from azure.mgmt.storage import StorageManagementClient from azure.mgmt.applicationinsights import ApplicationInsightsManagementClient @@ -982,7 +982,7 @@ def progress_callback(current, total): client.web_apps.sync_function_triggers_slot(resource_group_name, name, slot) else: client.web_apps.sync_function_triggers(resource_group_name, name) - except CloudError as ex: + except HttpResponseError as ex: # This SDK function throws an error if Status Code is 200 if ex.status_code != 200: raise ex @@ -2695,7 +2695,7 @@ def enable_local_git(cmd, resource_group_name, name, slot=None): def sync_site_repo(cmd, resource_group_name, name, slot=None): try: return _generic_site_operation(cmd.cli_ctx, resource_group_name, name, 'sync_repository', slot) - except CloudError as ex: # Because of bad spec, sdk throws on 200. We capture it here + except HttpResponseError as ex: # Because of bad spec, sdk throws on 200. We capture it here if ex.status_code not in [200, 204]: raise ex diff --git a/src/azure-cli/azure/cli/command_modules/appservice/logicapp/custom.py b/src/azure-cli/azure/cli/command_modules/appservice/logicapp/custom.py index d16fdac9660..e1ab42e76cf 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/logicapp/custom.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/logicapp/custom.py @@ -4,7 +4,7 @@ # -------------------------------------------------------------------------------------------- from knack.log import get_logger -from msrestazure.tools import is_valid_resource_id, parse_resource_id +from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id from azure.cli.core.commands import LongRunningOperation from azure.cli.core.azclierror import MutuallyExclusiveArgumentError diff --git a/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py b/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py index 9ecbcf22047..07556462862 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py @@ -11,7 +11,7 @@ from azure.cli.core.azclierror import (ResourceNotFoundError, ValidationError, RequiredArgumentMissingError, InvalidArgumentValueError, UnauthorizedError) from knack.log import get_logger -from msrestazure.tools import parse_resource_id +from azure.mgmt.core.tools import parse_resource_id from urllib.parse import urlparse import uuid from datetime import datetime, timedelta diff --git a/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_logicapp_commands.py b/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_logicapp_commands.py index e752bae43a7..23645a7f2b7 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_logicapp_commands.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_logicapp_commands.py @@ -16,7 +16,7 @@ from azure.cli.testsdk import (ScenarioTest, LocalContextScenarioTest, LiveScenarioTest, ResourceGroupPreparer, StorageAccountPreparer, JMESPathCheck, live_only) from azure.cli.testsdk.checkers import JMESPathPatternCheck -from msrestazure.tools import resource_id, parse_resource_id +from azure.mgmt.core.tools import resource_id, parse_resource_id TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) diff --git a/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_webapp_commands_thru_mock.py b/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_webapp_commands_thru_mock.py index 0a8ffd66813..d59f6698a65 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_webapp_commands_thru_mock.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_webapp_commands_thru_mock.py @@ -6,7 +6,7 @@ from unittest import mock import os -from msrestazure.azure_exceptions import CloudError +from azure.core.exceptions import HttpResponseError from azure.mgmt.web import WebSiteManagementClient from knack.util import CLIError @@ -267,7 +267,7 @@ def test_show_webapp(self, file_ftp_mock, rename_mock, is_centauri_functionapp_m def test_sync_repository_skip_bad_error(self, site_op_mock): resp = FakedResponse(200) # because of bad spec, sdk throws on 200. setattr(resp, 'text', '{"Message": ""}') - site_op_mock.side_effect = CloudError(resp, error="bad error") + site_op_mock.side_effect = HttpResponseError(resp, error="bad error") # action sync_site_repo(mock.MagicMock(), 'myRG', 'myweb') # assert diff --git a/src/azure-cli/azure/cli/command_modules/appservice/utils.py b/src/azure-cli/azure/cli/command_modules/appservice/utils.py index 6419f305802..d1569e6abae 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/utils.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/utils.py @@ -18,7 +18,7 @@ from azure.cli.core.util import should_disable_connection_verify, send_raw_request from azure.cli.core.commands.client_factory import get_subscription_id -from msrestazure.tools import parse_resource_id, is_valid_resource_id, resource_id +from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id, resource_id from ._client_factory import web_client_factory, providers_client_factory from ._constants import LOGICAPP_KIND, FUNCTIONAPP_KIND, LINUXAPP_KIND diff --git a/src/azure-cli/azure/cli/command_modules/aro/_dynamic_validators.py b/src/azure-cli/azure/cli/command_modules/aro/_dynamic_validators.py index c67ba2e789c..b9177c791e5 100644 --- a/src/azure-cli/azure/cli/command_modules/aro/_dynamic_validators.py +++ b/src/azure-cli/azure/cli/command_modules/aro/_dynamic_validators.py @@ -19,8 +19,8 @@ RequiredArgumentMissingError from azure.core.exceptions import ResourceNotFoundError from knack.log import get_logger -from msrestazure.tools import is_valid_resource_id, parse_resource_id -from msrestazure.azure_exceptions import CloudError +from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id +from azure.core.exceptions import HttpResponseError import azure.cli.command_modules.aro.custom @@ -314,7 +314,7 @@ def _validate_resource_permissions(cmd, f"Resource {parts['name']} is missing role assignment " + f"{role} for service principal {sp_id} " + "(These roles will be automatically added during cluster creation)"]) - except CloudError as e: + except HttpResponseError as e: logger.error(e.message) raise return errors diff --git a/src/azure-cli/azure/cli/command_modules/aro/_format.py b/src/azure-cli/azure/cli/command_modules/aro/_format.py index 0b758d15ed4..71a884939db 100644 --- a/src/azure-cli/azure/cli/command_modules/aro/_format.py +++ b/src/azure-cli/azure/cli/command_modules/aro/_format.py @@ -5,7 +5,7 @@ import collections -from msrestazure.tools import parse_resource_id +from azure.mgmt.core.tools import parse_resource_id def aro_list_table_format(results): diff --git a/src/azure-cli/azure/cli/command_modules/aro/_rbac.py b/src/azure-cli/azure/cli/command_modules/aro/_rbac.py index 9116c2ab942..f239882c10a 100644 --- a/src/azure-cli/azure/cli/command_modules/aro/_rbac.py +++ b/src/azure-cli/azure/cli/command_modules/aro/_rbac.py @@ -11,7 +11,7 @@ from azure.cli.core.profiles import ResourceType from knack.log import get_logger from msrest.exceptions import ValidationError -from msrestazure.tools import resource_id +from azure.mgmt.core.tools import resource_id ROLE_NETWORK_CONTRIBUTOR = '4d97b98b-1d4f-4787-a291-c67834d212e7' ROLE_READER = 'acdd72a7-3385-48ef-bd42-f606fba81ae7' diff --git a/src/azure-cli/azure/cli/command_modules/aro/_validators.py b/src/azure-cli/azure/cli/command_modules/aro/_validators.py index de187eba9e1..ee04d103e2f 100644 --- a/src/azure-cli/azure/cli/command_modules/aro/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/aro/_validators.py @@ -14,10 +14,9 @@ from azure.cli.core.profiles import ResourceType from azure.cli.core.azclierror import CLIInternalError, InvalidArgumentValueError, \ RequiredArgumentMissingError -from azure.core.exceptions import ResourceNotFoundError +from azure.core.exceptions import ResourceNotFoundError, HttpResponseError from knack.log import get_logger -from msrestazure.azure_exceptions import CloudError -from msrestazure.tools import is_valid_resource_id, parse_resource_id, resource_id +from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id, resource_id logger = get_logger(__name__) @@ -81,7 +80,7 @@ def validate_disk_encryption_set(cmd, namespace): try: compute_client.disk_encryption_sets.get(resource_group_name=desid['resource_group'], disk_encryption_set_name=desid['name']) - except CloudError as err: + except HttpResponseError as err: raise InvalidArgumentValueError( f"Invalid --disk-encryption-set, error when getting '{namespace.disk_encryption_set}':" f" {str(err)}") from err diff --git a/src/azure-cli/azure/cli/command_modules/aro/custom.py b/src/azure-cli/azure/cli/command_modules/aro/custom.py index 08a24a95683..64a161ac469 100644 --- a/src/azure-cli/azure/cli/command_modules/aro/custom.py +++ b/src/azure-cli/azure/cli/command_modules/aro/custom.py @@ -27,8 +27,8 @@ from knack.log import get_logger -from msrestazure.azure_exceptions import CloudError -from msrestazure.tools import resource_id, parse_resource_id +from azure.core.exceptions import HttpResponseError +from azure.mgmt.core.tools import resource_id, parse_resource_id from msrest.exceptions import HttpOperationError from tabulate import tabulate @@ -237,7 +237,7 @@ def __init__(self, disk_encryption_id, master_subnet_id, worker_subnet_id, preco # Get cluster resources we need to assign permissions on, sort to ensure the same order of operations resources = {ROLE_NETWORK_CONTRIBUTOR: sorted(get_cluster_network_resources(cmd.cli_ctx, cluster, True)), ROLE_READER: sorted(get_disk_encryption_resources(cluster))} - except (CloudError, HttpOperationError) as e: + except (HttpResponseError, HttpOperationError) as e: logger.error(e.message) raise @@ -343,7 +343,7 @@ def aro_delete(cmd, client, resource_group_name, resource_name, no_wait=False): try: oc = client.open_shift_clusters.get(resource_group_name, resource_name) - except CloudError as e: + except HttpResponseError as e: if e.status_code == 404: raise ResourceNotFoundError(e.message) from e logger.info(e.message) @@ -619,7 +619,7 @@ def ensure_resource_permissions(cli_ctx, oc, fail, sp_obj_ids): # Get cluster resources we need to assign permissions on, sort to ensure the same order of operations resources = {ROLE_NETWORK_CONTRIBUTOR: sorted(get_cluster_network_resources(cli_ctx, oc, fail)), ROLE_READER: sorted(get_disk_encryption_resources(oc))} - except (CloudError, HttpOperationError) as e: + except (HttpResponseError, HttpOperationError) as e: if fail: logger.error(e.message) raise @@ -634,7 +634,7 @@ def ensure_resource_permissions(cli_ctx, oc, fail, sp_obj_ids): resource_contributor_exists = True try: resource_contributor_exists = has_role_assignment_on_resource(cli_ctx, resource, sp_id, role) - except CloudError as e: + except HttpResponseError as e: if fail: logger.error(e.message) raise diff --git a/src/azure-cli/azure/cli/command_modules/aro/tests/latest/custom_preparers.py b/src/azure-cli/azure/cli/command_modules/aro/tests/latest/custom_preparers.py index ac64d1210fa..a180d175987 100644 --- a/src/azure-cli/azure/cli/command_modules/aro/tests/latest/custom_preparers.py +++ b/src/azure-cli/azure/cli/command_modules/aro/tests/latest/custom_preparers.py @@ -6,7 +6,7 @@ from azure.cli.testsdk.preparers import RoleBasedServicePrincipalPreparer from azure.cli.testsdk.scenario_tests.utilities import is_text_payload from azure.cli.testsdk.utilities import GraphClientPasswordReplacer -from msrestazure.tools import resource_id +from azure.mgmt.core.tools import resource_id MOCK_GUID = '00000000-0000-0000-0000-000000000001' MOCK_SECRET = 'fake-secret' diff --git a/src/azure-cli/azure/cli/command_modules/aro/tests/latest/test_aro_commands.py b/src/azure-cli/azure/cli/command_modules/aro/tests/latest/test_aro_commands.py index 7a8012f51d9..7ea235bb7b6 100644 --- a/src/azure-cli/azure/cli/command_modules/aro/tests/latest/test_aro_commands.py +++ b/src/azure-cli/azure/cli/command_modules/aro/tests/latest/test_aro_commands.py @@ -24,7 +24,7 @@ class AroScenarioTests(ScenarioTest): @ResourceGroupPreparer(random_name_length=28, name_prefix='clitestaro_create', location='eastus') @AROClusterServicePrincipalPreparer(name_prefix='clitestaro_create') def test_aro_create(self, resource_group): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id subscription = self.get_subscription_id() @@ -61,7 +61,7 @@ def test_aro_create(self, resource_group): @ResourceGroupPreparer(random_name_length=28, name_prefix='clitestaro_validate', location='eastus') @AROClusterServicePrincipalPreparer(name_prefix='clitestaro_validate') def test_aro_validate(self, resource_group): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id subscription = self.get_subscription_id() @@ -92,7 +92,7 @@ def test_aro_validate(self, resource_group): @ResourceGroupPreparer(random_name_length=28, name_prefix='clitestaro_listcred', location='eastus') @AROClusterServicePrincipalPreparer(name_prefix='clitestaro_listcred') def test_aro_list_credentials(self, resource_group): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id subscription = self.get_subscription_id() @@ -125,7 +125,7 @@ def test_aro_list_credentials(self, resource_group): @ResourceGroupPreparer(random_name_length=28, name_prefix='clitestaro_admin', location='eastus') @AROClusterServicePrincipalPreparer(name_prefix='clitestaro_admin') def test_aro_get_admin_kubeconfig(self, resource_group): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id subscription = self.get_subscription_id() @@ -165,7 +165,7 @@ def test_aro_get_admin_kubeconfig(self, resource_group): @ResourceGroupPreparer(random_name_length=28, name_prefix='clitestaro_show', location='eastus') @AROClusterServicePrincipalPreparer(name_prefix='clitestaro_show') def test_aro_show(self, resource_group): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id subscription = self.get_subscription_id() @@ -204,7 +204,7 @@ def test_aro_show(self, resource_group): @ResourceGroupPreparer(random_name_length=28, name_prefix='clitestaro_list', location='eastus') @AROClusterServicePrincipalPreparer(name_prefix='clitestaro_list') def test_aro_list(self, resource_group): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id subscription = self.get_subscription_id() @@ -241,7 +241,7 @@ def test_aro_list(self, resource_group): @ResourceGroupPreparer(random_name_length=28, name_prefix='clitestaro_delete', location='eastus') @AROClusterServicePrincipalPreparer(name_prefix='clitestaro_delete') def test_aro_delete(self, resource_group): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id subscription = self.get_subscription_id() @@ -274,7 +274,7 @@ def test_aro_delete(self, resource_group): @ResourceGroupPreparer(random_name_length=28, name_prefix='clitestaro_update', location='eastus') @AROClusterServicePrincipalPreparer(name_prefix='clitestaro_update') def test_aro_update(self, resource_group): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id subscription = self.get_subscription_id() diff --git a/src/azure-cli/azure/cli/command_modules/batch/_exception_handler.py b/src/azure-cli/azure/cli/command_modules/batch/_exception_handler.py index 74075115247..6f1402151d9 100644 --- a/src/azure-cli/azure/cli/command_modules/batch/_exception_handler.py +++ b/src/azure-cli/azure/cli/command_modules/batch/_exception_handler.py @@ -8,7 +8,7 @@ def batch_exception_handler(ex): from msrest.exceptions import ValidationError, ClientRequestError - from msrestazure.azure_exceptions import CloudError + from azure.core.exceptions import HttpResponseError from azure.batch.models import BatchErrorException if isinstance(ex, BatchErrorException): @@ -22,7 +22,7 @@ def batch_exception_handler(ex): raise CLIError(ex) elif isinstance(ex, (ValidationError, ClientRequestError)): raise CLIError(ex) - elif isinstance(ex, CloudError): + elif isinstance(ex, HttpResponseError): raise CLIError(ex) else: raise ex diff --git a/src/azure-cli/azure/cli/command_modules/batch/_validators.py b/src/azure-cli/azure/cli/command_modules/batch/_validators.py index 05137c6fe7a..65500802f81 100644 --- a/src/azure-cli/azure/cli/command_modules/batch/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/batch/_validators.py @@ -332,7 +332,7 @@ def validate_client_parameters(cmd, namespace): acc = next((x for x in client.batch_account.list() if x.name == namespace.account_name and x.account_endpoint == host), None) if acc: - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id rg = parse_resource_id(acc.id)['resource_group'] namespace.account_key = \ client.batch_account.get_keys(rg, # pylint: disable=no-member diff --git a/src/azure-cli/azure/cli/command_modules/batchai/_format.py b/src/azure-cli/azure/cli/command_modules/batchai/_format.py index 18037354ae9..60947200a1c 100644 --- a/src/azure-cli/azure/cli/command_modules/batchai/_format.py +++ b/src/azure-cli/azure/cli/command_modules/batchai/_format.py @@ -34,7 +34,7 @@ def cluster_list_table_format(result): def cluster_show_table_format(result): """Format cluster as a table.""" - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id row = OrderedDict() row['Name'] = result['name'] row['Resource Group'] = result['resourceGroup'] @@ -62,7 +62,7 @@ def experiment_list_table_format(result): def experiment_show_table_format(experiment): """Format the experiment as a table""" - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id row = OrderedDict() row['Name'] = experiment['name'] row['Resource Group'] = experiment['resourceGroup'] @@ -81,7 +81,7 @@ def job_list_table_format(result): def job_show_table_format(job): """Format job as a table.""" - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id row = OrderedDict() row['Name'] = job['name'] cluster = parse_resource_id(job['cluster']['id']) diff --git a/src/azure-cli/azure/cli/command_modules/batchai/custom.py b/src/azure-cli/azure/cli/command_modules/batchai/custom.py index f17a2e3e3f2..b200318ea3a 100644 --- a/src/azure-cli/azure/cli/command_modules/batchai/custom.py +++ b/src/azure-cli/azure/cli/command_modules/batchai/custom.py @@ -23,15 +23,14 @@ from knack.log import get_logger from knack.util import CLIError from msrest.serialization import Deserializer -from msrestazure.azure_exceptions import CloudError -from msrestazure.tools import is_valid_resource_id, parse_resource_id +from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id from urllib.parse import urlparse from azure.cli.core import keys from azure.cli.core.util import get_default_admin_username from azure.cli.core.commands.client_factory import get_mgmt_service_client from azure.cli.core.profiles import ResourceType, get_sdk -from azure.core.exceptions import ResourceNotFoundError +from azure.core.exceptions import ResourceNotFoundError, HttpResponseError from azure.mgmt.batchai import models # Environment variables for specifying azure storage account and key. We want the user to make explicit @@ -133,7 +132,7 @@ def _ensure_subnet_is_valid(client, subnet, nfs_resource_group, nfs_workspace, n nfs = None # type: models.FileServer try: nfs = client.file_servers.get(nfs_resource_group, nfs_workspace, nfs_name) - except CloudError as e: + except HttpResponseError as e: if e.status_code != 404: raise if not nfs: diff --git a/src/azure-cli/azure/cli/command_modules/botservice/_exception_handler.py b/src/azure-cli/azure/cli/command_modules/botservice/_exception_handler.py index b01bcc54df9..8594e5be35c 100644 --- a/src/azure-cli/azure/cli/command_modules/botservice/_exception_handler.py +++ b/src/azure-cli/azure/cli/command_modules/botservice/_exception_handler.py @@ -8,7 +8,6 @@ def bot_exception_handler(ex): from azure.core.exceptions import HttpResponseError - from msrestazure.azure_exceptions import CloudError from msrest.exceptions import ClientRequestError # pylint: disable=import-error if isinstance(ex, HttpResponseError): message = 'An error occurred. {0}: {1}'.format( @@ -16,8 +15,6 @@ def bot_exception_handler(ex): ex.error.message ) raise azure.cli.core.azclierror.AzureResponseError(message) - if isinstance(ex, CloudError) and ex.status_code == 404: - return None if isinstance(ex, ClientRequestError): message = 'Error occurred in sending request. Please file an issue on {0}'.format( 'https://github.com/microsoft/botframework-sdk' diff --git a/src/azure-cli/azure/cli/command_modules/cdn/custom/custom.py b/src/azure-cli/azure/cli/command_modules/cdn/custom/custom.py index 7575cc051fa..6a353cab597 100644 --- a/src/azure-cli/azure/cli/command_modules/cdn/custom/custom.py +++ b/src/azure-cli/azure/cli/command_modules/cdn/custom/custom.py @@ -53,7 +53,7 @@ from knack.log import get_logger from msrest.polling import LROPoller, NoPolling -from msrestazure.tools import is_valid_resource_id +from azure.mgmt.core.tools import is_valid_resource_id logger = get_logger(__name__) diff --git a/src/azure-cli/azure/cli/command_modules/cdn/custom/custom_rule_util.py b/src/azure-cli/azure/cli/command_modules/cdn/custom/custom_rule_util.py index b3add0c508a..5e208fb0f99 100644 --- a/src/azure-cli/azure/cli/command_modules/cdn/custom/custom_rule_util.py +++ b/src/azure-cli/azure/cli/command_modules/cdn/custom/custom_rule_util.py @@ -6,7 +6,7 @@ from azure.cli.core.aaz._base import has_value from azure.mgmt.cdn.models import (RequestMethodOperator, RuleIsCompressionEnabled) -from msrestazure.tools import is_valid_resource_id +from azure.mgmt.core.tools import is_valid_resource_id def create_condition(match_variable, diff --git a/src/azure-cli/azure/cli/command_modules/cognitiveservices/_params.py b/src/azure-cli/azure/cli/command_modules/cognitiveservices/_params.py index 7f245d19dcd..6a9fa61f826 100644 --- a/src/azure-cli/azure/cli/command_modules/cognitiveservices/_params.py +++ b/src/azure-cli/azure/cli/command_modules/cognitiveservices/_params.py @@ -101,7 +101,7 @@ def _filter_sku(_sku): def _validate_subnet(cmd, namespace): - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id from azure.cli.core.commands.client_factory import get_subscription_id subnet = namespace.subnet diff --git a/src/azure-cli/azure/cli/command_modules/cognitiveservices/custom.py b/src/azure-cli/azure/cli/command_modules/cognitiveservices/custom.py index 9b3d9ba028c..aefb53664a3 100644 --- a/src/azure-cli/azure/cli/command_modules/cognitiveservices/custom.py +++ b/src/azure-cli/azure/cli/command_modules/cognitiveservices/custom.py @@ -174,7 +174,7 @@ def add_network_rule(client, resource_group_name, account_name, subnet=None, rules = default_network_acls() if subnet: - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id if not is_valid_resource_id(subnet): raise CLIError("Expected fully qualified resource ID: got '{}'".format(subnet)) diff --git a/src/azure-cli/azure/cli/command_modules/container/_validators.py b/src/azure-cli/azure/cli/command_modules/container/_validators.py index fceb5c2de9a..1461d68ad34 100644 --- a/src/azure-cli/azure/cli/command_modules/container/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/container/_validators.py @@ -69,7 +69,7 @@ def validate_msi(namespace): def validate_subnet(ns): - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id # vnet_name is depricated, using for backwards compatability if ns.vnet_name and not ns.vnet: diff --git a/src/azure-cli/azure/cli/command_modules/container/custom.py b/src/azure-cli/azure/cli/command_modules/container/custom.py index 0cd37a94b39..675449d5490 100644 --- a/src/azure-cli/azure/cli/command_modules/container/custom.py +++ b/src/azure-cli/azure/cli/command_modules/container/custom.py @@ -294,7 +294,7 @@ def _build_identities_info(identities): def _get_subnet_id(cmd, location, resource_group_name, vnet, vnet_address_prefix, subnet, subnet_address_prefix): - from msrestazure.tools import parse_resource_id, is_valid_resource_id + from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id from azure.cli.core.commands import LongRunningOperation from azure.core.exceptions import HttpResponseError from .aaz.latest.network.vnet import Create as VNetCreate, Show as VNetShow @@ -387,7 +387,7 @@ def _get_subnet_id(cmd, location, resource_group_name, vnet, vnet_address_prefix def _get_diagnostics_from_workspace(cli_ctx, log_analytics_workspace): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id log_analytics_workspace_client = cf_log_analytics_workspace(cli_ctx) log_analytics_workspace_shared_keys_client = cf_log_analytics_workspace_shared_keys(cli_ctx) @@ -481,7 +481,7 @@ def _create_resource_requirements(cpu, memory): def _create_image_registry_credentials(cmd, resource_group_name, registry_login_server, registry_username, registry_password, image, identity): - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id image_registry_credentials = None if identity: diff --git a/src/azure-cli/azure/cli/command_modules/container/tests/latest/test_container_commands.py b/src/azure-cli/azure/cli/command_modules/container/tests/latest/test_container_commands.py index 90494c3bbbe..71b8289f7f1 100644 --- a/src/azure-cli/azure/cli/command_modules/container/tests/latest/test_container_commands.py +++ b/src/azure-cli/azure/cli/command_modules/container/tests/latest/test_container_commands.py @@ -449,7 +449,6 @@ def test_container_create_with_acr(self, resource_group, resource_group_location # Test create container with VNET argument validations. @ResourceGroupPreparer() def test_container_create_with_vnet(self, resource_group, resource_group_location): - from msrestazure.tools import resource_id from azure.core.exceptions import HttpResponseError from knack.util import CLIError diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/_acr_run_polling.py b/src/azure-cli/azure/cli/command_modules/containerapp/_acr_run_polling.py index 1a71a87c99a..1050f7b7d1b 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/_acr_run_polling.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/_acr_run_polling.py @@ -7,7 +7,7 @@ import time from msrest import Deserializer -from msrestazure.azure_exceptions import CloudError +from azure.core.exceptions import HttpResponseError from azure.cli.core.profiles import ResourceType from azure.cli.command_modules.acr._constants import get_acr_task_models from azure.core.polling import PollingMethod, LROPoller @@ -90,7 +90,7 @@ def _set_operation_status(self, response): self.operation_result = self._deserialize(response) self.operation_status = self.operation_result.status return - raise CloudError(response) + raise HttpResponseError(response) def _update_status(self): self._response = self._client._pipeline.run( # pylint: disable=protected-access diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/_archive_utils.py b/src/azure-cli/azure/cli/command_modules/containerapp/_archive_utils.py index d9224c8d8fb..c97281326c1 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/_archive_utils.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/_archive_utils.py @@ -11,7 +11,7 @@ from io import open import requests from knack.log import get_logger -from msrestazure.azure_exceptions import CloudError +from azure.core.exceptions import HttpResponseError from azure.cli.core.azclierror import (CLIInternalError) from azure.cli.core.profiles import ResourceType, get_sdk from azure.cli.command_modules.acr._constants import TASK_VALID_VSTS_URLS @@ -47,7 +47,7 @@ def upload_source_code(cmd, client, resource_group_name, registry_name) upload_url = source_upload_location.upload_url relative_path = source_upload_location.relative_path - except (AttributeError, CloudError) as e: + except (AttributeError, HttpResponseError) as e: raise CLIInternalError("Failed to get a SAS URL to upload context. Error: {}".format(e.message)) from e if not upload_url: diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/_up_utils.py b/src/azure-cli/azure/cli/command_modules/containerapp/_up_utils.py index d859f44ecb1..6dd0269842c 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/_up_utils.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/_up_utils.py @@ -26,7 +26,7 @@ from azure.mgmt.containerregistry import ContainerRegistryManagementClient from knack.log import get_logger -from msrestazure.tools import parse_resource_id, is_valid_resource_id, resource_id +from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id, resource_id from ._clients import ManagedEnvironmentClient, ContainerAppClient, GitHubActionClient, ContainerAppsJobClient diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/_utils.py b/src/azure-cli/azure/cli/command_modules/containerapp/_utils.py index dc84bf3a4c2..4e3d83c976f 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/_utils.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/_utils.py @@ -39,7 +39,7 @@ from azure.mgmt.servicelinker import ServiceLinkerManagementClient from knack.log import get_logger -from msrestazure.tools import parse_resource_id, is_valid_resource_id, resource_id +from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id, resource_id from ._clients import ContainerAppClient, ManagedEnvironmentClient, WorkloadProfileClient, ContainerAppsJobClient from ._client_factory import handle_raw_exception, providers_client_factory, cf_resource_groups, log_analytics_client_factory, log_analytics_shared_key_client_factory diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/_validators.py b/src/azure-cli/azure/cli/command_modules/containerapp/_validators.py index 5cd3cc481b2..dcc2c2a738c 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/_validators.py @@ -7,7 +7,7 @@ import re from azure.cli.core.azclierror import (ValidationError, ResourceNotFoundError, InvalidArgumentValueError, MutuallyExclusiveArgumentError) -from msrestazure.tools import is_valid_resource_id, parse_resource_id +from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id from knack.log import get_logger from ._clients import ContainerAppClient, ManagedEnvironmentClient @@ -75,7 +75,7 @@ def validate_cpu(namespace): def validate_managed_env_name_or_id(cmd, namespace): from azure.cli.core.commands.client_factory import get_subscription_id - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id if namespace.managed_env: if not is_valid_resource_id(namespace.managed_env): @@ -90,7 +90,7 @@ def validate_managed_env_name_or_id(cmd, namespace): def validate_storage_name_or_id(cmd, namespace): from azure.cli.core.commands.client_factory import get_subscription_id - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id if namespace.storage_account: if not is_valid_resource_id(namespace.storage_account): diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/commands.py b/src/azure-cli/azure/cli/command_modules/containerapp/commands.py index 6793aabc883..631c6c2a9a0 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/commands.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/commands.py @@ -5,7 +5,6 @@ # pylint: disable=line-too-long, too-many-statements, bare-except # from azure.cli.core.commands import CliCommandType -# from msrestazure.tools import is_valid_resource_id, parse_resource_id from azure.cli.command_modules.containerapp._client_factory import ex_handler_factory from ._validators import validate_ssh from ._transformers import (transform_containerapp_output, diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/containerapp_decorator.py b/src/azure-cli/azure/cli/command_modules/containerapp/containerapp_decorator.py index cbcdb55d440..0ff45d2c491 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/containerapp_decorator.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/containerapp_decorator.py @@ -18,7 +18,7 @@ from knack.log import get_logger from knack.util import CLIError -from msrestazure.tools import parse_resource_id, is_valid_resource_id +from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id from msrest.exceptions import DeserializationError from .base_resource import BaseResource diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/containerapp_env_decorator.py b/src/azure-cli/azure/cli/command_modules/containerapp/containerapp_env_decorator.py index 0b1b7b7eda3..88bba2d014c 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/containerapp_env_decorator.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/containerapp_env_decorator.py @@ -11,7 +11,7 @@ from azure.cli.core.azclierror import RequiredArgumentMissingError, ValidationError from azure.cli.core.commands import AzCliCommand from knack.util import CLIError -from msrestazure.tools import is_valid_resource_id +from azure.mgmt.core.tools import is_valid_resource_id from ._constants import CONTAINER_APPS_RP from ._utils import (get_vnet_location, diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/containerapp_job_decorator.py b/src/azure-cli/azure/cli/command_modules/containerapp/containerapp_job_decorator.py index b975853b85a..a9945c97310 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/containerapp_job_decorator.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/containerapp_job_decorator.py @@ -21,7 +21,7 @@ from knack.log import get_logger -from msrestazure.tools import parse_resource_id, is_valid_resource_id +from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id from msrest.exceptions import DeserializationError from ._decorator_utils import process_loaded_yaml, load_yaml_file, create_deserializer diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/custom.py b/src/azure-cli/azure/cli/command_modules/containerapp/custom.py index 9709cf3256d..c7ac7d26e2f 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/custom.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/custom.py @@ -26,7 +26,7 @@ from knack.log import get_logger from knack.prompting import prompt_y_n, prompt as prompt_str -from msrestazure.tools import parse_resource_id, is_valid_resource_id +from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id from msrest.exceptions import DeserializationError from .containerapp_job_decorator import ContainerAppJobDecorator, ContainerAppJobCreateDecorator diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerapp_commands.py b/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerapp_commands.py index 5123a8cb89e..3301965d606 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerapp_commands.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerapp_commands.py @@ -10,7 +10,7 @@ from azure.cli.core.azclierror import ValidationError from azure.cli.testsdk.scenario_tests import AllowLargeResponse, live_only from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer, JMESPathCheck, LogAnalyticsWorkspacePreparer) -from msrestazure.tools import parse_resource_id +from azure.mgmt.core.tools import parse_resource_id from azure.cli.command_modules.containerapp.tests.latest.common import (write_test_file, clean_up_test_file) from .common import TEST_LOCATION diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerapp_ingress_sticky_session.py b/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerapp_ingress_sticky_session.py index c37e14cf605..e7bacad734b 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerapp_ingress_sticky_session.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerapp_ingress_sticky_session.py @@ -5,7 +5,7 @@ import os -from msrestazure.tools import parse_resource_id +from azure.mgmt.core.tools import parse_resource_id from azure.cli.testsdk.scenario_tests import AllowLargeResponse from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer, JMESPathCheck, live_only) diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerapp_scenario.py b/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerapp_scenario.py index f2a680ad4a3..c9859b6816b 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerapp_scenario.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerapp_scenario.py @@ -9,7 +9,7 @@ import time import unittest -from msrestazure.tools import parse_resource_id +from azure.mgmt.core.tools import parse_resource_id from azure.cli.command_modules.containerapp.custom import containerapp_ssh from azure.cli.command_modules.containerapp.tests.latest.utils import create_containerapp_env, \ diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_crud.py b/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_crud.py index bd5915e9fa0..ed837708c87 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_crud.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_crud.py @@ -5,7 +5,7 @@ import os -from msrestazure.tools import parse_resource_id +from azure.mgmt.core.tools import parse_resource_id from azure.cli.testsdk.scenario_tests import AllowLargeResponse from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer, JMESPathCheck, LogAnalyticsWorkspacePreparer) diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_event_triggered_crud.py b/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_event_triggered_crud.py index 12bea33d055..227908fc0c9 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_event_triggered_crud.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_event_triggered_crud.py @@ -6,7 +6,7 @@ import os import time -from msrestazure.tools import parse_resource_id +from azure.mgmt.core.tools import parse_resource_id from azure.cli.testsdk.scenario_tests import AllowLargeResponse from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer, JMESPathCheck) diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_executions.py b/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_executions.py index f283750d1a8..d34b8bd1d2f 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_executions.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_executions.py @@ -6,7 +6,7 @@ import os import time -from msrestazure.tools import parse_resource_id +from azure.mgmt.core.tools import parse_resource_id from azure.cli.testsdk.scenario_tests import AllowLargeResponse from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer, JMESPathCheck, LogAnalyticsWorkspacePreparer) diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_registry.py b/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_registry.py index 529306dc60e..f5122756983 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_registry.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_registry.py @@ -5,8 +5,6 @@ import os -from msrestazure.tools import parse_resource_id - from azure.cli.testsdk.scenario_tests import AllowLargeResponse from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer, JMESPathCheck, JMESPathCheckExists, JMESPathCheckNotExists) diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_with_identity.py b/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_with_identity.py index 2ccf58777f8..793b33c335c 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_with_identity.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_with_identity.py @@ -5,7 +5,7 @@ import os -from msrestazure.tools import parse_resource_id +from azure.mgmt.core.tools import parse_resource_id from azure.cli.testsdk.scenario_tests import AllowLargeResponse from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer, JMESPathCheck, JMESPathCheckExists, diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_with_secrets.py b/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_with_secrets.py index af2fae0010b..be7c348365d 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_with_secrets.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_containerappjob_with_secrets.py @@ -6,7 +6,7 @@ import os import time -from msrestazure.tools import parse_resource_id +from azure.mgmt.core.tools import parse_resource_id from azure.cli.testsdk.scenario_tests import AllowLargeResponse from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer, JMESPathCheck, LogAnalyticsWorkspacePreparer) diff --git a/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py b/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py index d3c208512d9..e55fe2fd7c4 100644 --- a/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py +++ b/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py @@ -426,7 +426,7 @@ def cli_cosmosdb_update(client, update_consistency_policy = True if network_acl_bypass_resource_ids is not None: - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id from azure.cli.core.azclierror import InvalidArgumentValueError for resource_id in network_acl_bypass_resource_ids: if not is_valid_resource_id(resource_id): @@ -1664,7 +1664,7 @@ def cli_cosmosdb_identity_remove(client, def _get_virtual_network_id(cmd, resource_group_name, subnet, virtual_network): from azure.cli.core.commands.client_factory import get_subscription_id - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id if not is_valid_resource_id(subnet): if virtual_network is None: raise CLIError("usage error: --subnet ID | --subnet NAME --vnet-name NAME") diff --git a/src/azure-cli/azure/cli/command_modules/dls/_validators.py b/src/azure-cli/azure/cli/command_modules/dls/_validators.py index f4a561a837a..e042dbb5163 100644 --- a/src/azure-cli/azure/cli/command_modules/dls/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/dls/_validators.py @@ -17,7 +17,7 @@ def _get_resource_group_from_account_name(client, account_name): :return: resource group name or None :rtype: str """ - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id for acct in client.list(): id_comps = parse_resource_id(acct.id) if id_comps['name'] == account_name: @@ -42,7 +42,7 @@ def validate_resource_group_name(cmd, ns): # Validates if a subnet id or name have been given by the user. If subnet id is given, vnet-name should not be provided. def validate_subnet(cmd, namespace): - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id from azure.cli.core.commands.client_factory import get_subscription_id subnet = namespace.subnet diff --git a/src/azure-cli/azure/cli/command_modules/dls/tests/latest/test_dls_commands.py b/src/azure-cli/azure/cli/command_modules/dls/tests/latest/test_dls_commands.py index 33a1ee417a3..eb457fff2a6 100644 --- a/src/azure-cli/azure/cli/command_modules/dls/tests/latest/test_dls_commands.py +++ b/src/azure-cli/azure/cli/command_modules/dls/tests/latest/test_dls_commands.py @@ -8,7 +8,7 @@ import os import time from shutil import rmtree -from msrestazure.azure_exceptions import CloudError +from azure.core.exceptions import HttpResponseError from azure.cli.testsdk import ScenarioTest, ResourceGroupPreparer, LiveScenarioTest, VirtualNetworkPreparer from azure.cli.testsdk.scenario_tests import AllowLargeResponse @@ -326,7 +326,7 @@ def test_dls_account_mgmt(self, resource_group): ]) # attempt to enable the key vault when it is already enabled, which should throw - with self.assertRaises(CloudError): + with self.assertRaises(HttpResponseError): self.cmd('dls account enable-key-vault -n {dls} -g {rg}') self.cmd('dls account list -g {rg}', checks=[ diff --git a/src/azure-cli/azure/cli/command_modules/eventgrid/custom.py b/src/azure-cli/azure/cli/command_modules/eventgrid/custom.py index d528310c747..3a9601b2f16 100644 --- a/src/azure-cli/azure/cli/command_modules/eventgrid/custom.py +++ b/src/azure-cli/azure/cli/command_modules/eventgrid/custom.py @@ -8,7 +8,7 @@ import re from knack.log import get_logger from knack.util import CLIError -from msrestazure.tools import parse_resource_id +from azure.mgmt.core.tools import parse_resource_id from dateutil.parser import parse # pylint: disable=import-error,relative-import from azure.cli.core.azclierror import MutuallyExclusiveArgumentError diff --git a/src/azure-cli/azure/cli/command_modules/eventhubs/_validator.py b/src/azure-cli/azure/cli/command_modules/eventhubs/_validator.py index 62e4d40fa9f..93457c03bad 100644 --- a/src/azure-cli/azure/cli/command_modules/eventhubs/_validator.py +++ b/src/azure-cli/azure/cli/command_modules/eventhubs/_validator.py @@ -11,7 +11,7 @@ def validate_storageaccount(cmd, namespace): from azure.cli.core.commands.client_factory import get_subscription_id - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id if namespace.storage_account: if not is_valid_resource_id(namespace.storage_account): namespace.storage_account = resource_id( @@ -24,7 +24,7 @@ def validate_storageaccount(cmd, namespace): def validate_partner_namespace(cmd, namespace): from azure.cli.core.commands.client_factory import get_subscription_id - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id if namespace.partner_namespace: if not is_valid_resource_id(namespace.partner_namespace): namespace.partner_namespace = resource_id( diff --git a/src/azure-cli/azure/cli/command_modules/eventhubs/tests/latest/test_eventhub_commands_privateendpoint_test.py b/src/azure-cli/azure/cli/command_modules/eventhubs/tests/latest/test_eventhub_commands_privateendpoint_test.py index 12ba97af016..65e9593ccda 100644 --- a/src/azure-cli/azure/cli/command_modules/eventhubs/tests/latest/test_eventhub_commands_privateendpoint_test.py +++ b/src/azure-cli/azure/cli/command_modules/eventhubs/tests/latest/test_eventhub_commands_privateendpoint_test.py @@ -18,7 +18,6 @@ class EHNetworkCURDScenarioTest(ScenarioTest): @ResourceGroupPreparer(name_prefix='cli_test_eh_network') def test_eh_privateendpoint(self, resource_group): - from msrestazure.azure_exceptions import CloudError self.kwargs.update({ 'namespacename': self.create_random_name(prefix='eventhubs-nscli', length=20), 'loc': 'eastus', diff --git a/src/azure-cli/azure/cli/command_modules/hdinsight/_completers.py b/src/azure-cli/azure/cli/command_modules/hdinsight/_completers.py index 493d53a0c23..b1e8f0372f5 100644 --- a/src/azure-cli/azure/cli/command_modules/hdinsight/_completers.py +++ b/src/azure-cli/azure/cli/command_modules/hdinsight/_completers.py @@ -18,7 +18,7 @@ def subnet_completion_list(cmd, prefix, namespace, **kwargs): # pylint: disable=unused-argument def worker(cmd, prefix, namespace): # pylint: disable=unused-argument - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id from .aaz.latest.network.vnet.subnet import List subnets = [] diff --git a/src/azure-cli/azure/cli/command_modules/hdinsight/_validators.py b/src/azure-cli/azure/cli/command_modules/hdinsight/_validators.py index 22ab70e829a..259d50c373c 100644 --- a/src/azure-cli/azure/cli/command_modules/hdinsight/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/hdinsight/_validators.py @@ -5,7 +5,7 @@ import threading from knack.util import CLIError -from msrestazure.tools import is_valid_resource_id +from azure.mgmt.core.tools import is_valid_resource_id from azure.cli.core.commands.parameters import get_resources_in_subscription from .util import get_resource_id_by_name diff --git a/src/azure-cli/azure/cli/command_modules/hdinsight/custom.py b/src/azure-cli/azure/cli/command_modules/hdinsight/custom.py index b9907c3f283..02b417878ca 100644 --- a/src/azure-cli/azure/cli/command_modules/hdinsight/custom.py +++ b/src/azure-cli/azure/cli/command_modules/hdinsight/custom.py @@ -547,7 +547,7 @@ def create_hdi_application(cmd, client, resource_group_name, cluster_name, appli def enable_hdi_monitoring(cmd, client, resource_group_name, cluster_name, workspace, primary_key=None, workspace_type='resource_id', no_validation_timeout=False): from azure.mgmt.hdinsight.models import ClusterMonitoringRequest - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id from ._client_factory import cf_log_analytics if workspace_type != 'resource_id' and not primary_key: @@ -589,7 +589,7 @@ def enable_hdi_monitoring(cmd, client, resource_group_name, cluster_name, worksp def enable_hdi_azure_monitor(cmd, client, resource_group_name, cluster_name, workspace, primary_key=None, workspace_type='resource_id', no_validation_timeout=False): from azure.mgmt.hdinsight.models import AzureMonitorRequest - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id from ._client_factory import cf_log_analytics if workspace_type != 'resource_id' and not primary_key: @@ -632,7 +632,7 @@ def enable_hdi_azure_monitor(cmd, client, resource_group_name, cluster_name, wor def enable_hdi_azure_monitor_agent(cmd, client, resource_group_name, cluster_name, workspace, primary_key=None, workspace_type='resource_id', no_validation_timeout=False): from azure.mgmt.hdinsight.models import AzureMonitorRequest - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id from ._client_factory import cf_log_analytics if workspace_type != 'resource_id' and not primary_key: diff --git a/src/azure-cli/azure/cli/command_modules/hdinsight/util.py b/src/azure-cli/azure/cli/command_modules/hdinsight/util.py index 10a36fa25b3..c3bcbe24f88 100644 --- a/src/azure-cli/azure/cli/command_modules/hdinsight/util.py +++ b/src/azure-cli/azure/cli/command_modules/hdinsight/util.py @@ -125,7 +125,7 @@ class NodeRoleType: # pylint: disable=too-few-public-methods def get_key_for_storage_account(cmd, storage_account): # pylint: disable=unused-argument from ._client_factory import cf_storage - from msrestazure.tools import parse_resource_id, is_valid_resource_id + from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id from knack.util import CLIError storage_account_key = None @@ -144,7 +144,7 @@ def get_key_for_storage_account(cmd, storage_account): # pylint: disable=unused def get_storage_account_endpoint(cmd, storage_account, is_wasb): from ._client_factory import cf_storage - from msrestazure.tools import parse_resource_id, is_valid_resource_id + from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id host = None if is_valid_resource_id(storage_account): parsed_storage_account = parse_resource_id(storage_account) @@ -181,7 +181,7 @@ def build_identities_info(identities): def build_virtual_network_profile(subnet): - from msrestazure.tools import resource_id, parse_resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, parse_resource_id, is_valid_resource_id from azure.mgmt.hdinsight.models import VirtualNetworkProfile from knack.util import CLIError @@ -206,7 +206,7 @@ def build_virtual_network_profile(subnet): def parse_domain_name(domain): - from msrestazure.tools import parse_resource_id, is_valid_resource_id + from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id domain_name = None if is_valid_resource_id(domain): parsed_domain_id = parse_resource_id(domain) diff --git a/src/azure-cli/azure/cli/command_modules/iot/custom.py b/src/azure-cli/azure/cli/command_modules/iot/custom.py index a71fa8e8e2d..54c8b652a61 100644 --- a/src/azure-cli/azure/cli/command_modules/iot/custom.py +++ b/src/azure-cli/azure/cli/command_modules/iot/custom.py @@ -9,7 +9,7 @@ from enum import Enum from knack.log import get_logger from knack.util import CLIError -from msrestazure.azure_exceptions import CloudError +from azure.core.exceptions import HttpResponseError from azure.cli.core.azclierror import ( ArgumentUsageError, BadRequestError, @@ -586,7 +586,7 @@ def identity_assignment(lro): hub_description.identity.principal_id = principal_id for scope in identity_scopes: assign_identity(cmd.cli_ctx, lambda: hub_description, lambda hub: hub_description, identity_role=identity_role, identity_scope=scope) - except CloudError as e: + except HttpResponseError as e: raise e create = client.iot_hub_resource.begin_create_or_update(resource_group_name, hub_name, hub_description) diff --git a/src/azure-cli/azure/cli/command_modules/iot/tests/latest/test_iot_central_commands.py b/src/azure-cli/azure/cli/command_modules/iot/tests/latest/test_iot_central_commands.py index 80df3609822..6f643e95cf6 100644 --- a/src/azure-cli/azure/cli/command_modules/iot/tests/latest/test_iot_central_commands.py +++ b/src/azure-cli/azure/cli/command_modules/iot/tests/latest/test_iot_central_commands.py @@ -117,7 +117,6 @@ def test_iot_central_app(self, resource_group, resource_group_location): @live_only() @ResourceGroupPreparer() # name_prefix not required, but can be useful def test_iot_central_private_link_and_private_endpoint(self, resource_group): - from msrestazure.azure_exceptions import CloudError name = self.create_random_name(prefix='iotc-cli-test', length=24) self.kwargs.update({ 'app_name': name, diff --git a/src/azure-cli/azure/cli/command_modules/keyvault/_validators.py b/src/azure-cli/azure/cli/command_modules/keyvault/_validators.py index 87184bc166a..36d84850801 100644 --- a/src/azure-cli/azure/cli/command_modules/keyvault/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/keyvault/_validators.py @@ -45,7 +45,7 @@ def _get_resource_group_from_resource_name(cli_ctx, vault_name, hsm_name=None): :return: resource group name or None :rtype: str """ - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id if vault_name: client = get_mgmt_service_client(cli_ctx, ResourceType.MGMT_KEYVAULT).vaults @@ -383,7 +383,7 @@ def validate_deleted_vault_or_hsm_name(cmd, ns): """ Validate a deleted vault name; populate or validate location and resource_group_name """ - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id vault_name = getattr(ns, 'vault_name', None) hsm_name = getattr(ns, 'hsm_name', None) @@ -502,7 +502,7 @@ def get_hsm_base_url_type(cli_ctx): def _construct_vnet(cmd, resource_group_name, vnet_name, subnet_name): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id from azure.cli.core.commands.client_factory import get_subscription_id return resource_id( @@ -516,7 +516,7 @@ def _construct_vnet(cmd, resource_group_name, vnet_name, subnet_name): def validate_subnet(cmd, namespace): - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id subnet = namespace.subnet subnet_is_id = is_valid_resource_id(subnet) diff --git a/src/azure-cli/azure/cli/command_modules/keyvault/custom.py b/src/azure-cli/azure/cli/command_modules/keyvault/custom.py index 735a0e36c5b..e3f9938854d 100644 --- a/src/azure-cli/azure/cli/command_modules/keyvault/custom.py +++ b/src/azure-cli/azure/cli/command_modules/keyvault/custom.py @@ -477,7 +477,7 @@ def _parse_network_acls(cmd, resource_group_name, network_acls_json, network_acl network_acls = _create_network_rule_set(cmd, bypass, default_action) - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id network_acls.virtual_network_rules = [] for vnet_rule in network_acls_json.get('vnet', []): diff --git a/src/azure-cli/azure/cli/command_modules/lab/tests/latest/test_lab_validators.py b/src/azure-cli/azure/cli/command_modules/lab/tests/latest/test_lab_validators.py index 3ce1b190525..b0d17070cfc 100644 --- a/src/azure-cli/azure/cli/command_modules/lab/tests/latest/test_lab_validators.py +++ b/src/azure-cli/azure/cli/command_modules/lab/tests/latest/test_lab_validators.py @@ -5,7 +5,7 @@ import unittest from knack.util import CLIError -from msrestazure.tools import is_valid_resource_id +from azure.mgmt.core.tools import is_valid_resource_id from azure.cli.command_modules.lab.validators import _update_artifacts diff --git a/src/azure-cli/azure/cli/command_modules/lab/validators.py b/src/azure-cli/azure/cli/command_modules/lab/validators.py index 40087671584..d1ca340d9ea 100644 --- a/src/azure-cli/azure/cli/command_modules/lab/validators.py +++ b/src/azure-cli/azure/cli/command_modules/lab/validators.py @@ -37,7 +37,7 @@ def validate_lab_vm_create(cmd, namespace): def validate_lab_vm_list(cmd, namespace): """ Validates parameters for lab vm list and updates namespace. """ - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id collection = [namespace.filters, namespace.all, namespace.claimable] if _any(collection) and not _single(collection): raise CLIError("usage error: [--filters FILTER | [[--all | --claimable][--environment ENVIRONMENT]]") @@ -85,7 +85,7 @@ def validate_user_name(namespace): def validate_template_id(cmd, namespace): - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id from azure.cli.core.commands.client_factory import get_subscription_id if not is_valid_resource_id(namespace.arm_template): if not namespace.artifact_source_name: @@ -291,7 +291,7 @@ def _use_gallery_image(cli_ctx, namespace): # pylint: disable=no-member def _use_custom_image(cli_ctx, namespace): """ Retrieve custom image from lab and update namespace """ - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id if is_valid_resource_id(namespace.image): namespace.custom_image_id = namespace.image else: @@ -351,7 +351,7 @@ def _validate_other_parameters(namespace, formula=None): def validate_artifacts(cmd, namespace): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id if namespace.artifacts: from azure.cli.core.commands.client_factory import get_subscription_id if hasattr(namespace, 'resource_group'): @@ -395,7 +395,7 @@ def _update_artifacts(artifacts, lab_resource_id): def _update_artifact_id(artifact_id, lab_resource_id): - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id if not is_valid_resource_id(artifact_id): return "{}{}".format(lab_resource_id, artifact_id) return artifact_id diff --git a/src/azure-cli/azure/cli/command_modules/monitor/operations/activity_log_alerts.py b/src/azure-cli/azure/cli/command_modules/monitor/operations/activity_log_alerts.py index 8e38a6530d7..7bd9158d0a6 100644 --- a/src/azure-cli/azure/cli/command_modules/monitor/operations/activity_log_alerts.py +++ b/src/azure-cli/azure/cli/command_modules/monitor/operations/activity_log_alerts.py @@ -152,7 +152,7 @@ def pre_operations(self): process_condition_parameter_for_alert(args) webhook_properties = process_webhook_properties(args) if not has_value(args.scope_ui): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id from azure.cli.core.commands.client_factory import get_subscription_id # args.scopes = [resource_id(subscription=get_subscription_id(self.cli_ctx), # resource_group=args.resource_group)] @@ -471,7 +471,7 @@ def pre_instance_update(self, instance): def _normalize_names(cli_ctx, resource_names, resource_group, namespace, resource_type): """Normalize a group of resource names. Returns a set of resource ids. Throws if any of the name can't be correctly converted to a resource id.""" - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id from azure.cli.core.commands.client_factory import get_subscription_id rids = set() diff --git a/src/azure-cli/azure/cli/command_modules/monitor/operations/autoscale_settings.py b/src/azure-cli/azure/cli/command_modules/monitor/operations/autoscale_settings.py index 5410e338dc1..0320c0e0c4d 100644 --- a/src/azure-cli/azure/cli/command_modules/monitor/operations/autoscale_settings.py +++ b/src/azure-cli/azure/cli/command_modules/monitor/operations/autoscale_settings.py @@ -259,7 +259,7 @@ def autoscale_create(cmd, resource, count, autoscale_name=None, resource_group_n scale_mode=None, scale_look_ahead_time=None): if not autoscale_name: - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id autoscale_name = parse_resource_id(resource)['name'] min_count = min_count or count max_count = max_count or count diff --git a/src/azure-cli/azure/cli/command_modules/monitor/operations/diagnostics_settings.py b/src/azure-cli/azure/cli/command_modules/monitor/operations/diagnostics_settings.py index 242ea96146f..cc3c1322b3a 100644 --- a/src/azure-cli/azure/cli/command_modules/monitor/operations/diagnostics_settings.py +++ b/src/azure-cli/azure/cli/command_modules/monitor/operations/diagnostics_settings.py @@ -36,8 +36,7 @@ def create_resource_parameters(arg_schema, arg_group=None): def update_resource_parameters(ctx, alias="resource"): args = ctx.args - from msrestazure.tools import is_valid_resource_id - from azure.mgmt.core.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id from azure.cli.core.aaz import has_value name_or_id = args.resource.to_serialized_data() usage_error = CLIError('usage error: --{0} ID | --{0} NAME --resource-group NAME ' @@ -91,7 +90,7 @@ def _build_arguments_schema(cls, *args, **kwargs): def pre_operations(self): ctx = self.ctx from azure.cli.core.aaz import has_value - from msrestazure.tools import is_valid_resource_id, resource_id, parse_resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id, parse_resource_id update_resource_parameters(ctx) args = ctx.args rg = args.resource_group_name.to_serialized_data() diff --git a/src/azure-cli/azure/cli/command_modules/monitor/operations/metric_alert.py b/src/azure-cli/azure/cli/command_modules/monitor/operations/metric_alert.py index e373f451d1d..088a09f1cba 100644 --- a/src/azure-cli/azure/cli/command_modules/monitor/operations/metric_alert.py +++ b/src/azure-cli/azure/cli/command_modules/monitor/operations/metric_alert.py @@ -12,7 +12,7 @@ from azure.cli.core.azclierror import InvalidArgumentValueError from knack.log import get_logger from msrest.serialization import Serializer -from msrestazure.tools import is_valid_resource_id, resource_id +from azure.mgmt.core.tools import is_valid_resource_id, resource_id from ..aaz.latest.monitor.metrics.alert import Update as _MetricsAlertUpdate diff --git a/src/azure-cli/azure/cli/command_modules/monitor/operations/monitor_clone_util.py b/src/azure-cli/azure/cli/command_modules/monitor/operations/monitor_clone_util.py index 8dabc61a6a4..1bfd7c099ce 100644 --- a/src/azure-cli/azure/cli/command_modules/monitor/operations/monitor_clone_util.py +++ b/src/azure-cli/azure/cli/command_modules/monitor/operations/monitor_clone_util.py @@ -3,7 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- # pylint: disable=line-too-long, protected-access -from msrestazure.tools import parse_resource_id +from azure.mgmt.core.tools import parse_resource_id from knack.log import get_logger from knack.util import CLIError from azure.cli.core.commands.transform import _parse_id diff --git a/src/azure-cli/azure/cli/command_modules/monitor/tests/latest/test_monitor_general_operations.py b/src/azure-cli/azure/cli/command_modules/monitor/tests/latest/test_monitor_general_operations.py index 98a8831444f..bdb052ba736 100644 --- a/src/azure-cli/azure/cli/command_modules/monitor/tests/latest/test_monitor_general_operations.py +++ b/src/azure-cli/azure/cli/command_modules/monitor/tests/latest/test_monitor_general_operations.py @@ -8,7 +8,7 @@ from azure.cli.testsdk.scenario_tests import AllowLargeResponse from unittest import mock import unittest -from msrestazure.tools import resource_id +from azure.mgmt.core.tools import resource_id class MonitorCloneVMScenarios(ScenarioTest): diff --git a/src/azure-cli/azure/cli/command_modules/monitor/tests/latest/test_monitor_log_analytics_workspace.py b/src/azure-cli/azure/cli/command_modules/monitor/tests/latest/test_monitor_log_analytics_workspace.py index 1cf90c8289f..35655d7f3f2 100644 --- a/src/azure-cli/azure/cli/command_modules/monitor/tests/latest/test_monitor_log_analytics_workspace.py +++ b/src/azure-cli/azure/cli/command_modules/monitor/tests/latest/test_monitor_log_analytics_workspace.py @@ -148,7 +148,7 @@ def test_monitor_log_analytics_workspace_linked_service_common_scenario(self): location='eastus') def test_monitor_log_analytics_workspace_linked_storage(self, resource_group, account_1, account_2, account_3, account_4): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id self.kwargs.update({ 'name': self.create_random_name('clitest', 20), 'name_2': self.create_random_name('clitest', 20), @@ -407,7 +407,7 @@ def test_monitor_log_analytics_workspace_saved_search(self, resource_group): @StorageAccountPreparer(name_prefix='saws1', kind='StorageV2', sku='Standard_LRS', parameter_name='account_1', location='eastus') def test_monitor_log_analytics_workspace_data_export(self, resource_group, account_1): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id self.kwargs.update({ 'workspace_name': self.create_random_name('clitest', 20), 'data_export_name': 'clitest', diff --git a/src/azure-cli/azure/cli/command_modules/monitor/tests/latest/test_monitor_metric_alert_scenarios.py b/src/azure-cli/azure/cli/command_modules/monitor/tests/latest/test_monitor_metric_alert_scenarios.py index 9775579ae66..312bd3009be 100644 --- a/src/azure-cli/azure/cli/command_modules/monitor/tests/latest/test_monitor_metric_alert_scenarios.py +++ b/src/azure-cli/azure/cli/command_modules/monitor/tests/latest/test_monitor_metric_alert_scenarios.py @@ -16,7 +16,7 @@ class MonitorTests(ScenarioTest): @StorageAccountPreparer() def test_metric_alert_v2_scenario(self, resource_group, storage_account): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id self.kwargs.update({ 'alert': 'alert1', 'sa': storage_account, @@ -237,7 +237,7 @@ def _check_webhooks(actions, uris_to_check): @ResourceGroupPreparer(name_prefix='cli_test_metric_alert_v1') @VMPreparer(parameter_name='vm1') def test_metric_alert_single_scope(self, resource_group, vm1): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id self.kwargs.update({ 'alert': 'alert1', 'plan': 'plan1', @@ -301,7 +301,7 @@ def test_metric_alert_for_sql_database_scope(self, resource_group, resource_grou @VMPreparer(parameter_name='vm1') @VMPreparer(parameter_name='vm2') def test_metric_alert_multiple_scopes(self, resource_group, vm1, vm2): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id self.kwargs.update({ 'alert': 'alert1', 'plan': 'plan1', @@ -511,7 +511,7 @@ def test_metric_alert_condition_create(self, resource_group, vm1, vm2): @VMPreparer(parameter_name='vm1') @VMPreparer(parameter_name='vm2', resource_group_parameter_name='resource_group_2') def test_metric_alert_for_rg_and_sub(self, resource_group, resource_group_2): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id self.kwargs.update({ 'alert': 'rg-alert', 'alert2': 'sub-alert', diff --git a/src/azure-cli/azure/cli/command_modules/monitor/tests/latest/test_monitor_metrics.py b/src/azure-cli/azure/cli/command_modules/monitor/tests/latest/test_monitor_metrics.py index 4d7b77af465..49d76541344 100644 --- a/src/azure-cli/azure/cli/command_modules/monitor/tests/latest/test_monitor_metrics.py +++ b/src/azure-cli/azure/cli/command_modules/monitor/tests/latest/test_monitor_metrics.py @@ -11,7 +11,7 @@ class TestMonitorMetrics(ScenarioTest): @ResourceGroupPreparer() @StorageAccountPreparer() def test_monitor_metrics_scenario(self, resource_group, storage_account): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id self.kwargs.update({ 'sa_id': resource_id( resource_group=resource_group, diff --git a/src/azure-cli/azure/cli/command_modules/monitor/tests/latest/test_monitor_subscription_diagnostic_settings.py b/src/azure-cli/azure/cli/command_modules/monitor/tests/latest/test_monitor_subscription_diagnostic_settings.py index f508172d93c..2ce4528f34a 100644 --- a/src/azure-cli/azure/cli/command_modules/monitor/tests/latest/test_monitor_subscription_diagnostic_settings.py +++ b/src/azure-cli/azure/cli/command_modules/monitor/tests/latest/test_monitor_subscription_diagnostic_settings.py @@ -11,7 +11,7 @@ class TestDiagnosticSettingsSubscriptionScenarios(ScenarioTest): @ResourceGroupPreparer(location='southcentralus') @StorageAccountPreparer(location='southcentralus') def test_monitor_diagnostic_settings_subscription(self, resource_group, storage_account): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id self.kwargs.update({ 'name': self.create_random_name('clitest', 20), 'ws': self.create_random_name('cliws', 20), diff --git a/src/azure-cli/azure/cli/command_modules/monitor/validators.py b/src/azure-cli/azure/cli/command_modules/monitor/validators.py index c24da2d586f..fbcea987795 100644 --- a/src/azure-cli/azure/cli/command_modules/monitor/validators.py +++ b/src/azure-cli/azure/cli/command_modules/monitor/validators.py @@ -10,7 +10,7 @@ def process_autoscale_create_namespace(cmd, namespace): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id validate_tags(namespace) get_target_resource_validator('resource', required=True, preserve_resource_group_parameter=True)(cmd, namespace) @@ -102,7 +102,7 @@ def validate_autoscale_timegrain(namespace): def get_target_resource_validator(dest, required, preserve_resource_group_parameter=False, alias='resource'): def _validator(cmd, namespace): - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id name_or_id = getattr(namespace, dest) rg = namespace.resource_group_name res_ns = namespace.namespace @@ -203,7 +203,7 @@ def validate_metrics_alert_condition(namespace): def validate_diagnostic_settings(cmd, namespace): from azure.cli.core.commands.client_factory import get_subscription_id - from msrestazure.tools import is_valid_resource_id, resource_id, parse_resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id, parse_resource_id get_target_resource_validator('resource_uri', required=True, preserve_resource_group_parameter=True)(cmd, namespace) if not namespace.resource_group_name: @@ -338,7 +338,7 @@ def validate_action_groups(cmd, namespace): if not action_groups: return - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id from azure.cli.core.commands.client_factory import get_subscription_id subscription = get_subscription_id(cmd.cli_ctx) @@ -362,7 +362,7 @@ def validate_action_group_ids(cmd, namespace): if not action_groups: return - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id from azure.cli.core.commands.client_factory import get_subscription_id action_group_ids = [] @@ -384,7 +384,7 @@ def validate_action_group_ids(cmd, namespace): def validate_storage_accounts_name_or_id(cmd, namespace): if namespace.storage_account_ids: - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id from azure.cli.core.commands.client_factory import get_subscription_id for index, storage_account_id in enumerate(namespace.storage_account_ids): if not is_valid_resource_id(storage_account_id): diff --git a/src/azure-cli/azure/cli/command_modules/mysql/_network.py b/src/azure-cli/azure/cli/command_modules/mysql/_network.py index 61e91ddc991..f8ec98bcf1e 100644 --- a/src/azure-cli/azure/cli/command_modules/mysql/_network.py +++ b/src/azure-cli/azure/cli/command_modules/mysql/_network.py @@ -5,7 +5,7 @@ # pylint: disable=unused-argument, line-too-long, import-outside-toplevel from requests import get -from msrestazure.tools import is_valid_resource_id, parse_resource_id, is_valid_resource_name, resource_id # pylint: disable=import-error +from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id, is_valid_resource_name, resource_id # pylint: disable=import-error from knack.log import get_logger from azure.cli.core.commands import LongRunningOperation from azure.cli.core.commands.client_factory import get_subscription_id diff --git a/src/azure-cli/azure/cli/command_modules/mysql/_util.py b/src/azure-cli/azure/cli/command_modules/mysql/_util.py index b86a7e75f27..b99d4eab7ce 100644 --- a/src/azure-cli/azure/cli/command_modules/mysql/_util.py +++ b/src/azure-cli/azure/cli/command_modules/mysql/_util.py @@ -19,8 +19,7 @@ from knack.log import get_logger from knack.arguments import ignore_type from knack.prompting import prompt_pass, prompt_y_n, NoTTYException -from msrestazure.tools import parse_resource_id -from msrestazure.azure_exceptions import CloudError +from azure.mgmt.core.tools import parse_resource_id from azure.cli.core.commands.client_factory import get_subscription_id from azure.cli.core.commands.progress import IndeterminateProgressBar from azure.cli.core.util import CLIError @@ -442,7 +441,7 @@ def fill_action_template(cmd, database_engine, server, database_name, administra database_engine=database_engine, server=server, repository=repository) - except CloudError: + except HttpResponseError: raise AuthenticationError('You do not have authorization to create a service principal to run azure service in github actions. \n' 'Please create a service principal that has access to the database server and add "AZURE_CREDENTIALS" secret to your github repository. \n' 'Follow the instruction here "aka.ms/github-actions-azure-credentials".') diff --git a/src/azure-cli/azure/cli/command_modules/mysql/_validators.py b/src/azure-cli/azure/cli/command_modules/mysql/_validators.py index e63089b72c3..30ae700a85a 100644 --- a/src/azure-cli/azure/cli/command_modules/mysql/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/mysql/_validators.py @@ -6,7 +6,7 @@ import re from knack.util import CLIError from knack.log import get_logger -from msrestazure.tools import parse_resource_id, resource_id, is_valid_resource_id, is_valid_resource_name +from azure.mgmt.core.tools import parse_resource_id, resource_id, is_valid_resource_id, is_valid_resource_name from azure.cli.core.azclierror import ValidationError, ArgumentUsageError, InvalidArgumentValueError from azure.cli.core.commands.client_factory import get_mgmt_service_client, get_subscription_id from azure.cli.core.util import parse_proxy_resource_id diff --git a/src/azure-cli/azure/cli/command_modules/mysql/custom.py b/src/azure-cli/azure/cli/command_modules/mysql/custom.py index c23f9638fc1..21cf8f911b8 100644 --- a/src/azure-cli/azure/cli/command_modules/mysql/custom.py +++ b/src/azure-cli/azure/cli/command_modules/mysql/custom.py @@ -12,9 +12,8 @@ from knack.log import get_logger from urllib.request import urlretrieve from importlib import import_module -from msrestazure.azure_exceptions import CloudError -from msrestazure.tools import resource_id, is_valid_resource_id, parse_resource_id -from azure.core.exceptions import ResourceNotFoundError +from azure.mgmt.core.tools import resource_id, is_valid_resource_id, parse_resource_id +from azure.core.exceptions import ResourceNotFoundError, HttpResponseError from azure.cli.core.commands.client_factory import get_subscription_id from azure.cli.command_modules.mysql.random.generate import generate_username from azure.cli.core.util import CLIError, sdk_no_wait, user_confirmation @@ -1240,7 +1239,7 @@ def flexible_parameter_update(client, server_name, configuration_name, resource_ parameter = client.get(resource_group_name, server_name, configuration_name) value = parameter.default_value # reset value to default source = "system-default" - except CloudError as e: + except HttpResponseError as e: raise CLIError('Unable to get default parameter value: {}.'.format(str(e))) elif source is None: source = "user-override" @@ -1266,7 +1265,7 @@ def flexible_parameter_update_batch(client, server_name, resource_group_name, so parameter = client.get(resource_group_name, server_name, name) value = parameter.default_value # reset value to default source = "system-default" - except CloudError as e: + except HttpResponseError as e: raise CLIError('Unable to get default parameter value: {}.'.format(str(e))) elif source is None: source = "user-override" diff --git a/src/azure-cli/azure/cli/command_modules/netappfiles/custom.py b/src/azure-cli/azure/cli/command_modules/netappfiles/custom.py index 7a3bc7d960e..28f82c673b1 100644 --- a/src/azure-cli/azure/cli/command_modules/netappfiles/custom.py +++ b/src/azure-cli/azure/cli/command_modules/netappfiles/custom.py @@ -10,7 +10,7 @@ from knack.log import get_logger from azure.cli.core.azclierror import ValidationError from azure.cli.core.aaz import has_value, AAZJsonSelector -from msrestazure.tools import is_valid_resource_id, parse_resource_id +from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id from .aaz.latest.netappfiles import UpdateNetworkSiblingSet as _UpdateNetworkSiblingSet from .aaz.latest.netappfiles.account import Create as _AccountCreate, Update as _AccountUpdate from .aaz.latest.netappfiles.account.ad import Add as _ActiveDirectoryAdd, List as _ActiveDirectoryList, Update as _ActiveDirectoryUpdate diff --git a/src/azure-cli/azure/cli/command_modules/netappfiles/validators.py b/src/azure-cli/azure/cli/command_modules/netappfiles/validators.py index 0154431438d..550fbeb5761 100644 --- a/src/azure-cli/azure/cli/command_modules/netappfiles/validators.py +++ b/src/azure-cli/azure/cli/command_modules/netappfiles/validators.py @@ -23,7 +23,7 @@ def _getattr(obj, attr): # Command validators def validate_resync_quotarule(cmd, namespace): - from msrestazure.tools import parse_resource_id, is_valid_resource_id + from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id # Get volume params netAppVolumeClient = volumes_mgmt_client_factory(cmd.cli_ctx, None) netAppVolumeQuotaRuleClient = volume_quota_rules_mgmt_client_factory(cmd.cli_ctx, None) diff --git a/src/azure-cli/azure/cli/command_modules/network/_format.py b/src/azure-cli/azure/cli/command_modules/network/_format.py index 2e6ad60e949..419447fe6bf 100644 --- a/src/azure-cli/azure/cli/command_modules/network/_format.py +++ b/src/azure-cli/azure/cli/command_modules/network/_format.py @@ -200,7 +200,7 @@ def transform_effective_route_table(result): def transform_effective_nsg(result): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id transformed = [] for item in result['value']: association = item['association'] diff --git a/src/azure-cli/azure/cli/command_modules/network/_validators.py b/src/azure-cli/azure/cli/command_modules/network/_validators.py index 134b414b0f5..134f9e118fd 100644 --- a/src/azure-cli/azure/cli/command_modules/network/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/network/_validators.py @@ -45,7 +45,7 @@ def _resolve_api_version(rcf, resource_provider_namespace, parent_resource_path, def get_vnet_validator(dest): - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id def _validate_vnet_name_or_id(cmd, namespace): SubResource = cmd.get_models('SubResource', resource_type=ResourceType.MGMT_RESOURCE_RESOURCES) @@ -79,7 +79,7 @@ def _validate_vpn_gateway_generation(namespace): def validate_ddos_name_or_id(cmd, namespace): if namespace.ddos_protection_plan: - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id if not is_valid_resource_id(namespace.ddos_protection_plan): namespace.ddos_protection_plan = resource_id( subscription=get_subscription_id(cmd.cli_ctx), @@ -96,7 +96,7 @@ def dns_zone_name_type(value): def _generate_ag_subproperty_id(cli_ctx, namespace, child_type, child_name, subscription=None): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id return resource_id( subscription=subscription or get_subscription_id(cli_ctx), resource_group=namespace.resource_group_name, @@ -108,7 +108,7 @@ def _generate_ag_subproperty_id(cli_ctx, namespace, child_type, child_name, subs def _generate_lb_subproperty_id(cli_ctx, namespace, child_type, child_name, subscription=None): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id return resource_id( subscription=subscription or get_subscription_id(cli_ctx), resource_group=namespace.resource_group_name, @@ -120,7 +120,7 @@ def _generate_lb_subproperty_id(cli_ctx, namespace, child_type, child_name, subs def _generate_lb_id_list_from_names_or_ids(cli_ctx, namespace, prop, child_type): - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id raw = getattr(namespace, prop) if not raw: return @@ -144,7 +144,7 @@ def validate_address_pool_id_list(cmd, namespace): def validate_address_pool_name_or_id(cmd, namespace): - from msrestazure.tools import is_valid_resource_id, parse_resource_id + from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id address_pool = namespace.backend_address_pool lb_name = namespace.load_balancer_name gateway_name = namespace.application_gateway_name @@ -231,7 +231,7 @@ def validate_dns_record_type(namespace): def validate_user_assigned_identity(cmd, namespace): - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id if namespace.user_assigned_identity and not is_valid_resource_id(namespace.user_assigned_identity): namespace.user_assigned_identity = resource_id( @@ -244,7 +244,7 @@ def validate_user_assigned_identity(cmd, namespace): def validate_waf_policy(cmd, namespace): - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id if namespace.firewall_policy and not is_valid_resource_id(namespace.firewall_policy): namespace.firewall_policy = resource_id( subscription=get_subscription_id(cmd.cli_ctx), @@ -261,7 +261,7 @@ def validate_inbound_nat_rule_id_list(cmd, namespace): def validate_inbound_nat_rule_name_or_id(cmd, namespace): - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id rule_name = namespace.inbound_nat_rule lb_name = namespace.load_balancer_name @@ -286,7 +286,7 @@ def validate_ip_tags(namespace): def validate_frontend_ip_configs(cmd, namespace): - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id if namespace.frontend_ip_configurations: config_ids = [] for item in namespace.frontend_ip_configurations: @@ -299,7 +299,7 @@ def validate_frontend_ip_configs(cmd, namespace): def validate_local_gateway(cmd, namespace): - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id if namespace.gateway_default_site and not is_valid_resource_id(namespace.gateway_default_site): namespace.gateway_default_site = resource_id( subscription=get_subscription_id(cmd.cli_ctx), @@ -323,7 +323,7 @@ def validate_peering_type(namespace): def validate_public_ip_prefix(cmd, namespace): - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id if namespace.public_ip_prefix and not is_valid_resource_id(namespace.public_ip_prefix): namespace.public_ip_prefix = resource_id( subscription=get_subscription_id(cmd.cli_ctx), @@ -334,7 +334,7 @@ def validate_public_ip_prefix(cmd, namespace): def validate_nat_gateway(cmd, namespace): - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id if namespace.nat_gateway and not is_valid_resource_id(namespace.nat_gateway): namespace.nat_gateway = resource_id( subscription=get_subscription_id(cmd.cli_ctx), @@ -353,7 +353,7 @@ def get_public_ip_validator(has_type_field=False, allow_none=False, allow_new=Fa default_none=False): """ Retrieves a validator for public IP address. Accepting all defaults will perform a check for an existing name or ID with no ARM-required -type parameter. """ - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id def simple_validator(cmd, namespace): if namespace.public_ip_address: @@ -385,7 +385,7 @@ def complex_validator_with_type(cmd, namespace): def get_subnet_validator(has_type_field=False, allow_none=False, allow_new=False, default_none=False): - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id def simple_validator(cmd, namespace): if namespace.virtual_network_name is None and namespace.subnet is None: @@ -427,7 +427,7 @@ def complex_validator_with_type(cmd, namespace): def get_nsg_validator(has_type_field=False, allow_none=False, allow_new=False, default_none=False): - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id def simple_validator(cmd, namespace): if namespace.network_security_group: @@ -450,7 +450,7 @@ def complex_validator_with_type(cmd, namespace): def validate_service_endpoint_policy(cmd, namespace): - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id if namespace.service_endpoint_policy: policy_ids = [] for policy in namespace.service_endpoint_policy: @@ -480,7 +480,7 @@ def validate_servers(namespace): def validate_private_dns_zone(cmd, namespace): - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id if namespace.private_dns_zone and not is_valid_resource_id(namespace.private_dns_zone): namespace.private_dns_zone = resource_id( subscription=get_subscription_id(cmd.cli_ctx), @@ -492,7 +492,7 @@ def validate_private_dns_zone(cmd, namespace): def get_virtual_network_validator(has_type_field=False, allow_none=False, allow_new=False, default_none=False): - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id def simple_validator(cmd, namespace): if namespace.virtual_network: @@ -598,7 +598,7 @@ def _validate_cert(namespace, param_name): def process_vpn_connection_create_namespace(cmd, namespace): - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id get_default_location_from_resource_group(cmd, namespace) validate_tags(namespace) @@ -657,7 +657,7 @@ def load_cert_validator(namespace): def get_network_watcher_from_location(remove=False, watcher_name='watcher_name', rg_name='watcher_rg'): def _validator(cmd, namespace): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id from .aaz.latest.network.watcher import List location = namespace.location @@ -676,7 +676,7 @@ def _validator(cmd, namespace): def _process_vnet_name_and_id(vnet, cmd, resource_group_name): - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id if vnet and not is_valid_resource_id(vnet): vnet = resource_id( subscription=get_subscription_id(cmd.cli_ctx), @@ -689,7 +689,7 @@ def _process_vnet_name_and_id(vnet, cmd, resource_group_name): def _process_subnet_name_and_id(subnet, vnet, cmd, resource_group_name): from azure.cli.core.azclierror import UnrecognizedArgumentError - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id if subnet and not is_valid_resource_id(subnet): vnet = _process_vnet_name_and_id(vnet, cmd, resource_group_name) if vnet is None: @@ -700,7 +700,7 @@ def _process_subnet_name_and_id(subnet, vnet, cmd, resource_group_name): def process_nw_flow_log_show_namespace(cmd, namespace): - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id from azure.cli.core.commands.arm import get_arm_resource_by_id if hasattr(namespace, 'nsg') and namespace.nsg is not None: @@ -722,7 +722,7 @@ def process_nw_flow_log_show_namespace(cmd, namespace): def process_lb_outbound_rule_namespace(cmd, namespace): - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id validate_frontend_ip_configs(cmd, namespace) @@ -733,7 +733,7 @@ def process_lb_outbound_rule_namespace(cmd, namespace): def validate_ag_address_pools(cmd, namespace): - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id address_pools = namespace.app_gateway_backend_address_pools gateway_name = namespace.application_gateway_name delattr(namespace, 'application_gateway_name') @@ -865,7 +865,7 @@ def process_private_link_resource_id_argument(cmd, namespace): namespace.resource_provider])): raise CLIError("usage error: --id / -g -n --type") - from msrestazure.tools import is_valid_resource_id, parse_resource_id + from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id if not is_valid_resource_id(namespace.id): raise CLIError("Resource ID is invalid. Please check it.") split_resource_id = parse_resource_id(namespace.id) diff --git a/src/azure-cli/azure/cli/command_modules/network/azure_stack/_format.py b/src/azure-cli/azure/cli/command_modules/network/azure_stack/_format.py index b01e35cfd88..74844f7d79a 100644 --- a/src/azure-cli/azure/cli/command_modules/network/azure_stack/_format.py +++ b/src/azure-cli/azure/cli/command_modules/network/azure_stack/_format.py @@ -152,7 +152,7 @@ def transform_effective_route_table(result): def transform_effective_nsg(result): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id transformed = [] for item in result['value']: association = item['association'] diff --git a/src/azure-cli/azure/cli/command_modules/network/azure_stack/_validators.py b/src/azure-cli/azure/cli/command_modules/network/azure_stack/_validators.py index df87a657720..71699b7b24e 100644 --- a/src/azure-cli/azure/cli/command_modules/network/azure_stack/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/network/azure_stack/_validators.py @@ -17,7 +17,7 @@ def get_vnet_validator(dest): - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id def _validate_vnet_name_or_id(cmd, namespace): SubResource = cmd.get_models('SubResource') @@ -46,7 +46,7 @@ def _validate_vnet_name_or_id(cmd, namespace): def validate_ddos_name_or_id(cmd, namespace): if namespace.ddos_protection_plan: - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id if not is_valid_resource_id(namespace.ddos_protection_plan): namespace.ddos_protection_plan = resource_id( subscription=get_subscription_id(cmd.cli_ctx), @@ -63,7 +63,7 @@ def dns_zone_name_type(value): def _generate_ag_subproperty_id(cli_ctx, namespace, child_type, child_name, subscription=None): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id return resource_id( subscription=subscription or get_subscription_id(cli_ctx), resource_group=namespace.resource_group_name, @@ -75,7 +75,7 @@ def _generate_ag_subproperty_id(cli_ctx, namespace, child_type, child_name, subs def _generate_lb_subproperty_id(cli_ctx, namespace, child_type, child_name, subscription=None): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id return resource_id( subscription=subscription or get_subscription_id(cli_ctx), resource_group=namespace.resource_group_name, @@ -87,7 +87,7 @@ def _generate_lb_subproperty_id(cli_ctx, namespace, child_type, child_name, subs def validate_address_pool_name_or_id(cmd, namespace): - from msrestazure.tools import is_valid_resource_id, parse_resource_id + from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id address_pool = namespace.backend_address_pool lb_name = namespace.load_balancer_name gateway_name = getattr(namespace, 'application_gateway_name', None) @@ -145,7 +145,7 @@ def validate_metadata(namespace): def validate_public_ip_prefix(cmd, namespace): - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id if namespace.public_ip_prefix and not is_valid_resource_id(namespace.public_ip_prefix): namespace.public_ip_prefix = resource_id( subscription=get_subscription_id(cmd.cli_ctx), @@ -164,7 +164,7 @@ def get_public_ip_validator(has_type_field=False, allow_none=False, allow_new=Fa default_none=False): """ Retrieves a validator for public IP address. Accepting all defaults will perform a check for an existing name or ID with no ARM-required -type parameter. """ - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id def simple_validator(cmd, namespace): if namespace.public_ip_address: @@ -196,7 +196,7 @@ def complex_validator_with_type(cmd, namespace): def get_subnet_validator(has_type_field=False, allow_none=False, allow_new=False, default_none=False): - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id def simple_validator(cmd, namespace): if namespace.virtual_network_name is None and namespace.subnet is None: @@ -299,7 +299,7 @@ def _inform_coming_breaking_change_for_public_ip(namespace): def process_vpn_connection_create_namespace(cmd, namespace): - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id get_default_location_from_resource_group(cmd, namespace) validate_tags(namespace) @@ -359,7 +359,7 @@ def process_private_link_resource_id_argument(cmd, namespace): namespace.resource_provider])): raise CLIError("usage error: --id / -g -n --type") - from msrestazure.tools import is_valid_resource_id, parse_resource_id + from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id if not is_valid_resource_id(namespace.id): raise CLIError("Resource ID is invalid. Please check it.") split_resource_id = parse_resource_id(namespace.id) diff --git a/src/azure-cli/azure/cli/command_modules/network/azure_stack/custom.py b/src/azure-cli/azure/cli/command_modules/network/azure_stack/custom.py index 8a55d11b35a..9e04a803a93 100644 --- a/src/azure-cli/azure/cli/command_modules/network/azure_stack/custom.py +++ b/src/azure-cli/azure/cli/command_modules/network/azure_stack/custom.py @@ -4,7 +4,7 @@ # -------------------------------------------------------------------------------------------- from collections import Counter, OrderedDict -from msrestazure.tools import parse_resource_id, is_valid_resource_id, resource_id +from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id, resource_id from knack.log import get_logger diff --git a/src/azure-cli/azure/cli/command_modules/network/azure_stack/profile_2020_09_01_hybrid/operations/public_ip.py b/src/azure-cli/azure/cli/command_modules/network/azure_stack/profile_2020_09_01_hybrid/operations/public_ip.py index de5b450d341..80a67d4bea6 100644 --- a/src/azure-cli/azure/cli/command_modules/network/azure_stack/profile_2020_09_01_hybrid/operations/public_ip.py +++ b/src/azure-cli/azure/cli/command_modules/network/azure_stack/profile_2020_09_01_hybrid/operations/public_ip.py @@ -30,7 +30,7 @@ def create_public_ip(cmd, resource_group_name, public_ip_address_name, location= } if public_ip_prefix: - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id metadata = parse_resource_id(public_ip_prefix) resource_group_name = metadata["resource_group"] public_ip_prefix_name = metadata["resource_name"] diff --git a/src/azure-cli/azure/cli/command_modules/network/custom.py b/src/azure-cli/azure/cli/command_modules/network/custom.py index c151f03cf10..d10a3fce474 100644 --- a/src/azure-cli/azure/cli/command_modules/network/custom.py +++ b/src/azure-cli/azure/cli/command_modules/network/custom.py @@ -10,7 +10,7 @@ import socket from knack.log import get_logger -from msrestazure.tools import parse_resource_id, is_valid_resource_id, resource_id +from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id, resource_id from azure.cli.core.aaz import AAZClientConfiguration, has_value, register_client from azure.cli.core.aaz._client import AAZMgmtClient diff --git a/src/azure-cli/azure/cli/command_modules/network/operations/load_balancer.py b/src/azure-cli/azure/cli/command_modules/network/operations/load_balancer.py index c3c1219e2f5..02fbb201fcd 100644 --- a/src/azure-cli/azure/cli/command_modules/network/operations/load_balancer.py +++ b/src/azure-cli/azure/cli/command_modules/network/operations/load_balancer.py @@ -7,7 +7,7 @@ from azure.cli.core.azclierror import ArgumentUsageError from azure.cli.core.aaz import register_command, AAZResourceIdArgFormat, has_value, AAZListArg, AAZResourceIdArg, \ AAZStrArg, AAZArgEnum -from msrestazure.tools import is_valid_resource_id, parse_resource_id +from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id from ..aaz.latest.network.lb import Delete as _LBDelete, Update as _LBUpdate, List as _LBList, Show as _LBShow from ..aaz.latest.network.lb.frontend_ip import Create as _LBFrontendIPCreate, Update as _LBFrontendIPUpdate, \ Show as _LBFrontendIPShow, Delete as _LBFrontendIPDelete, List as _LBFrontendIPList diff --git a/src/azure-cli/azure/cli/command_modules/network/operations/watcher.py b/src/azure-cli/azure/cli/command_modules/network/operations/watcher.py index a05138f4089..5d6a04b4253 100644 --- a/src/azure-cli/azure/cli/command_modules/network/operations/watcher.py +++ b/src/azure-cli/azure/cli/command_modules/network/operations/watcher.py @@ -5,7 +5,7 @@ # pylint: disable=line-too-long, protected-access, too-few-public-methods from knack.log import get_logger from knack.util import CLIError -from msrestazure.tools import is_valid_resource_id, parse_resource_id, resource_id +from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id, resource_id from azure.cli.core.azclierror import ValidationError, RequiredArgumentMissingError, MutuallyExclusiveArgumentError from azure.cli.core.commands.arm import get_arm_resource_by_id diff --git a/src/azure-cli/azure/cli/command_modules/network/tests/hybrid_2018_03_01/test_network_commands.py b/src/azure-cli/azure/cli/command_modules/network/tests/hybrid_2018_03_01/test_network_commands.py index a0dba114fb7..c49e5925e6c 100644 --- a/src/azure-cli/azure/cli/command_modules/network/tests/hybrid_2018_03_01/test_network_commands.py +++ b/src/azure-cli/azure/cli/command_modules/network/tests/hybrid_2018_03_01/test_network_commands.py @@ -17,7 +17,7 @@ from knack.util import CLIError -from msrestazure.tools import resource_id +from azure.mgmt.core.tools import resource_id TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) diff --git a/src/azure-cli/azure/cli/command_modules/network/tests/hybrid_2019_03_01/test_network_commands.py b/src/azure-cli/azure/cli/command_modules/network/tests/hybrid_2019_03_01/test_network_commands.py index 1ced392baae..955b280fb26 100644 --- a/src/azure-cli/azure/cli/command_modules/network/tests/hybrid_2019_03_01/test_network_commands.py +++ b/src/azure-cli/azure/cli/command_modules/network/tests/hybrid_2019_03_01/test_network_commands.py @@ -16,7 +16,7 @@ from knack.util import CLIError -from msrestazure.tools import resource_id +from azure.mgmt.core.tools import resource_id TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) diff --git a/src/azure-cli/azure/cli/command_modules/network/tests/hybrid_2020_09_01/test_network_commands.py b/src/azure-cli/azure/cli/command_modules/network/tests/hybrid_2020_09_01/test_network_commands.py index 1c83f356d95..b48135d76c4 100644 --- a/src/azure-cli/azure/cli/command_modules/network/tests/hybrid_2020_09_01/test_network_commands.py +++ b/src/azure-cli/azure/cli/command_modules/network/tests/hybrid_2020_09_01/test_network_commands.py @@ -16,7 +16,7 @@ from knack.util import CLIError -from msrestazure.tools import resource_id +from azure.mgmt.core.tools import resource_id TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) diff --git a/src/azure-cli/azure/cli/command_modules/network/tests/latest/test_network_commands.py b/src/azure-cli/azure/cli/command_modules/network/tests/latest/test_network_commands.py index aad409045bc..19fde927f08 100644 --- a/src/azure-cli/azure/cli/command_modules/network/tests/latest/test_network_commands.py +++ b/src/azure-cli/azure/cli/command_modules/network/tests/latest/test_network_commands.py @@ -21,7 +21,7 @@ from knack.util import CLIError -from msrestazure.tools import resource_id +from azure.mgmt.core.tools import resource_id from .credential_replacer import ExpressRoutePortLOAContentReplacer @@ -284,7 +284,6 @@ def test_network_private_endpoint_asg(self, storage_account): @ResourceGroupPreparer(name_prefix='fanqiu_cli_test_network_private_endpoints', location='CentralUSEuap') @StorageAccountPreparer(name_prefix='saplr', kind='StorageV2') def test_network_private_endpoint_private_dns_zone_group(self, resource_group, storage_account): - from msrestazure.azure_exceptions import CloudError self.kwargs.update({ 'sa': storage_account, 'loc': 'CentralUSEuap', @@ -3481,7 +3480,6 @@ def test_network_express_route_global_reach(self, resource_group): @record_only() # record_only as the express route is extremely expensive, contact service team for an available ER @ResourceGroupPreparer(name_prefix='cli_test_express_route_peer_connection') def test_network_express_route_peer_connection(self, resource_group): - from msrestazure.azure_exceptions import CloudError from azure.core.exceptions import ResourceNotFoundError self.kwargs.update({ 'er1': 'er1', diff --git a/src/azure-cli/azure/cli/command_modules/network/tests/latest/test_private_endpoint_commands.py b/src/azure-cli/azure/cli/command_modules/network/tests/latest/test_private_endpoint_commands.py index e0efb9a6678..7620f445de0 100644 --- a/src/azure-cli/azure/cli/command_modules/network/tests/latest/test_private_endpoint_commands.py +++ b/src/azure-cli/azure/cli/command_modules/network/tests/latest/test_private_endpoint_commands.py @@ -283,7 +283,6 @@ def test_private_link_resource_storage_account(self, storage_account): @ResourceGroupPreparer(name_prefix='cli_test_sa_pe') @StorageAccountPreparer(name_prefix='saplr', kind='StorageV2') def test_private_endpoint_connection_storage_account(self, storage_account): - from msrestazure.azure_exceptions import CloudError self.kwargs.update({ 'sa': storage_account, 'loc': 'eastus', diff --git a/src/azure-cli/azure/cli/command_modules/network/tests/profile_2017_03_09/test_network_commands.py b/src/azure-cli/azure/cli/command_modules/network/tests/profile_2017_03_09/test_network_commands.py index 206405456f4..53faf6f4386 100644 --- a/src/azure-cli/azure/cli/command_modules/network/tests/profile_2017_03_09/test_network_commands.py +++ b/src/azure-cli/azure/cli/command_modules/network/tests/profile_2017_03_09/test_network_commands.py @@ -16,7 +16,7 @@ from knack.util import CLIError -from msrestazure.tools import resource_id +from azure.mgmt.core.tools import resource_id TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) diff --git a/src/azure-cli/azure/cli/command_modules/policyinsights/_validators.py b/src/azure-cli/azure/cli/command_modules/policyinsights/_validators.py index 8d4a7d11434..33dcf0b6133 100644 --- a/src/azure-cli/azure/cli/command_modules/policyinsights/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/policyinsights/_validators.py @@ -3,7 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from msrestazure.tools import is_valid_resource_id +from azure.mgmt.core.tools import is_valid_resource_id from knack.util import CLIError diff --git a/src/azure-cli/azure/cli/command_modules/policyinsights/custom.py b/src/azure-cli/azure/cli/command_modules/policyinsights/custom.py index cc56a5f1252..82eff831094 100644 --- a/src/azure-cli/azure/cli/command_modules/policyinsights/custom.py +++ b/src/azure-cli/azure/cli/command_modules/policyinsights/custom.py @@ -3,7 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from msrestazure.tools import is_valid_resource_id, resource_id +from azure.mgmt.core.tools import is_valid_resource_id, resource_id from azure.cli.core.commands.client_factory import get_subscription_id from azure.cli.core.util import sdk_no_wait diff --git a/src/azure-cli/azure/cli/command_modules/privatedns/_validators.py b/src/azure-cli/azure/cli/command_modules/privatedns/_validators.py index 9be6d375e5f..6326b0084a7 100644 --- a/src/azure-cli/azure/cli/command_modules/privatedns/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/privatedns/_validators.py @@ -4,7 +4,7 @@ # -------------------------------------------------------------------------------------------- # pylint:disable=import-error -from msrestazure.tools import is_valid_resource_id, resource_id +from azure.mgmt.core.tools import is_valid_resource_id, resource_id from azure.cli.core.commands.client_factory import get_subscription_id diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/_flexible_server_util.py b/src/azure-cli/azure/cli/command_modules/rdbms/_flexible_server_util.py index 458c01718d2..97aa3614f95 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/_flexible_server_util.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/_flexible_server_util.py @@ -15,8 +15,7 @@ import yaml from knack.log import get_logger from knack.prompting import prompt_y_n, NoTTYException -from msrestazure.tools import parse_resource_id -from msrestazure.azure_exceptions import CloudError +from azure.mgmt.core.tools import parse_resource_id from azure.cli.core.util import CLIError from azure.cli.core.azclierror import AuthenticationError from azure.core.exceptions import HttpResponseError @@ -386,7 +385,7 @@ def fill_action_template(cmd, database_engine, server, database_name, administra database_engine=database_engine, server=server, repository=repository) - except CloudError: + except HttpResponseError: raise AuthenticationError('You do not have authorization to create a service principal to run azure service in github actions. \n' 'Please create a service principal that has access to the database server and add "AZURE_CREDENTIALS" secret to your github repository. \n' 'Follow the instruction here "aka.ms/github-actions-azure-credentials".') diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/custom.py b/src/azure-cli/azure/cli/command_modules/rdbms/custom.py index 791a4b1713a..4a300ed062b 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/custom.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/custom.py @@ -8,12 +8,11 @@ from importlib import import_module import re from dateutil.tz import tzutc # pylint: disable=import-error -from msrestazure.azure_exceptions import CloudError -from msrestazure.tools import resource_id, is_valid_resource_id, parse_resource_id # pylint: disable=import-error +from azure.mgmt.core.tools import resource_id, is_valid_resource_id, parse_resource_id # pylint: disable=import-error from knack.log import get_logger from knack.util import todict from urllib.request import urlretrieve -from azure.core.exceptions import ResourceNotFoundError +from azure.core.exceptions import ResourceNotFoundError, HttpResponseError from azure.cli.core._profile import Profile from azure.cli.core.commands.client_factory import get_subscription_id from azure.cli.core.util import CLIError, sdk_no_wait @@ -334,7 +333,7 @@ def _replica_create(cmd, client, resource_group_name, server_name, source_server source_server_id_parts = parse_resource_id(source_server) try: source_server_object = client.get(source_server_id_parts['resource_group'], source_server_id_parts['name']) - except CloudError as e: + except HttpResponseError as e: raise CLIError('Unable to get source server: {}.'.format(str(e))) if location is None: diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_postgres.py b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_postgres.py index 2b1fe4753d2..cbf7408c415 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_postgres.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_postgres.py @@ -12,8 +12,7 @@ from urllib.request import urlretrieve from dateutil.tz import tzutc # pylint: disable=import-error import uuid -from msrestazure.azure_exceptions import CloudError -from msrestazure.tools import resource_id, is_valid_resource_id, parse_resource_id # pylint: disable=import-error +from azure.mgmt.core.tools import resource_id, is_valid_resource_id, parse_resource_id # pylint: disable=import-error from knack.log import get_logger from azure.cli.core.commands.client_factory import get_subscription_id from azure.cli.core.local_context import ALL @@ -464,7 +463,7 @@ def flexible_parameter_update(client, server_name, configuration_name, resource_ # this should be 'system-default' but there is currently a bug in PG, so keeping as what it is for now # this will reset source to be 'system-default' anyway source = parameter.source - except CloudError as e: + except HttpResponseError as e: raise CLIError('Unable to get default parameter value: {}.'.format(str(e))) elif source is None: source = "user-override" diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_virtual_network.py b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_virtual_network.py index 74231012ff4..51cab375c2f 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_virtual_network.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_virtual_network.py @@ -5,7 +5,7 @@ # pylint: disable=unused-argument, line-too-long, import-outside-toplevel from requests import get -from msrestazure.tools import is_valid_resource_id, parse_resource_id, is_valid_resource_name, resource_id # pylint: disable=import-error +from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id, is_valid_resource_name, resource_id # pylint: disable=import-error from knack.log import get_logger from azure.cli.core.commands import LongRunningOperation from azure.cli.core.commands.client_factory import get_subscription_id diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_commands.py b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_commands.py index 8d808b49932..8ff844624db 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_commands.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_commands.py @@ -7,7 +7,6 @@ from datetime import datetime from dateutil.tz import tzutc # pylint: disable=import-error from azure.cli.testsdk.scenario_tests import AllowLargeResponse -from msrestazure.azure_exceptions import CloudError from azure.core.exceptions import HttpResponseError from azure.cli.core.util import CLIError from azure.cli.core.util import parse_proxy_resource_id diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_flexible_commands_postgres_migration.py b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_flexible_commands_postgres_migration.py index 8b7e8c9303e..6cf76b96a7e 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_flexible_commands_postgres_migration.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_flexible_commands_postgres_migration.py @@ -14,7 +14,6 @@ from time import sleep from dateutil.tz import tzutc # pylint: disable=import-error from azure.cli.testsdk.scenario_tests import AllowLargeResponse -from msrestazure.azure_exceptions import CloudError from azure.cli.core.util import CLIError from azure.cli.core.util import parse_proxy_resource_id from azure.cli.testsdk.base import execute diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/validators.py b/src/azure-cli/azure/cli/command_modules/rdbms/validators.py index 578758ea19f..a6dae5caedf 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/validators.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/validators.py @@ -8,7 +8,7 @@ from knack.util import CLIError from knack.log import get_logger import math -from msrestazure.tools import parse_resource_id, resource_id, is_valid_resource_id, is_valid_resource_name +from azure.mgmt.core.tools import parse_resource_id, resource_id, is_valid_resource_id, is_valid_resource_name from azure.cli.core.azclierror import ValidationError, ArgumentUsageError from azure.cli.core.commands.client_factory import get_mgmt_service_client, get_subscription_id from azure.cli.core.commands.validators import ( diff --git a/src/azure-cli/azure/cli/command_modules/redis/custom.py b/src/azure-cli/azure/cli/command_modules/redis/custom.py index 5cd5ec3c20c..bb6f21b2d19 100644 --- a/src/azure-cli/azure/cli/command_modules/redis/custom.py +++ b/src/azure-cli/azure/cli/command_modules/redis/custom.py @@ -140,7 +140,7 @@ def get_key_value_pair(string): def cli_redis_create_server_link(cmd, client, resource_group_name, name, server_to_link, replication_role): redis_client = cf_redis(cmd.cli_ctx) from azure.cli.core.commands.client_factory import get_subscription_id - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id if not is_valid_resource_id(server_to_link): server_to_link = resource_id( subscription=get_subscription_id(cmd.cli_ctx), @@ -179,7 +179,7 @@ def cli_redis_list_cache(client, resource_group_name=None): def get_cache_from_resource_id(client, cache_resource_id): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id id_comps = parse_resource_id(cache_resource_id) return client.get(id_comps['resource_group'], id_comps['name']) diff --git a/src/azure-cli/azure/cli/command_modules/resource/_validators.py b/src/azure-cli/azure/cli/command_modules/resource/_validators.py index a10094869a2..5d0909b53f2 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/resource/_validators.py @@ -109,7 +109,7 @@ def internal_validate_lock_parameters(namespace, resource_group, resource_provid parent_resource_path, resource_type, resource_name): if resource_group is None: if resource_name is not None: - from msrestazure.tools import parse_resource_id, is_valid_resource_id + from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id if not is_valid_resource_id(resource_name): raise CLIError('--resource is not a valid resource ID. ' '--resource as a resource name is ignored if --resource-group is not given.') diff --git a/src/azure-cli/azure/cli/command_modules/resource/custom.py b/src/azure-cli/azure/cli/command_modules/resource/custom.py index 9cacc492668..888a7b0f97e 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/custom.py +++ b/src/azure-cli/azure/cli/command_modules/resource/custom.py @@ -19,7 +19,7 @@ from urllib.request import urlopen from urllib.parse import urlparse, unquote -from msrestazure.tools import is_valid_resource_id, parse_resource_id +from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id from azure.mgmt.resource.resources.models import GenericResource, DeploymentMode @@ -66,7 +66,7 @@ def _build_resource_id(**kwargs): - from msrestazure.tools import resource_id as resource_id_from_dict + from azure.mgmt.core.tools import resource_id as resource_id_from_dict try: return resource_id_from_dict(**kwargs) except KeyError: @@ -3257,7 +3257,7 @@ def create_policy_assignment(cmd, policy=None, policy_set_definition=None, def _get_resource_id(cli_ctx, val, resource_group, resource_type, resource_namespace): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id if is_valid_resource_id(val): return val diff --git a/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource.py b/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource.py index 1d651e1a0cf..c6f2b07fd98 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource.py +++ b/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource.py @@ -4577,7 +4577,7 @@ def test_managedappdef(self, resource_group): with mock.patch('azure.cli.command_modules.role.custom._gen_guid', side_effect=self.create_guid): role_assignment = self.cmd( 'role assignment create --assignee {upn} --role contributor --scope "/subscriptions/{sub}" ').get_output_in_json() - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id role_definition_id = parse_resource_id(role_assignment['roleDefinitionId'])['name'] self.kwargs.update({ @@ -4656,7 +4656,7 @@ def test_managedappdef_inline(self, resource_group): with mock.patch('azure.cli.command_modules.role.custom._gen_guid', side_effect=self.create_guid): role_assignment = self.cmd( 'role assignment create --assignee {upn} --role contributor --scope "/subscriptions/{sub}" ').get_output_in_json() - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id role_definition_id = parse_resource_id(role_assignment['roleDefinitionId'])['name'] self.kwargs.update({ @@ -4717,7 +4717,7 @@ def test_managed_app_def_deployment_mode(self): with mock.patch('azure.cli.command_modules.role.custom._gen_guid', side_effect=self.create_guid): role_assignment = self.cmd( 'role assignment create --assignee {upn} --role contributor --scope "/subscriptions/{sub}" ').get_output_in_json() - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id role_definition_id = parse_resource_id(role_assignment['roleDefinitionId'])['name'] self.kwargs.update({ 'app_def': self.create_random_name('def', 10), @@ -4750,7 +4750,7 @@ def test_managedapp(self, resource_group): with mock.patch('azure.cli.command_modules.role.custom._gen_guid', side_effect=self.create_guid): role_assignment = self.cmd('role assignment create --assignee {upn} --role contributor --scope "/subscriptions/{sub}" ').get_output_in_json() - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id role_definition_id = parse_resource_id(role_assignment['roleDefinitionId'])['name'] self.kwargs.update({ diff --git a/src/azure-cli/azure/cli/command_modules/role/custom.py b/src/azure-cli/azure/cli/command_modules/role/custom.py index ea087f35189..c88c1567db0 100644 --- a/src/azure-cli/azure/cli/command_modules/role/custom.py +++ b/src/azure-cli/azure/cli/command_modules/role/custom.py @@ -23,7 +23,7 @@ from dateutil.relativedelta import relativedelta from knack.log import get_logger from knack.util import CLIError, todict -from msrestazure.azure_exceptions import CloudError +from azure.core.exceptions import HttpResponseError from azure.cli.core.profiles import ResourceType from azure.cli.core.util import get_file_json, shell_safe_json_parse, is_guid @@ -102,7 +102,7 @@ def _create_update_role_definition(cmd, role_definition, for_update): scopes = (scopes_in_definition if scopes_in_definition else ['/subscriptions/' + definitions_client._config.subscription_id]) if role_resource_id: - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id role_id = parse_resource_id(role_resource_id)['name'] role_name = role_definition['roleName'] else: @@ -275,7 +275,7 @@ def list_role_assignments(cmd, assignee=None, role=None, resource_group_name=Non if principal_dics.get(worker.get_role_property(i, 'principalId')): worker.set_role_property(i, 'principalName', principal_dics[worker.get_role_property(i, 'principalId')]) - except (CloudError, GraphError) as ex: + except (HttpResponseError, GraphError) as ex: # failure on resolving principal due to graph permission should not fail the whole thing logger.info("Failed to resolve graph object information per error '%s'", ex) @@ -862,7 +862,7 @@ def _get_grant_permissions(client, client_sp_object_id=None, query_filter=None): try: # Make the REST request immediately so that errors can be raised and handled. return list(grant_info) - except CloudError as ex: + except HttpResponseError as ex: if ex.status_code == 404: raise CLIError("Service principal with appId or objectId '{id}' doesn't exist. " "If '{id}' is an appId, make sure an associated service principal is created " diff --git a/src/azure-cli/azure/cli/command_modules/security/custom.py b/src/azure-cli/azure/cli/command_modules/security/custom.py index 421f6e386d5..d306d496ae7 100644 --- a/src/azure-cli/azure/cli/command_modules/security/custom.py +++ b/src/azure-cli/azure/cli/command_modules/security/custom.py @@ -31,8 +31,8 @@ from azure.mgmt.security.v2023_01_01.models import (Extension) from azure.cli.core.commands.client_factory import get_subscription_id from azure.cli.core.azclierror import (MutuallyExclusiveArgumentError) -from msrestazure.tools import resource_id -from msrestazure.azure_exceptions import CloudError +from azure.mgmt.core.tools import resource_id +from azure.core.exceptions import HttpResponseError from knack.log import get_logger from ._utils import ( run_cli_cmd @@ -619,7 +619,7 @@ def get_security_assessment_metadata(client, resource_name): try: return client.get(resource_name) - except CloudError: + except HttpResponseError: return client.get_in_subscription(resource_name) diff --git a/src/azure-cli/azure/cli/command_modules/security/tests/latest/test_tasks_scenario.py b/src/azure-cli/azure/cli/command_modules/security/tests/latest/test_tasks_scenario.py index 6286e79fb7d..6b189e2453d 100644 --- a/src/azure-cli/azure/cli/command_modules/security/tests/latest/test_tasks_scenario.py +++ b/src/azure-cli/azure/cli/command_modules/security/tests/latest/test_tasks_scenario.py @@ -5,7 +5,7 @@ from azure.cli.testsdk import ScenarioTest from azure.cli.testsdk.scenario_tests import AllowLargeResponse -from msrestazure.tools import parse_resource_id +from azure.mgmt.core.tools import parse_resource_id import re diff --git a/src/azure-cli/azure/cli/command_modules/servicebus/_validators.py b/src/azure-cli/azure/cli/command_modules/servicebus/_validators.py index f21c16e8f0b..3223679b6ea 100644 --- a/src/azure-cli/azure/cli/command_modules/servicebus/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/servicebus/_validators.py @@ -65,7 +65,7 @@ def _validate_auto_delete_on_idle(namespace): def validate_partner_namespace(cmd, namespace): from azure.cli.core.commands.client_factory import get_subscription_id - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id if namespace.partner_namespace: if not is_valid_resource_id(namespace.partner_namespace): namespace.partner_namespace = resource_id( @@ -78,7 +78,7 @@ def validate_partner_namespace(cmd, namespace): def validate_target_namespace(cmd, namespace): from azure.cli.core.commands.client_factory import get_subscription_id - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id if namespace.target_namespace: if not is_valid_resource_id(namespace.target_namespace): namespace.target_namespace = resource_id( @@ -96,7 +96,7 @@ def validate_premiumsku_capacity(namespace): # Validates if a subnet id or name have been given by the user. If subnet id is given, vnet-name should not be provided. def validate_subnet(cmd, namespace): - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id from azure.cli.core.commands.client_factory import get_subscription_id subnet = namespace.subnet diff --git a/src/azure-cli/azure/cli/command_modules/servicebus/tests/latest/test_servicebus_commands_privateendpoint_test.py b/src/azure-cli/azure/cli/command_modules/servicebus/tests/latest/test_servicebus_commands_privateendpoint_test.py index c8704c1e84d..ae9051ff34c 100644 --- a/src/azure-cli/azure/cli/command_modules/servicebus/tests/latest/test_servicebus_commands_privateendpoint_test.py +++ b/src/azure-cli/azure/cli/command_modules/servicebus/tests/latest/test_servicebus_commands_privateendpoint_test.py @@ -18,7 +18,6 @@ class SBNamespacePrivateEndpointCRUDScenarioTest(ScenarioTest): @ResourceGroupPreparer(name_prefix='cli_test_sb_private') def test_sb_privateendpoint(self, resource_group): - from msrestazure.azure_exceptions import CloudError self.kwargs.update({ 'namespacename': self.create_random_name(prefix='servicebus-nscli', length=20), 'loc': 'eastus', diff --git a/src/azure-cli/azure/cli/command_modules/servicefabric/_sf_utils.py b/src/azure-cli/azure/cli/command_modules/servicefabric/_sf_utils.py index 25a60ef4717..23b60d0516e 100644 --- a/src/azure-cli/azure/cli/command_modules/servicefabric/_sf_utils.py +++ b/src/azure-cli/azure/cli/command_modules/servicefabric/_sf_utils.py @@ -12,11 +12,11 @@ def _get_resource_group_by_name(cli_ctx, resource_group_name): - from msrestazure.azure_exceptions import CloudError + from azure.core.exceptions import HttpResponseError try: resource_client = resource_client_factory(cli_ctx).resource_groups return resource_client.get(resource_group_name) - except CloudError as ex: + except HttpResponseError as ex: if ex.status_code == 404: return None raise diff --git a/src/azure-cli/azure/cli/command_modules/servicefabric/_validators.py b/src/azure-cli/azure/cli/command_modules/servicefabric/_validators.py index c45329415b8..a9e5f9375c2 100644 --- a/src/azure-cli/azure/cli/command_modules/servicefabric/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/servicefabric/_validators.py @@ -3,7 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from msrestazure.azure_exceptions import CloudError +from azure.core.exceptions import HttpResponseError from knack.log import get_logger from knack.util import CLIError from azure.cli.core.azclierror import ValidationError @@ -332,8 +332,8 @@ def validate_create_managed_application(cmd, namespace): def _safe_get_resource(getResourceAction, params): try: return getResourceAction(*params) - except CloudError as ex: - if ex.error.error == 'ResourceNotFound': + except HttpResponseError as ex: + if ex.status_code == '404': return None logger.warning("Unable to get resource, exception: %s", ex) raise diff --git a/src/azure-cli/azure/cli/command_modules/servicefabric/custom.py b/src/azure-cli/azure/cli/command_modules/servicefabric/custom.py index 010b1c423d4..cf706d44eb9 100644 --- a/src/azure-cli/azure/cli/command_modules/servicefabric/custom.py +++ b/src/azure-cli/azure/cli/command_modules/servicefabric/custom.py @@ -17,15 +17,13 @@ except ImportError: from urlparse import urlparse # pylint: disable=import-error -from msrestazure.azure_exceptions import CloudError - from azure.cli.core.util import CLIError, get_file_json, b64_to_hex, sdk_no_wait from azure.cli.core.commands import LongRunningOperation from azure.graphrbac import GraphRbacManagementClient from azure.cli.core.profiles import ResourceType, get_sdk from azure.cli.command_modules.servicefabric._arm_deployment_utils import validate_and_deploy_arm_template from azure.cli.command_modules.servicefabric._sf_utils import _get_resource_group_by_name, _create_resource_group_name -from azure.core.exceptions import ResourceNotFoundError +from azure.core.exceptions import ResourceNotFoundError, HttpResponseError from azure.mgmt.servicefabric.models import (ClusterUpdateParameters, ClientCertificateThumbprint, @@ -1360,8 +1358,8 @@ def _safe_get_vault(cli_ctx, resource_group_name, vault_name): return vault except ResourceNotFoundError: return None - except CloudError as ex: - if ex.error.error == 'ResourceNotFound': + except HttpResponseError as ex: + if ex.status_code == '404': return None raise diff --git a/src/azure-cli/azure/cli/command_modules/sql/_validators.py b/src/azure-cli/azure/cli/command_modules/sql/_validators.py index 8c49b7a618c..9c35e09cce7 100644 --- a/src/azure-cli/azure/cli/command_modules/sql/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/sql/_validators.py @@ -79,7 +79,7 @@ def _expansion_validator_impl(namespace): # Validates if a subnet id or name have been given by the user. If subnet id is given, vnet-name should not be provided. def validate_subnet(cmd, namespace): - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id from azure.cli.core.commands.client_factory import get_subscription_id # Different custom function arg names, instance pool has subnet_id diff --git a/src/azure-cli/azure/cli/command_modules/sql/custom.py b/src/azure-cli/azure/cli/command_modules/sql/custom.py index e12d1d04948..628b49e1dce 100644 --- a/src/azure-cli/azure/cli/command_modules/sql/custom.py +++ b/src/azure-cli/azure/cli/command_modules/sql/custom.py @@ -596,7 +596,7 @@ def _complete_maintenance_configuration_id(cli_ctx, argument_value=None): Completes maintenance configuration id from short to full type if needed ''' - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id from azure.cli.core.commands.client_factory import get_subscription_id if argument_value and not is_valid_resource_id(argument_value): @@ -736,7 +736,7 @@ def _get_managed_db_resource_id( Gets the Managed db resource id in this Azure environment. ''' from azure.cli.core.commands.client_factory import get_subscription_id - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id return resource_id( subscription=subscription_id if subscription_id else get_subscription_id(cli_ctx), @@ -780,7 +780,7 @@ def _get_managed_dropped_db_resource_id( from urllib.parse import quote from azure.cli.core.commands.client_factory import get_subscription_id - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id return (resource_id( subscription=subscription_id if subscription_id else get_subscription_id(cli_ctx), @@ -803,7 +803,7 @@ def _get_managed_instance_resource_id( ''' from azure.cli.core.commands.client_factory import get_subscription_id - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id return (resource_id( subscription=subscription_id if subscription_id else get_subscription_id(cli_ctx), @@ -822,7 +822,7 @@ def _get_managed_instance_pool_resource_id( ''' from azure.cli.core.commands.client_factory import get_subscription_id - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id if instance_pool_name: return (resource_id( @@ -1023,7 +1023,7 @@ def _validate_elastic_pool_id( Returns the elastic_pool_id, which may have been updated and may be None. ''' - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id from azure.cli.core.commands.client_factory import get_subscription_id if elastic_pool_id and not is_valid_resource_id(elastic_pool_id): diff --git a/src/azure-cli/azure/cli/command_modules/sqlvm/_format.py b/src/azure-cli/azure/cli/command_modules/sqlvm/_format.py index a9fc74c3f70..76220578200 100644 --- a/src/azure-cli/azure/cli/command_modules/sqlvm/_format.py +++ b/src/azure-cli/azure/cli/command_modules/sqlvm/_format.py @@ -11,7 +11,7 @@ def transform_sqlvm_group_output(result): Transforms the result of SQL virtual machine group to eliminate unnecessary parameters. ''' from collections import OrderedDict - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id try: resource_group = getattr(result, 'resource_group', None) or parse_resource_id(result.id)['resource_group'] wsfc_object = format_wsfc_domain_profile(result.wsfc_domain_profile) @@ -44,7 +44,7 @@ def transform_sqlvm_output(result): Transforms the result of SQL virtual machine group to eliminate unnecessary parameters. ''' from collections import OrderedDict - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id try: resource_group = getattr(result, 'resource_group', None) or parse_resource_id(result.id)['resource_group'] # Create a dictionary with the relevant parameters @@ -94,7 +94,7 @@ def transform_aglistener_output(result): Transforms the result of Availability Group Listener to eliminate unnecessary parameters. ''' from collections import OrderedDict - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id try: resource_group = getattr(result, 'resource_group', None) or parse_resource_id(result.id)['resource_group'] # Create a dictionary with the relevant parameters diff --git a/src/azure-cli/azure/cli/command_modules/sqlvm/_validators.py b/src/azure-cli/azure/cli/command_modules/sqlvm/_validators.py index 090479c4042..f47096a5ab0 100644 --- a/src/azure-cli/azure/cli/command_modules/sqlvm/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/sqlvm/_validators.py @@ -5,7 +5,7 @@ from datetime import datetime import json -from msrestazure.tools import resource_id, is_valid_resource_id +from azure.mgmt.core.tools import resource_id, is_valid_resource_id from azure.cli.core.azclierror import ( InvalidArgumentValueError, RequiredArgumentMissingError, diff --git a/src/azure-cli/azure/cli/command_modules/sqlvm/custom.py b/src/azure-cli/azure/cli/command_modules/sqlvm/custom.py index 2c60850e35f..c545e28fb92 100644 --- a/src/azure-cli/azure/cli/command_modules/sqlvm/custom.py +++ b/src/azure-cli/azure/cli/command_modules/sqlvm/custom.py @@ -3,7 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from msrestazure.tools import is_valid_resource_id, resource_id +from azure.mgmt.core.tools import is_valid_resource_id, resource_id from knack.prompting import prompt_pass from azure.cli.core.azclierror import ( RequiredArgumentMissingError, diff --git a/src/azure-cli/azure/cli/command_modules/storage/_validators.py b/src/azure-cli/azure/cli/command_modules/storage/_validators.py index 77d083091dd..c43a5c60bf1 100644 --- a/src/azure-cli/azure/cli/command_modules/storage/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/storage/_validators.py @@ -52,7 +52,7 @@ def _query_account_rg(cli_ctx, account_name): scf = storage_client_factory(cli_ctx) acc = next((x for x in scf.storage_accounts.list() if x.name == account_name), None) if acc: - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id return parse_resource_id(acc.id)['resource_group'], scf raise ValueError("Storage account '{}' not found.".format(account_name)) @@ -74,7 +74,7 @@ def _cancel_timer_event_handler(_, **__): # region PARAMETER VALIDATORS def parse_storage_account(cmd, namespace): """Parse storage account which can be either account name or account id""" - from msrestazure.tools import parse_resource_id, is_valid_resource_id + from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id if namespace.account_name and is_valid_resource_id(namespace.account_name): namespace.resource_group_name = parse_resource_id(namespace.account_name)['resource_group'] @@ -1365,7 +1365,7 @@ def process_metric_update_namespace(namespace): def validate_subnet(cmd, namespace): - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id from azure.cli.core.commands.client_factory import get_subscription_id subnet = namespace.subnet @@ -1885,7 +1885,7 @@ def validate_match_condition(namespace): def validate_or_policy(cmd, namespace): - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id from azure.cli.core.commands.client_factory import get_subscription_id error_elements = [] if namespace.properties is None: diff --git a/src/azure-cli/azure/cli/command_modules/storage/_validators_azure_stack.py b/src/azure-cli/azure/cli/command_modules/storage/_validators_azure_stack.py index 12bbc6e47b1..417e1bbd642 100644 --- a/src/azure-cli/azure/cli/command_modules/storage/_validators_azure_stack.py +++ b/src/azure-cli/azure/cli/command_modules/storage/_validators_azure_stack.py @@ -48,7 +48,7 @@ def _query_account_rg(cli_ctx, account_name): scf = storage_client_factory(cli_ctx) acc = next((x for x in scf.storage_accounts.list() if x.name == account_name), None) if acc: - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id return parse_resource_id(acc.id)['resource_group'], scf raise ValueError("Storage account '{}' not found.".format(account_name)) @@ -70,7 +70,7 @@ def _cancel_timer_event_handler(_, **__): # region PARAMETER VALIDATORS def parse_storage_account(cmd, namespace): """Parse storage account which can be either account name or account id""" - from msrestazure.tools import parse_resource_id, is_valid_resource_id + from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id if namespace.account_name and is_valid_resource_id(namespace.account_name): namespace.resource_group_name = parse_resource_id(namespace.account_name)['resource_group'] @@ -947,7 +947,7 @@ def process_metric_update_namespace(namespace): def validate_subnet(cmd, namespace): - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id from azure.cli.core.commands.client_factory import get_subscription_id subnet = namespace.subnet diff --git a/src/azure-cli/azure/cli/command_modules/storage/operations/account.py b/src/azure-cli/azure/cli/command_modules/storage/operations/account.py index 1d4bc274f38..b75531ecb71 100644 --- a/src/azure-cli/azure/cli/command_modules/storage/operations/account.py +++ b/src/azure-cli/azure/cli/command_modules/storage/operations/account.py @@ -203,7 +203,7 @@ def create_storage_account(cmd, resource_group_name, account_name, sku=None, loc if bypass and not default_action: raise CLIError('incorrect usage: --default-action ACTION [--bypass SERVICE ...]') if subnet: - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id if not is_valid_resource_id(subnet): raise CLIError("Expected fully qualified resource ID: got '{}'".format(subnet)) VirtualNetworkRule = cmd.get_models('VirtualNetworkRule') @@ -365,7 +365,7 @@ def show_storage_account_usage_no_location(cmd): def get_storage_account_properties(cli_ctx, account_id): scf = storage_client_factory(cli_ctx) - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id result = parse_resource_id(account_id) return scf.storage_accounts.get_properties(result['resource_group'], result['name']) @@ -689,7 +689,7 @@ def add_network_rule(cmd, client, resource_group_name, account_name, action='All if not subnet and not ip_address: logger.warning('No subnet or ip address supplied.') if subnet: - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id if not is_valid_resource_id(subnet): raise CLIError("Expected fully qualified resource ID: got '{}'".format(subnet)) VirtualNetworkRule = cmd.get_models('VirtualNetworkRule') @@ -993,7 +993,7 @@ def create_or_policy(cmd, client, account_name, resource_group_name=None, proper object_replication_policy_id=policy_id, properties=or_policy) except HttpResponseError as ex: if ex.error.code == 'InvalidRequestPropertyValue' and policy_id == 'default': - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id if account_name == parse_resource_id(or_policy.source_account)['name']: raise CLIError('ValueError: Please specify --policy-id with auto-generated policy id value on ' 'destination account.') diff --git a/src/azure-cli/azure/cli/command_modules/synapse/manual/_validators.py b/src/azure-cli/azure/cli/command_modules/synapse/manual/_validators.py index 33fae5544ba..41bc4b0337c 100644 --- a/src/azure-cli/azure/cli/command_modules/synapse/manual/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/synapse/manual/_validators.py @@ -6,11 +6,11 @@ # pylint: disable=line-too-long from knack.util import CLIError from knack.log import get_logger -from msrestazure.tools import is_valid_resource_id +from azure.mgmt.core.tools import is_valid_resource_id def validate_storage_account(namespace): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id if is_valid_resource_id(namespace.storage_account): parsed_storage = parse_resource_id(namespace.storage_account) storage_name = parsed_storage['resource_name'] @@ -21,7 +21,7 @@ def example_name_or_id_validator(cmd, namespace): # Example of a storage account name or ID validator. # See: https://github.com/Azure/azure-cli/blob/dev/doc/authoring_command_modules/authoring_commands.md#supporting-name-or-id-parameters from azure.cli.core.commands.client_factory import get_subscription_id - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id if namespace.storage_account: if not is_valid_resource_id(namespace.RESOURCE): namespace.storage_account = resource_id( diff --git a/src/azure-cli/azure/cli/command_modules/synapse/manual/operations/sqlpoolsensitivitylabel.py b/src/azure-cli/azure/cli/command_modules/synapse/manual/operations/sqlpoolsensitivitylabel.py index 1b1cb068628..b78a47780ca 100644 --- a/src/azure-cli/azure/cli/command_modules/synapse/manual/operations/sqlpoolsensitivitylabel.py +++ b/src/azure-cli/azure/cli/command_modules/synapse/manual/operations/sqlpoolsensitivitylabel.py @@ -44,7 +44,7 @@ def sqlpool_sensitivity_label_update( # Get the information protection policy from azure.mgmt.security import SecurityCenter - from msrestazure.azure_exceptions import CloudError + from azure.core.exceptions import HttpResponseError security_center_client = get_mgmt_service_client(cmd.cli_ctx, SecurityCenter, asc_location="centralus") @@ -69,8 +69,8 @@ def sqlpool_sensitivity_label_update( sensitivity_label.information_type = current_label.information_type sensitivity_label.information_type_id = current_label.information_type_id - except CloudError as ex: - if not (ex.error and ex.error.error and 'SensitivityLabelsLabelNotFound' in ex.error.error): + except HttpResponseError as ex: + if not (ex.status_code and ex.status_code == '404'): raise ex # Find the label id and information type id in the policy by the label name provided diff --git a/src/azure-cli/azure/cli/command_modules/vm/_format.py b/src/azure-cli/azure/cli/command_modules/vm/_format.py index 44271508fd3..f319122254e 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_format.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_format.py @@ -35,7 +35,7 @@ def transform_vm(vm): def transform_vm_create_output(result): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id from collections import OrderedDict try: resource_group = getattr(result, 'resource_group', None) or parse_resource_id(result.id)['resource_group'] diff --git a/src/azure-cli/azure/cli/command_modules/vm/_image_builder.py b/src/azure-cli/azure/cli/command_modules/vm/_image_builder.py index 7eff6efc788..346011e048e 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_image_builder.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_image_builder.py @@ -21,7 +21,7 @@ from knack.util import CLIError from knack.log import get_logger -from msrestazure.tools import is_valid_resource_id, resource_id, parse_resource_id +from azure.mgmt.core.tools import is_valid_resource_id, resource_id, parse_resource_id from azure.core.exceptions import HttpResponseError diff --git a/src/azure-cli/azure/cli/command_modules/vm/_template_builder.py b/src/azure-cli/azure/cli/command_modules/vm/_template_builder.py index b480e20d78f..6dbc2b52905 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_template_builder.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_template_builder.py @@ -266,7 +266,7 @@ def build_vnet_resource(_, name, location, tags, vnet_prefix=None, subnet=None, def build_msi_role_assignment(vm_vmss_name, vm_vmss_resource_id, role_definition_id, role_assignment_guid, identity_scope, is_vm=True): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id result = parse_resource_id(identity_scope) if result.get('type'): # is a resource id? name = '{}/Microsoft.Authorization/{}'.format(result['name'], role_assignment_guid) diff --git a/src/azure-cli/azure/cli/command_modules/vm/_validators.py b/src/azure-cli/azure/cli/command_modules/vm/_validators.py index 0de6199fd0f..9121ddbbdbf 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_validators.py @@ -34,7 +34,7 @@ def validate_asg_names_or_ids(cmd, namespace): - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id from azure.cli.core.commands.client_factory import get_subscription_id resource_group = namespace.resource_group_name @@ -58,7 +58,7 @@ def validate_asg_names_or_ids(cmd, namespace): def validate_nsg_name(cmd, namespace): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id from azure.cli.core.commands.client_factory import get_subscription_id vm_id = resource_id(name=namespace.vm_name, resource_group=namespace.resource_group_name, namespace='Microsoft.Compute', type='virtualMachines', @@ -83,7 +83,7 @@ def validate_vm_name_for_monitor_metrics(cmd, namespace): def _validate_proximity_placement_group(cmd, namespace): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id if namespace.proximity_placement_group: namespace.proximity_placement_group = _get_resource_id(cmd.cli_ctx, namespace.proximity_placement_group, @@ -98,7 +98,7 @@ def _validate_proximity_placement_group(cmd, namespace): def process_vm_secret_format(cmd, namespace): - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id from azure.cli.core._output import (get_output_format, set_output_format) keyvault_usage = CLIError('usage error: [--keyvault NAME --resource-group NAME | --keyvault ID]') @@ -132,7 +132,7 @@ def _get_resource_group_from_vault_name(cli_ctx, vault_name): """ from azure.cli.core.profiles import ResourceType from azure.cli.core.commands.client_factory import get_mgmt_service_client - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id client = get_mgmt_service_client(cli_ctx, ResourceType.MGMT_KEYVAULT).vaults for vault in client.list(): id_comps = parse_resource_id(vault.id) @@ -142,7 +142,7 @@ def _get_resource_group_from_vault_name(cli_ctx, vault_name): def _get_resource_id(cli_ctx, val, resource_group, resource_type, resource_namespace): - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id from azure.cli.core.commands.client_factory import get_subscription_id if is_valid_resource_id(val): return val @@ -238,7 +238,7 @@ def _validate_secrets(secrets, os_type): def _parse_image_argument(cmd, namespace): """ Systematically determines what type is supplied for the --image parameter. Updates the namespace and returns the type for subsequent processing. """ - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id from azure.core.exceptions import HttpResponseError import re @@ -374,7 +374,7 @@ def _validate_location(cmd, namespace, zone_info, size_info): # pylint: disable=too-many-branches, too-many-statements, too-many-locals def _validate_vm_create_storage_profile(cmd, namespace, for_scale_set=False): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id _validate_vm_vmss_create_ephemeral_placement(namespace) @@ -649,7 +649,7 @@ def _validate_vm_create_storage_profile(cmd, namespace, for_scale_set=False): def _validate_vm_create_storage_account(cmd, namespace): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id if namespace.storage_account: storage_id = parse_resource_id(namespace.storage_account) rg = storage_id.get('resource_group', namespace.resource_group_name) @@ -689,7 +689,7 @@ def _validate_vm_create_storage_account(cmd, namespace): def _validate_vm_create_availability_set(cmd, namespace): - from msrestazure.tools import parse_resource_id, resource_id + from azure.mgmt.core.tools import parse_resource_id, resource_id from azure.cli.core.commands.client_factory import get_subscription_id if namespace.availability_set: as_id = parse_resource_id(namespace.availability_set) @@ -709,7 +709,7 @@ def _validate_vm_create_availability_set(cmd, namespace): def _validate_vm_create_vmss(cmd, namespace): - from msrestazure.tools import parse_resource_id, resource_id + from azure.mgmt.core.tools import parse_resource_id, resource_id from azure.cli.core.commands.client_factory import get_subscription_id if namespace.vmss: as_id = parse_resource_id(namespace.vmss) @@ -745,7 +745,7 @@ def _validate_vm_create_dedicated_host(cmd, namespace): :param namespace: :return: """ - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id from azure.cli.core.commands.client_factory import get_subscription_id if namespace.dedicated_host and namespace.dedicated_host_group: @@ -763,7 +763,7 @@ def _validate_vm_create_dedicated_host(cmd, namespace): def _validate_vm_vmss_create_vnet(cmd, namespace, for_scale_set=False): - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id vnet = namespace.vnet_name subnet = namespace.subnet rg = namespace.resource_group_name @@ -1075,7 +1075,7 @@ def validate_delete_option(string): def _validate_vm_create_nics(cmd, namespace): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id from azure.cli.core.commands.client_factory import get_subscription_id nic_ids = namespace.nics delete_option = validate_delete_options(nic_ids, getattr(namespace, 'nic_delete_option', None)) @@ -1445,7 +1445,7 @@ def _validate_generation_version_and_trusted_launch(cmd, namespace): # create vm with os disk if hasattr(namespace, 'attach_os_disk') and namespace.attach_os_disk is not None: - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id if urlparse(namespace.attach_os_disk).scheme and "://" in namespace.attach_os_disk: # vhd does not support trusted launch return @@ -1585,7 +1585,7 @@ def _validate_vmss_single_placement_group(namespace): def _validate_vmss_create_load_balancer_or_app_gateway(cmd, namespace): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id from azure.cli.core.profiles import ResourceType from azure.core.exceptions import HttpResponseError std_lb_is_available = cmd.supported_api_version(min_api='2017-08-01', resource_type=ResourceType.MGMT_NETWORK) @@ -2052,7 +2052,7 @@ def process_snapshot_create_namespace(cmd, namespace): def process_image_create_namespace(cmd, namespace): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id validate_tags(namespace) validate_edge_zone(cmd, namespace) source_from_vm = False @@ -2395,7 +2395,7 @@ def _disk_encryption_set_format(cmd, namespace, name): :param name: string :return: ID """ - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id from azure.cli.core.commands.client_factory import get_subscription_id if name is not None and not is_valid_resource_id(name): name = resource_id( @@ -2517,7 +2517,7 @@ def _validate_vmss_automatic_repairs(cmd, namespace): # pylint: disable=unused- def _validate_vmss_create_host_group(cmd, namespace): - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id from azure.cli.core.commands.client_factory import get_subscription_id if namespace.host_group: if not is_valid_resource_id(namespace.host_group): @@ -2581,7 +2581,7 @@ def _validate_capacity_reservation_group(cmd, namespace): if namespace.capacity_reservation_group and namespace.capacity_reservation_group != 'None': - from msrestazure.tools import is_valid_resource_id, resource_id + from azure.mgmt.core.tools import is_valid_resource_id, resource_id from azure.cli.core.commands.client_factory import get_subscription_id if not is_valid_resource_id(namespace.capacity_reservation_group): namespace.capacity_reservation_group = resource_id( diff --git a/src/azure-cli/azure/cli/command_modules/vm/_vm_utils.py b/src/azure-cli/azure/cli/command_modules/vm/_vm_utils.py index b416916028d..b8ad25bb8be 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_vm_utils.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_vm_utils.py @@ -80,7 +80,7 @@ def check_existence(cli_ctx, value, resource_group, provider_namespace, resource # check for name or ID and set the type flags from azure.cli.core.commands.client_factory import get_mgmt_service_client from azure.core.exceptions import HttpResponseError - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id from azure.cli.core.profiles import ResourceType id_parts = parse_resource_id(value) resource_client = get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES, @@ -172,7 +172,7 @@ def normalize_disk_info(image_data_disks=None, data_disk_delete_option=None, source_snapshots_or_disks=None, source_snapshots_or_disks_size_gb=None, source_disk_restore_point=None, source_disk_restore_point_size_gb=None): - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id from ._validators import validate_delete_options is_lv_size = re.search('_L[0-9]+s', size, re.I) # we should return a dictionary with info like below diff --git a/src/azure-cli/azure/cli/command_modules/vm/custom.py b/src/azure-cli/azure/cli/command_modules/vm/custom.py index 022b3377fbd..3f45338503b 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/custom.py +++ b/src/azure-cli/azure/cli/command_modules/vm/custom.py @@ -306,7 +306,7 @@ def _trim_away_build_number(version): def _parse_rg_name(strid): '''From an ID, extract the contained (resource group, name) tuple.''' - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id parts = parse_resource_id(strid) return (parts['resource_group'], parts['name']) @@ -328,7 +328,7 @@ def _show_missing_access_warning(resource_group, name, command): def _parse_aux_subscriptions(resource_id): - from msrestazure.tools import is_valid_resource_id, parse_resource_id + from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id if is_valid_resource_id(resource_id): res = parse_resource_id(resource_id) return [res['subscription']] @@ -360,7 +360,7 @@ def create_managed_disk(cmd, resource_group_name, disk_name, location=None, # p upload_type=None, secure_vm_disk_encryption_set=None, performance_plus=None, optimized_for_frequent_attach=None): - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id from azure.cli.core.commands.client_factory import get_subscription_id Disk, CreationData, DiskCreateOption, Encryption = cmd.get_models( @@ -408,7 +408,7 @@ def create_managed_disk(cmd, resource_group_name, disk_name, location=None, # p else: # error raise CLIError('usage error: --image-reference should be ID or URN (publisher:offer:sku:version).') else: - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id terms = parse_resource_id(image_reference) disk_publisher, disk_offer, disk_sku, disk_version = \ terms['child_name_1'], terms['child_name_3'], terms['child_name_4'], terms['child_name_5'] @@ -548,7 +548,7 @@ def update_managed_disk(cmd, resource_group_name, instance, size_gb=None, sku=No network_access_policy=None, disk_access=None, max_shares=None, disk_iops_read_only=None, disk_mbps_read_only=None, enable_bursting=None, public_network_access=None, accelerated_network=None, architecture=None, data_access_auth_mode=None): - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id from azure.cli.core.commands.client_factory import get_subscription_id if size_gb is not None: @@ -677,7 +677,7 @@ def create_snapshot(cmd, resource_group_name, snapshot_name, location=None, size encryption_type=None, network_access_policy=None, disk_access=None, edge_zone=None, public_network_access=None, accelerated_network=None, architecture=None, elastic_san_resource_id=None, bandwidth_copy_speed=None): - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id from azure.cli.core.commands.client_factory import get_subscription_id Snapshot, CreationData, DiskCreateOption, Encryption = cmd.get_models( @@ -759,7 +759,7 @@ def grant_snapshot_access(cmd, resource_group_name, snapshot_name, duration_in_s def update_snapshot(cmd, resource_group_name, instance, sku=None, disk_encryption_set=None, encryption_type=None, network_access_policy=None, disk_access=None, public_network_access=None, accelerated_network=None, architecture=None): - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id from azure.cli.core.commands.client_factory import get_subscription_id if sku is not None: @@ -913,7 +913,7 @@ def create_vm(cmd, vm_name, resource_group_name, image=None, size='Standard_DS1_ build_vm_linux_log_analytics_workspace_agent, build_vm_windows_log_analytics_workspace_agent) from azure.cli.command_modules.vm._vm_utils import ArmTemplateBuilder20190401 - from msrestazure.tools import resource_id, is_valid_resource_id, parse_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id, parse_resource_id # In the latest profile, the default public IP will be expected to be changed from Basic to Standard, # and Basic option will be removed. @@ -1241,7 +1241,7 @@ def create_vm(cmd, vm_name, resource_group_name, image=None, size='Standard_DS1_ def auto_shutdown_vm(cmd, resource_group_name, vm_name, off=None, email=None, webhook=None, time=None, location=None): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id from azure.mgmt.devtestlabs.models import Schedule from azure.cli.core.commands.client_factory import get_subscription_id subscription_id = get_subscription_id(cmd.cli_ctx) @@ -1300,7 +1300,7 @@ def get_vm_to_update(cmd, resource_group_name, vm_name): def get_vm_details(cmd, resource_group_name, vm_name, include_user_data=False): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id NicShow = import_aaz_by_profile(cmd.cli_ctx.cloud.profile, "network.nic").Show PublicIPShow = import_aaz_by_profile(cmd.cli_ctx.cloud.profile, "network.public_ip").Show @@ -1364,7 +1364,7 @@ def list_skus(cmd, location=None, size=None, zone=None, show_all=None, resource_ # pylint: disable=redefined-builtin def list_vm(cmd, resource_group_name=None, show_details=False, vmss=None): - from msrestazure.tools import resource_id, is_valid_resource_id, parse_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id, parse_resource_id from azure.cli.core.commands.client_factory import get_subscription_id ccf = _compute_client_factory(cmd.cli_ctx) if vmss is not None: @@ -1453,7 +1453,7 @@ def list_vm_ip_addresses(cmd, resource_group_name=None, vm_name=None): def open_vm_port(cmd, resource_group_name, vm_name, port, priority=900, network_security_group_name=None, apply_to_subnet=False): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id _nic = import_aaz_by_profile(cmd.cli_ctx.cloud.profile, "network.nic") NicShow, NicUpdate = _nic.Show, _nic.Update _subnet = import_aaz_by_profile(cmd.cli_ctx.cloud.profile, "network.vnet.subnet") @@ -1618,7 +1618,7 @@ def update_vm(cmd, resource_group_name, vm_name, os_disk=None, disk_caching=None dedicated_host=None, dedicated_host_group=None, size=None, ephemeral_os_disk_placement=None, enable_hibernation=None, v_cpus_available=None, v_cpus_per_core=None, disk_controller_type=None, security_type=None, enable_proxy_agent=None, proxy_agent_mode=None, **kwargs): - from msrestazure.tools import parse_resource_id, resource_id, is_valid_resource_id + from azure.mgmt.core.tools import parse_resource_id, resource_id, is_valid_resource_id from ._vm_utils import update_write_accelerator_settings, update_disk_caching SecurityProfile, UefiSettings = cmd.get_models('SecurityProfile', 'UefiSettings') vm = kwargs['parameters'] @@ -2038,7 +2038,7 @@ def show_default_diagnostics_configuration(is_windows_os=False): def attach_managed_data_disk(cmd, resource_group_name, vm_name, disk=None, ids=None, disks=None, new=False, sku=None, size_gb=1023, lun=None, caching=None, enable_write_accelerator=False): '''attach multiple managed disks''' - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id vm = get_vm_to_update(cmd, resource_group_name, vm_name) DataDisk, ManagedDiskParameters, DiskCreateOption = cmd.get_models( 'DataDisk', 'ManagedDiskParameters', 'DiskCreateOptionTypes') @@ -2486,7 +2486,7 @@ def get_terms(cmd, urn=None, publisher=None, offer=None, plan=None): # region VirtualMachines NetworkInterfaces (NICs) def show_vm_nic(cmd, resource_group_name, vm_name, nic): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id NicShow = import_aaz_by_profile(cmd.cli_ctx.cloud.profile, "network.nic").Show @@ -2870,7 +2870,7 @@ def get_vm_format_secret(cmd, secrets, certificate_store=None, keyvault=None, re def add_vm_secret(cmd, resource_group_name, vm_name, keyvault, certificate, certificate_store=None): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id from ._vm_utils import create_data_plane_keyvault_certificate_client, get_key_vault_base_url VaultSecretGroup, SubResource, VaultCertificate = cmd.get_models( 'VaultSecretGroup', 'SubResource', 'VaultCertificate') @@ -3206,7 +3206,7 @@ def create_vmss(cmd, vmss_name, resource_group_name, image=None, uniform_str = 'Uniform' flexible_str = 'Flexible' if orchestration_mode: - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id if disk_info: storage_sku = disk_info['os'].get('storageAccountType') @@ -3737,7 +3737,7 @@ def get_vmss_instance_view(cmd, resource_group_name, vm_scale_set_name, instance def list_vmss_instance_connection_info(cmd, resource_group_name, vm_scale_set_name): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id LBShow = import_aaz_by_profile(cmd.cli_ctx.cloud.profile, "network.lb").Show PublicIPAddress = import_aaz_by_profile(cmd.cli_ctx.cloud.profile, "network.public_ip").Show @@ -4838,7 +4838,7 @@ def create_image_version(cmd, resource_group_name, gallery_name, gallery_image_n replication_mode=None, target_region_cvm_encryption=None, virtual_machine=None, image_version=None, target_zone_encryption=None, target_edge_zones=None, allow_replicated_location_deletion=None): - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id from azure.cli.core.commands.client_factory import get_subscription_id ImageVersionPublishingProfile, GalleryArtifactSource, ManagedArtifact, ImageVersion, TargetRegion = cmd.get_models( @@ -5137,7 +5137,7 @@ def _get_log_analytics_client(cmd): def _prepare_workspace(cmd, resource_group_name, workspace): - from msrestazure.tools import is_valid_resource_id + from azure.mgmt.core.tools import is_valid_resource_id from azure.core.exceptions import HttpResponseError @@ -5242,7 +5242,7 @@ def create_disk_encryption_set( cmd, client, resource_group_name, disk_encryption_set_name, key_url, source_vault=None, encryption_type=None, location=None, tags=None, no_wait=False, enable_auto_key_rotation=None, federated_client_id=None, mi_system_assigned=None, mi_user_assigned=None): - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id from azure.cli.core.commands.client_factory import get_subscription_id DiskEncryptionSet, EncryptionSetIdentity, KeyForDiskEncryptionSet, SourceVault = cmd.get_models( 'DiskEncryptionSet', 'EncryptionSetIdentity', 'KeyForDiskEncryptionSet', 'SourceVault') @@ -5275,7 +5275,7 @@ def create_disk_encryption_set( def update_disk_encryption_set(cmd, instance, client, resource_group_name, key_url=None, source_vault=None, enable_auto_key_rotation=None, federated_client_id=None): - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id from azure.cli.core.commands.client_factory import get_subscription_id if key_url: instance.active_key.key_url = key_url diff --git a/src/azure-cli/azure/cli/command_modules/vm/disk_encryption.py b/src/azure-cli/azure/cli/command_modules/vm/disk_encryption.py index 4f57d799408..2943922e0cf 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/disk_encryption.py +++ b/src/azure-cli/azure/cli/command_modules/vm/disk_encryption.py @@ -71,7 +71,7 @@ def encrypt_vm(cmd, resource_group_name, vm_name, # pylint: disable=too-many-lo volume_type=None, encrypt_format_all=False, force=False): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id from knack.util import CLIError # pylint: disable=no-member @@ -390,7 +390,7 @@ def encrypt_vmss(cmd, resource_group_name, vmss_name, # pylint: disable=too-man key_encryption_algorithm='RSA-OAEP', volume_type=None, force=False): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id # pylint: disable=no-member UpgradeMode, VirtualMachineScaleSetExtension, VirtualMachineScaleSetExtensionProfile = cmd.get_models( @@ -547,7 +547,7 @@ def _report_client_side_validation_error(msg): from azure.cli.core.commands.client_factory import get_mgmt_service_client from azure.cli.core.profiles import ResourceType - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id client = get_mgmt_service_client(cli_ctx, ResourceType.MGMT_KEYVAULT).vaults disk_vault_resource_info = parse_resource_id(disk_vault_id) diff --git a/src/azure-cli/azure/cli/command_modules/vm/tests/hybrid_2018_03_01/test_vm_commands.py b/src/azure-cli/azure/cli/command_modules/vm/tests/hybrid_2018_03_01/test_vm_commands.py index fa8844d9ac5..04dbd6b7c1a 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/tests/hybrid_2018_03_01/test_vm_commands.py +++ b/src/azure-cli/azure/cli/command_modules/vm/tests/hybrid_2018_03_01/test_vm_commands.py @@ -1136,7 +1136,7 @@ class VMCreateExistingIdsOptions(ScenarioTest): @StorageAccountPreparer() def test_vm_create_existing_ids_options(self, resource_group, storage_account): from azure.cli.core.commands.client_factory import get_subscription_id - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id subscription_id = self.get_subscription_id() @@ -1700,7 +1700,7 @@ class VMSSCreateExistingIdsOptions(ScenarioTest): @ResourceGroupPreparer(name_prefix='cli_test_vmss_create_existing_ids') def test_vmss_create_existing_ids_options(self, resource_group): - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id subscription_id = self.get_subscription_id() self.kwargs.update({ diff --git a/src/azure-cli/azure/cli/command_modules/vm/tests/hybrid_2019_03_01/test_vm_commands.py b/src/azure-cli/azure/cli/command_modules/vm/tests/hybrid_2019_03_01/test_vm_commands.py index eac7c1030ee..457e968fc8b 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/tests/hybrid_2019_03_01/test_vm_commands.py +++ b/src/azure-cli/azure/cli/command_modules/vm/tests/hybrid_2019_03_01/test_vm_commands.py @@ -1329,7 +1329,7 @@ class VMCreateExistingIdsOptions(ScenarioTest): @StorageAccountPreparer() def test_vm_create_existing_ids_options(self, resource_group, storage_account): from azure.cli.core.commands.client_factory import get_subscription_id - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id subscription_id = self.get_subscription_id() @@ -1933,7 +1933,7 @@ class VMSSCreateExistingIdsOptions(ScenarioTest): @ResourceGroupPreparer(name_prefix='cli_test_vmss_create_existing_ids') def test_vmss_create_existing_ids_options(self, resource_group): - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id subscription_id = self.get_subscription_id() self.kwargs.update({ diff --git a/src/azure-cli/azure/cli/command_modules/vm/tests/hybrid_2020_09_01/test_vm_commands.py b/src/azure-cli/azure/cli/command_modules/vm/tests/hybrid_2020_09_01/test_vm_commands.py index c7b964267e5..0f689328461 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/tests/hybrid_2020_09_01/test_vm_commands.py +++ b/src/azure-cli/azure/cli/command_modules/vm/tests/hybrid_2020_09_01/test_vm_commands.py @@ -894,7 +894,7 @@ class VMCreateExistingIdsOptions(ScenarioTest): @StorageAccountPreparer() def test_vm_create_existing_ids_options(self, resource_group, storage_account): from azure.cli.core.commands.client_factory import get_subscription_id - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id subscription_id = self.get_subscription_id() @@ -1344,7 +1344,7 @@ class VMSSCreateExistingIdsOptions(ScenarioTest): @ResourceGroupPreparer(name_prefix='cli_test_vmss_create_existing_ids') def test_vmss_create_existing_ids_options(self, resource_group): - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id subscription_id = self.get_subscription_id() self.kwargs.update({ @@ -2208,7 +2208,7 @@ def test_ppg_update(self, resource_group): # # however, the CLI does not replace resource group values in payloads in the recordings. def _assert_ids_equal(self, id_1, id_2, rg_prefix=None): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id id_1, id_2, rg_prefix = id_1.lower(), id_2.lower(), rg_prefix.lower() if rg_prefix else rg_prefix diff --git a/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_image_builder_commands.py b/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_image_builder_commands.py index 93e5ec8972a..a0c6b6d7f5e 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_image_builder_commands.py +++ b/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_image_builder_commands.py @@ -8,7 +8,7 @@ from azure.core.exceptions import HttpResponseError from knack.util import CLIError -from msrestazure.tools import parse_resource_id +from azure.mgmt.core.tools import parse_resource_id from azure.cli.testsdk import ScenarioTest, ResourceGroupPreparer, StorageAccountPreparer from azure.cli.testsdk.scenario_tests import AllowLargeResponse diff --git a/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py b/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py index f3762b3595a..fdfa83c5340 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py +++ b/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py @@ -3301,7 +3301,7 @@ class VMCreateExistingIdsOptions(ScenarioTest): @StorageAccountPreparer() def test_vm_create_existing_ids_options(self, resource_group, storage_account): from azure.cli.core.commands.client_factory import get_subscription_id - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id subscription_id = self.get_subscription_id() @@ -5101,7 +5101,7 @@ class VMSSCreateExistingIdsOptions(ScenarioTest): @ResourceGroupPreparer(name_prefix='cli_test_vmss_create_existing_ids') def test_vmss_create_existing_ids_options(self, resource_group): - from msrestazure.tools import resource_id, is_valid_resource_id + from azure.mgmt.core.tools import resource_id, is_valid_resource_id subscription_id = self.get_subscription_id() self.kwargs.update({ @@ -6883,7 +6883,7 @@ def test_gallery_image_version_vhd(self, resource_group): @AllowLargeResponse() @ResourceGroupPreparer(name_prefix='cli_test_image_version_create_os_vhd') def test_image_version_create_os_vhd(self, resource_group): - from msrestazure.tools import resource_id + from azure.mgmt.core.tools import resource_id self.kwargs.update({ 'vm': 'myvm', @@ -7950,7 +7950,7 @@ def test_ppg_update(self, resource_group): # # however, the CLI does not replace resource group values in payloads in the recordings. def _assert_ids_equal(self, id_1, id_2, rg_prefix=None): - from msrestazure.tools import parse_resource_id + from azure.mgmt.core.tools import parse_resource_id id_1, id_2, rg_prefix = id_1.lower(), id_2.lower(), rg_prefix.lower() if rg_prefix else rg_prefix From efbb8b6571ad13ce23a91fc8310d3626994aa9b2 Mon Sep 17 00:00:00 2001 From: Yishi Wang Date: Fri, 6 Sep 2024 17:23:46 +0800 Subject: [PATCH 2/4] fix tests --- .../cli/command_modules/acs/tests/latest/test_helpers.py | 4 ++-- .../appservice/tests/latest/test_webapp_commands_thru_mock.py | 4 ++-- .../cli/command_modules/dls/tests/latest/test_dls_commands.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py index 369f91160b0..3ca168ade7f 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_helpers.py @@ -324,7 +324,7 @@ def test_get_user_assigned_identity(self): ) self.assertEqual(user_assigned_identity, mock_user_assigned_identity) - cloud_error_2 = HttpResponseError(Mock(status_code="xxx"), "mock user assigned identity was not found") + cloud_error_2 = HttpResponseError(response=Mock(status_code="xxx", reason="mock user assigned identity was not found")) mock_user_assigned_identity_operations_2 = Mock( user_assigned_identities=Mock(get=Mock(side_effect=cloud_error_2)) ) @@ -334,7 +334,7 @@ def test_get_user_assigned_identity(self): ), self.assertRaises(ResourceNotFoundError): get_user_assigned_identity("mock_cli_ctx", "mock_sub_id", "mock_rg", "mock_identity_name") - cloud_error_3 = HttpResponseError(Mock(status_code="xxx"), "test_error_msg") + cloud_error_3 = HttpResponseError(response=Mock(status_code="xxx", reason="test_error_msg")) mock_user_assigned_identity_operations_3 = Mock( user_assigned_identities=Mock(get=Mock(side_effect=cloud_error_3)) ) diff --git a/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_webapp_commands_thru_mock.py b/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_webapp_commands_thru_mock.py index d59f6698a65..fdc7eda995c 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_webapp_commands_thru_mock.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_webapp_commands_thru_mock.py @@ -266,8 +266,8 @@ def test_show_webapp(self, file_ftp_mock, rename_mock, is_centauri_functionapp_m @mock.patch('azure.cli.command_modules.appservice.custom._generic_site_operation', autospec=True) def test_sync_repository_skip_bad_error(self, site_op_mock): resp = FakedResponse(200) # because of bad spec, sdk throws on 200. - setattr(resp, 'text', '{"Message": ""}') - site_op_mock.side_effect = HttpResponseError(resp, error="bad error") + setattr(resp, 'reason', 'bad error') + site_op_mock.side_effect = HttpResponseError(response=resp) # action sync_site_repo(mock.MagicMock(), 'myRG', 'myweb') # assert diff --git a/src/azure-cli/azure/cli/command_modules/dls/tests/latest/test_dls_commands.py b/src/azure-cli/azure/cli/command_modules/dls/tests/latest/test_dls_commands.py index eb457fff2a6..33a1ee417a3 100644 --- a/src/azure-cli/azure/cli/command_modules/dls/tests/latest/test_dls_commands.py +++ b/src/azure-cli/azure/cli/command_modules/dls/tests/latest/test_dls_commands.py @@ -8,7 +8,7 @@ import os import time from shutil import rmtree -from azure.core.exceptions import HttpResponseError +from msrestazure.azure_exceptions import CloudError from azure.cli.testsdk import ScenarioTest, ResourceGroupPreparer, LiveScenarioTest, VirtualNetworkPreparer from azure.cli.testsdk.scenario_tests import AllowLargeResponse @@ -326,7 +326,7 @@ def test_dls_account_mgmt(self, resource_group): ]) # attempt to enable the key vault when it is already enabled, which should throw - with self.assertRaises(HttpResponseError): + with self.assertRaises(CloudError): self.cmd('dls account enable-key-vault -n {dls} -g {rg}') self.cmd('dls account list -g {rg}', checks=[ From bbac861272e88e9aa7108b0ed730dd3a26ff8bf8 Mon Sep 17 00:00:00 2001 From: Yishi Wang Date: Mon, 9 Sep 2024 16:39:18 +0800 Subject: [PATCH 3/4] cli-core and cli-testsdk --- src/azure-cli-core/azure/cli/core/util.py | 5 ++--- src/azure-cli-testsdk/azure/cli/testsdk/preparers.py | 4 ++-- src/azure-cli/azure/cli/command_modules/acr/_run_polling.py | 2 +- .../azure/cli/command_modules/acs/addonconfiguration.py | 2 +- .../cli/command_modules/acs/managed_cluster_decorator.py | 2 +- .../azure/cli/command_modules/appservice/_validators.py | 2 +- .../cli/command_modules/appservice/access_restrictions.py | 2 +- .../cli/command_modules/appservice/appservice_environment.py | 2 +- .../azure/cli/command_modules/appservice/static_sites.py | 2 +- .../azure/cli/command_modules/aro/_dynamic_validators.py | 5 ++--- src/azure-cli/azure/cli/command_modules/aro/_rbac.py | 2 +- src/azure-cli/azure/cli/command_modules/aro/_validators.py | 2 +- src/azure-cli/azure/cli/command_modules/aro/custom.py | 4 ++-- src/azure-cli/azure/cli/command_modules/cdn/custom/custom.py | 2 +- .../azure/cli/command_modules/containerapp/_up_utils.py | 3 +-- .../azure/cli/command_modules/containerapp/_utils.py | 2 +- .../command_modules/containerapp/containerapp_decorator.py | 2 +- .../azure/cli/command_modules/containerapp/custom.py | 2 +- src/azure-cli/azure/cli/command_modules/eventgrid/custom.py | 2 +- src/azure-cli/azure/cli/command_modules/iot/custom.py | 1 - .../cli/command_modules/monitor/operations/metric_alert.py | 2 +- .../command_modules/monitor/operations/monitor_clone_util.py | 2 +- src/azure-cli/azure/cli/command_modules/mysql/_network.py | 2 +- .../azure/cli/command_modules/network/azure_stack/custom.py | 5 +---- src/azure-cli/azure/cli/command_modules/rdbms/custom.py | 2 +- .../command_modules/rdbms/flexible_server_custom_postgres.py | 2 +- .../command_modules/rdbms/flexible_server_virtual_network.py | 2 +- .../azure/cli/command_modules/servicefabric/_validators.py | 2 +- .../azure/cli/command_modules/servicefabric/custom.py | 2 +- src/azure-cli/azure/cli/command_modules/sqlvm/custom.py | 4 +--- 30 files changed, 33 insertions(+), 42 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/util.py b/src/azure-cli-core/azure/cli/core/util.py index 3366aa8e14c..041225223bf 100644 --- a/src/azure-cli-core/azure/cli/core/util.py +++ b/src/azure-cli-core/azure/cli/core/util.py @@ -56,10 +56,9 @@ def handle_exception(ex): # pylint: disable=too-many-locals, too-many-statements, too-many-branches # For error code, follow guidelines at https://docs.python.org/2/library/sys.html#sys.exit, from jmespath.exceptions import JMESPathError - from msrestazure.azure_exceptions import CloudError from msrest.exceptions import HttpOperationError, ValidationError, ClientRequestError from azure.common import AzureException - from azure.core.exceptions import AzureError, ServiceRequestError + from azure.core.exceptions import AzureError, ServiceRequestError, HttpResponseError from requests.exceptions import SSLError, HTTPError from azure.cli.core import azclierror from msal_extensions.persistence import PersistenceError @@ -83,7 +82,7 @@ def handle_exception(ex): # pylint: disable=too-many-locals, too-many-statement az_error = azclierror.AzureConnectionError(error_msg) az_error.set_recommendation(SSLERROR_TEMPLATE) - elif isinstance(ex, CloudError): + elif isinstance(ex, HttpResponseError): if extract_common_error_message(ex): error_msg = extract_common_error_message(ex) status_code = str(getattr(ex, 'status_code', 'Unknown Code')) diff --git a/src/azure-cli-testsdk/azure/cli/testsdk/preparers.py b/src/azure-cli-testsdk/azure/cli/testsdk/preparers.py index dc6e7f41bda..926923a63eb 100644 --- a/src/azure-cli-testsdk/azure/cli/testsdk/preparers.py +++ b/src/azure-cli-testsdk/azure/cli/testsdk/preparers.py @@ -432,12 +432,12 @@ def create_resource(self, name, **kwargs): def remove_resource(self, name, **kwargs): if not self.dev_setting_name: - from msrestazure.azure_exceptions import CloudError + from azure.core.exceptions import HttpResponseError try: self.live_only_execute( self.cli_ctx, 'az network vnet delete --name {} --resource-group {}'.format(name, self._get_resource_group(**kwargs))) - except CloudError: + except HttpResponseError: # deletion of vnet may fail as service could create subresources like IPConfig. We could rely on the deletion of resource group to delete the vnet. pass diff --git a/src/azure-cli/azure/cli/command_modules/acr/_run_polling.py b/src/azure-cli/azure/cli/command_modules/acr/_run_polling.py index 7117b21199b..ad2d6020205 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_run_polling.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_run_polling.py @@ -6,8 +6,8 @@ import time from azure.core.polling import PollingMethod, LROPoller -from msrest import Deserializer from azure.core.exceptions import HttpResponseError +from msrest import Deserializer from ._constants import get_acr_task_models, get_finished_run_status, get_succeeded_run_status diff --git a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py index c21a8a6a250..0c6b0083fac 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py +++ b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py @@ -23,8 +23,8 @@ from azure.cli.core.profiles import ResourceType from azure.cli.core.util import send_raw_request from azure.core.exceptions import HttpResponseError -from knack.log import get_logger from azure.mgmt.core.tools import parse_resource_id, resource_id +from knack.log import get_logger logger = get_logger(__name__) # mapping for azure public cloud diff --git a/src/azure-cli/azure/cli/command_modules/acs/managed_cluster_decorator.py b/src/azure-cli/azure/cli/command_modules/acs/managed_cluster_decorator.py index ff1b17c6951..e93f122536a 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/managed_cluster_decorator.py +++ b/src/azure-cli/azure/cli/command_modules/acs/managed_cluster_decorator.py @@ -107,10 +107,10 @@ from azure.cli.core.profiles import ResourceType from azure.cli.core.util import sdk_no_wait, truncate_text, get_file_json from azure.core.exceptions import HttpResponseError +from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id from knack.log import get_logger from knack.prompting import NoTTYException, prompt, prompt_pass, prompt_y_n from knack.util import CLIError -from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id logger = get_logger(__name__) diff --git a/src/azure-cli/azure/cli/command_modules/appservice/_validators.py b/src/azure-cli/azure/cli/command_modules/appservice/_validators.py index ab2ed4e4bc9..a3b8ed826a3 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/_validators.py @@ -10,9 +10,9 @@ ResourceNotFoundError, ValidationError, MutuallyExclusiveArgumentError) from azure.cli.core.commands.client_factory import get_mgmt_service_client, get_subscription_id from azure.cli.core.commands.validators import validate_tags +from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id from knack.log import get_logger -from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id from ._appservice_utils import _generic_site_operation from ._client_factory import web_client_factory diff --git a/src/azure-cli/azure/cli/command_modules/appservice/access_restrictions.py b/src/azure-cli/azure/cli/command_modules/appservice/access_restrictions.py index 639a81747aa..378dc166523 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/access_restrictions.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/access_restrictions.py @@ -9,10 +9,10 @@ MutuallyExclusiveArgumentError) from azure.cli.core.commands import LongRunningOperation from azure.cli.core.commands.client_factory import get_subscription_id +from azure.mgmt.core.tools import is_valid_resource_id, resource_id, parse_resource_id from azure.mgmt.web.models import IpSecurityRestriction from importlib import import_module from knack.log import get_logger -from azure.mgmt.core.tools import is_valid_resource_id, resource_id, parse_resource_id from ._appservice_utils import _generic_site_operation from .custom import get_site_configs diff --git a/src/azure-cli/azure/cli/command_modules/appservice/appservice_environment.py b/src/azure-cli/azure/cli/command_modules/appservice/appservice_environment.py index 3bcb5ac5b6f..b387e31fdcb 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/appservice_environment.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/appservice_environment.py @@ -13,6 +13,7 @@ from azure.mgmt.privatedns.models import (PrivateZone, VirtualNetworkLink, RecordSet, ARecord) # Utils +from azure.mgmt.core.tools import (parse_resource_id, is_valid_resource_id, resource_id) from azure.cli.core.commands import LongRunningOperation from azure.cli.core.commands.client_factory import (get_mgmt_service_client, get_subscription_id) from azure.cli.core.commands.arm import ArmTemplateBuilder @@ -21,7 +22,6 @@ MutuallyExclusiveArgumentError) from importlib import import_module from knack.log import get_logger -from azure.mgmt.core.tools import (parse_resource_id, is_valid_resource_id, resource_id) VERSION_2019_08_01 = "2019-08-01" VERSION_2019_10_01 = "2019-10-01" diff --git a/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py b/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py index 07556462862..14644d9a731 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py @@ -10,8 +10,8 @@ from azure.cli.core.commands import LongRunningOperation from azure.cli.core.azclierror import (ResourceNotFoundError, ValidationError, RequiredArgumentMissingError, InvalidArgumentValueError, UnauthorizedError) -from knack.log import get_logger from azure.mgmt.core.tools import parse_resource_id +from knack.log import get_logger from urllib.parse import urlparse import uuid from datetime import datetime, timedelta diff --git a/src/azure-cli/azure/cli/command_modules/aro/_dynamic_validators.py b/src/azure-cli/azure/cli/command_modules/aro/_dynamic_validators.py index b9177c791e5..e1d156042ce 100644 --- a/src/azure-cli/azure/cli/command_modules/aro/_dynamic_validators.py +++ b/src/azure-cli/azure/cli/command_modules/aro/_dynamic_validators.py @@ -17,10 +17,9 @@ from azure.cli.core.profiles import ResourceType from azure.cli.core.azclierror import CLIInternalError, InvalidArgumentValueError, \ RequiredArgumentMissingError -from azure.core.exceptions import ResourceNotFoundError -from knack.log import get_logger +from azure.core.exceptions import ResourceNotFoundError, HttpResponseError from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id -from azure.core.exceptions import HttpResponseError +from knack.log import get_logger import azure.cli.command_modules.aro.custom diff --git a/src/azure-cli/azure/cli/command_modules/aro/_rbac.py b/src/azure-cli/azure/cli/command_modules/aro/_rbac.py index f239882c10a..590894218aa 100644 --- a/src/azure-cli/azure/cli/command_modules/aro/_rbac.py +++ b/src/azure-cli/azure/cli/command_modules/aro/_rbac.py @@ -9,9 +9,9 @@ from azure.cli.core.commands.client_factory import get_subscription_id from azure.cli.core.profiles import get_sdk from azure.cli.core.profiles import ResourceType +from azure.mgmt.core.tools import resource_id from knack.log import get_logger from msrest.exceptions import ValidationError -from azure.mgmt.core.tools import resource_id ROLE_NETWORK_CONTRIBUTOR = '4d97b98b-1d4f-4787-a291-c67834d212e7' ROLE_READER = 'acdd72a7-3385-48ef-bd42-f606fba81ae7' diff --git a/src/azure-cli/azure/cli/command_modules/aro/_validators.py b/src/azure-cli/azure/cli/command_modules/aro/_validators.py index ee04d103e2f..e512ff1491b 100644 --- a/src/azure-cli/azure/cli/command_modules/aro/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/aro/_validators.py @@ -15,8 +15,8 @@ from azure.cli.core.azclierror import CLIInternalError, InvalidArgumentValueError, \ RequiredArgumentMissingError from azure.core.exceptions import ResourceNotFoundError, HttpResponseError -from knack.log import get_logger from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id, resource_id +from knack.log import get_logger logger = get_logger(__name__) diff --git a/src/azure-cli/azure/cli/command_modules/aro/custom.py b/src/azure-cli/azure/cli/command_modules/aro/custom.py index 64a161ac469..93a427b60c2 100644 --- a/src/azure-cli/azure/cli/command_modules/aro/custom.py +++ b/src/azure-cli/azure/cli/command_modules/aro/custom.py @@ -8,6 +8,8 @@ from base64 import b64decode import textwrap +from azure.core.exceptions import HttpResponseError +from azure.mgmt.core.tools import resource_id, parse_resource_id import azure.mgmt.redhatopenshift.models as openshiftcluster from azure.cli.core.commands.client_factory import get_mgmt_service_client @@ -27,8 +29,6 @@ from knack.log import get_logger -from azure.core.exceptions import HttpResponseError -from azure.mgmt.core.tools import resource_id, parse_resource_id from msrest.exceptions import HttpOperationError from tabulate import tabulate diff --git a/src/azure-cli/azure/cli/command_modules/cdn/custom/custom.py b/src/azure-cli/azure/cli/command_modules/cdn/custom/custom.py index 6a353cab597..ff7a19195d3 100644 --- a/src/azure-cli/azure/cli/command_modules/cdn/custom/custom.py +++ b/src/azure-cli/azure/cli/command_modules/cdn/custom/custom.py @@ -43,6 +43,7 @@ from azure.mgmt.cdn.models._cdn_management_client_enums import CacheType from azure.mgmt.cdn.operations import (OriginsOperations, OriginGroupsOperations) +from azure.mgmt.core.tools import is_valid_resource_id from azure.cli.core.commands.client_factory import get_subscription_id from azure.cli.core.util import (sdk_no_wait) @@ -53,7 +54,6 @@ from knack.log import get_logger from msrest.polling import LROPoller, NoPolling -from azure.mgmt.core.tools import is_valid_resource_id logger = get_logger(__name__) diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/_up_utils.py b/src/azure-cli/azure/cli/command_modules/containerapp/_up_utils.py index 6dd0269842c..81e7b2c662d 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/_up_utils.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/_up_utils.py @@ -24,9 +24,8 @@ from azure.cli.command_modules.acr.custom import acr_show from azure.cli.core.commands.client_factory import get_mgmt_service_client from azure.mgmt.containerregistry import ContainerRegistryManagementClient -from knack.log import get_logger - from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id, resource_id +from knack.log import get_logger from ._clients import ManagedEnvironmentClient, ContainerAppClient, GitHubActionClient, ContainerAppsJobClient diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/_utils.py b/src/azure-cli/azure/cli/command_modules/containerapp/_utils.py index 4e3d83c976f..22ea0ab0cc8 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/_utils.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/_utils.py @@ -37,9 +37,9 @@ from azure.mgmt.containerregistry import ContainerRegistryManagementClient from azure.mgmt.resource import ResourceManagementClient from azure.mgmt.servicelinker import ServiceLinkerManagementClient +from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id, resource_id from knack.log import get_logger -from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id, resource_id from ._clients import ContainerAppClient, ManagedEnvironmentClient, WorkloadProfileClient, ContainerAppsJobClient from ._client_factory import handle_raw_exception, providers_client_factory, cf_resource_groups, log_analytics_client_factory, log_analytics_shared_key_client_factory diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/containerapp_decorator.py b/src/azure-cli/azure/cli/command_modules/containerapp/containerapp_decorator.py index 0ff45d2c491..1d3071614e0 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/containerapp_decorator.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/containerapp_decorator.py @@ -14,11 +14,11 @@ RequiredArgumentMissingError, ValidationError) from azure.cli.core.commands.client_factory import get_subscription_id +from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id from knack.log import get_logger from knack.util import CLIError -from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id from msrest.exceptions import DeserializationError from .base_resource import BaseResource diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/custom.py b/src/azure-cli/azure/cli/command_modules/containerapp/custom.py index c7ac7d26e2f..e9167daa0e5 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/custom.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/custom.py @@ -23,10 +23,10 @@ MutuallyExclusiveArgumentError) from azure.cli.core.commands.client_factory import get_subscription_id from azure.cli.core.util import open_page_in_browser +from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id from knack.log import get_logger from knack.prompting import prompt_y_n, prompt as prompt_str -from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id from msrest.exceptions import DeserializationError from .containerapp_job_decorator import ContainerAppJobDecorator, ContainerAppJobCreateDecorator diff --git a/src/azure-cli/azure/cli/command_modules/eventgrid/custom.py b/src/azure-cli/azure/cli/command_modules/eventgrid/custom.py index 3a9601b2f16..26fd4e7e270 100644 --- a/src/azure-cli/azure/cli/command_modules/eventgrid/custom.py +++ b/src/azure-cli/azure/cli/command_modules/eventgrid/custom.py @@ -8,10 +8,10 @@ import re from knack.log import get_logger from knack.util import CLIError -from azure.mgmt.core.tools import parse_resource_id from dateutil.parser import parse # pylint: disable=import-error,relative-import from azure.cli.core.azclierror import MutuallyExclusiveArgumentError +from azure.mgmt.core.tools import parse_resource_id from azure.mgmt.eventgrid.models import ( EventSubscription, EventSubscriptionUpdateParameters, diff --git a/src/azure-cli/azure/cli/command_modules/iot/custom.py b/src/azure-cli/azure/cli/command_modules/iot/custom.py index 54c8b652a61..d6e0ea12dd2 100644 --- a/src/azure-cli/azure/cli/command_modules/iot/custom.py +++ b/src/azure-cli/azure/cli/command_modules/iot/custom.py @@ -1529,7 +1529,6 @@ def get_private_endpoint_connection(client, resource_group_name=None, connection def _update_private_endpoint_connection_status(client, resource_group_name, account_name, connection_id, private_endpoint_connection_name, is_approved=True, description=None): # pylint: disable=unused-argument - from azure.core.exceptions import HttpResponseError getInfoArr = get_private_endpoint_connection(client, resource_group_name=resource_group_name, connection_id=connection_id, diff --git a/src/azure-cli/azure/cli/command_modules/monitor/operations/metric_alert.py b/src/azure-cli/azure/cli/command_modules/monitor/operations/metric_alert.py index 088a09f1cba..f1b21be8a4e 100644 --- a/src/azure-cli/azure/cli/command_modules/monitor/operations/metric_alert.py +++ b/src/azure-cli/azure/cli/command_modules/monitor/operations/metric_alert.py @@ -10,9 +10,9 @@ MetricAlertConditionParser, MetricAlertConditionValidator from azure.cli.core.aaz import has_value from azure.cli.core.azclierror import InvalidArgumentValueError +from azure.mgmt.core.tools import is_valid_resource_id, resource_id from knack.log import get_logger from msrest.serialization import Serializer -from azure.mgmt.core.tools import is_valid_resource_id, resource_id from ..aaz.latest.monitor.metrics.alert import Update as _MetricsAlertUpdate diff --git a/src/azure-cli/azure/cli/command_modules/monitor/operations/monitor_clone_util.py b/src/azure-cli/azure/cli/command_modules/monitor/operations/monitor_clone_util.py index 1bfd7c099ce..89f7c2677bf 100644 --- a/src/azure-cli/azure/cli/command_modules/monitor/operations/monitor_clone_util.py +++ b/src/azure-cli/azure/cli/command_modules/monitor/operations/monitor_clone_util.py @@ -3,9 +3,9 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- # pylint: disable=line-too-long, protected-access -from azure.mgmt.core.tools import parse_resource_id from knack.log import get_logger from knack.util import CLIError +from azure.mgmt.core.tools import parse_resource_id from azure.cli.core.commands.transform import _parse_id from azure.cli.command_modules.network.custom import _convert_to_snake_case from azure.cli.command_modules.monitor.util import gen_guid diff --git a/src/azure-cli/azure/cli/command_modules/mysql/_network.py b/src/azure-cli/azure/cli/command_modules/mysql/_network.py index f8ec98bcf1e..aa13fa31ac1 100644 --- a/src/azure-cli/azure/cli/command_modules/mysql/_network.py +++ b/src/azure-cli/azure/cli/command_modules/mysql/_network.py @@ -5,12 +5,12 @@ # pylint: disable=unused-argument, line-too-long, import-outside-toplevel from requests import get -from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id, is_valid_resource_name, resource_id # pylint: disable=import-error from knack.log import get_logger from azure.cli.core.commands import LongRunningOperation from azure.cli.core.commands.client_factory import get_subscription_id from azure.cli.core.util import CLIError, user_confirmation from azure.cli.core.azclierror import ValidationError +from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id, is_valid_resource_name, resource_id from azure.mgmt.privatedns.models import PrivateZone from azure.mgmt.privatedns.models import SubResource from azure.mgmt.privatedns.models import VirtualNetworkLink diff --git a/src/azure-cli/azure/cli/command_modules/network/azure_stack/custom.py b/src/azure-cli/azure/cli/command_modules/network/azure_stack/custom.py index 9e04a803a93..668e07f2e46 100644 --- a/src/azure-cli/azure/cli/command_modules/network/azure_stack/custom.py +++ b/src/azure-cli/azure/cli/command_modules/network/azure_stack/custom.py @@ -3,11 +3,8 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- from collections import Counter, OrderedDict - -from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id, resource_id - from knack.log import get_logger - +from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id, resource_id # pylint: disable=no-self-use,no-member,too-many-lines,unused-argument, line-too-long from azure.cli.core.commands.client_factory import get_subscription_id, get_mgmt_service_client diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/custom.py b/src/azure-cli/azure/cli/command_modules/rdbms/custom.py index 4a300ed062b..b71cbb72999 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/custom.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/custom.py @@ -8,7 +8,6 @@ from importlib import import_module import re from dateutil.tz import tzutc # pylint: disable=import-error -from azure.mgmt.core.tools import resource_id, is_valid_resource_id, parse_resource_id # pylint: disable=import-error from knack.log import get_logger from knack.util import todict from urllib.request import urlretrieve @@ -17,6 +16,7 @@ from azure.cli.core.commands.client_factory import get_subscription_id from azure.cli.core.util import CLIError, sdk_no_wait from azure.cli.core.local_context import ALL +from azure.mgmt.core.tools import resource_id, is_valid_resource_id, parse_resource_id from azure.mgmt.rdbms import postgresql, mysql, mariadb from azure.mgmt.rdbms.mysql.operations._servers_operations import ServersOperations as MySqlServersOperations from azure.mgmt.rdbms.postgresql.operations._location_based_performance_tier_operations import LocationBasedPerformanceTierOperations as PostgreSQLLocationOperations diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_postgres.py b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_postgres.py index cbf7408c415..e1c885e0997 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_postgres.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_postgres.py @@ -12,12 +12,12 @@ from urllib.request import urlretrieve from dateutil.tz import tzutc # pylint: disable=import-error import uuid -from azure.mgmt.core.tools import resource_id, is_valid_resource_id, parse_resource_id # pylint: disable=import-error from knack.log import get_logger from azure.cli.core.commands.client_factory import get_subscription_id from azure.cli.core.local_context import ALL from azure.cli.core.util import CLIError, sdk_no_wait, user_confirmation from azure.core.exceptions import HttpResponseError, ResourceNotFoundError +from azure.mgmt.core.tools import resource_id, is_valid_resource_id, parse_resource_id from azure.cli.core.azclierror import BadRequestError, FileOperationError, MutuallyExclusiveArgumentError, RequiredArgumentMissingError, ArgumentUsageError, InvalidArgumentValueError from azure.mgmt.rdbms import postgresql_flexibleservers from ._client_factory import cf_postgres_flexible_firewall_rules, get_postgresql_flexible_management_client, \ diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_virtual_network.py b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_virtual_network.py index 51cab375c2f..f3ec944e82c 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_virtual_network.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_virtual_network.py @@ -5,8 +5,8 @@ # pylint: disable=unused-argument, line-too-long, import-outside-toplevel from requests import get -from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id, is_valid_resource_name, resource_id # pylint: disable=import-error from knack.log import get_logger +from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id, is_valid_resource_name, resource_id # pylint: disable=import-error from azure.cli.core.commands import LongRunningOperation from azure.cli.core.commands.client_factory import get_subscription_id from azure.cli.core.util import CLIError, user_confirmation diff --git a/src/azure-cli/azure/cli/command_modules/servicefabric/_validators.py b/src/azure-cli/azure/cli/command_modules/servicefabric/_validators.py index a9e5f9375c2..5bc64c0bdc2 100644 --- a/src/azure-cli/azure/cli/command_modules/servicefabric/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/servicefabric/_validators.py @@ -3,9 +3,9 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from azure.core.exceptions import HttpResponseError from knack.log import get_logger from knack.util import CLIError +from azure.core.exceptions import HttpResponseError from azure.cli.core.azclierror import ValidationError from azure.cli.core.commands.validators import validate_tags from azure.cli.command_modules.servicefabric._sf_utils import _get_resource_group_by_name diff --git a/src/azure-cli/azure/cli/command_modules/servicefabric/custom.py b/src/azure-cli/azure/cli/command_modules/servicefabric/custom.py index cf706d44eb9..6a5e878d356 100644 --- a/src/azure-cli/azure/cli/command_modules/servicefabric/custom.py +++ b/src/azure-cli/azure/cli/command_modules/servicefabric/custom.py @@ -1657,7 +1657,7 @@ def _get_current_user_object_id(graph_client): current_user = graph_client.signed_in_user.get() if current_user and current_user.object_id: # pylint:disable=no-member return current_user.object_id # pylint:disable=no-member - except CloudError: + except HttpResponseError: pass diff --git a/src/azure-cli/azure/cli/command_modules/sqlvm/custom.py b/src/azure-cli/azure/cli/command_modules/sqlvm/custom.py index c545e28fb92..fc97c06cc81 100644 --- a/src/azure-cli/azure/cli/command_modules/sqlvm/custom.py +++ b/src/azure-cli/azure/cli/command_modules/sqlvm/custom.py @@ -2,8 +2,6 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- - -from azure.mgmt.core.tools import is_valid_resource_id, resource_id from knack.prompting import prompt_pass from azure.cli.core.azclierror import ( RequiredArgumentMissingError, @@ -14,7 +12,7 @@ from azure.cli.core.util import ( sdk_no_wait ) - +from azure.mgmt.core.tools import is_valid_resource_id, resource_id from azure.mgmt.sqlvirtualmachine.models import ( WsfcDomainProfile, SqlVirtualMachineGroup, From e9ac45b4fed5accdb73fb16b303827ae75368d25 Mon Sep 17 00:00:00 2001 From: Yishi Wang Date: Tue, 10 Sep 2024 12:47:06 +0800 Subject: [PATCH 4/4] fix core test --- .../azure/cli/core/tests/test_util.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/tests/test_util.py b/src/azure-cli-core/azure/cli/core/tests/test_util.py index 9393f754a84..dfbbd529966 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_util.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_util.py @@ -486,21 +486,19 @@ def test_handle_exception_clierror(self, mock_logger_error): self.assertEqual(ex_result, 1) @mock.patch('azure.cli.core.azclierror.logger.error', autospec=True) - def test_handle_exception_clouderror(self, mock_logger_error): - from msrestazure.azure_exceptions import CloudError + def test_handle_exception_httpresponseerror(self, mock_logger_error): + from azure.core.exceptions import HttpResponseError - # create test CloudError Exception - err_detail = "There was a Cloud Error." - err_msg = "CloudError" - mock_cloud_error = mock.MagicMock(spec=CloudError) - mock_cloud_error.args = (err_detail, err_msg) + # create test HttpResponseError Exception + mock_http_response_error = HttpResponseError(response=mock.MagicMock(status_code="xxx", + reason="There was a Http Response Error.")) # call handle_exception - ex_result = handle_exception(mock_cloud_error) + ex_result = handle_exception(mock_http_response_error) # test behavior self.assertTrue(mock_logger_error.called) - self.assertIn(mock_cloud_error.args[0], mock_logger_error.call_args[0][0]) + self.assertIn(mock_http_response_error.args[0], mock_logger_error.call_args[0][0]) self.assertEqual(ex_result, 1) @mock.patch('azure.cli.core.azclierror.logger.error', autospec=True)