Skip to content

Commit

Permalink
[Compute] Direct sharing support (#18503)
Browse files Browse the repository at this point in the history
* init

* 'test'

* update test

* update test

* test recording

* style

* remove generated test

* add command to get shared galleries

* fix test

* wait command

* Update src/azure-cli/azure/cli/command_modules/vm/generated/_help.py

Co-authored-by: Feiyue Yu <[email protected]>

* delete sig share update

* change the command format

* lint

* remove is_experimental

* update command design

* update command name and enum value

* add wait command

* linter

* Update src/azure-cli/azure/cli/command_modules/vm/manual/_help.py

Co-authored-by: Feiyue Yu <[email protected]>

* Update src/azure-cli/azure/cli/command_modules/vm/manual/_help.py

Co-authored-by: Feiyue Yu <[email protected]>

* Update src/azure-cli/azure/cli/command_modules/vm/generated/_params.py

Co-authored-by: Feiyue Yu <[email protected]>

* help info

* regenerate command interface but manual not work

* test pass

* fix test

* resolve comments

* fix style

* Update src/azure-cli/azure/cli/command_modules/vm/manual/_help.py

Co-authored-by: xfz11 <[email protected]>

* test pass

* revert

* revert

* delete

* fix typo

* refine help

* Apply suggestions from code review

Co-authored-by: Xing Zhou <[email protected]>

* add permission to create

Co-authored-by: xiaofanzhou <[email protected]>
Co-authored-by: xfz11 <[email protected]>
Co-authored-by: Feiyue Yu <[email protected]>
Co-authored-by: Xing Zhou <[email protected]>
  • Loading branch information
5 people authored Jun 23, 2021
1 parent d22ac08 commit e94eced
Show file tree
Hide file tree
Showing 15 changed files with 5,301 additions and 755 deletions.
3 changes: 2 additions & 1 deletion src/azure-cli-core/azure/cli/core/profiles/_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ def default_api_version(self):
'disk_encryption_sets': '2020-12-01',
'disk_accesses': '2020-05-01',
'snapshots': '2020-12-01',
'galleries': '2019-12-01',
'galleries': '2020-09-30',
'gallery_images': '2020-09-30',
'gallery_image_versions': '2020-09-30',
'shared_galleries': '2020-09-30',
'virtual_machine_scale_sets': '2021-03-01'
}),
ResourceType.MGMT_RESOURCE_FEATURES: '2015-12-01',
Expand Down
23 changes: 23 additions & 0 deletions src/azure-cli/azure/cli/command_modules/vm/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,26 @@ def _dev_test_labs_client_factory(cli_ctx, subscription_id, *_):
from azure.mgmt.devtestlabs import DevTestLabsClient
from azure.cli.core.commands.client_factory import get_mgmt_service_client
return get_mgmt_service_client(cli_ctx, DevTestLabsClient, subscription_id=subscription_id)


def cf_vm_cl(cli_ctx, *_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.mgmt.compute import ComputeManagementClient
return get_mgmt_service_client(cli_ctx,
ComputeManagementClient)


def cf_shared_galleries(cli_ctx, *_):
return cf_vm_cl(cli_ctx).shared_galleries


def cf_gallery_sharing_profile(cli_ctx, *_):
return cf_vm_cl(cli_ctx).gallery_sharing_profile


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
116 changes: 114 additions & 2 deletions src/azure-cli/azure/cli/command_modules/vm/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@

helps['sig image-definition'] = """
type: group
short-summary: create an image definition
short-summary: Manage shared gallery image with VM
"""

helps['sig image-definition create'] = """
Expand All @@ -611,6 +611,28 @@
az sig image-definition create -g MyResourceGroup --gallery-name MyGallery --gallery-image-definition MyImage --publisher GreatPublisher --offer GreatOffer --sku GreatSku --os-type linux
"""

helps['sig image-definition list-shared'] = """
type: command
short-summary: List shared gallery images by subscription id or tenant id.
examples:
- name: List shared images by subscription id.
text: |-
az sig image-definition list-shared --gallery-unique-name "galleryUniqueName" --location "myLocation"
- name: List shared images by tenant id.
text: |-
az sig image-definition list-shared --gallery-unique-name "galleryUniqueName" --location "myLocation" --shared-to tenant
"""

helps['sig image-definition show-shared'] = """
type: command
short-summary: Get a shared gallery image.
examples:
- name: Get a shared gallery image.
text: |-
az sig image-definition show-shared --gallery-image-definition "myGalleryImageName" \
--gallery-unique-name "galleryUniqueName" --location "myLocation"
"""

helps['sig image-definition update'] = """
type: command
short-summary: update a share image defintiion.
Expand All @@ -623,7 +645,7 @@

helps['sig image-version'] = """
type: group
short-summary: create a new version from an image defintion
short-summary: Manage shared gallery image version with VM
"""

helps['sig image-version create'] = """
Expand Down Expand Up @@ -684,6 +706,30 @@
az sig image-version create -g MyResourceGroup --gallery-name MyGallery --gallery-image-definition MyImage --gallery-image-version 1.0.0 --os-vhd-uri <vhd-uri> --os-vhd-storage-account account
"""

helps['sig image-version list-shared'] = """
type: command
short-summary: List shared gallery image versions by subscription id or tenant id.
examples:
- name: List shared image versions by subscription id.
text: |-
az sig image-version list-shared --gallery-image-definition "myGalleryImageName" --gallery-unique-name \
"galleryUniqueName" --location "myLocation"
- name: List shared image versions by tenant id.
text: |-
az sig image-version list-shared --gallery-image-definition "myGalleryImageName" --gallery-unique-name \
"galleryUniqueName" --location "myLocation" --shared-to tenant
"""

helps['sig image-version show-shared'] = """
type: command
short-summary: Get a shared gallery image version.
examples:
- name: Get a shared gallery image version.
text: |-
az sig image-version show-shared --gallery-image-definition "myGalleryImageName" \
--gallery-image-version "myGalleryImageVersionName" --gallery-unique-name "galleryUniqueName" --location "myLocation"
"""

helps['sig image-version update'] = """
type: command
short-summary: update a share image version
Expand Down Expand Up @@ -722,11 +768,77 @@
crafted: true
"""

helps['sig list-shared'] = """
type: command
short-summary: List shared galleries by subscription id or tenant id.
examples:
- name: List shared galleries by subscription id.
text: |-
az sig list-shared --location "myLocation"
- name: List shared galleries by tenant id.
text: |-
az sig list-shared --location "myLocation" --shared-to tenant
"""

helps['sig list'] = """
type: command
short-summary: list share image galleries.
"""

helps['sig share'] = """
type: group
short-summary: Manage gallery sharing profile
"""

helps['sig share add'] = """
type: command
short-summary: Add sharing id to the sharing profile of a gallery.
examples:
- name: Add sharing id to the sharing profile of a gallery.
text: |-
az sig share add --gallery-name "myGalleryName" --resource-group "myResourceGroup" \
--subscription-ids "34a4ab42-0d72-47d9-bd1a-aed207386dac" "380fd389-260b-41aa-bad9-0a83108c370b" \
--tenant-ids "c24c76aa-8897-4027-9b03-8f7928b54ff6"
"""

helps['sig share remove'] = """
type: command
short-summary: Remove sharing profile of a gallery.
examples:
- name: Remove sharing ID to the sharing profile of a gallery.
text: |-
az sig share remove --gallery-name "myGalleryName" --resource-group "myResourceGroup" \
--subscription-ids "34a4ab42-0d72-47d9-bd1a-aed207386dac" "380fd389-260b-41aa-bad9-0a83108c370b" \
--tenant-ids "c24c76aa-8897-4027-9b03-8f7928b54ff6"
"""

helps['sig share reset'] = """
type: command
short-summary: Reset sharing profile of a gallery.
examples:
- name: Reset sharing profile of a gallery.
text: |-
az sig share reset --gallery-name "myGalleryName" --resource-group "myResourceGroup"
"""

helps['sig share wait'] = """
type: command
short-summary: Place the CLI in a waiting state until a condition of a shared gallery is met.
examples:
- name: Place the CLI in a waiting state until the gallery sharing object is updated.
text: |
az sig share wait --updated -g MyResourceGroup --gallery-name Gallery
"""

helps['sig show-shared'] = """
type: command
short-summary: Get a shared gallery.
examples:
- name: Get a shared gallery.
text: |-
az sig show-shared --gallery-unique-name "galleryUniqueName" --location "myLocation"
"""

helps['sig update'] = """
type: command
short-summary: update a share image gallery.
Expand Down
76 changes: 76 additions & 0 deletions src/azure-cli/azure/cli/command_modules/vm/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def load_arguments(self, _):
DedicatedHostLicenseTypes = self.get_models('DedicatedHostLicenseTypes')
OrchestrationServiceNames, OrchestrationServiceStateAction = self.get_models('OrchestrationServiceNames', 'OrchestrationServiceStateAction', operation_group='virtual_machine_scale_sets')
RebootSetting, VMGuestPatchClassificationWindows, VMGuestPatchClassificationLinux = self.get_models('VMGuestPatchRebootSetting', 'VMGuestPatchClassificationWindows', 'VMGuestPatchClassificationLinux')
GallerySharingPermissionTypes = self.get_models('GallerySharingPermissionTypes', operation_group='shared_galleries')

# REUSABLE ARGUMENT DEFINITIONS
name_arg_type = CLIArgumentType(options_list=['--name', '-n'], metavar='NAME')
Expand Down Expand Up @@ -103,6 +104,13 @@ def load_arguments(self, _):
is_preview=True
)

t_shared_to = self.get_models('SharedToValues', operation_group='shared_galleries')
shared_to_type = CLIArgumentType(
arg_type=get_enum_type(t_shared_to),
help='The query parameter to decide what shared galleries to fetch when doing listing operations. '
'If not specified, list by subscription id.'
)

# region MixedScopes
for scope in ['vm', 'disk', 'snapshot', 'image', 'sig']:
with self.argument_context(scope) as c:
Expand Down Expand Up @@ -917,6 +925,32 @@ def load_arguments(self, _):
c.argument('gallery_name', options_list=['--gallery-name', '-r'], id_part='name', help='gallery name')
c.argument('gallery_image_name', options_list=['--gallery-image-definition', '-i'], id_part='child_name_1', help='gallery image definition')

with self.argument_context('sig list-shared') as c:
c.argument('location', arg_type=get_location_type(self.cli_ctx))
c.argument('shared_to', shared_to_type)

with self.argument_context('sig show-shared') as c:
c.argument('location', arg_type=get_location_type(self.cli_ctx), id_part='name')
c.argument('gallery_unique_name', type=str, help='The unique name of the Shared Gallery.',
id_part='child_name_1')

for scope in ['sig share add', 'sig share remove']:
with self.argument_context(scope) as c:
c.argument('gallery_name', type=str, help='The name of the Shared Image Gallery.', id_part='name')
c.argument('subscription_ids', nargs='+', help='A list of subscription ids to share the gallery.')
c.argument('tenant_ids', nargs='+', help='A list of tenant ids to share the gallery.')

with self.argument_context('sig share add') as c:
c.argument('op_type', default='Add', deprecate_info=c.deprecate(hide=True),
help='distinguish add operation and remove operation')

with self.argument_context('sig share remove') as c:
c.argument('op_type', default='Remove', deprecate_info=c.deprecate(hide=True),
help='distinguish add operation and remove operation')

with self.argument_context('sig share reset') as c:
c.argument('gallery_name', type=str, help='The name of the Shared Image Gallery.', id_part='name')

with self.argument_context('sig image-definition create') as c:
c.argument('offer', options_list=['--offer', '-f'], help='image offer')
c.argument('sku', options_list=['--sku', '-s'], help='image sku')
Expand All @@ -940,10 +974,31 @@ def load_arguments(self, _):
c.argument('disallowed_disk_types', nargs='*', help='disk types which would not work with the image, e.g., Standard_LRS')
c.argument('features', help='A list of gallery image features. E.g. "IsSecureBootSupported=true IsMeasuredBootSupported=false"')

with self.argument_context('sig image-definition list-shared') as c:
c.argument('location', arg_type=get_location_type(self.cli_ctx), id_part='name')
c.argument('gallery_unique_name', type=str, help='The unique name of the Shared Gallery.',
id_part='child_name_1')
c.argument('shared_to', shared_to_type)

with self.argument_context('sig image-definition show-shared') as c:
c.argument('location', arg_type=get_location_type(self.cli_ctx), id_part='name')
c.argument('gallery_unique_name', type=str, help='The unique name of the Shared Gallery.',
id_part='child_name_1')
c.argument('gallery_image_name', options_list=['--gallery-image-definition', '-i'], type=str, help='The name '
'of the Shared Gallery Image Definition from which the Image Versions are to be listed.',
id_part='child_name_2')

with self.argument_context('sig create') as c:
c.argument('description', help='the description of the gallery')
c.argument('permissions', arg_type=get_enum_type(GallerySharingPermissionTypes), arg_group='Sharing Profile',
min_api='2020-09-30', is_experimental=True,
help='This property allows you to specify the permission of sharing gallery.')
with self.argument_context('sig update') as c:
c.ignore('gallery')
c.argument('permissions', arg_type=get_enum_type(GallerySharingPermissionTypes), arg_group='Sharing Profile',
min_api='2020-09-30', is_experimental=True,
help='This property allows you to specify the permission of sharing gallery.')

with self.argument_context('sig image-definition create') as c:
c.argument('description', help='the description of the gallery image definition')
with self.argument_context('sig image-definition update') as c:
Expand Down Expand Up @@ -975,9 +1030,30 @@ def load_arguments(self, _):
c.argument('data_vhds_luns', nargs='+', help='Logical unit numbers (space-delimited) of source VHD URIs of data disks')
c.argument('data_vhds_storage_accounts', options_list=['--data-vhds-storage-accounts', '--data-vhds-sa'], nargs='+', help='Names or IDs (space-delimited) of storage accounts of source VHD URIs of data disks')

with self.argument_context('sig image-version list-shared') as c:
c.argument('location', arg_type=get_location_type(self.cli_ctx), id_part='name')
c.argument('gallery_unique_name', type=str, help='The unique name of the Shared Gallery.',
id_part='child_name_1')
c.argument('gallery_image_name', options_list=['--gallery-image-definition', '-i'], type=str, help='The name '
'of the Shared Gallery Image Definition from which the Image Versions are to be listed.',
id_part='child_name_2')
c.argument('shared_to', shared_to_type)

with self.argument_context('sig image-version show') as c:
c.argument('expand', help="The expand expression to apply on the operation, e.g. 'ReplicationStatus'")

with self.argument_context('sig image-version show-shared') as c:
c.argument('location', arg_type=get_location_type(self.cli_ctx), id_part='name')
c.argument('gallery_unique_name', type=str, help='The unique name of the Shared Gallery.',
id_part='child_name_1')
c.argument('gallery_image_name', options_list=['--gallery-image-definition', '-i'], type=str, help='The name '
'of the Shared Gallery Image Definition from which the Image Versions are to be listed.',
id_part='child_name_2')
c.argument('gallery_image_version_name', options_list=['--gallery-image-version', '-e'], type=str, help='The '
'name of the gallery image version to be created. Needs to follow semantic version name pattern: '
'The allowed characters are digit and period. Digits must be within the range of a 32-bit integer. '
'Format: <MajorVersion>.<MinorVersion>.<Patch>', id_part='child_name_3')

for scope in ['sig image-version create', 'sig image-version update']:
with self.argument_context(scope) as c:
c.argument('target_regions', nargs='*', validator=process_gallery_image_version_namespace,
Expand Down
53 changes: 51 additions & 2 deletions src/azure-cli/azure/cli/command_modules/vm/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
cf_proximity_placement_groups,
cf_dedicated_hosts, cf_dedicated_host_groups,
cf_log_analytics_data_plane,
cf_disk_encryption_set)
cf_disk_encryption_set, cf_shared_galleries,
cf_gallery_sharing_profile, cf_shared_gallery_image,
cf_shared_gallery_image_version)
from azure.cli.command_modules.vm._format import (
transform_ip_addresses, transform_vm, transform_vm_create_output, transform_vm_usage_list, transform_vm_list,
transform_sku_for_table_output, transform_disk_show_table_output, transform_extension_show_table_output,
Expand Down Expand Up @@ -471,7 +473,7 @@ def load_command_table(self, _):
g.show_command('show', 'get')
g.custom_command('list', 'list_image_galleries')
g.command('delete', 'begin_delete')
g.generic_update_command('update', setter_name='begin_create_or_update', setter_arg_name='gallery')
g.generic_update_command('update', setter_type=compute_custom, setter_name='update_image_galleries', 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')
Expand All @@ -488,6 +490,53 @@ def load_command_table(self, _):
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)
g.wait_command('wait')

vm_shared_gallery = CliCommandType(
operations_tmpl='azure.mgmt.compute.operations._shared_galleries_operations#SharedGalleriesOperations.{}',
client_factory=cf_shared_galleries,
operation_group='shared_galleries'
)
with self.command_group('sig', vm_shared_gallery) as g:
g.custom_command('list-shared', 'sig_shared_gallery_list', client_factory=cf_shared_galleries,
is_experimental=True, operation_group='shared_galleries', min_api='2020-09-30')
g.command('show-shared', 'get', is_experimental=True, operation_group='shared_galleries', min_api='2020-09-30')

vm_gallery_sharing_profile = CliCommandType(
operations_tmpl=(
'azure.mgmt.compute.operations._gallery_sharing_profile_operations#GallerySharingProfileOperations.{}'
),
client_factory=cf_gallery_sharing_profile,
operation_group='shared_galleries'
)
with self.command_group('sig share', vm_gallery_sharing_profile,
client_factory=cf_gallery_sharing_profile,
operation_group='shared_galleries',
is_experimental=True, min_api='2020-09-30') as g:
g.custom_command('add', 'sig_share_update', supports_no_wait=True)
g.custom_command('remove', 'sig_share_update', supports_no_wait=True)
g.custom_command('reset', 'sig_share_reset', supports_no_wait=True)
g.wait_command('wait', getter_name='get_gallery_instance', getter_type=compute_custom)

vm_shared_gallery_image = CliCommandType(
operations_tmpl='azure.mgmt.compute.operations._shared_gallery_images_operations#SharedGalleryImagesOperations.'
'{}',
client_factory=cf_shared_gallery_image,
operation_group='shared_galleries')
with self.command_group('sig image-definition', vm_shared_gallery_image, min_api='2020-09-30', operation_group='shared_galleries',
client_factory=cf_shared_gallery_image) as g:
g.custom_command('list-shared', 'sig_shared_image_definition_list', is_experimental=True)
g.command('show-shared', 'get', is_experimental=True)

vm_shared_gallery_image_version = CliCommandType(
operations_tmpl='azure.mgmt.compute.operations._shared_gallery_image_versions_operations#SharedGalleryImageVers'
'ionsOperations.{}',
client_factory=cf_shared_gallery_image_version,
operation_group='shared_galleries')
with self.command_group('sig image-version', vm_shared_gallery_image_version, min_api='2020-09-30',
operation_group='shared_galleries',
client_factory=cf_shared_gallery_image_version) as g:
g.custom_command('list-shared', 'sig_shared_image_version_list', is_experimental=True)
g.command('show-shared', 'get', is_experimental=True)

with self.command_group('ppg', compute_proximity_placement_groups_sdk, min_api='2018-04-01', client_factory=cf_proximity_placement_groups) as g:
g.show_command('show', 'get')
g.custom_command('create', 'create_proximity_placement_group')
Expand Down
Loading

0 comments on commit e94eced

Please sign in to comment.