diff --git a/src/azure-cli/azure/cli/command_modules/vm/_client_factory.py b/src/azure-cli/azure/cli/command_modules/vm/_client_factory.py index cccec5d2bf7..ab8afe696f0 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_client_factory.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_client_factory.py @@ -12,22 +12,6 @@ def _compute_client_factory(cli_ctx, **kwargs): aux_subscriptions=kwargs.get('aux_subscriptions')) -def cf_vm(cli_ctx, _): - return _compute_client_factory(cli_ctx).virtual_machines - - -def cf_vm_ext(cli_ctx, _): - return _compute_client_factory(cli_ctx).virtual_machine_extensions - - -def cf_vm_ext_image(cli_ctx, _): - return _compute_client_factory(cli_ctx).virtual_machine_extension_images - - -def cf_vm_image(cli_ctx, _): - return _compute_client_factory(cli_ctx).virtual_machine_images - - def cf_vm_image_term(cli_ctx, _): from azure.cli.core.commands.client_factory import get_mgmt_service_client from azure.mgmt.marketplaceordering import MarketplaceOrderingAgreements @@ -35,54 +19,6 @@ def cf_vm_image_term(cli_ctx, _): return market_place_client.marketplace_agreements -def cf_vmss(cli_ctx, _): - return _compute_client_factory(cli_ctx).virtual_machine_scale_sets - - -def cf_vmss_vm(cli_ctx, _): - return _compute_client_factory(cli_ctx).virtual_machine_scale_set_vms - - -def cf_vm_sizes(cli_ctx, _): - return _compute_client_factory(cli_ctx).virtual_machine_sizes - - -def cf_disks(cli_ctx, _): - return _compute_client_factory(cli_ctx).disks - - -def cf_snapshots(cli_ctx, _): - return _compute_client_factory(cli_ctx).snapshots - - -def cf_disk_accesses(cli_ctx, _): - return _compute_client_factory(cli_ctx).disk_accesses - - -def cf_rolling_upgrade_commands(cli_ctx, _): - return _compute_client_factory(cli_ctx).virtual_machine_scale_set_rolling_upgrades - - -def cf_gallery_images(cli_ctx, _): - return _compute_client_factory(cli_ctx).gallery_images - - -def cf_gallery_image_versions(cli_ctx, _): - return _compute_client_factory(cli_ctx).gallery_image_versions - - -def cf_proximity_placement_groups(cli_ctx, _): - return _compute_client_factory(cli_ctx).proximity_placement_groups - - -def cf_dedicated_host_groups(cli_ctx, _): - return _compute_client_factory(cli_ctx).dedicated_host_groups - - -def cf_dedicated_hosts(cli_ctx, _): - return _compute_client_factory(cli_ctx).dedicated_hosts - - def _log_analytics_client_factory(cli_ctx, subscription_id, *_): from azure.mgmt.loganalytics import LogAnalyticsManagementClient from azure.cli.core.commands.client_factory import get_mgmt_service_client @@ -115,29 +51,5 @@ def cf_vm_cl(cli_ctx, *_): ComputeManagementClient) -def cf_shared_galleries(cli_ctx, *_): - return cf_vm_cl(cli_ctx).shared_galleries - - -def cf_shared_gallery_image(cli_ctx, *_): - return cf_vm_cl(cli_ctx).shared_gallery_images - - -def cf_shared_gallery_image_version(cli_ctx, *_): - return cf_vm_cl(cli_ctx).shared_gallery_image_versions - - def cf_community_gallery(cli_ctx, *_): return cf_vm_cl(cli_ctx).community_galleries - - -def cf_community_gallery_image(cli_ctx, *_): - return cf_vm_cl(cli_ctx).community_gallery_images - - -def cf_community_gallery_image_version(cli_ctx, *_): - return cf_vm_cl(cli_ctx).community_gallery_image_versions - - -def cf_capacity_reservations(cli_ctx, *_): - return cf_vm_cl(cli_ctx).capacity_reservations diff --git a/src/azure-cli/azure/cli/command_modules/vm/commands.py b/src/azure-cli/azure/cli/command_modules/vm/commands.py index c490c56ffcc..5253c3d39bf 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/commands.py +++ b/src/azure-cli/azure/cli/command_modules/vm/commands.py @@ -3,15 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from azure.cli.command_modules.vm._client_factory import (cf_vm, - cf_vm_ext, cf_vm_ext_image, - cf_vm_image_term, - cf_vmss, - cf_gallery_images, cf_gallery_image_versions, - cf_proximity_placement_groups, - cf_log_analytics_data_plane, - cf_capacity_reservations, - cf_community_gallery) +from azure.cli.command_modules.vm._client_factory import cf_vm_image_term, cf_log_analytics_data_plane from azure.cli.command_modules.vm._format import ( transform_ip_addresses, transform_vm, transform_vm_create_output, transform_vm_list, transform_disk_create_table_output, transform_sku_for_table_output, transform_disk_show_table_output, @@ -56,76 +48,16 @@ def load_command_table(self, _): client_factory=image_builder_client_factory ) - compute_availset_profile = CliCommandType( - operations_tmpl='azure.mgmt.compute.operations#AvailabilitySetsOperations.{}', - operation_group='availability_sets' - ) - - compute_vm_sdk = CliCommandType( - operations_tmpl='azure.mgmt.compute.operations#VirtualMachinesOperations.{}', - client_factory=cf_vm - ) - - compute_vm_extension_sdk = CliCommandType( - operations_tmpl='azure.mgmt.compute.operations#VirtualMachineExtensionsOperations.{}', - client_factory=cf_vm_ext - ) - - compute_vm_extension_image_sdk = CliCommandType( - operations_tmpl='azure.mgmt.compute.operations#VirtualMachineExtensionImagesOperations.{}', - client_factory=cf_vm_ext_image - ) - compute_vm_image_term_sdk = CliCommandType( operations_tmpl='azure.mgmt.marketplaceordering.operations#MarketplaceAgreementsOperations.{}', client_factory=cf_vm_image_term ) - compute_vm_run_profile = CliCommandType( - operations_tmpl='azure.mgmt.compute.operations#VirtualMachineRunCommandsOperations.{}' - ) - - compute_vmss_run_sdk = CliCommandType( - operations_tmpl='azure.mgmt.compute.operations#VirtualMachineScaleSetVmRunCommandsOperations.{}' - ) - - compute_vmss_sdk = CliCommandType( - operations_tmpl='azure.mgmt.compute.operations#VirtualMachineScaleSetsOperations.{}', - client_factory=cf_vmss, - operation_group='virtual_machine_scale_sets' - ) - - compute_gallery_images_sdk = CliCommandType( - operations_tmpl='azure.mgmt.compute.operations#GalleryImagesOperations.{}', - client_factory=cf_gallery_images, - ) - - compute_gallery_image_versions_sdk = CliCommandType( - operations_tmpl='azure.mgmt.compute.operations#GalleryImageVersionsOperations.{}', - client_factory=cf_gallery_image_versions, - ) - - compute_gallery_application_profile = CliCommandType( - operations_tmpl='azure.mgmt.compute.operations#GalleryApplicationsOperations.{}', - ) - - compute_gallery_application_version_profile = CliCommandType( - operations_tmpl='azure.mgmt.compute.operations#GalleryApplicationVersionsOperations.{}', - ) - - compute_proximity_placement_groups_sdk = CliCommandType( - operations_tmpl='azure.mgmt.compute.operations#ProximityPlacementGroupsOperations.{}', - ) - image_builder_image_templates_sdk = CliCommandType( operations_tmpl="azure.mgmt.imagebuilder.operations#VirtualMachineImageTemplatesOperations.{}", client_factory=cf_img_bldr_image_templates, ) - compute_disk_encryption_set_profile = CliCommandType( - operations_tmpl='azure.mgmt.compute.operations#DiskEncryptionSetsOperations.{}' - ) - monitor_custom = CliCommandType( operations_tmpl='azure.cli.command_modules.monitor.custom#{}', exception_handler=monitor_exception_handler @@ -139,23 +71,6 @@ def load_command_table(self, _): exception_handler=monitor_exception_handler ) - capacity_reservations_sdk = CliCommandType( - operations_tmpl='azure.mgmt.compute.operations#CapacityReservationsOperations.{}', - client_factory=cf_capacity_reservations - ) - - restore_point = CliCommandType( - operations_tmpl='azure.mgmt.compute.operations#RestorePointsOperations.{}', - ) - - restore_point_collection = CliCommandType( - operations_tmpl='azure.mgmt.compute.operations#RestorePointCollectionsOperations.{}' - ) - - community_gallery_sdk = CliCommandType( - operations_tmpl='azure.mgmt.compute.operations#CommunityGalleriesOperations.{}', - client_factory=cf_community_gallery) - with self.command_group("ppg"): from .operations.ppg import PPGShow self.command_table["ppg show"] = PPGShow(loader=self) @@ -174,12 +89,12 @@ def load_command_table(self, _): from .operations.disk import DiskConfigUpdate self.command_table["disk config update"] = DiskConfigUpdate(loader=self) - with self.command_group('disk-encryption-set', compute_disk_encryption_set_profile, operation_group='disk_encryption_sets'): + with self.command_group('disk-encryption-set', operation_group='disk_encryption_sets'): from .operations.disk_encryption_set import DiskEncryptionSetCreate, DiskEncryptionSetUpdate self.command_table['disk-encryption-set create'] = DiskEncryptionSetCreate(loader=self) self.command_table['disk-encryption-set update'] = DiskEncryptionSetUpdate(loader=self) - with self.command_group('disk-encryption-set identity', compute_disk_encryption_set_profile, operation_group='disk_encryption_sets') as g: + with self.command_group('disk-encryption-set identity', operation_group='disk_encryption_sets') as g: from .operations.disk_encryption_set_identity import DiskEncryptionSetIdentityAssign, DiskEncryptionSetIdentityRemove self.command_table['disk-encryption-set identity assign'] = DiskEncryptionSetIdentityAssign(loader=self) self.command_table['disk-encryption-set identity remove'] = DiskEncryptionSetIdentityRemove(loader=self) @@ -269,7 +184,7 @@ def load_command_table(self, _): self.command_table['vm capture'] = VMCapture(loader=self) self.command_table['vm deallocate'] = VMDeallocate(loader=self) - with self.command_group('vm availability-set', compute_availset_profile) as g: + with self.command_group('vm availability-set') as g: g.custom_command('create', 'create_av_set', table_transformer=deployment_validate_table_format, supports_no_wait=True, exception_handler=handle_template_based_exception) from .operations.vm_availability_set import AvailabilitySetUpdate, AvailabilitySetConvert self.command_table['vm availability-set update'] = AvailabilitySetUpdate(loader=self) @@ -284,7 +199,7 @@ def load_command_table(self, _): g.custom_command('set', 'set_diagnostics_extension') g.custom_command('get-default-config', 'show_default_diagnostics_configuration') - with self.command_group('vm disk', compute_vm_sdk, min_api='2017-03-30') as g: + with self.command_group('vm disk', min_api='2017-03-30') as g: g.custom_command('attach', 'attach_managed_data_disk', validator=process_vm_disk_attach_namespace) g.custom_command('detach', 'detach_managed_data_disk', validator=process_vm_disk_detach_namespace) @@ -293,12 +208,12 @@ def load_command_table(self, _): g.custom_command('disable', 'decrypt_vm') 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: + with self.command_group('vm extension') as g: g.custom_show_command('show', 'show_extensions', 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) - with self.command_group('vm extension image', compute_vm_extension_image_sdk) as g: + with self.command_group('vm extension image') as g: g.custom_command('list', 'list_vm_extension_images') with self.command_group('vm image') as g: @@ -315,14 +230,14 @@ def load_command_table(self, _): g.custom_command('cancel', 'cancel_terms') g.custom_show_command('show', 'get_terms') - with self.command_group('vm nic', compute_vm_sdk) as g: + with self.command_group('vm nic') as g: g.custom_command('add', 'add_vm_nic') g.custom_command('remove', 'remove_vm_nic') g.custom_command('set', 'set_vm_nic') g.custom_show_command('show', 'show_vm_nic') g.custom_command('list', 'list_vm_nics') - with self.command_group('vm run-command', compute_vm_run_profile, operation_group='virtual_machine_run_commands') as g: + with self.command_group('vm run-command', operation_group='virtual_machine_run_commands') as g: g.custom_command('invoke', 'vm_run_command_invoke', supports_no_wait=True) g.custom_command('list', 'vm_run_command_list') g.custom_show_command('show', 'vm_run_command_show') @@ -330,7 +245,7 @@ def load_command_table(self, _): g.custom_command('update', 'vm_run_command_update', supports_no_wait=True) g.custom_wait_command('wait', 'vm_run_command_show') - with self.command_group('vm secret', compute_vm_sdk) as g: + with self.command_group('vm secret') as g: g.custom_command('format', 'get_vm_format_secret', validator=process_vm_secret_format) g.custom_command('add', 'add_vm_secret') g.custom_command('list', 'list_vm_secrets') @@ -341,7 +256,7 @@ def load_command_table(self, _): g.custom_command('detach', 'detach_unmanaged_data_disk') g.custom_command('list', 'list_unmanaged_disks') - with self.command_group('vm user', compute_vm_sdk, supports_no_wait=True) as g: + with self.command_group('vm user', supports_no_wait=True) as g: g.custom_command('update', 'set_user') g.custom_command('delete', 'delete_user') g.custom_command('reset-ssh', 'reset_linux_ssh') @@ -363,13 +278,11 @@ def load_command_table(self, _): 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_show_command('show', 'get_vmss_by_aaz', table_transformer=get_vmss_table_output_transformer(self, False)) - g.generic_update_command('update', getter_name='get_vmss_modified_by_aaz', setter_name='update_vmss', supports_no_wait=True, command_type=compute_custom, validator=validate_vmss_update_namespace) - g.wait_command('wait', getter_name='get_vmss_by_aaz', getter_type=compute_custom) + g.custom_command('deallocate', 'deallocate_vmss', 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('identity assign', 'assign_vmss_identity', validator=process_assign_identity_namespace) g.custom_command('identity remove', 'remove_vmss_identity', validator=process_remove_identity_namespace, is_preview=True) g.custom_show_command('identity show', 'show_vmss_identity') - g.custom_command('deallocate', 'deallocate_vmss', supports_no_wait=True) g.custom_command('list-instance-connection-info', 'list_vmss_instance_connection_info') g.custom_command('list-instance-public-ips', 'list_vmss_instance_public_ips') g.custom_command('list-instances', 'get_instances_list') @@ -377,15 +290,11 @@ def load_command_table(self, _): g.custom_command('restart', 'restart_vmss', supports_no_wait=True) g.custom_command('scale', 'scale_vmss', supports_no_wait=True) g.custom_command('set-orchestration-service-state', 'set_orchestration_service_state', supports_no_wait=True) + g.custom_show_command('show', 'get_vmss_by_aaz', table_transformer=get_vmss_table_output_transformer(self, False)) g.custom_command('stop', 'stop_vmss', supports_no_wait=True, validator=process_vm_vmss_stop) - - with self.command_group('vmss application', operation_group='virtual_machine_scale_sets') as g: - g.custom_command('set', 'set_vmss_applications', validator=process_set_applications_namespace) - g.custom_command('list', 'list_vmss_applications') - - with self.command_group('vmss', compute_vmss_sdk, operation_group='virtual_machine_scale_sets') as g: - g.custom_command('get-instance-view', 'get_vmss_instance_view', table_transformer='{ProvisioningState:statuses[0].displayStatus, PowerState:statuses[1].displayStatus}') + g.generic_update_command('update', getter_name='get_vmss_modified_by_aaz', setter_name='update_vmss', supports_no_wait=True, command_type=compute_custom, validator=validate_vmss_update_namespace) g.custom_command('update-instances', 'update_vmss_instances', supports_no_wait=True) + g.wait_command('wait', getter_name='get_vmss_by_aaz', getter_type=compute_custom) from .aaz.latest.vmss import List as VMSSList self.command_table['vmss list'] = VMSSList(loader=self, @@ -394,6 +303,10 @@ def load_command_table(self, _): from .operations.vmss_vms import VMSSGetResiliencyView self.command_table['vmss get-resiliency-view'] = VMSSGetResiliencyView(loader=self) + with self.command_group('vmss application') as g: + g.custom_command('set', 'set_vmss_applications', validator=process_set_applications_namespace) + g.custom_command('list', 'list_vmss_applications') + with self.command_group('vmss diagnostics') as g: g.custom_command('set', 'set_vmss_diagnostics_extension') g.custom_command('get-default-config', 'show_default_diagnostics_configuration') @@ -407,17 +320,17 @@ def load_command_table(self, _): g.custom_command('disable', 'decrypt_vmss') g.custom_show_command('show', 'show_vmss_encryption_status') - with self.command_group('vmss extension', compute_vmss_sdk) as g: + with self.command_group('vmss extension') as g: g.custom_command('delete', 'delete_vmss_extension', supports_no_wait=True) g.custom_show_command('show', 'get_vmss_extension') g.custom_command('set', 'set_vmss_extension', supports_no_wait=True) g.custom_command('list', 'list_vmss_extensions') g.custom_command('upgrade', 'upgrade_vmss_extension', min_api='2020-06-01', supports_no_wait=True) - with self.command_group('vmss extension image', compute_vm_extension_image_sdk) as g: + with self.command_group('vmss extension image') as g: g.custom_command('list', 'list_vm_extension_images') - with self.command_group('vmss run-command', compute_vmss_run_sdk) as g: + with self.command_group('vmss run-command') as g: g.custom_command('invoke', 'vmss_run_command_invoke') g.custom_show_command('show', 'vmss_run_command_show') g.custom_command('create', 'vmss_run_command_create', supports_no_wait=True) @@ -429,14 +342,14 @@ def load_command_table(self, _): self.command_table['sig update'] = SigUpdate(loader=self) self.command_table['sig show'] = SigShow(loader=self) - with self.command_group('sig', community_gallery_sdk, client_factory=cf_community_gallery, operation_group='shared_galleries', min_api='2022-01-03') as g: + with self.command_group('sig', operation_group='shared_galleries', min_api='2022-01-03') as g: g.custom_command('list-community', 'sig_community_gallery_list') with self.command_group('sig identity') as g: from .operations.sig import SigIdentityRemove self.command_table['sig identity remove'] = SigIdentityRemove(loader=self) - with self.command_group('sig image-definition', compute_gallery_images_sdk, operation_group='gallery_images', min_api='2018-06-01') as g: + with self.command_group('sig image-definition', operation_group='gallery_images') as g: g.custom_command('create', 'create_gallery_image') from .operations.sig_image_definition import SigImageDefinitionUpdate self.command_table['sig image-definition update'] = SigImageDefinitionUpdate(loader=self) @@ -445,24 +358,19 @@ def load_command_table(self, _): from .operations.sig_image_definition import SigImageDefinitionListShared self.command_table['sig image-definition list-shared'] = SigImageDefinitionListShared(loader=self) - with self.command_group('sig image-version', compute_gallery_image_versions_sdk, operation_group='gallery_image_versions', min_api='2018-06-01') as g: + with self.command_group('sig image-version', operation_group='gallery_image_versions') as g: g.custom_command('create', 'create_image_version', supports_no_wait=True, validator=process_image_version_create_namespace) g.custom_command('undelete', 'undelete_image_version', supports_no_wait=True, validator=process_image_version_undelete_namespace, is_preview=True) g.generic_update_command('update', getter_name='get_image_version_to_update', setter_arg_name='gallery_image_version', setter_name='update_image_version', setter_type=compute_custom, command_type=compute_custom, supports_no_wait=True, validator=process_image_version_update_namespace) from .aaz.latest.sig.image_version import Show as SigImageVersionShow self.command_table['sig image-version show'] = SigImageVersionShow(loader=self, table_transformer='{Name:name, ResourceGroup:resourceGroup, ProvisioningState:provisioningState, TargetRegions: publishingProfile.targetRegions && join(`, `, publishingProfile.targetRegions[*].name), EdgeZones: publishingProfile.targetExtendedLocations && join(`, `, publishingProfile.targetExtendedLocations[*].name), ReplicationState:replicationStatus.aggregatedState}') + with self.command_group('sig image-version'): from .operations.sig_image_version import SigImageVersionListShared self.command_table['sig image-version list-shared'] = SigImageVersionListShared(loader=self) - vm_gallery_sharing_profile = CliCommandType( - operations_tmpl=( - 'azure.mgmt.compute.operations._gallery_sharing_profile_operations#GallerySharingProfileOperations.{}' - ), - operation_group='shared_galleries' - ) - with self.command_group('sig share', vm_gallery_sharing_profile, operation_group='shared_galleries'): + with self.command_group('sig share', operation_group='shared_galleries'): from .operations.sig_share import SigShareAdd, SigShareRemove, SigShareReset, SigShareEnableCommunity, SigShareWait self.command_table['sig share add'] = SigShareAdd(loader=self) self.command_table['sig share remove'] = SigShareRemove(loader=self) @@ -470,11 +378,11 @@ def load_command_table(self, _): self.command_table['sig share enable-community'] = SigShareEnableCommunity(loader=self) self.command_table['sig share wait'] = SigShareWait(loader=self) - with self.command_group('sig gallery-application', compute_gallery_application_profile, operation_group='gallery_applications') as g: + with self.command_group('sig gallery-application', operation_group='gallery_applications') as g: from .operations.sig_gallery_application import SigGalleryApplicationCreate self.command_table['sig gallery-application create'] = SigGalleryApplicationCreate(loader=self) - with self.command_group('sig gallery-application version', compute_gallery_application_version_profile, operation_group='gallery_application_versions'): + with self.command_group('sig gallery-application version', operation_group='gallery_application_versions'): from .operations.sig_gallery_application_version import SigGalleryApplicationVersionCreate, SiggalleryApplicationversionUpdate self.command_table['sig gallery-application version create'] = SigGalleryApplicationVersionCreate(loader=self) self.command_table['sig gallery-application version update'] = SiggalleryApplicationversionUpdate(loader=self) @@ -484,7 +392,7 @@ def load_command_table(self, _): self.command_table['sig in-vm-access-control-profile-version create'] = SigInVMAccessControlProfileVersionCreate(loader=self) self.command_table['sig in-vm-access-control-profile-version update'] = SigInVMAccessControlProfileVersionUpdate(loader=self) - with self.command_group('ppg', compute_proximity_placement_groups_sdk, min_api='2018-04-01', client_factory=cf_proximity_placement_groups) as g: + with self.command_group('ppg') as g: from .operations.ppg import PPGCreate, PPGUpdate self.command_table['ppg create'] = PPGCreate(loader=self) self.command_table['ppg update'] = PPGUpdate(loader=self) @@ -510,16 +418,14 @@ def load_command_table(self, _): from .operations.capacity_reservation_group import CapacityReservationGroupList self.command_table['capacity reservation group list'] = CapacityReservationGroupList(loader=self) - with self.command_group('capacity reservation', capacity_reservations_sdk, min_api='2021-04-01', - client_factory=cf_capacity_reservations) as g: + with self.command_group('capacity reservation') as g: from .operations.capacity_reservation import CapacityReservationUpdate, CapacityReservationShow self.command_table['capacity reservation update'] = CapacityReservationUpdate(loader=self) self.command_table['capacity reservation show'] = CapacityReservationShow(loader=self) - with self.command_group('restore-point', restore_point) as g: + with self.command_group('restore-point') as g: g.custom_show_command('show', 'restore_point_show') g.custom_command('create', 'restore_point_create', supports_no_wait=True) - g.wait_command('wait') - with self.command_group('restore-point collection', restore_point_collection) as g: + with self.command_group('restore-point collection') as g: g.custom_show_command('show', 'restore_point_collection_show') 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 944f3ba348a..ff4e8c7e4e4 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/custom.py +++ b/src/azure-cli/azure/cli/command_modules/vm/custom.py @@ -33,7 +33,7 @@ from azure.cli.core.commands.validators import validate_file_or_dict from azure.cli.core.commands import LongRunningOperation, DeploymentOutputLongRunningOperation -from azure.cli.core.commands.client_factory import get_mgmt_service_client +from azure.cli.core.commands.client_factory import get_mgmt_service_client, get_subscription_id from azure.cli.core.profiles import ResourceType from azure.cli.core.util import sdk_no_wait @@ -42,7 +42,7 @@ from ._actions import (load_images_from_aliases_doc, load_extension_images_thru_services, load_images_thru_services, _get_latest_image_version_by_aaz) -from ._client_factory import (_compute_client_factory, cf_vm_image_term) +from ._client_factory import _compute_client_factory, cf_log_analytics, cf_log_analytics_data_sources, cf_vm_image_term from .aaz.latest.vm.disk import AttachDetachDataDisk from .aaz.latest.vm import Update as UpdateVM @@ -434,7 +434,6 @@ def create_managed_disk(cmd, resource_group_name, disk_name, location=None, # p supported_security_option=None): from azure.mgmt.core.tools import resource_id, is_valid_resource_id - from azure.cli.core.commands.client_factory import get_subscription_id location = location or _get_resource_group_location(cmd.cli_ctx, resource_group_name) if security_data_uri: @@ -890,19 +889,6 @@ def setter(vm, external_identities=external_identities): # region VirtualMachines -def capture_vm(cmd, resource_group_name, vm_name, vhd_name_prefix, - storage_container='vhds', overwrite=True): - VirtualMachineCaptureParameters = cmd.get_models('VirtualMachineCaptureParameters') - client = _compute_client_factory(cmd.cli_ctx) - parameter = VirtualMachineCaptureParameters(vhd_prefix=vhd_name_prefix, - destination_container_name=storage_container, - overwrite_vhds=overwrite) - poller = client.virtual_machines.begin_capture(resource_group_name, vm_name, parameter) - result = LongRunningOperation(cmd.cli_ctx)(poller) - output = getattr(result, 'output', None) or result.resources[0] - print(json.dumps(output, indent=2)) # pylint: disable=no-member - - # pylint: disable=too-many-locals, unused-argument, too-many-statements, too-many-branches, broad-except def create_vm(cmd, vm_name, resource_group_name, image=None, size='Standard_D2s_v5', location=None, tags=None, no_wait=False, authentication_type=None, admin_password=None, computer_name=None, @@ -1392,19 +1378,6 @@ def get_vm_by_aaz(cmd, resource_group_name, vm_name, expand=None): return VMShow(cli_ctx=cmd.cli_ctx)(command_args=command_args) -def get_vm(cmd, resource_group_name, vm_name, expand=None): - client = _compute_client_factory(cmd.cli_ctx) - return client.virtual_machines.get(resource_group_name, vm_name, expand=expand) - - -def get_vm_to_update(cmd, resource_group_name, vm_name): - client = _compute_client_factory(cmd.cli_ctx) - vm = client.virtual_machines.get(resource_group_name, vm_name) - # To avoid unnecessary permission check of image - vm.storage_profile.image_reference = None - return vm - - def get_vm_to_update_by_aaz(cmd, resource_group_name, vm_name): from .operations.vm import VMShow @@ -1742,20 +1715,6 @@ def stop_vm(cmd, resource_group_name, vm_name, no_wait=False, skip_shutdown=Fals return VMStop(cli_ctx=cmd.cli_ctx)(command_args=command_args) -def set_vm(cmd, instance, lro_operation=None, no_wait=False): - instance.resources = None # Issue: https://github.com/Azure/autorest/issues/934 - client = _compute_client_factory(cmd.cli_ctx) - parsed_id = _parse_rg_name(instance.id) - poller = sdk_no_wait(no_wait, client.virtual_machines.begin_create_or_update, - resource_group_name=parsed_id[0], - vm_name=parsed_id[1], - parameters=instance) - if lro_operation: - return lro_operation(poller) - - return LongRunningOperation(cmd.cli_ctx)(poller) - - # Notes: vm format is in snake_case def set_vm_by_aaz(cmd, vm, no_wait=False): from .aaz.latest.vm import Create as _VMCreate @@ -1784,19 +1743,6 @@ def _output(self, *args, **kwargs): return vm -def patch_vm(cmd, resource_group_name, vm_name, vm): - client = _compute_client_factory(cmd.cli_ctx) - poller = client.virtual_machines.begin_update(resource_group_name, vm_name, vm) - return LongRunningOperation(cmd.cli_ctx)(poller) - - -def patch_disk_encryption_set(cmd, resource_group_name, disk_encryption_set_name, disk_encryption_set_update): - client = _compute_client_factory(cmd.cli_ctx) - poller = client.disk_encryption_sets.begin_update(resource_group_name, disk_encryption_set_name, - disk_encryption_set_update) - return LongRunningOperation(cmd.cli_ctx)(poller) - - def show_vm(cmd, resource_group_name, vm_name, show_details=False, include_user_data=False): if show_details: return get_vm_details(cmd, resource_group_name, vm_name, include_user_data) @@ -2656,10 +2602,8 @@ def set_extension(cmd, resource_group_name, vm_name, vm_extension_name, publishe # region VirtualMachines Extension Images -def list_vm_extension_images( - cmd, image_location=None, publisher_name=None, name=None, version=None, latest=False): - return load_extension_images_thru_services( - cmd.cli_ctx, publisher_name, name, version, image_location, latest) +def list_vm_extension_images(cmd, image_location=None, publisher_name=None, name=None, version=None, latest=False): + return load_extension_images_thru_services(cmd.cli_ctx, publisher_name, name, version, image_location, latest) # endregion @@ -4282,26 +4226,6 @@ def deallocate_vmss(cmd, resource_group_name, vm_scale_set_name, instance_ids=No return VmssDeallocate(cli_ctx=cmd.cli_ctx)(command_args=command_args) -def get_vmss(cmd, resource_group_name, name, instance_id=None, include_user_data=False): - client = _compute_client_factory(cmd.cli_ctx) - - expand = None - if include_user_data: - expand = 'userData' - - if instance_id is not None: - if cmd.supported_api_version(min_api='2020-12-01', operation_group='virtual_machine_scale_sets'): - return client.virtual_machine_scale_set_vms.get(resource_group_name=resource_group_name, - vm_scale_set_name=name, instance_id=instance_id, - expand=expand) - return client.virtual_machine_scale_set_vms.get(resource_group_name=resource_group_name, - vm_scale_set_name=name, instance_id=instance_id) - - if cmd.supported_api_version(min_api='2021-03-01', operation_group='virtual_machine_scale_sets'): - return client.virtual_machine_scale_sets.get(resource_group_name, name, expand=expand) - return client.virtual_machine_scale_sets.get(resource_group_name, name) - - def get_vmss_by_aaz(cmd, resource_group_name, name, instance_id=None, include_user_data=False): from .operations.vmss import VMSSShow from .operations.vmss_vms import VMSSVMSShow @@ -5919,7 +5843,7 @@ def undelete_image_version(cmd, resource_group_name, gallery_name, gallery_image def fix_gallery_image_date_info(date_info): - # here we add needed time, if only date is provided, so the setting can be accepted by servie end + # here we add needed time, if only date is provided, so the setting can be accepted by service end if date_info and 't' not in date_info.lower(): date_info += 'T12:59:59Z' return date_info @@ -6083,7 +6007,6 @@ def update_dedicated_host(cmd, host_group_name, host_name, resource_group_name, # region VMMonitor def _get_log_analytics_client(cmd): - from ._client_factory import cf_log_analytics from azure.cli.core.commands.client_factory import get_subscription_id subscription_id = get_subscription_id(cmd.cli_ctx) return cf_log_analytics(cmd.cli_ctx, subscription_id) @@ -6120,7 +6043,6 @@ def _prepare_workspace(cmd, resource_group_name, workspace): def _set_data_source_for_workspace(cmd, os_type, resource_group_name, workspace_name): - from ._client_factory import cf_log_analytics_data_sources from azure.cli.core.commands.client_factory import get_subscription_id from azure.mgmt.loganalytics.models import DataSource from azure.core.exceptions import HttpResponseError