Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/azure-cli-core/azure/cli/core/profiles/_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def default_api_version(self):
'gallery_image_versions': '2021-10-01',
'gallery_applications': '2021-07-01',
'gallery_application_versions': '2021-07-01',
'shared_galleries': '2020-09-30',
'shared_galleries': '2022-01-03',
'virtual_machine_scale_sets': '2021-11-01',
}),
ResourceType.MGMT_RESOURCE_FEATURES: '2021-07-01',
Expand Down
31 changes: 31 additions & 0 deletions src/azure-cli/azure/cli/command_modules/vm/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,17 @@
--resource-group MyResourceGroup --remove recommended.vCpUs.min
"""

helps['sig image-definition list-community'] = """
type: command
short-summary: List VM Image definitions in a gallery community (preview).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a feature request for GA. we need to delete the (preview) tag, right? @kangsun-ctrl

long-summary: List VM Image definitions in a gallery community (private preview feature, please contact community image gallery team by email sigpmdev@microsoft.com to register for preview if you're interested in using this feature).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove (private preview feature, please contact community image gallery team by email sigpmdev@microsoft.com to register for preview if you're interested in using this feature).

examples:
- name: List an image definition in a gallery community.
text: |
az sig image-definition list-community --public-gallery-name publicGalleryName \\
--location myLocation
"""

helps['sig image-version'] = """
type: group
short-summary: Manage shared gallery image version with VM
Expand Down Expand Up @@ -948,6 +959,17 @@
--set publishingProfile.endOfLifeDate=2024-08-02T00:00:00+00:00
"""

helps['sig image-version list-community'] = """
type: command
short-summary: List VM Image Versions in a gallery community (preview).
long-summary: List VM Image Versions in a gallery community (private preview feature, please contact community image gallery team by email sigpmdev@microsoft.com to register for preview if you're interested in using this feature).
Comment on lines +964 to +965

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same as above

examples:
- name: List an image versions in a gallery community.
text: |
az sig image-version list-community --public-gallery-name publicGalleryName \\
--gallery-image-definition MyImage --location myLocation
"""

helps['sig image-version wait'] = """
type: command
short-summary: wait for image version related operation
Expand Down Expand Up @@ -1022,6 +1044,15 @@
az sig share reset --resource-group MyResourceGroup --gallery-name MyGallery
"""

helps['sig share enable-community'] = """
type: command
short-summary: Allow to share gallery to the community
examples:
- name: Allow to share gallery to the community
text: |
az sig share enable-community --resource-group MyResourceGroup --gallery-name MyGallery
"""

helps['sig share wait'] = """
type: command
short-summary: Place the CLI in a waiting state until a condition of a shared gallery is met.
Expand Down
48 changes: 44 additions & 4 deletions src/azure-cli/azure/cli/command_modules/vm/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ def load_arguments(self, _):
enable_vtpm_type = CLIArgumentType(arg_type=get_three_state_flag(), min_api='2020-12-01', help='Enable vTPM.')
enable_secure_boot_type = CLIArgumentType(arg_type=get_three_state_flag(), min_api='2020-12-01', help='Enable secure boot.')
security_type = CLIArgumentType(arg_type=get_enum_type(['TrustedLaunch']), min_api='2020-12-01', help='Specify if the VM is Trusted Launch enabled. See https://docs.microsoft.com/azure/virtual-machines/trusted-launch.')
gallery_image_name_type = CLIArgumentType(options_list=['--gallery-image-definition', '-i'], help='The name of the community gallery image definition from which the image versions are to be listed.', id_part='child_name_2')
gallery_image_name_version_type = CLIArgumentType(options_list=['--gallery-image-version', '-e'], 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')
public_gallery_name_type = CLIArgumentType(help='The public name of community gallery.', id_part='child_name_1')

# region MixedScopes
for scope in ['vm', 'disk', 'snapshot', 'image', 'sig']:
Expand Down Expand Up @@ -1139,6 +1142,41 @@ def load_arguments(self, _):
c.argument('gallery_unique_name', type=str, help='The unique name of the Shared Gallery.',
id_part='child_name_1')

with self.argument_context('sig show-community') as c:
c.argument('location', arg_type=get_location_type(self.cli_ctx), id_part='name')
c.argument('public_gallery_name', public_gallery_name_type)

with self.argument_context('sig image-definition show-community') as c:
c.argument('location', arg_type=get_location_type(self.cli_ctx), id_part='name')
c.argument('public_gallery_name', public_gallery_name_type)
c.argument('gallery_image_name', gallery_image_name_type)

with self.argument_context('sig image-definition list-community') as c:
c.argument('location', arg_type=get_location_type(self.cli_ctx), id_part='name')
c.argument('public_gallery_name', public_gallery_name_type)
c.argument('marker', arg_type=marker_type)
c.argument('show_next_marker', action='store_true', help='Show nextMarker in result when specified.')

with self.argument_context('sig image-version show-community') as c:
c.argument('location', arg_type=get_location_type(self.cli_ctx), id_part='name')
c.argument('public_gallery_name', public_gallery_name_type)
c.argument('gallery_image_name', gallery_image_name_type)
c.argument('gallery_image_version_name', gallery_image_name_version_type)

with self.argument_context('sig image-version list-community') as c:
c.argument('location', arg_type=get_location_type(self.cli_ctx), id_part='name')
c.argument('public_gallery_name', public_gallery_name_type)
c.argument('gallery_image_name', gallery_image_name_type)
c.argument('marker', arg_type=marker_type)
c.argument('show_next_marker', action='store_true', help='Show nextMarker in result when specified.')

with self.argument_context('sig share enable-community') 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.')
c.argument('op_type', default='EnableCommunity', deprecate_info=c.deprecate(hide=True),
help='distinguish add operation and remove operation')

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')
Expand Down Expand Up @@ -1199,16 +1237,18 @@ def load_arguments(self, _):
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.')
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', is_preview=True,
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.')
c.argument('publisher_contact', options_list=['--publisher-email'], help='Community gallery publisher contact email.')
c.argument('eula', help='Community gallery publisher eula.')
c.argument('public_name_prefix', help='Community gallery public name prefix.')
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.')
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', is_preview=True,
help='Enable soft-deletion for resources in this gallery, '
'allowing them to be recovered within retention time.')
Expand Down
28 changes: 27 additions & 1 deletion src/azure-cli/azure/cli/command_modules/vm/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
cf_capacity_reservation_groups, cf_capacity_reservations,
cf_vmss_run_commands, cf_gallery_application,
cf_gallery_application_version, cf_restore_point,
cf_restore_point_collection)
cf_restore_point_collection, cf_community_gallery,
cf_community_gallery_image,
cf_community_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 @@ -239,6 +241,18 @@ def load_command_table(self, _):
client_factory=cf_restore_point_collection
)

community_gallery_sdk = CliCommandType(
operations_tmpl='azure.mgmt.compute.operations#CommunityGalleriesOperations.{}',
client_factory=cf_community_gallery)

community_gallery_image_sdk = CliCommandType(
operations_tmpl='azure.mgmt.compute.operations#CommunityGalleryImagesOperations.{}',
client_factory=cf_community_gallery_image)

community_gallery_image_version_sdk = CliCommandType(
operations_tmpl='azure.mgmt.compute.operations#CommunityGalleryImageVersionsOperations.{}',
client_factory=cf_community_gallery_image_version)

with self.command_group('disk', compute_disk_sdk, operation_group='disks', min_api='2017-03-30') as g:
g.custom_command('create', 'create_managed_disk', supports_no_wait=True, table_transformer=transform_disk_show_table_output, validator=process_disk_or_snapshot_create_namespace)
g.command('delete', 'begin_delete', supports_no_wait=True, confirmation=True)
Expand Down Expand Up @@ -529,6 +543,17 @@ def load_command_table(self, _):
g.command('delete', 'begin_delete')
g.generic_update_command('update', setter_type=compute_custom, setter_name='update_image_galleries', setter_arg_name='gallery')

with self.command_group('sig', community_gallery_sdk, client_factory=cf_community_gallery, operation_group='shared_galleries', min_api='2022-01-03') as g:
g.command('show-community', 'get')

with self.command_group('sig image-definition', community_gallery_image_sdk, client_factory=cf_community_gallery_image, operation_group='shared_galleries', min_api='2022-01-03') as g:
g.command('show-community', 'get')
g.custom_command('list-community', 'sig_community_image_definition_list')

with self.command_group('sig image-version', community_gallery_image_version_sdk, client_factory=cf_community_gallery_image_version, operation_group='shared_galleries', min_api='2022-01-03') as g:
g.command('show-community', 'get')
g.custom_command('list-community', 'sig_community_image_version_list')

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')
g.command('list', 'list_by_gallery')
Expand Down Expand Up @@ -568,6 +593,7 @@ def load_command_table(self, _):
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.custom_command('enable-community', 'sig_share_update', supports_no_wait=True)
g.wait_command('wait', getter_name='get_gallery_instance', getter_type=compute_custom)

vm_shared_gallery_image = CliCommandType(
Expand Down
33 changes: 30 additions & 3 deletions src/azure-cli/azure/cli/command_modules/vm/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -4127,7 +4127,8 @@ def show_image_gallery(cmd, resource_group_name, gallery_name, select=None, shar


def create_image_gallery(cmd, resource_group_name, gallery_name, description=None,
location=None, no_wait=False, tags=None, permissions=None, soft_delete=None):
location=None, no_wait=False, tags=None, permissions=None, soft_delete=None,
publisher_uri=None, publisher_contact=None, eula=None, public_name_prefix=None):
Gallery = cmd.get_models('Gallery')
location = location or _get_resource_group_location(cmd.cli_ctx, resource_group_name)
gallery = Gallery(description=description, location=location, tags=(tags or {}))
Expand All @@ -4137,6 +4138,17 @@ def create_image_gallery(cmd, resource_group_name, gallery_name, description=Non
if permissions:
SharingProfile = cmd.get_models('SharingProfile', operation_group='shared_galleries')
gallery.sharing_profile = SharingProfile(permissions=permissions)
if permissions == 'Community':
if publisher_uri is None or publisher_contact is None or eula is None or public_name_prefix is None:
raise RequiredArgumentMissingError('If you want to share to the community, '
'you need to fill in all the following parameters:'
' --publisher-uri, --publisher-email, --eula, --public-name-prefix.')

CommunityGalleryInfo = cmd.get_models('CommunityGalleryInfo', operation_group='shared_galleries')
gallery.sharing_profile.community_gallery_info = CommunityGalleryInfo(publisher_uri=publisher_uri,
publisher_contact=publisher_contact,
eula=eula,
public_name_prefix=public_name_prefix)

return sdk_no_wait(no_wait, client.galleries.begin_create_or_update, resource_group_name, gallery_name, gallery)

Expand Down Expand Up @@ -4684,8 +4696,9 @@ def sig_share_update(cmd, client, resource_group_name, gallery_name, subscriptio
op_type=None):
SharingProfileGroup, SharingUpdate, SharingProfileGroupTypes = cmd.get_models(
'SharingProfileGroup', 'SharingUpdate', 'SharingProfileGroupTypes', operation_group='shared_galleries')
if subscription_ids is None and tenant_ids is None:
raise RequiredArgumentMissingError('At least one of subscription ids or tenant ids must be provided')
if op_type != 'EnableCommunity':
if subscription_ids is None and tenant_ids is None:
raise RequiredArgumentMissingError('At least one of subscription ids or tenant ids must be provided')
groups = []
if subscription_ids:
groups.append(SharingProfileGroup(type=SharingProfileGroupTypes.SUBSCRIPTIONS, ids=subscription_ids))
Expand Down Expand Up @@ -5106,3 +5119,17 @@ def restore_point_collection_update(client,
parameters=parameters)

# endRegion


# region Community gallery
def sig_community_image_definition_list(client, location, public_gallery_name, marker=None, show_next_marker=None):
generator = client.list(location=location, public_gallery_name=public_gallery_name)
return get_page_result(generator, marker, show_next_marker)


def sig_community_image_version_list(client, location, public_gallery_name, gallery_image_name, marker=None,
show_next_marker=None):
generator = client.list(location=location, public_gallery_name=public_gallery_name,
gallery_image_name=gallery_image_name)
return get_page_result(generator, marker, show_next_marker)
# endRegion
Loading