Skip to content
1 change: 1 addition & 0 deletions src/command_modules/azure-cli-vm/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Release History

2.2.7
++++++
* `image create`: expose storage-sku argument for setting the image's default storage account type
* `vm resize`: fix bug where `--no-wait` option causes command to crash

2.2.6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1395,8 +1395,7 @@
- name: Create an image from an existing disk.
text: |
az image create -g MyResourceGroup -n image1 --os-type Linux \\
--source /subscriptions/db5eb68e-73e2-4fa8-b18a-0123456789999/resourceGroups/rg1/providers/Microsoft.Compute/snapshots/s1 \\
--data-snapshot /subscriptions/db5eb68e-73e2-4fa8-b18a-0123456789999/resourceGroups/rg/providers/Microsoft.Compute/snapshots/s2
--source /subscriptions/db5eb68e-73e2-4fa8-b18a-0123456789999/resourceGroups/rg1/providers/Microsoft.Compute/snapshots/s1
- name: Create an image by capturing an existing generalized virtual machine in the same resource group.
text: az image create -g MyResourceGroup -n image1 --source MyVm1
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

# pylint: disable=too-many-statements, too-many-branches
def load_arguments(self, _):
from azure.mgmt.compute.models import CachingTypes, UpgradeMode
StorageAccountTypes, UpgradeMode, CachingTypes = self.get_models('StorageAccountTypes', 'UpgradeMode', 'CachingTypes')

# REUSABLE ARGUMENT DEFINITIONS
name_arg_type = CLIArgumentType(options_list=['--name', '-n'], metavar='NAME')
Expand All @@ -40,11 +40,12 @@ def load_arguments(self, _):
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')
if self.supported_api_version(min_api='2018-06-01', operation_group='disks') or self.supported_api_version(min_api='2018-06-01', operation_group='virtual_machines'):
disk_sku = CLIArgumentType(arg_type=get_enum_type(['Premium_LRS', 'Standard_LRS', 'StandardSSD_LRS', 'UltraSSD_LRS']))
elif self.supported_api_version(min_api='2018-04-01', operation_group='disks') or self.supported_api_version(min_api='2018-06-01', operation_group='virtual_machines'):
disk_sku = CLIArgumentType(arg_type=get_enum_type(['Premium_LRS', 'Standard_LRS', 'StandardSSD_LRS']))

if StorageAccountTypes:
disk_sku = CLIArgumentType(arg_type=get_enum_type(StorageAccountTypes))
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let us get rid of this else

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yugangw-msft, i added this because .get_models(storageaccounttypes) fails for some profiles.

See this job in this previous CI build. Also see the other failed job in the build.

Copy link
Contributor Author

@adewaleo adewaleo Oct 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will verify this works and open an issue in our repo to reference the service end bug.

# StorageAccountTypes introduced in api version 2016_04_30_preview of Resource.MGMT.Compute package..
# However, 2017-03-09-profile targets version 2016-03-30 of compute package.
disk_sku = CLIArgumentType(arg_type=get_enum_type(['Premium_LRS', 'Standard_LRS']))

# special case for `network nic scale-set list` command alias
Expand Down Expand Up @@ -110,6 +111,7 @@ def load_arguments(self, _):
c.argument('data_disk_sources', nargs='+', help='Space-separated list of data disk sources, including unmanaged blob URI, managed disk ID or name, or snapshot ID or name')
c.argument('zone_resilient', min_api='2017-12-01', arg_type=get_three_state_flag(), help='Specifies whether an image is zone resilient or not. '
'Default is false. Zone resilient images can be created only in regions that provide Zone Redundant Storage')
c.argument('storage_sku', arg_type=disk_sku, help='The SKU of the storage account with which to create the VM image. Unused if source VM is specified.')
c.ignore('source_virtual_machine', 'os_blob_uri', 'os_disk', 'os_snapshot', 'data_blob_uris', 'data_disks', 'data_snapshots')
# endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def update_managed_disk(cmd, instance, size_gb=None, sku=None, disk_iops_read_wr
# region Images (Managed)
def create_image(cmd, resource_group_name, name, source, os_type=None, data_disk_sources=None, location=None, # pylint: disable=too-many-locals,unused-argument
# below are generated internally from 'source' and 'data_disk_sources'
source_virtual_machine=None,
source_virtual_machine=None, storage_sku=None,
os_blob_uri=None, data_blob_uris=None,
os_snapshot=None, data_snapshots=None,
os_disk=None, data_disks=None, tags=None, zone_resilient=None):
Expand All @@ -330,7 +330,8 @@ def create_image(cmd, resource_group_name, name, source, os_type=None, data_disk
os_state=OperatingSystemStateTypes.generalized,
snapshot=SubResource(id=os_snapshot) if os_snapshot else None,
managed_disk=SubResource(id=os_disk) if os_disk else None,
blob_uri=os_blob_uri)
blob_uri=os_blob_uri,
storage_account_type=storage_sku)
all_data_disks = []
lun = 0
if data_blob_uris:
Expand Down
Loading