-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[HORIZONDB] az horizondb create | show | delete: Introduce commands for Azure HorizonDB
#9840
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
Open
nasc17
wants to merge
5
commits into
Azure:main
Choose a base branch
from
nasc17:nasc/onboardHorizonDB430
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+17,442
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| .. :changelog: | ||
|
|
||
| Release History | ||
| =============== | ||
|
|
||
| 0.1.0 | ||
| ++++++ | ||
| * Initial release. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Azure CLI HorizonDB Extension | ||
|
|
||
| This is the extension for Azure HorizonDB. It provides commands to manage HorizonDB clusters. | ||
|
|
||
| ## How to use | ||
|
|
||
| Install this extension using the following CLI command: | ||
|
|
||
| ```bash | ||
| az extension add --name horizondb | ||
| ``` | ||
|
|
||
| ## Included Features | ||
|
|
||
| ### HorizonDB Cluster Management | ||
|
|
||
| *Commands:* | ||
|
|
||
| - `az horizondb create`: Create a new Azure HorizonDB cluster. | ||
| - `az horizondb delete`: Delete an Azure HorizonDB cluster. | ||
| - `az horizondb show`: Show details of an Azure HorizonDB cluster. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # 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 azure.cli.core.commands import CliCommandType | ||
| from azext_horizondb.utils._context import HorizonDBArgumentContext | ||
| from azext_horizondb._help import helps # pylint: disable=unused-import | ||
|
|
||
|
|
||
| class HorizonDBCommandsLoader(AzCommandsLoader): | ||
|
|
||
| def __init__(self, cli_ctx=None): | ||
| horizondb_custom = CliCommandType( | ||
| operations_tmpl='azext_horizondb.commands.custom_commands#{}') | ||
| super().__init__( | ||
| cli_ctx=cli_ctx, | ||
| custom_command_type=horizondb_custom, | ||
| argument_context_cls=HorizonDBArgumentContext) | ||
|
|
||
| def load_command_table(self, args): | ||
| from azext_horizondb.cluster_commands import load_command_table | ||
| load_command_table(self, args) | ||
| return self.command_table | ||
|
|
||
| def load_arguments(self, command): | ||
| from azext_horizondb._params import load_arguments | ||
| load_arguments(self, command) | ||
|
|
||
|
|
||
| COMMAND_LOADER_CLS = HorizonDBCommandsLoader |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # 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.commands.client_factory import get_mgmt_service_client | ||
| from azure.cli.core.profiles import ResourceType | ||
|
|
||
| # pylint: disable=import-outside-toplevel | ||
|
|
||
| RM_URI_OVERRIDE = 'AZURE_CLI_HORIZONDB_FLEXIBLE_RM_URI' | ||
| SUB_ID_OVERRIDE = 'AZURE_CLI_HORIZONDB_FLEXIBLE_SUB_ID' | ||
|
|
||
|
|
||
| def get_horizondb_management_client(cli_ctx, subscription_id=None, **_): | ||
| from os import getenv | ||
| from azext_horizondb.vendored_sdks import HorizonDBMgmtClient | ||
| # Allow overriding resource manager URI using environment variable | ||
| # for testing purposes. Subscription id is also determined by environment | ||
| # variable. | ||
| rm_uri_override = getenv(RM_URI_OVERRIDE) | ||
| subscription = subscription_id if subscription_id is not None else getenv(SUB_ID_OVERRIDE) | ||
| if rm_uri_override: | ||
| return get_mgmt_service_client( | ||
| cli_ctx, | ||
| HorizonDBMgmtClient, | ||
| subscription_id=subscription, | ||
| base_url=rm_uri_override) | ||
| # Normal production scenario. | ||
| return get_mgmt_service_client(cli_ctx, HorizonDBMgmtClient, subscription_id=subscription) | ||
|
|
||
|
|
||
| def resource_client_factory(cli_ctx, subscription_id=None): | ||
| return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES, subscription_id=subscription_id) | ||
|
|
||
|
|
||
| def cf_horizondb_clusters(cli_ctx, _): | ||
| return get_horizondb_management_client(cli_ctx).horizon_db_clusters |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # 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. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| from knack.help_files import helps # pylint: disable=unused-import | ||
|
|
||
| # pylint: disable=line-too-long, too-many-lines | ||
|
|
||
|
|
||
| helps['horizondb'] = """ | ||
| type: group | ||
| short-summary: Manage Azure HorizonDB. | ||
| """ | ||
|
|
||
|
|
||
| helps['horizondb create'] = """ | ||
| type: command | ||
| short-summary: Create a new Azure HorizonDB cluster. | ||
| examples: | ||
| - name: Create a new HorizonDB cluster. | ||
| text: az horizondb create --name examplecluster --resource-group exampleresourcegroup --location centralus --admin-user myadmin --admin-password examplepassword --version 17 --v-cores 4 --replica-count 3 | ||
| - name: Create a HorizonDB cluster with zone placement policy. | ||
| text: az horizondb create --name examplecluster --resource-group exampleresourcegroup --location centralus --admin-user myadmin --admin-password examplepassword --version 17 --v-cores 4 --replica-count 3 --zone-placement-policy Strict | ||
| """ | ||
|
|
||
|
|
||
| helps['horizondb delete'] = """ | ||
| type: command | ||
| short-summary: Delete an Azure HorizonDB cluster. | ||
| examples: | ||
| - name: Delete an Azure HorizonDB cluster. | ||
| text: az horizondb delete --name examplecluster --resource-group exampleresourcegroup | ||
| """ | ||
|
|
||
|
|
||
| helps['horizondb show'] = """ | ||
| type: command | ||
| short-summary: Show details of an Azure HorizonDB cluster. | ||
| examples: | ||
| - name: Show details of an Azure HorizonDB cluster. | ||
| text: az horizondb show --name examplecluster --resource-group exampleresourcegroup | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # 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-statements | ||
|
|
||
| from knack.arguments import CLIArgumentType | ||
| from azure.cli.core.commands.parameters import ( | ||
| resource_group_name_type, | ||
| get_location_type, | ||
| tags_type, | ||
| get_enum_type) | ||
| from azure.cli.core.local_context import LocalContextAttribute, LocalContextAction | ||
|
|
||
|
|
||
| def load_arguments(self, _): # pylint: disable=too-many-statements, too-many-locals | ||
|
|
||
| # HorizonDB | ||
| # pylint: disable=too-many-locals, too-many-branches | ||
| def _horizondb_params(): | ||
|
|
||
| yes_arg_type = CLIArgumentType( | ||
| options_list=['--yes', '-y'], | ||
| action='store_true', | ||
| help='Do not prompt for confirmation.' | ||
| ) | ||
|
|
||
| cluster_name_arg_type = CLIArgumentType( | ||
| metavar='NAME', | ||
| options_list=['--name', '-n'], | ||
| id_part='name', | ||
| help="Name of the cluster. The name can contain only lowercase letters, numbers, and the hyphen (-) character. Minimum 3 characters and maximum 63 characters.", | ||
| local_context_attribute=LocalContextAttribute( | ||
| name='cluster_name', | ||
| actions=[LocalContextAction.SET, LocalContextAction.GET], | ||
| scopes=['horizondb'])) | ||
|
|
||
| administrator_login_arg_type = CLIArgumentType( | ||
| options_list=['--admin-user', '-u'], | ||
| help='The administrator login name for the cluster.') | ||
|
|
||
| administrator_login_password_arg_type = CLIArgumentType( | ||
| options_list=['--admin-password', '-p'], | ||
| help='The administrator login password.') | ||
|
|
||
| version_arg_type = CLIArgumentType( | ||
| options_list=['--version', '-v'], | ||
| help='The version of the HorizonDb cluster.') | ||
|
|
||
| replica_count_arg_type = CLIArgumentType( | ||
| options_list=['--replica-count'], | ||
| type=int, | ||
| help='Number of replicas.') | ||
|
|
||
| v_cores_arg_type = CLIArgumentType( | ||
| options_list=['--v-cores'], | ||
| type=int, | ||
| help='Number of vCores.') | ||
|
|
||
| zone_placement_policy_arg_type = CLIArgumentType( | ||
| options_list=['--zone-placement-policy'], | ||
| arg_type=get_enum_type(['Strict', 'BestEffort']), | ||
| help='Defines how replicas are placed across availability zones.') | ||
|
|
||
| with self.argument_context('horizondb') as c: | ||
| c.argument('resource_group_name', arg_type=resource_group_name_type) | ||
| c.argument('cluster_name', arg_type=cluster_name_arg_type) | ||
|
|
||
| with self.argument_context('horizondb create') as c: | ||
| c.argument('location', arg_type=get_location_type(self.cli_ctx)) | ||
| c.argument('tags', tags_type) | ||
| c.argument('administrator_login', arg_type=administrator_login_arg_type) | ||
| c.argument('administrator_login_password', arg_type=administrator_login_password_arg_type) | ||
| c.argument('version', arg_type=version_arg_type) | ||
| c.argument('replica_count', arg_type=replica_count_arg_type) | ||
| c.argument('v_cores', arg_type=v_cores_arg_type) | ||
| c.argument('zone_placement_policy', arg_type=zone_placement_policy_arg_type) | ||
|
|
||
| with self.argument_context('horizondb delete') as c: | ||
| c.argument('yes', arg_type=yes_arg_type) | ||
|
|
||
| _horizondb_params() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "azext.minCliCoreVersion": "2.17.1", | ||
| "azext.isPreview": true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # 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.commands import CliCommandType | ||
| from azext_horizondb._client_factory import ( | ||
| cf_horizondb_clusters) | ||
| from azext_horizondb.utils._transformers import ( | ||
| table_transform_output) | ||
|
|
||
|
|
||
| # pylint: disable=too-many-locals, too-many-statements, line-too-long | ||
| def load_command_table(self, _): | ||
| horizondb_clusters_sdk = CliCommandType( | ||
| operations_tmpl='azext_horizondb.vendored_sdks.operations#HorizonDbClustersOperations.{}', | ||
| client_factory=cf_horizondb_clusters | ||
| ) | ||
|
|
||
| custom_commands = CliCommandType( | ||
| operations_tmpl='azext_horizondb.commands.custom_commands#{}') | ||
| with self.command_group('horizondb', horizondb_clusters_sdk, | ||
| custom_command_type=custom_commands, | ||
| client_factory=cf_horizondb_clusters) as g: | ||
| g.custom_command('create', 'horizondb_cluster_create', table_transformer=table_transform_output) | ||
| g.custom_command('delete', 'horizondb_cluster_delete') | ||
| g.show_command('show', 'get') | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
| # -------------------------------------------------------------------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # 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, too-many-locals | ||
|
|
||
| from knack.log import get_logger | ||
| from azure.cli.core.util import sdk_no_wait, user_confirmation | ||
| from azure.cli.core.azclierror import AzCLIError | ||
|
|
||
| logger = get_logger(__name__) | ||
|
|
||
|
|
||
| def horizondb_cluster_create(client, resource_group_name, cluster_name, location, | ||
| administrator_login, administrator_login_password, | ||
| tags=None, version=None, | ||
| replica_count=None, v_cores=None, | ||
| zone_placement_policy=None, | ||
| no_wait=False): | ||
| from azext_horizondb.vendored_sdks.models import HorizonDbCluster, HorizonDbClusterProperties | ||
|
|
||
| properties = HorizonDbClusterProperties( | ||
| administrator_login=administrator_login, | ||
| administrator_login_password=administrator_login_password, | ||
| version=version, | ||
| create_mode="Create", | ||
| replica_count=replica_count, | ||
| v_cores=v_cores, | ||
| zone_placement_policy=zone_placement_policy, | ||
| ) | ||
|
|
||
| resource = HorizonDbCluster( | ||
| location=location, | ||
| tags=tags, | ||
| properties=properties, | ||
| ) | ||
|
|
||
| return sdk_no_wait(no_wait, client.begin_create_or_update, | ||
| resource_group_name=resource_group_name, | ||
| cluster_name=cluster_name, | ||
| resource=resource) | ||
|
|
||
|
|
||
| def horizondb_cluster_delete(cmd, client, resource_group_name, cluster_name, no_wait=False, yes=False): | ||
| if not yes: | ||
| user_confirmation( | ||
| "Are you sure you want to delete the cluster '{0}' in resource group '{1}'".format(cluster_name, | ||
| resource_group_name), yes=yes) | ||
| try: | ||
| result = sdk_no_wait(no_wait, client.begin_delete, | ||
| resource_group_name=resource_group_name, | ||
| cluster_name=cluster_name) | ||
| if cmd.cli_ctx.local_context.is_on: | ||
| local_context_file = cmd.cli_ctx.local_context._get_local_context_file() # pylint: disable=protected-access | ||
| local_context_file.remove_option('horizondb', 'cluster_name') | ||
| except Exception as ex: # pylint: disable=broad-except | ||
| logger.error(ex) | ||
| raise AzCLIError(ex) | ||
| return result | ||
|
|
||
|
|
||
| def horizondb_cluster_list(client, resource_group_name=None): | ||
| if resource_group_name: | ||
| return client.list_by_resource_group(resource_group_name=resource_group_name) | ||
| return client.list_by_subscription() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
| # -------------------------------------------------------------------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
| # -------------------------------------------------------------------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| # Constants | ||
| CLUSTER_NAME_PREFIX = 'horizondbclitest-' | ||
| CLUSTER_NAME_MAX_LENGTH = 40 | ||
| DEFAULT_LOCATION = 'centralus' |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.