Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Compute] sig list-community: Add new command to support listing community gallery and GA SIG related feature #22979

Merged
merged 2 commits into from
Jun 30, 2022
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
53 changes: 53 additions & 0 deletions src/azure-cli/azure/cli/command_modules/vm/_arg_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import json

from azure.cli.core.util import send_raw_request
from azure.cli.core.azclierror import HTTPError, AzureResponseError


class ARGClient: # pylint: disable=too-few-public-methods
"""A lightweight Microsoft ARG API client.

For what ARG is, please see https://docs.microsoft.com/en-us/azure/governance/resource-graph/overview for details.
The reason for directly using this client to request REST is that ARG API does not return "nextLink" data,
so the Python SDK "azure-mgmt-resourcegraph" cannot support paging

"""

def __init__(self, cli_ctx):
self._cli_ctx = cli_ctx

self._endpoint = cli_ctx.cloud.endpoints.resource_manager.rstrip('/')
self._resource_provider_uri = 'providers/Microsoft.ResourceGraph/resources'
self._api_version = '2021-03-01'
self._method = 'post'

def send(self, query_body):
url = f'{self._endpoint}/{self._resource_provider_uri}?api-version={self._api_version}'

if isinstance(query_body, QueryBody):
# Serialize QueryBody object and ignore the None value
query_body = json.dumps(query_body,
default=lambda o: dict((key, value) for key, value in o.__dict__.items() if value))

try:
response = send_raw_request(self._cli_ctx, self._method, url, body=query_body)
except HTTPError as ex:
raise AzureResponseError(ex.response.json()['error']['message'], ex.response) from ex
# Other exceptions like AuthenticationError should not be handled here, so we don't catch CLIError

if response.text:
return response.json()

return response


class QueryBody: # pylint: disable=too-few-public-methods

def __init__(self, query, options=None):
self.query = query
self.options = options
57 changes: 35 additions & 22 deletions src/azure-cli/azure/cli/command_modules/vm/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,8 +735,8 @@

helps['sig image-definition list-shared'] = """
type: command
short-summary: List VM Image definitions in a gallery shared directly to your subscription or tenant (preview).
long-summary: List VM Image definitions in a gallery shared directly to your subscription or tenant (private preview feature, please contact shared image gallery team by email sigpmdev@microsoft.com to register for preview if you're interested in using this feature).
short-summary: List VM Image definitions in a gallery shared directly to your subscription or tenant
long-summary: List VM Image definitions in a gallery shared directly to your subscription or tenant
examples:
- name: List an image definition in a gallery shared directly to your subscription in the given location.
text: |
Expand All @@ -750,8 +750,8 @@

helps['sig image-definition show-shared'] = """
type: command
short-summary: Get a shared gallery image (preview).
long-summary: Get a shared gallery image that has been shared directly to your subscription or tenant (private preview feature, please contact shared image gallery team by email sigpmdev@microsoft.com to register for preview if you're interested in using this feature).
short-summary: Get a shared gallery image
long-summary: Get a shared gallery image that has been shared directly to your subscription or tenant
examples:
- name: Get an image definition in a gallery shared directly to your subscription or tenant in the given location.
text: |
Expand Down Expand Up @@ -779,8 +779,8 @@

helps['sig image-definition list-community'] = """
type: command
short-summary: List VM Image definitions in a gallery community (preview).
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).
short-summary: List VM Image definitions in a gallery community
long-summary: List VM Image definitions in a gallery community
examples:
- name: List an image definition in a gallery community.
text: |
Expand Down Expand Up @@ -912,8 +912,8 @@

helps['sig image-version list-shared'] = """
type: command
short-summary: List VM Image Versions in a gallery shared directly to your subscription or tenant (preview).
long-summary: List VM Image Versions in a gallery shared directly to your subscription or tenant (private preview feature, please contact shared image gallery team by email sigpmdev@microsoft.com to register for preview if you're interested in using this feature).
short-summary: List VM Image Versions in a gallery shared directly to your subscription or tenant
long-summary: List VM Image Versions in a gallery shared directly to your subscription or tenant
examples:
- name: List image versions in a gallery shared directly to your subscription in the given location and image definition.
text: |
Expand All @@ -927,8 +927,8 @@

helps['sig image-version show-shared'] = """
type: command
short-summary: Get an image version in a gallery shared directly to your subscription or tenant (preview).
long-summary: Get an image version in a gallery shared directly to your subscription or tenant (private preview feature, please contact shared image gallery team by email sigpmdev@microsoft.com to register for preview if you're interested in using this feature).
short-summary: Get an image version in a gallery shared directly to your subscription or tenant
long-summary: Get an image version in a gallery shared directly to your subscription or tenant
examples:
- name: Get an image version in a gallery shared directly to your subscription or tenant in the given location.
text: |
Expand Down Expand Up @@ -967,8 +967,8 @@

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).
short-summary: List VM Image Versions in a gallery community
long-summary: List VM Image Versions in a gallery community
examples:
- name: List an image versions in a gallery community.
text: |
Expand All @@ -995,17 +995,30 @@

helps['sig list-shared'] = """
type: command
short-summary: List all galleries shared directly to your subscription or tenant (preview).
long-summary: List all galleries shared directly to your subscription or tenant (private preview feature, please contact shared image gallery team by email sigpmdev@microsoft.com to register for preview if you're interested in using this feature).
short-summary: List all shared galleries shared directly to your subscription or tenant
long-summary: List all shared galleries shared directly to your subscription or tenant
examples:
- name: List galleries shared directly to your subscription in a given location
- name: List shared galleries shared directly to your subscription in a given location
text: |
az sig list-shared --location myLocation
- name: List galleries shared directly to your tenant in a given location
- name: List shared galleries shared directly to your tenant in a given location
text: |
az sig list-shared --location myLocation --shared-to tenant
"""

helps['sig list-community'] = """
type: command
short-summary: List all community galleries shared directly to your subscription or tenant
long-summary: List all community galleries shared directly to your subscription or tenant
examples:
- name: List community galleries shared directly to your subscription in a given location
text: |
az sig list-community --location myLocation
- name: List paging community galleries shared directly to your tenant in a given location according to next marker
text: |
az sig list-community --location myLocation --marker nextMarker
"""

helps['sig list'] = """
type: command
short-summary: list share image galleries.
Expand Down Expand Up @@ -1070,8 +1083,8 @@

helps['sig show-shared'] = """
type: command
short-summary: Get a gallery that has been shared directly to your subscription or tenant (preview).
long-summary: Get a gallery that has been shared directly to your subscription or tenant (private preview feature, please contact shared image gallery team by email sigpmdev@microsoft.com to register for preview if you're interested in using this feature).
short-summary: Get a gallery that has been shared directly to your subscription or tenant
long-summary: Get a gallery that has been shared directly to your subscription or tenant
examples:
- name: Get a gallery that has been shared directly to your subscription or tenant in the given location.
text: |
Expand Down Expand Up @@ -1506,10 +1519,10 @@
- name: Create multiple VMs. In this example, 3 VMs are created. They are MyVm0, MyVm1, MyVm2.
text: >
az vm create -n MyVm -g MyResourceGroup --image centos --count 3
- name: Create a VM from shared gallery image (private preview feature, please contact shared image gallery team by email sigpmdev@microsoft.com to register for preview if you're interested in using this feature).
- name: Create a VM from shared gallery image
text: >
az vm create -n MyVm -g MyResourceGroup --image /SharedGalleries/{gallery_unique_name}/Images/{image}/Versions/{version}
- name: Create a VM from community gallery image (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).
- name: Create a VM from community gallery image
text: >
az vm create -n MyVm -g MyResourceGroup --image /CommunityGalleries/{gallery_unique_name}/Images/{image}/Versions/{version}
"""
Expand Down Expand Up @@ -2883,10 +2896,10 @@
- name: Create a VMSS that supports SpotRestore.
text: >
az vmss create -n MyVmss -g MyResourceGroup --location NorthEurope --instance-count 2 --image Centos --priority Spot --eviction-policy Deallocate --single-placement-group --enable-spot-restore True --spot-restore-timeout PT1H
- name: Create a VMSS from shared gallery image. (private preview feature, please contact shared image gallery team by email sigpmdev@microsoft.com to register for preview if you're interested in using this feature).
- name: Create a VMSS from shared gallery image.
text: >
az vmss create -n MyVmss -g MyResourceGroup --image /SharedGalleries/{gallery_unique_name}/Images/{image}/Versions/{version}
- name: Create a VMSS from community gallery image (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).
- name: Create a VMSS from community gallery image.
text: >
az vmss create -n MyVmss -g MyResourceGroup --image /CommunityGalleries/{gallery_unique_name}/Images/{image}/Versions/{version}
- name: Create a Windows VMSS with patch mode 'Manual' (Currently patch mode 'AutomaticByPlatform' is not supported during VMSS creation as health extension which is required for 'AutomaticByPlatform' mode cannot be set during VMSS creation).
Expand Down
76 changes: 41 additions & 35 deletions src/azure-cli/azure/cli/command_modules/vm/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,41 +1145,6 @@ 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 @@ -1322,6 +1287,47 @@ def load_arguments(self, _):
help='Space-separated list of regions and their replica counts. Use `<region>[=<replica count>][=<storage account type>]` to optionally set the replica count and/or storage account type for each region. '
'If a replica count is not specified, the default replica count will be used. If a storage account type is not specified, the default storage account type will be used')
c.argument('replica_count', help='The default number of replicas to be created per region. To set regional replication counts, use --target-regions', type=int)

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 list-community') as c:
c.argument('location', arg_type=get_location_type(self.cli_ctx))
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-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')

# endregion

# region Gallery applications
Expand Down
Loading