Skip to content

Commit

Permalink
[Compute] Adopt track2 SDK, azure-mgmt-compute==18.0.0 (#15750)
Browse files Browse the repository at this point in the history
* [Compute] azure-mgmt-compute==17.0.0

* Fix test_vm_disk_upload, test_vm_managed_disk

* fix 13 tests

* Fix test

* fix more test

* Fix more test

* Fix more test

* Fix more test

* Fix more test

* Fix style

* Fix delete

* Compute 18.0.0

* Fix more test

* image begin_delete

* image begin_create_or_update

* image begin_create_or_update

* snapshot begin_remoke_access

* Add begin_

* vm host begin_create_or_update

* gallery, image-definition, begin_create_or_update

* Fix test in hybrid-2019-03-01

* Fix test of hybrid-2018-03-01

* Fix network test

* Fix backup

* Fix backup

* Fix backup test

* Fix backup test

* Fix backup test

* Fix network test

* patch_models.py

* remove debug code

* Fix test_disable_encryption_error_cases_handling

* Fix test_disable_encryption_error_cases_handling

* Fix style

* auxiliary token

* Fix test_disable_encryption_error_cases_handling in hybrid_2020_09_01

* Fix test_disable_encryption_error_cases_handling in hybrid_2020_09_01

* fix test in vm in hybrid_2020_09_01
  • Loading branch information
qwordy authored Dec 8, 2020
1 parent 5df0938 commit d07ee66
Show file tree
Hide file tree
Showing 149 changed files with 154,196 additions and 140,406 deletions.
4 changes: 3 additions & 1 deletion scripts/sdk_process/patch_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"""

track2_header = copyright_header + b"""import datetime
import msrest
import msrest.serialization
from typing import Dict, List, Optional, Union
from msrest.exceptions import HttpOperationError
Expand Down Expand Up @@ -232,7 +233,8 @@ def find_autorest_generated_folder(module_prefix="azure.mgmt"):

track2_packages = [
'azure.mgmt.keyvault',
'azure.mgmt.storage'
'azure.mgmt.storage',
'azure.mgmt.compute'
]
prefix = sys.argv[1] if len(sys.argv) >= 2 else "azure.mgmt"
for autorest_package in find_autorest_generated_folder(prefix):
Expand Down
4 changes: 4 additions & 0 deletions src/azure-cli-core/azure/cli/core/adal_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ def _get_token(self, sdk_resource=None):

return scheme, token, full_token, external_tenant_tokens

def get_all_tokens(self, *scopes):
scheme, token, full_token, external_tenant_tokens = self._get_token(_try_scopes_to_resource(scopes))
return scheme, token, full_token, external_tenant_tokens

# This method is exposed for Azure Core.
def get_token(self, *scopes, **kwargs): # pylint:disable=unused-argument
logger.debug("AdalAuthentication.get_token invoked by Track 2 SDK with scopes=%s", scopes)
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions src/azure-cli/azure/cli/command_modules/vm/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# pylint:disable=too-many-lines

import os

try:
from urllib.parse import urlparse
except ImportError:
Expand All @@ -21,6 +22,7 @@
check_existence, get_target_network_api, get_storage_blob_uri, list_sku_info)
from azure.cli.command_modules.vm._template_builder import StorageProfile
import azure.cli.core.keys as keys
from azure.core.exceptions import ResourceNotFoundError

from ._client_factory import _compute_client_factory
from ._actions import _get_latest_image_version
Expand Down Expand Up @@ -462,15 +464,15 @@ def _validate_vm_create_storage_profile(cmd, namespace, for_scale_set=False):
compute_client = _compute_client_factory(cmd.cli_ctx, subscription_id=res['subscription'])
if res['type'].lower() == 'images':
image_info = compute_client.images.get(res['resource_group'], res['name'])
namespace.os_type = image_info.storage_profile.os_disk.os_type.value
namespace.os_type = image_info.storage_profile.os_disk.os_type
image_data_disks = image_info.storage_profile.data_disks or []
image_data_disks = [{'lun': disk.lun} for disk in image_data_disks]

elif res['type'].lower() == 'galleries':
image_info = compute_client.gallery_images.get(resource_group_name=res['resource_group'],
gallery_name=res['name'],
gallery_image_name=res['child_name_1'])
namespace.os_type = image_info.os_type.value
namespace.os_type = image_info.os_type
gallery_image_version = res.get('child_name_2', '')
if gallery_image_version.lower() in ['latest', '']:
image_version_infos = compute_client.gallery_image_versions.list_by_gallery_image(
Expand Down Expand Up @@ -1483,7 +1485,6 @@ def process_disk_or_snapshot_create_namespace(cmd, namespace):

def process_image_create_namespace(cmd, namespace):
from msrestazure.tools import parse_resource_id
from msrestazure.azure_exceptions import CloudError
validate_tags(namespace)
source_from_vm = False
try:
Expand All @@ -1495,12 +1496,12 @@ def process_image_create_namespace(cmd, namespace):
compute_client = _compute_client_factory(cmd.cli_ctx, subscription_id=res['subscription'])
vm_info = compute_client.virtual_machines.get(res['resource_group'], res['name'])
source_from_vm = True
except CloudError:
except ResourceNotFoundError:
pass

if source_from_vm:
# pylint: disable=no-member
namespace.os_type = vm_info.storage_profile.os_disk.os_type.value
namespace.os_type = vm_info.storage_profile.os_disk.os_type
namespace.source_virtual_machine = res_id
if namespace.data_disk_sources:
raise CLIError("'--data-disk-sources' is not allowed when capturing "
Expand All @@ -1526,7 +1527,6 @@ def process_image_create_namespace(cmd, namespace):


def _figure_out_storage_source(cli_ctx, resource_group_name, source):
from msrestazure.azure_exceptions import CloudError
source_blob_uri = None
source_disk = None
source_snapshot = None
Expand All @@ -1542,7 +1542,7 @@ def _figure_out_storage_source(cli_ctx, resource_group_name, source):
try:
info = compute_client.snapshots.get(resource_group_name, source)
source_snapshot = info.id
except CloudError:
except ResourceNotFoundError:
info = compute_client.disks.get(resource_group_name, source)
source_disk = info.id

Expand Down
64 changes: 32 additions & 32 deletions src/azure-cli/azure/cli/command_modules/vm/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,18 @@ def load_command_table(self, _):

with self.command_group('disk', compute_disk_sdk, operation_group='disks', min_api='2017-03-30') as g:
g.custom_command('create', 'create_managed_disk', supports_no_wait=True, table_transformer=transform_disk_show_table_output, validator=process_disk_or_snapshot_create_namespace)
g.command('delete', 'delete', supports_no_wait=True, confirmation=True)
g.command('delete', 'begin_delete', supports_no_wait=True, confirmation=True)
g.custom_command('grant-access', 'grant_disk_access')
g.custom_command('list', 'list_managed_disks', table_transformer='[].' + transform_disk_show_table_output)
g.command('revoke-access', 'revoke_access')
g.command('revoke-access', 'begin_revoke_access')
g.show_command('show', 'get', table_transformer=transform_disk_show_table_output)
g.generic_update_command('update', custom_func_name='update_managed_disk', setter_arg_name='disk', supports_no_wait=True)
g.generic_update_command('update', custom_func_name='update_managed_disk', setter_name='begin_create_or_update', setter_arg_name='disk', supports_no_wait=True)
g.wait_command('wait')

with self.command_group('disk-encryption-set', compute_disk_encryption_set_sdk, operation_group='disk_encryption_sets', client_factory=cf_disk_encryption_set, min_api='2019-07-01') as g:
g.custom_command('create', 'create_disk_encryption_set', supports_no_wait=True)
g.command('delete', 'delete')
g.generic_update_command('update', custom_func_name='update_disk_encryption_set', setter_arg_name='disk_encryption_set')
g.command('delete', 'begin_delete')
g.generic_update_command('update', custom_func_name='update_disk_encryption_set', setter_arg_name='disk_encryption_set', setter_name='begin_create_or_update')
g.show_command('show', 'get')
g.custom_command('list', 'list_disk_encryption_sets')
g.command('list-associated-resources', 'list_associated_resources', min_api='2020-06-30')
Expand All @@ -220,14 +220,14 @@ def load_command_table(self, _):
g.show_command('show', 'get')
g.custom_command('list', 'list_disk_accesses')
g.wait_command('wait')
g.command('delete', 'delete')
g.command('delete', 'begin_delete')

with self.command_group('image', compute_image_sdk, min_api='2016-04-30-preview') as g:
g.custom_command('create', 'create_image', validator=process_image_create_namespace)
g.custom_command('list', 'list_images')
g.show_command('show', 'get')
g.command('delete', 'delete')
g.generic_update_command('update', custom_func_name='update_image')
g.command('delete', 'begin_delete')
g.generic_update_command('update', setter_name='begin_create_or_update', custom_func_name='update_image')

with self.command_group('image builder', image_builder_image_templates_sdk, custom_command_type=image_builder_custom) as g:
g.custom_command('create', 'create_image_template', supports_no_wait=True, supports_local_cache=True, validator=process_image_template_create_namespace)
Expand All @@ -252,12 +252,12 @@ def load_command_table(self, _):

with self.command_group('snapshot', compute_snapshot_sdk, operation_group='snapshots', min_api='2016-04-30-preview') as g:
g.custom_command('create', 'create_snapshot', validator=process_disk_or_snapshot_create_namespace, supports_no_wait=True)
g.command('delete', 'delete')
g.command('delete', 'begin_delete')
g.custom_command('grant-access', 'grant_snapshot_access')
g.custom_command('list', 'list_snapshots')
g.command('revoke-access', 'revoke_access')
g.command('revoke-access', 'begin_revoke_access')
g.show_command('show', 'get')
g.generic_update_command('update', custom_func_name='update_snapshot', setter_arg_name='snapshot', supports_no_wait=True)
g.generic_update_command('update', custom_func_name='update_snapshot', setter_name='begin_create_or_update', setter_arg_name='snapshot', supports_no_wait=True)
g.wait_command('wait')

with self.command_group('vm', compute_vm_sdk) as g:
Expand All @@ -267,9 +267,9 @@ def load_command_table(self, _):

g.custom_command('capture', 'capture_vm')
g.custom_command('create', 'create_vm', transform=transform_vm_create_output, supports_no_wait=True, table_transformer=deployment_validate_table_format, validator=process_vm_create_namespace, exception_handler=handle_template_based_exception)
g.command('convert', 'convert_to_managed_disks', min_api='2016-04-30-preview')
g.command('deallocate', 'deallocate', supports_no_wait=True)
g.command('delete', 'delete', confirmation=True, supports_no_wait=True)
g.command('convert', 'begin_convert_to_managed_disks', min_api='2016-04-30-preview')
g.command('deallocate', 'begin_deallocate', supports_no_wait=True)
g.command('delete', 'begin_delete', confirmation=True, supports_no_wait=True)
g.command('generalize', 'generalize', supports_no_wait=True)
g.custom_command('get-instance-view', 'get_instance_view', table_transformer='{Name:name, ResourceGroup:resourceGroup, Location:location, ProvisioningState:provisioningState, PowerState:instanceView.statuses[1].displayStatus}')
g.custom_command('list', 'list_vm', table_transformer=transform_vm_list)
Expand All @@ -279,19 +279,19 @@ def load_command_table(self, _):
g.command('list-usage', 'list', command_type=compute_vm_usage_sdk, transform=transform_vm_usage_list, table_transformer='[].{Name:localName, CurrentValue:currentValue, Limit:limit}')
g.command('list-vm-resize-options', 'list_available_sizes')
g.custom_command('open-port', 'open_vm_port')
g.command('perform-maintenance', 'perform_maintenance', min_api='2017-03-30')
g.command('redeploy', 'redeploy', supports_no_wait=True)
g.command('perform-maintenance', 'begin_perform_maintenance', min_api='2017-03-30')
g.command('redeploy', 'begin_redeploy', supports_no_wait=True)
g.custom_command('resize', 'resize_vm', supports_no_wait=True)
g.custom_command('restart', 'restart_vm', supports_no_wait=True)
g.custom_show_command('show', 'show_vm', table_transformer=transform_vm)
g.command('simulate-eviction', 'simulate_eviction', min_api='2019-12-01')
g.command('start', 'start', supports_no_wait=True)
g.command('stop', 'power_off', supports_no_wait=True, validator=process_vm_vmss_stop)
g.command('reapply', 'reapply', supports_no_wait=True, min_api='2019-07-01')
g.command('start', 'begin_start', supports_no_wait=True)
g.command('stop', 'begin_power_off', supports_no_wait=True, validator=process_vm_vmss_stop)
g.command('reapply', 'begin_reapply', supports_no_wait=True, min_api='2019-07-01')
g.generic_update_command('update', getter_name='get_vm_to_update', setter_name='update_vm', setter_type=compute_custom, command_type=compute_custom, supports_no_wait=True)
g.wait_command('wait', getter_name='get_instance_view', getter_type=compute_custom)
g.custom_command('auto-shutdown', 'auto_shutdown_vm')
g.command('assess-patches', 'assess_patches', min_api='2020-06-01')
g.command('assess-patches', 'begin_assess_patches', min_api='2020-06-01')

with self.command_group('vm availability-set', compute_availset_sdk) as g:
g.custom_command('convert', 'convert_av_set_to_managed_disk', min_api='2016-04-30-preview')
Expand Down Expand Up @@ -322,7 +322,7 @@ def load_command_table(self, _):
g.custom_show_command('show', 'show_vm_encryption_status', table_transformer=transform_vm_encryption_show_table_output)

with self.command_group('vm extension', compute_vm_extension_sdk) as g:
g.command('delete', 'delete', supports_no_wait=True)
g.command('delete', 'begin_delete', supports_no_wait=True)
g.show_command('show', 'get', table_transformer=transform_extension_show_table_output)
g.custom_command('set', 'set_extension', supports_no_wait=True)
g.custom_command('list', 'list_extensions', table_transformer='[].' + transform_extension_show_table_output)
Expand Down Expand Up @@ -382,8 +382,8 @@ def load_command_table(self, _):
g.custom_command('get-instance-view', 'get_dedicated_host_instance_view')
g.custom_command('create', 'create_dedicated_host')
g.command('list', 'list_by_host_group')
g.generic_update_command('update')
g.command('delete', 'delete', confirmation=True)
g.generic_update_command('update', setter_name='begin_create_or_update')
g.command('delete', 'begin_delete', confirmation=True)

with self.command_group('vm host group', compute_dedicated_host_groups_sdk, client_factory=cf_dedicated_host_groups,
min_api='2019-03-01') as g:
Expand All @@ -400,7 +400,7 @@ def load_command_table(self, _):
g.custom_show_command('identity show', 'show_vmss_identity')
g.custom_command('create', 'create_vmss', transform=DeploymentOutputLongRunningOperation(self.cli_ctx, 'Starting vmss create'), supports_no_wait=True, table_transformer=deployment_validate_table_format, validator=process_vmss_create_namespace, exception_handler=handle_template_based_exception)
g.custom_command('deallocate', 'deallocate_vmss', supports_no_wait=True)
g.command('delete', 'delete', supports_no_wait=True)
g.command('delete', 'begin_delete', supports_no_wait=True)
g.custom_command('delete-instances', 'delete_vmss_instances', supports_no_wait=True)
g.custom_command('get-instance-view', 'get_vmss_instance_view', table_transformer='{ProvisioningState:statuses[0].displayStatus, PowerState:statuses[1].displayStatus}')
g.custom_command('list', 'list_vmss', table_transformer=get_vmss_table_output_transformer(self))
Expand All @@ -409,7 +409,7 @@ def load_command_table(self, _):
g.custom_command('list-instance-public-ips', 'list_vmss_instance_public_ips')
g.command('list-skus', 'list_skus')
g.custom_command('reimage', 'reimage_vmss', supports_no_wait=True, min_api='2017-03-30')
g.command('perform-maintenance', 'perform_maintenance', min_api='2017-12-01')
g.command('perform-maintenance', 'begin_perform_maintenance', min_api='2017-12-01')
g.custom_command('restart', 'restart_vmss', supports_no_wait=True)
g.custom_command('scale', 'scale_vmss', supports_no_wait=True)
g.custom_show_command('show', 'get_vmss', table_transformer=get_vmss_table_output_transformer(self, False))
Expand Down Expand Up @@ -459,26 +459,26 @@ def load_command_table(self, _):
g.show_command('show', 'get')

with self.command_group('vmss rolling-upgrade', compute_vmss_rolling_upgrade_sdk, min_api='2017-03-30') as g:
g.command('cancel', 'cancel')
g.command('cancel', 'begin_cancel')
g.command('get-latest', 'get_latest')
g.command('start', 'start_os_upgrade')
g.command('start', 'begin_start_os_upgrade')

with self.command_group('sig', compute_galleries_sdk, operation_group='galleries', min_api='2018-06-01') as g:
g.custom_command('create', 'create_image_gallery')
g.show_command('show', 'get')
g.custom_command('list', 'list_image_galleries')
g.command('delete', 'delete')
g.generic_update_command('update', setter_arg_name='gallery')
g.command('delete', 'begin_delete')
g.generic_update_command('update', setter_name='begin_create_or_update', setter_arg_name='gallery')

with self.command_group('sig image-definition', compute_gallery_images_sdk, operation_group='gallery_images', min_api='2018-06-01') as g:
g.custom_command('create', 'create_gallery_image')
g.command('list', 'list_by_gallery')
g.show_command('show', 'get')
g.command('delete', 'delete')
g.generic_update_command('update', setter_arg_name='gallery_image')
g.command('delete', 'begin_delete')
g.generic_update_command('update', setter_name='begin_create_or_update', setter_arg_name='gallery_image')

with self.command_group('sig image-version', compute_gallery_image_versions_sdk, operation_group='gallery_image_versions', min_api='2018-06-01') as g:
g.command('delete', 'delete')
g.command('delete', 'begin_delete')
g.show_command('show', 'get', table_transformer='{Name:name, ResourceGroup:resourceGroup, ProvisioningState:provisioningState, TargetRegions: publishingProfile.targetRegions && join(`, `, publishingProfile.targetRegions[*].name), ReplicationState:replicationStatus.aggregatedState}')
g.command('list', 'list_by_gallery_image')
g.custom_command('create', 'create_image_version', supports_no_wait=True)
Expand Down
Loading

0 comments on commit d07ee66

Please sign in to comment.