-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add compatible logic for the track 2 migration of resource #3355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -201,9 +201,11 @@ def create_connectedk8s(cmd, client, resource_group_name, cluster_name, https_pr | |||
|
|
||||
| # Resource group Creation | ||||
| if resource_group_exists(cmd.cli_ctx, resource_group_name, subscription_id) is False: | ||||
| resource_group_params = {'location': location} | ||||
| from azure.cli.core.profiles import ResourceType | ||||
| ResourceGroup = cmd.get_models('ResourceGroup', resource_type=ResourceType.MGMT_RESOURCE_RESOURCES) | ||||
| parameters = ResourceGroup(location=location) | ||||
| try: | ||||
| resourceClient.resource_groups.create_or_update(resource_group_name, resource_group_params) | ||||
| resourceClient.resource_groups.create_or_update(resource_group_name, parameters) | ||||
|
||||
| providerDetails = resourceClient.providers.get('Microsoft.Kubernetes') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your reminder~ In fact, I know it. However, there is no breaking change for this operation (code link), so no additional compatibility logic is required.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,18 +98,16 @@ def _invoke_deployment(cmd, resource_group_name, deployment_name, template, para | |
| logger.info(json.dumps(template, indent=2)) | ||
| logger.info('==== END TEMPLATE ====') | ||
|
|
||
| if cmd.supported_api_version(min_api='2019-10-01', resource_type=ResourceType.MGMT_RESOURCE_RESOURCES): | ||
| deployment_temp = cmd.get_models('Deployment', resource_type=ResourceType.MGMT_RESOURCE_RESOURCES) | ||
| deployment = deployment_temp(properties=properties) | ||
|
|
||
| if validate: | ||
| validation_poller = smc.validate(resource_group_name, deployment_name, deployment) | ||
| deployment_temp = cmd.get_models('Deployment', resource_type=ResourceType.MGMT_RESOURCE_RESOURCES) | ||
| deployment = deployment_temp(properties=properties) | ||
| if validate: | ||
| if cmd.supported_api_version(min_api='2019-10-01', resource_type=ResourceType.MGMT_RESOURCE_RESOURCES): | ||
| validation_poller = smc.begin_validate(resource_group_name, deployment_name, deployment) | ||
| return LongRunningOperation(cmd.cli_ctx)(validation_poller) | ||
| return sdk_no_wait(no_wait, smc.create_or_update, resource_group_name, deployment_name, deployment) | ||
| else: | ||
| return smc.validate(resource_group_name, deployment_name, deployment) | ||
|
|
||
| if validate: | ||
| return smc.validate(resource_group_name, deployment_name, properties) | ||
| return sdk_no_wait(no_wait, smc.create_or_update, resource_group_name, deployment_name, properties) | ||
| return sdk_no_wait(no_wait, smc.begin_create_or_update, resource_group_name, deployment_name, deployment) | ||
|
||
|
|
||
|
|
||
| def _ensure_default_log_analytics_workspace_for_monitoring(cmd, subscription_id, | ||
|
|
@@ -201,6 +199,9 @@ def _ensure_default_log_analytics_workspace_for_monitoring(cmd, subscription_id, | |
| "usgovvirginia": "usgovvirginia" | ||
| } | ||
|
|
||
| from azure.core.exceptions import HttpResponseError | ||
| from azure.cli.core.profiles import ResourceType | ||
|
|
||
| cluster_location = '' | ||
| resources = cf_resources(cmd.cli_ctx, subscription_id) | ||
|
|
||
|
|
@@ -209,7 +210,7 @@ def _ensure_default_log_analytics_workspace_for_monitoring(cmd, subscription_id, | |
| try: | ||
| resource = resources.get_by_id(cluster_resource_id, '2020-01-01-preview') | ||
| cluster_location = resource.location.lower() | ||
| except CloudError as ex: | ||
| except HttpResponseError as ex: | ||
| raise ex | ||
|
|
||
| cloud_name = cmd.cli_ctx.cloud.name.lower() | ||
|
|
@@ -261,23 +262,18 @@ def _ensure_default_log_analytics_workspace_for_monitoring(cmd, subscription_id, | |
| try: | ||
| resource = resources.get_by_id(default_workspace_resource_id, '2015-11-01-preview') | ||
| return resource.id | ||
| except CloudError as ex: | ||
| except HttpResponseError as ex: | ||
| if ex.status_code != 404: | ||
| raise ex | ||
| else: | ||
| resource_groups.create_or_update(default_workspace_resource_group, { | ||
| 'location': workspace_region}) | ||
|
|
||
| default_workspace_params = { | ||
| 'location': workspace_region, | ||
| 'properties': { | ||
| 'sku': { | ||
| 'name': 'standalone' | ||
| } | ||
| } | ||
| } | ||
| async_poller = resources.create_or_update_by_id(default_workspace_resource_id, '2015-11-01-preview', | ||
| default_workspace_params) | ||
| ResourceGroup = cmd.get_models('ResourceGroup', resource_type=ResourceType.MGMT_RESOURCE_RESOURCES) | ||
| resource_group = ResourceGroup(location=workspace_region) | ||
| resource_groups.create_or_update(default_workspace_resource_group, resource_group) | ||
|
|
||
| GenericResource = cmd.get_models('GenericResource', resource_type=ResourceType.MGMT_RESOURCE_RESOURCES) | ||
| generic_resource = GenericResource(location=workspace_region, properties={'sku': {'name': 'standalone'}}) | ||
| async_poller = resources.begin_create_or_update_by_id(default_workspace_resource_id, '2015-11-01-preview', | ||
| generic_resource) | ||
|
|
||
| ws_resource_id = '' | ||
| while True: | ||
|
|
@@ -294,11 +290,12 @@ def _ensure_container_insights_for_monitoring(cmd, workspace_resource_id): | |
| parsed = parse_resource_id(workspace_resource_id) | ||
| subscription_id, resource_group = parsed["subscription"], parsed["resource_group"] | ||
|
|
||
| from azure.core.exceptions import HttpResponseError | ||
| resources = cf_resources(cmd.cli_ctx, subscription_id) | ||
| try: | ||
| resource = resources.get_by_id(workspace_resource_id, '2015-11-01-preview') | ||
| location = resource.location | ||
| except CloudError as ex: | ||
| except HttpResponseError as ex: | ||
| raise ex | ||
|
|
||
| unix_time_in_millis = int( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is another place where we use ResourceType.MGMT_RESOURCE_RESOURCES.
azure-cli-extensions/src/connectedk8s/azext_connectedk8s/custom.py
Line 382 in 1010d2a
imported from:
azure-cli-extensions/src/connectedk8s/azext_connectedk8s/_client_factory.py
Line 32 in 1010d2a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I know it. However, there is no breaking change in this logic, so no additional compatibility logic is required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the breaking changes in the new
azure-mgmt-resourceSDK, please refer to the description of PR Azure/azure-cli#17783