Skip to content
Open
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
8 changes: 8 additions & 0 deletions src/horizondb/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. :changelog:

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

0.1.0
++++++
* Initial release.
21 changes: 21 additions & 0 deletions src/horizondb/README.md
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.
32 changes: 32 additions & 0 deletions src/horizondb/azext_horizondb/__init__.py
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
38 changes: 38 additions & 0 deletions src/horizondb/azext_horizondb/_client_factory.py
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
44 changes: 44 additions & 0 deletions src/horizondb/azext_horizondb/_help.py
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
"""
84 changes: 84 additions & 0 deletions src/horizondb/azext_horizondb/_params.py
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()
4 changes: 4 additions & 0 deletions src/horizondb/azext_horizondb/azext_metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"azext.minCliCoreVersion": "2.17.1",
"azext.isPreview": true
}
27 changes: 27 additions & 0 deletions src/horizondb/azext_horizondb/cluster_commands.py
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')
Comment thread
nasc17 marked this conversation as resolved.
4 changes: 4 additions & 0 deletions src/horizondb/azext_horizondb/commands/__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.
# --------------------------------------------------------------------------------------------
66 changes: 66 additions & 0 deletions src/horizondb/azext_horizondb/commands/custom_commands.py
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()
4 changes: 4 additions & 0 deletions src/horizondb/azext_horizondb/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.
# --------------------------------------------------------------------------------------------
4 changes: 4 additions & 0 deletions src/horizondb/azext_horizondb/tests/latest/__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.
# --------------------------------------------------------------------------------------------
9 changes: 9 additions & 0 deletions src/horizondb/azext_horizondb/tests/latest/constants.py
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'
Loading
Loading