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] Create a new extension image-gallery #4050

Merged
merged 7 commits into from
Nov 1, 2021
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,4 @@

/src/elastic/ @kairu-ms @jsntcy

/src/image-gallery/ @zhoxing-ms
7 changes: 7 additions & 0 deletions scripts/ci/credscan/CredScanSuppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@
"src\\diskpool\\README.md"
],
"_justification": "Faked password"
},
{
"file": [
"src\\image-gallery\\azext_image_gallery\\vendored_sdks\\azure_mgmt_compute\\models\\_models.py",
"src\\image-gallery\\azext_image_gallery\\vendored_sdks\\azure_mgmt_compute\\models\\_models_py3.py"
],
"_justification": "Python SDK uses the example of fake password to indicate the format"
}
]
}
8 changes: 8 additions & 0 deletions src/image-gallery/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. :changelog:

Release History
===============

0.1.0
+++++++++++++++
* Initial release.
36 changes: 36 additions & 0 deletions src/image-gallery/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Azure CLI image-gallery Extension #
This package is for the 'image-gallery' extension, i.e. 'az sig'

### How to use ###
Install this extension using the below CLI command
```
az extension add --name image-gallery
```

### Included Features
#### Image Gallery:
Manage Image Gallery: [more info](https://docs.microsoft.com/en-us/azure/virtual-machines/shared-image-galleries) \
*Examples:*

##### Get a gallery that has been community in the given location.
```
az sig show-community --public-gallery-name publicGalleryName \
--location myLocation
```

##### Get an image definition in a gallery community in the given location.
```
az sig image-definition show-community --public-gallery-name publicGalleryName \
--gallery-image-definition myGalleryImageName \
--location myLocation
```

##### Get an image version in a gallery community in the given location.
```
az sig image-version show-community --public-gallery-name publicGalleryName \
--gallery-image-definition MyImage \
--gallery-image-version 1.0.0 \
--location myLocation
```

If you have issues, please give feedback by opening an issue at https://github.com/Azure/azure-cli-extensions/issues.
33 changes: 33 additions & 0 deletions src/image-gallery/azext_image_gallery/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core import AzCommandsLoader

from ._help import helps # pylint: disable=unused-import


class ImageGalleryCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
from ._client_factory import cf_galleries
image_gallery_custom = CliCommandType(
operations_tmpl='azext_image_gallery.custom#{}',
client_factory=cf_galleries)
super(ImageGalleryCommandsLoader, self).__init__(cli_ctx=cli_ctx, custom_command_type=image_gallery_custom)

def load_command_table(self, args):
super(ImageGalleryCommandsLoader, self).load_command_table(args)
from .commands import load_command_table
load_command_table(self, args)
return self.command_table

def load_arguments(self, command):
super(ImageGalleryCommandsLoader, self).load_arguments(command)
from ._params import load_arguments
load_arguments(self, command)


COMMAND_LOADER_CLS = ImageGalleryCommandsLoader
30 changes: 30 additions & 0 deletions src/image-gallery/azext_image_gallery/_client_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------


def _compute_client_factory(cli_ctx):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from .vendored_sdks.azure_mgmt_compute._compute_management_client import ComputeManagementClient
return get_mgmt_service_client(cli_ctx, ComputeManagementClient)


def cf_galleries(cli_ctx, _):
return _compute_client_factory(cli_ctx).galleries


def cf_gallery_images(cli_ctx, _):
return _compute_client_factory(cli_ctx).gallery_images


def cf_community_gallery(cli_ctx, *_):
return _compute_client_factory(cli_ctx).community_galleries


def cf_community_gallery_image(cli_ctx, *_):
return _compute_client_factory(cli_ctx).community_gallery_images


def cf_community_gallery_image_version(cli_ctx, *_):
return _compute_client_factory(cli_ctx).community_gallery_image_versions
64 changes: 64 additions & 0 deletions src/image-gallery/azext_image_gallery/_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# coding=utf-8
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: disable=too-many-lines
# pylint: disable=line-too-long
from knack.help_files import helps # pylint: disable=unused-import


helps['sig show-community'] = """
type: command
short-summary: Get a gallery that has been community (preview).
long-summary: Get a gallery that has been 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).
examples:
- name: Get a gallery that has been community in the given location.
text: |
az sig show-community --public-gallery-name publicGalleryName --location myLocation
"""

helps['sig image-definition show-community'] = """
type: command
short-summary: Get an image in a gallery community (preview).
long-summary: Get an image 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).
examples:
- name: Get an image definition in a gallery community in the given location.
text: |
az sig image-definition show-community --public-gallery-name publicGalleryName \\
--gallery-image-definition myGalleryImageName --location myLocation
"""

# 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).
# 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 show-community'] = """
type: command
short-summary: Get an image version in a gallery community (preview).
long-summary: Get an image version 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).
examples:
- name: Get an image version in a gallery community in the given location.
text: |
az sig image-version show-community --public-gallery-name publicGalleryName \\
--gallery-image-definition MyImage --gallery-image-version 1.0.0 --location myLocation
"""

# 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).
# examples:
# - name: List image versions in a gallery community.
# text: |
# az sig image-version list-community --public-gallery-name publicGalleryName \\
# --gallery-image-definition MyImage --location myLocation
# """
52 changes: 52 additions & 0 deletions src/image-gallery/azext_image_gallery/_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=line-too-long
# pylint: disable=too-many-lines
# pylint: disable=too-many-statements

from knack.arguments import CLIArgumentType
from azure.cli.core.commands.parameters import get_location_type


def load_arguments(self, _):

public_gallery_name_type = CLIArgumentType(help='The public name of community gallery.', id_part='child_name_1')

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'
)

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)

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)
4 changes: 4 additions & 0 deletions src/image-gallery/azext_image_gallery/azext_metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"azext.isExperimental": true,
"azext.minCliCoreVersion": "2.3.0"
}
39 changes: 39 additions & 0 deletions src/image-gallery/azext_image_gallery/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: disable=line-too-long
# pylint: disable=too-many-lines
# pylint: disable=too-many-statements
# pylint: disable=too-many-locals
from azure.cli.core.commands import CliCommandType
from ._client_factory import cf_community_gallery, cf_community_gallery_image, cf_community_gallery_image_version


def load_command_table(self, _):

community_gallery_sdk = CliCommandType(
operations_tmpl='azext_image_gallery.vendored_sdks.azure_mgmt_compute.operations._community_galleries_operations#CommunityGalleriesOperations.{}',
client_factory=cf_community_gallery)

community_gallery_image_sdk = CliCommandType(
operations_tmpl='azext_image_gallery.vendored_sdks.azure_mgmt_compute.operations._community_gallery_images_operations#CommunityGalleryImagesOperations.{}',
client_factory=cf_community_gallery_image)

community_gallery_image_version_sdk = CliCommandType(
operations_tmpl='azext_image_gallery.vendored_sdks.azure_mgmt_compute.operations._community_gallery_image_versions_operations#CommunityGalleryImageVersionsOperations.{}',
client_factory=cf_community_gallery_image_version)

with self.command_group('sig', community_gallery_sdk, client_factory=cf_community_gallery) as g:
g.command('show-community', 'get', is_experimental=True)

with self.command_group('sig image-definition', community_gallery_image_sdk,
client_factory=cf_community_gallery_image) as g:
g.command('show-community', 'get', is_experimental=True)
# g.command('list-community', 'list', is_experimental=True)

with self.command_group('sig image-version', community_gallery_image_version_sdk,
client_factory=cf_community_gallery_image_version) as g:
g.command('show-community', 'get', is_experimental=True)
# g.command('list-community', 'list', is_experimental=True)
4 changes: 4 additions & 0 deletions src/image-gallery/azext_image_gallery/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
Loading