Skip to content

Commit

Permalink
fix style check
Browse files Browse the repository at this point in the history
  • Loading branch information
yanzhudd committed Nov 12, 2024
1 parent c88e1cc commit 4d3c63d
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def get_vmss_table_output_transformer(loader, for_list=True):
transform = '{Name:name, ResourceGroup:resourceGroup, Location:location, $zone$Capacity:sku.capacity, ' \
'Overprovision:overprovision, UpgradePolicy:upgradePolicy.mode}'
transform = transform.replace('$zone$', 'Zones: (!zones && \' \') || join(\' \', zones), '
if loader.supported_api_version(min_api='2017-03-30') else ' ')
if loader.supported_api_version(min_api='2017-03-30') else ' ')
return transform if not for_list else '[].' + transform


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ def _validate_location(location, location_names, location_display_names):
return location


def process_image_template_create_namespace(cmd,
namespace): # pylint: disable=too-many-locals, too-many-branches, too-many-statements
def process_image_template_create_namespace(cmd, namespace): # pylint: disable=too-many-locals, too-many-branches, too-many-statements
if namespace.image_template is not None:
return

Expand Down
15 changes: 5 additions & 10 deletions src/azure-cli/azure/cli/command_modules/vm/azure_stack/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ def load_arguments(self, _):
id_part='name')
vmss_name_type = CLIArgumentType(name_arg_type,
configured_default='vmss',
completer=get_resource_name_completion_list(
'Microsoft.Compute/virtualMachineScaleSets'),
completer=get_resource_name_completion_list('Microsoft.Compute/virtualMachineScaleSets'),
help="Scale set name. You can configure the default using `az configure --defaults vmss=<name>`",
id_part='name')

Expand Down Expand Up @@ -1487,9 +1486,8 @@ def load_arguments(self, _):
help='space-separated empty managed data disk sizes in GB to create')
c.ignore('disk_info', 'storage_account_type', 'public_ip_address_type', 'nsg_type', 'nic_type', 'vnet_type',
'load_balancer_type', 'app_gateway_type')
c.argument('os_caching', options_list=[
self.deprecate(target='--storage-caching', redirect='--os-disk-caching', hide=True),
'--os-disk-caching'], help='Storage caching type for the VM OS disk. Default: ReadWrite',
c.argument('os_caching', options_list=[self.deprecate(target='--storage-caching', redirect='--os-disk-caching', hide=True), '--os-disk-caching'],
help='Storage caching type for the VM OS disk. Default: ReadWrite',
arg_type=get_enum_type(CachingTypes))
c.argument('data_caching', options_list=['--data-disk-caching'], nargs='+',
help="storage caching type for data disk(s), including 'None', 'ReadOnly', 'ReadWrite', etc. Use a singular value to apply on all disks, or use `<lun>=<vaule1> <lun>=<value2>` to configure individual disk")
Expand Down Expand Up @@ -1749,8 +1747,7 @@ def load_arguments(self, _):
min_api='2020-09-30',
help='This property allows you to specify the permission of sharing gallery.')
c.argument('soft_delete', arg_type=get_three_state_flag(), min_api='2021-03-01',
deprecate_info=Deprecated(self.cli_ctx, hide=True, message_func=lambda
x: "Argument '--soft-delete' is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus"),
deprecate_info=Deprecated(self.cli_ctx, hide=True, message_func=lambda x: "Argument '--soft-delete' is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus"),
help='Enable soft-deletion for resources in this gallery, '
'allowing them to be recovered within retention time.')
c.argument('publisher_uri', help='Community gallery publisher uri.')
Expand Down Expand Up @@ -2026,9 +2023,7 @@ def load_arguments(self, _):
c.argument('disk_encryption_set_name', disk_encryption_set_name)
c.argument('key_url', help='URL pointing to a key or secret in KeyVault.')
c.argument('source_vault', help='Name or ID of the KeyVault containing the key or secret.')
c.argument('encryption_type', arg_type=get_enum_type(
['EncryptionAtRestWithPlatformKey', 'EncryptionAtRestWithCustomerKey',
'EncryptionAtRestWithPlatformAndCustomerKeys', 'ConfidentialVmEncryptedWithCustomerKey']),
c.argument('encryption_type', arg_type=get_enum_type(['EncryptionAtRestWithPlatformKey', 'EncryptionAtRestWithCustomerKey', 'EncryptionAtRestWithPlatformAndCustomerKeys', 'ConfidentialVmEncryptedWithCustomerKey']),
help='The type of key used to encrypt the data of the disk. EncryptionAtRestWithPlatformKey: Disk is encrypted at rest with Platform managed key. It is the default encryption type. EncryptionAtRestWithCustomerKey: Disk is encrypted at rest with Customer managed key that can be changed and revoked by a customer. EncryptionAtRestWithPlatformAndCustomerKeys: Disk is encrypted at rest with 2 layers of encryption. One of the keys is Customer managed and the other key is Platform managed. ConfidentialVmEncryptedWithCustomerKey: An additional encryption type accepted for confidential VM. Disk is encrypted at rest with Customer managed key.')
c.argument('location', validator=get_default_location_from_resource_group)
c.argument('tags', tags_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def validate_nsg_name(cmd, namespace):
namespace='Microsoft.Compute', type='virtualMachines',
subscription=get_subscription_id(cmd.cli_ctx))
namespace.network_security_group_name = namespace.network_security_group_name \
or '{}_NSG_{}'.format(namespace.vm_name, hash_string(vm_id, length=8))
or '{}_NSG_{}'.format(namespace.vm_name, hash_string(vm_id, length=8))


def validate_keyvault(cmd, namespace):
Expand Down Expand Up @@ -1366,7 +1366,7 @@ def _validate_vm_vmss_msi(cmd, namespace, is_identity_assign=False):
def _enable_msi_for_trusted_launch(namespace):
# Enable system assigned msi by default when Trusted Launch configuration is met
is_trusted_launch = namespace.security_type and namespace.security_type.lower() == 'trustedlaunch' \
and namespace.enable_vtpm and namespace.enable_secure_boot
and namespace.enable_vtpm and namespace.enable_secure_boot
if is_trusted_launch and namespace.enable_integrity_monitoring:
from ._vm_utils import MSI_LOCAL_ID
logger.info('The MSI is enabled by default when Trusted Launch configuration is met')
Expand Down Expand Up @@ -1646,8 +1646,7 @@ def _validate_vmss_create_load_balancer_or_app_gateway(cmd, namespace):
})
namespace.app_gateway_type = 'existing'
namespace.backend_pool_name = namespace.backend_pool_name or \
_get_default_address_pool(cmd.cli_ctx, rg, ag_name,
'application_gateways')
_get_default_address_pool(cmd.cli_ctx, rg, ag_name, 'application_gateways')
logger.debug("using specified existing application gateway '%s'", namespace.application_gateway)
except HttpResponseError:
namespace.app_gateway_type = 'new'
Expand Down Expand Up @@ -1685,7 +1684,7 @@ def _validate_vmss_create_load_balancer_or_app_gateway(cmd, namespace):
if lb:
namespace.load_balancer_type = 'existing'
namespace.backend_pool_name = namespace.backend_pool_name or \
_get_default_address_pool(cmd.cli_ctx, rg, lb_name, 'load_balancers')
_get_default_address_pool(cmd.cli_ctx, rg, lb_name, 'load_balancers')
if not namespace.nat_pool_name:
if len(lb['inboundNatPools']) > 1:
raise CLIError(
Expand Down Expand Up @@ -1986,8 +1985,8 @@ def process_disk_create_namespace(cmd, namespace):
'--source VHD_BLOB_URI [--source-storage-account-id ID]'
try:
namespace.source_blob_uri, namespace.source_disk, namespace.source_snapshot, \
namespace.source_restore_point, _ = _figure_out_storage_source(
cmd.cli_ctx, namespace.resource_group_name, namespace.source)
namespace.source_restore_point, _ = _figure_out_storage_source(
cmd.cli_ctx, namespace.resource_group_name, namespace.source)
if not namespace.source_blob_uri and namespace.source_storage_account_id:
raise ArgumentUsageError(usage_error)
except HttpResponseError:
Expand Down Expand Up @@ -2118,9 +2117,10 @@ def process_image_create_namespace(cmd, namespace):
raise CLIError("'--data-disk-sources' is not allowed when capturing "
"images from virtual machines")
else:
# pylint: disable=line-too-long
namespace.os_blob_uri, namespace.os_disk, namespace.os_snapshot, _, _ = _figure_out_storage_source(cmd.cli_ctx,
namespace.resource_group_name,
namespace.source) # pylint: disable=line-too-long
namespace.source)
namespace.data_blob_uris = []
namespace.data_disks = []
namespace.data_snapshots = []
Expand Down Expand Up @@ -2212,9 +2212,9 @@ def process_set_applications_namespace(cmd, namespace): # pylint: disable=unuse
def process_gallery_image_version_namespace(cmd, namespace):
from azure.cli.core.azclierror import InvalidArgumentValueError
TargetRegion, EncryptionImages, OSDiskImageEncryption, DataDiskImageEncryption, \
ConfidentialVMEncryptionType, GalleryTargetExtendedLocation, GalleryExtendedLocation = cmd.get_models(
'TargetRegion', 'EncryptionImages', 'OSDiskImageEncryption', 'DataDiskImageEncryption',
'ConfidentialVMEncryptionType', 'GalleryTargetExtendedLocation', 'GalleryExtendedLocation')
ConfidentialVMEncryptionType, GalleryTargetExtendedLocation, GalleryExtendedLocation = cmd.get_models(
'TargetRegion', 'EncryptionImages', 'OSDiskImageEncryption', 'DataDiskImageEncryption',
'ConfidentialVMEncryptionType', 'GalleryTargetExtendedLocation', 'GalleryExtendedLocation')

if namespace.target_regions:
if hasattr(namespace, 'target_region_encryption') and namespace.target_region_encryption:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ def display_region_recommendation(cmd, namespace):
if identified_region and cmd.cli_ctx.config.getboolean('core', 'display_region_identified', True):
from azure.cli.core.style import Style, print_styled_text
import sys
# pylint: disable=line-too-long
recommend_region = 'Selecting "' + identified_region + '" may reduce your costs. ' \
'The region you\'ve selected may cost more for the same services. ' \
'You can disable this message in the future with the command '
Expand Down
15 changes: 8 additions & 7 deletions src/azure-cli/azure/cli/command_modules/vm/azure_stack/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,7 @@ def create_vm(cmd, vm_name, resource_group_name, image=None, size='Standard_DS1_
from azure.cli.core.commands.client_factory import get_subscription_id
from azure.cli.core.util import random_string, hash_string
from azure.cli.core.commands.arm import ArmTemplateBuilder
# pylint: disable=line-too-long
from azure.cli.command_modules.vm.azure_stack._template_builder import (build_vm_resource,
build_storage_account_resource,
build_nic_resource,
Expand Down Expand Up @@ -1187,7 +1188,7 @@ def create_vm(cmd, vm_name, resource_group_name, image=None, size='Standard_DS1_

# Guest Attestation Extension and enable System Assigned MSI by default
is_trusted_launch = security_type and security_type.lower() == 'trustedlaunch' and \
enable_vtpm and enable_secure_boot
enable_vtpm and enable_secure_boot
if is_trusted_launch and enable_integrity_monitoring:
vm = get_vm(cmd, resource_group_name, vm_name, 'instanceView')
client = _compute_client_factory(cmd.cli_ctx)
Expand Down Expand Up @@ -2010,7 +2011,7 @@ def set_diagnostics_extension(
exts = vm.instance_view.extensions or []
major_ver = extension_mappings[_LINUX_DIAG_EXT]['version'].split('.')[0]
if next((e for e in exts if e.name == vm_extension_name and
not e.type_handler_version.startswith(major_ver + '.')), None):
not e.type_handler_version.startswith(major_ver + '.')), None):
logger.warning('There is an incompatible version of diagnostics extension installed. '
'We will update it with a new version')
poller = client.virtual_machine_extensions.begin_delete(resource_group_name, vm_name, vm_extension_name)
Expand Down Expand Up @@ -3638,7 +3639,7 @@ def _get_public_ip_address_allocation(value, sku):
vmss_info.identity.user_assigned_identities)
# Guest Attestation Extension and enable System Assigned MSI by default
is_trusted_launch = security_type and security_type.lower() == 'trustedlaunch' and \
enable_vtpm and enable_secure_boot
enable_vtpm and enable_secure_boot
if is_trusted_launch and enable_integrity_monitoring:
client = _compute_client_factory(cmd.cli_ctx)
vmss = client.virtual_machine_scale_sets.get(resource_group_name, vmss_name)
Expand Down Expand Up @@ -4332,7 +4333,7 @@ def set_vmss_diagnostics_extension(
# For VMSS, we don't do auto-removal like VM because there is no reliable API to wait for
# the removal done before we can install the newer one
if next((e for e in exts if e.name == _LINUX_DIAG_EXT and
not e.type_handler_version.startswith(major_ver + '.')), None):
not e.type_handler_version.startswith(major_ver + '.')), None):
delete_cmd = 'az vmss extension delete -g {} --vmss-name {} -n {}'.format(
resource_group_name, vmss_name, vm_extension_name)
raise CLIError("There is an incompatible version of diagnostics extension installed. "
Expand Down Expand Up @@ -5284,10 +5285,10 @@ def _set_data_source_for_workspace(cmd, os_type, resource_group_name, workspace_

default_data_sources = None
if os_type.lower() == 'linux':
from ._workspace_data_source_settings import default_linux_data_sources
from .._workspace_data_source_settings import default_linux_data_sources
default_data_sources = default_linux_data_sources
elif os_type.lower() == 'windows':
from ._workspace_data_source_settings import default_windows_data_sources
from .._workspace_data_source_settings import default_windows_data_sources
default_data_sources = default_windows_data_sources

if default_data_sources is not None:
Expand Down Expand Up @@ -6148,7 +6149,7 @@ def restore_point_collection_update(client,

# region Community gallery
def sig_community_gallery_list(cmd, location=None, marker=None, show_next_marker=None):
from ._arg_client import ARGClient, QueryBody
from .._arg_client import ARGClient, QueryBody

query_table = 'communitygalleryresources'
query_type = 'microsoft.compute/locations/communitygalleries'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def _show_post_action_message(resource_group_name, vmss_name, maunal_mode, enabl
"--instance-ids \"*\"' to propagate the change.\n".format(resource_group_name, vmss_name))
msg += ("Note, {} encryption will take a while to finish. Please query the status using "
"'az vmss encryption show -g {} -n {}'. For Linux VM, you will lose the access during the period".format(
'enabling' if enable else 'disabling', resource_group_name, vmss_name))
'enabling' if enable else 'disabling', resource_group_name, vmss_name))
logger.warning(msg)


Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/azure/cli/command_modules/vm/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
transform_disk_create_table_output, transform_sku_for_table_output, transform_disk_show_table_output,
transform_extension_show_table_output, get_vmss_table_output_transformer,
transform_vm_encryption_show_table_output, transform_log_analytics_query_output,
transform_vmss_list_with_zones_table_output, transform_vmss_list_without_zones_table_output)
transform_vmss_list_with_zones_table_output)
from azure.cli.command_modules.vm._validators import (
process_vm_create_namespace, process_vmss_create_namespace, process_image_create_namespace,
process_disk_create_namespace, process_snapshot_create_namespace,
Expand Down

0 comments on commit 4d3c63d

Please sign in to comment.