Skip to content

Commit

Permalink
add support for "az sig list-shared" command
Browse files Browse the repository at this point in the history
  • Loading branch information
yanzhudd committed Dec 12, 2024
1 parent cc943b1 commit 92631aa
Show file tree
Hide file tree
Showing 13 changed files with 835 additions and 744 deletions.
45 changes: 0 additions & 45 deletions src/azure-cli/azure/cli/command_modules/vm/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,20 +712,6 @@
--intent-vm-sizes Standard_E64s_v4 Standard_M416ms_v2
"""

# helps['sig create'] = """
# type: command
# short-summary: Create a shared image gallery.
# examples:
# - name: Create a shared image gallery
# text: |
# az sig create --resource-group MyResourceGroup --gallery-name MyGallery
# """

# helps['sig show'] = """
# type: command
# short-summary: Retrieve information about a Shared Image Gallery.
# """

helps['sig image-definition create'] = """
type: command
short-summary: create a gallery image definition
Expand Down Expand Up @@ -1124,19 +1110,6 @@
crafted: true
"""

helps['sig list-shared'] = """
type: command
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 shared galleries shared directly to your subscription in a given location
text: |
az sig list-shared --location myLocation
- 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
Expand Down Expand Up @@ -1202,24 +1175,6 @@
az sig share wait --updated --resource-group MyResourceGroup --gallery-name Gallery
"""

# helps['sig update'] = """
# type: command
# short-summary: update a share image gallery.
# parameters:
# - name: --select
# short-summary: The select expression to apply on the operation. "Permissions" Default value is None.
# examples:
# - name: Enable gallery to be shared to subscription or tenant
# text: |
# az sig update --resource-group myResourceGroup --gallery-name myGallery \\
# --permissions groups
# - name: Update gallery from private to community
# text: |
# az sig update -g myResourceGroup --gallery-name myGallery --permissions Community \\
# --publisher-uri myPublisherUri --publisher-email myPublisherEmail \\
# --eula myEula --public-name-prefix myPublicNamePrefix
# """

helps['sig gallery-application'] = """
type: group
short-summary: Manage gallery application
Expand Down
22 changes: 0 additions & 22 deletions src/azure-cli/azure/cli/command_modules/vm/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,28 +1316,6 @@ def load_arguments(self, _):
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 create') as c:
c.argument('description', help='the description of the gallery')

with self.argument_context('sig update') as c:
c.ignore('gallery')

for scope in ['sig create', 'sig update']:
with self.argument_context(scope) as c:
c.argument('permissions', arg_type=get_enum_type(GallerySharingPermissionTypes),
arg_group='Sharing Profile',
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',
deprecate_info=Deprecated(self.cli_ctx, hide=True, message_func=lambda x: "Argument '--soft-delete' is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus"),
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 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ._create import *
from ._delete import *
from ._list import *
from ._list_shared import *
from ._show import *
from ._show_community import *
from ._show_shared import *
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from azure.cli.core.aaz import *


@register_command(
"sig list-shared",
)
class ListShared(AAZCommand):
"""List all shared galleries shared directly to your subscription or tenant
:example: List shared galleries shared directly to your subscription in a given location
az sig list-shared --location myLocation
:example: List shared galleries shared directly to your tenant in a given location
az sig list-shared --location myLocation --shared-to tenant
"""

_aaz_info = {
"version": "2023-07-03",
"resources": [
["mgmt-plane", "/subscriptions/{}/providers/microsoft.compute/locations/{}/sharedgalleries", "2023-07-03"],
]
}

AZ_SUPPORT_PAGINATION = True

def _handler(self, command_args):
super()._handler(command_args)
return self.build_paging(self._execute_operations, self._output)

_args_schema = None

@classmethod
def _build_arguments_schema(cls, *args, **kwargs):
if cls._args_schema is not None:
return cls._args_schema
cls._args_schema = super()._build_arguments_schema(*args, **kwargs)

# define Arg Group ""

_args_schema = cls._args_schema
_args_schema.location = AAZResourceLocationArg(
required=True,
)
_args_schema.shared_to = AAZStrArg(
options=["--shared-to"],
help="The query parameter to decide what shared galleries to fetch when doing listing operations. If not specified, list by subscription id.",
enum={"tenant": "tenant"},
)
return cls._args_schema

def _execute_operations(self):
self.pre_operations()
self.SharedGalleriesList(ctx=self.ctx)()
self.post_operations()

@register_callback
def pre_operations(self):
pass

@register_callback
def post_operations(self):
pass

def _output(self, *args, **kwargs):
result = self.deserialize_output(self.ctx.vars.instance.value, client_flatten=True)
next_link = self.deserialize_output(self.ctx.vars.instance.next_link)
return result, next_link

class SharedGalleriesList(AAZHttpOperation):
CLIENT_TYPE = "MgmtClient"

def __call__(self, *args, **kwargs):
request = self.make_request()
session = self.client.send_request(request=request, stream=False, **kwargs)
if session.http_response.status_code in [200]:
return self.on_200(session)

return self.on_error(session.http_response)

@property
def url(self):
return self.client.format_url(
"/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/sharedGalleries",
**self.url_parameters
)

@property
def method(self):
return "GET"

@property
def error_format(self):
return "ODataV4Format"

@property
def url_parameters(self):
parameters = {
**self.serialize_url_param(
"location", self.ctx.args.location,
required=True,
),
**self.serialize_url_param(
"subscriptionId", self.ctx.subscription_id,
required=True,
),
}
return parameters

@property
def query_parameters(self):
parameters = {
**self.serialize_query_param(
"sharedTo", self.ctx.args.shared_to,
),
**self.serialize_query_param(
"api-version", "2023-07-03",
required=True,
),
}
return parameters

@property
def header_parameters(self):
parameters = {
**self.serialize_header_param(
"Accept", "application/json",
),
}
return parameters

def on_200(self, session):
data = self.deserialize_http_content(session)
self.ctx.set_var(
"instance",
data,
schema_builder=self._build_schema_on_200
)

_schema_on_200 = None

@classmethod
def _build_schema_on_200(cls):
if cls._schema_on_200 is not None:
return cls._schema_on_200

cls._schema_on_200 = AAZObjectType()

_schema_on_200 = cls._schema_on_200
_schema_on_200.next_link = AAZStrType(
serialized_name="nextLink",
)
_schema_on_200.value = AAZListType(
flags={"required": True},
)

value = cls._schema_on_200.value
value.Element = AAZObjectType()

_element = cls._schema_on_200.value.Element
_element.identifier = AAZObjectType(
flags={"client_flatten": True},
)
_element.location = AAZStrType(
flags={"read_only": True},
)
_element.name = AAZStrType(
flags={"read_only": True},
)
_element.properties = AAZObjectType(
flags={"client_flatten": True},
)

identifier = cls._schema_on_200.value.Element.identifier
identifier.unique_id = AAZStrType(
serialized_name="uniqueId",
)

properties = cls._schema_on_200.value.Element.properties
properties.artifact_tags = AAZDictType(
serialized_name="artifactTags",
flags={"read_only": True},
)

artifact_tags = cls._schema_on_200.value.Element.properties.artifact_tags
artifact_tags.Element = AAZStrType()

return cls._schema_on_200


class _ListSharedHelper:
"""Helper class for ListShared"""


__all__ = ["ListShared"]
22 changes: 0 additions & 22 deletions src/azure-cli/azure/cli/command_modules/vm/azure_stack/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1319,28 +1319,6 @@ def load_arguments(self, _):
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 create') as c:
c.argument('description', help='the description of the gallery')

with self.argument_context('sig update') as c:
c.ignore('gallery')

for scope in ['sig create', 'sig update']:
with self.argument_context(scope) as c:
c.argument('permissions', arg_type=get_enum_type(GallerySharingPermissionTypes),
arg_group='Sharing Profile',
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',
deprecate_info=Deprecated(self.cli_ctx, hide=True, message_func=lambda x: "Argument '--soft-delete' is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus"),
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 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
17 changes: 0 additions & 17 deletions src/azure-cli/azure/cli/command_modules/vm/azure_stack/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,14 +477,6 @@ def load_command_table(self, _):
g.custom_command('update', 'vmss_run_command_update', supports_no_wait=True)
g.custom_command('delete', 'vmss_run_command_delete', supports_no_wait=True, confirmation=True)

with self.command_group('sig', compute_galleries_sdk, operation_group='galleries', min_api='2018-06-01') as g:
# g.custom_command('create', 'create_image_gallery')
# g.custom_show_command('show', 'show_image_gallery')
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.custom_command('list-community', 'sig_community_gallery_list')

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')
Expand All @@ -503,15 +495,6 @@ 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, validator=process_image_version_update_namespace)
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,
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.{}'
Expand Down
Loading

0 comments on commit 92631aa

Please sign in to comment.