Skip to content

Commit

Permalink
[Compute] BREAKING CHANGE: az snapshot: Migrate commands using Code…
Browse files Browse the repository at this point in the history
… Gen V2 (Azure#30486)
  • Loading branch information
yanzhudd authored Dec 9, 2024
1 parent 025ac6c commit dd424b8
Show file tree
Hide file tree
Showing 49 changed files with 8,682 additions and 2,770 deletions.
40 changes: 0 additions & 40 deletions src/azure-cli/azure/cli/command_modules/vm/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1287,46 +1287,6 @@
text: az snapshot create -g MyResourceGroup -n MySnapshot --size-gb 10 --network-access-policy AllowPrivate --disk-access MyDiskAccessID
"""

helps['snapshot grant-access'] = """
type: command
short-summary: Grant read access to a snapshot.
examples:
- name: Grant read access to a snapshot. (autogenerated)
text: |
az snapshot grant-access --duration-in-seconds 3600 --name MySnapshot --resource-group MyResourceGroup
crafted: true
- name: Grant read access to a snapshot with specifying the file format.
text: |
az snapshot grant-access --duration-in-seconds 3600 --name MySnapshot --resource-group MyResourceGroup --file-format VHDX
"""

helps['snapshot update'] = """
type: command
short-summary: Update a snapshot.
examples:
- name: Update a snapshot and associate it with a disk access resource.
text: |
az snapshot update --name MySnapshot --resource-group MyResourceGroup --network-access-policy AllowPrivate --disk-access MyDiskAccessID
- name: Update a snapshot. (autogenerated)
text: |
az snapshot update --name MySnapshot --resource-group MyResourceGroup --subscription MySubscription
crafted: true
"""

helps['snapshot wait'] = """
type: command
short-summary: Place the CLI in a waiting state until a condition of a snapshot is met.
examples:
- name: Place the CLI in a waiting state until a condition of a snapshot is met. (autogenerated)
text: |
az snapshot wait --exists --name MySnapshot --resource-group MyResourceGroup
crafted: true
- name: Place the CLI in a waiting state until a condition of a snapshot is met. (autogenerated)
text: |
az snapshot wait --created --name MySnapshot --resource-group MyResourceGroup
crafted: true
"""

helps['vm'] = """
type: group
short-summary: Manage Linux or Windows virtual machines.
Expand Down
12 changes: 1 addition & 11 deletions src/azure-cli/azure/cli/command_modules/vm/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from azure.cli.command_modules.vm._validators import (
validate_nsg_name, validate_vm_nics, validate_vm_nic, validate_vmss_disk,
validate_asg_names_or_ids, validate_keyvault, _validate_proximity_placement_group,
validate_vm_name_for_monitor_metrics, validate_secure_vm_guest_state_sas)
validate_vm_name_for_monitor_metrics)

from azure.cli.command_modules.vm._vm_utils import MSI_LOCAL_ID
from azure.cli.command_modules.vm._image_builder import ScriptType
Expand Down Expand Up @@ -175,13 +175,6 @@ def load_arguments(self, _):
c.argument('secure_vm_disk_encryption_set', min_api='2021-08-01', help='Name or ID of disk encryption set created with ConfidentialVmEncryptedWithCustomerKey encryption type.')
# endregion

# region Disks
with self.argument_context('disk grant-access', resource_type=ResourceType.MGMT_COMPUTE, operation_group='disks') as c:
c.argument('secure_vm_guest_state_sas', options_list=['--secure-vm-guest-state-sas', '-s'], min_api='2022-03-02',
action='store_true', validator=validate_secure_vm_guest_state_sas,
help="Get SAS on managed disk with VM guest state. It will be used by default when the create option of disk is 'secureOSUpload'")
# endregion

# region Disks
with self.argument_context('disk', resource_type=ResourceType.MGMT_COMPUTE, operation_group='disks') as c:
# The `Standard` is used for backward compatibility to allow customers to keep their current behavior after changing the default values to Trusted Launch VMs in the future.
Expand Down Expand Up @@ -246,9 +239,6 @@ def load_arguments(self, _):
c.argument('bandwidth_copy_speed', min_api='2023-10-02',
help='If this field is set on a snapshot and createOption is CopyStart, the snapshot will be copied at a quicker speed.',
arg_type=get_enum_type(["None", "Enhanced"]))

with self.argument_context('snapshot grant-access', resource_type=ResourceType.MGMT_COMPUTE, operation_group='snapshots') as c:
c.argument('file_format', arg_type=get_enum_type(self.get_models('FileFormat', operation_group='snapshots')), help='Used to specify the file format when making request for SAS on a VHDX file format snapshot.')
# endregion

# region Images
Expand Down
9 changes: 0 additions & 9 deletions src/azure-cli/azure/cli/command_modules/vm/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2655,12 +2655,3 @@ def _validate_community_gallery_legal_agreement_acceptance(cmd, namespace):
if not prompt_y_n(msg, default="y"):
import sys
sys.exit(0)


def validate_secure_vm_guest_state_sas(cmd, namespace):
compute_client = _compute_client_factory(cmd.cli_ctx)
disk_info = compute_client.disks.get(namespace.resource_group_name, namespace.disk_name)
DiskCreateOption = cmd.get_models('DiskCreateOption')

if disk_info.creation_data and disk_info.creation_data.create_option == DiskCreateOption.upload_prepared_secure:
namespace.secure_vm_guest_state_sas = True
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
# flake8: noqa

from .__cmd_group import *
from ._create import *
from ._delete import *
from ._grant_access import *
from ._list import *
from ._revoke_access import *
from ._show import *
from ._update import *
from ._wait import *
Loading

0 comments on commit dd424b8

Please sign in to comment.