Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions src/horizondb/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
===============

1.0.0b4
+++++++
* Add `az horizondb parameter-group` commands to create, delete, list, and show HorizonDB parameter groups.

1.0.0b3
+++++++
* Add support for assigning a parameter group to HorizonDB clusters through `az horizondb update --parameter-group`.
Expand Down
4 changes: 4 additions & 0 deletions src/horizondb/azext_horizondb/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ def resource_client_factory(cli_ctx, subscription_id=None):

def cf_horizondb_clusters(cli_ctx, _):
return get_horizondb_management_client(cli_ctx).horizon_db_clusters


def cf_horizondb_parameter_groups(cli_ctx, _):
return get_horizondb_management_client(cli_ctx).horizon_db_parameter_groups
46 changes: 46 additions & 0 deletions src/horizondb/azext_horizondb/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,49 @@
- name: List Azure HorizonDB clusters in a resource group.
text: az horizondb list --resource-group exampleresourcegroup
"""


helps['horizondb parameter-group'] = """
type: group
short-summary: Manage Azure HorizonDB parameter groups.
"""


helps['horizondb parameter-group create'] = """
type: command
short-summary: Create a new Azure HorizonDB parameter group.
examples:
- name: Create a HorizonDB parameter group with custom parameter values. Unspecified parameters inherit the default PostgreSQL values.
text: az horizondb parameter-group create --name examplegroup --resource-group exampleresourcegroup --location centralus --version 17 --parameters max_connections=200 shared_buffers=2048 work_mem=8192
- name: Create a HorizonDB parameter group that applies parameters immediately.
text: az horizondb parameter-group create --name examplegroup --resource-group exampleresourcegroup --location centralus --version 17 --parameters maintenance_work_mem=262144 --apply-immediately true --description "Tuned for faster maintenance"
"""


helps['horizondb parameter-group delete'] = """
type: command
short-summary: Delete an Azure HorizonDB parameter group.
examples:
- name: Delete an Azure HorizonDB parameter group.
text: az horizondb parameter-group delete --name examplegroup --resource-group exampleresourcegroup
"""


helps['horizondb parameter-group show'] = """
type: command
short-summary: Show details of an Azure HorizonDB parameter group.
examples:
- name: Show details of an Azure HorizonDB parameter group.
text: az horizondb parameter-group show --name examplegroup --resource-group exampleresourcegroup
"""


helps['horizondb parameter-group list'] = """
type: command
short-summary: List Azure HorizonDB parameter groups.
examples:
- name: List all Azure HorizonDB parameter groups in the current subscription.
text: az horizondb parameter-group list
- name: List Azure HorizonDB parameter groups in a resource group.
text: az horizondb parameter-group list --resource-group exampleresourcegroup
"""
44 changes: 43 additions & 1 deletion src/horizondb/azext_horizondb/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
resource_group_name_type,
get_location_type,
tags_type,
get_three_state_flag,
get_enum_type)
from azure.cli.core.local_context import LocalContextAttribute, LocalContextAction
from azext_horizondb._validators import validate_parameters


def load_arguments(self, _): # pylint: disable=too-many-statements, too-many-locals
Expand Down Expand Up @@ -47,7 +49,7 @@ def _horizondb_params():

version_arg_type = CLIArgumentType(
options_list=['--version', '-v'],
help='The version of the HorizonDb cluster.')
help='Specifies the PostgreSQL major version.')

replica_count_arg_type = CLIArgumentType(
options_list=['--replica-count'],
Expand All @@ -67,6 +69,31 @@ def _horizondb_params():
parameter_group_arg_type = CLIArgumentType(
options_list=['--parameter-group'],
help='The resource ID of the parameter group.')

parameter_group_name_arg_type = CLIArgumentType(
metavar='NAME',
options_list=['--name', '-n'],
id_part='name',
help='Name of the parameter group.')

parameters_arg_type = CLIArgumentType(
options_list=['--parameters'],
nargs='+',
required=True,
validator=validate_parameters,
help="Space-separated list of parameters in 'name=value' format. "
"At least one parameter is required; any parameters you do not "
"specify inherit the PostgreSQL defaults for the parameter group.")
Comment thread
alxhghs marked this conversation as resolved.

description_arg_type = CLIArgumentType(
options_list=['--description'],
help='Description of the parameter group.')

apply_immediately_arg_type = CLIArgumentType(
options_list=['--apply-immediately'],
arg_type=get_three_state_flag(),
help='Indicates whether the parameters should be applied immediately.')

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)
Expand All @@ -90,4 +117,19 @@ def _horizondb_params():
with self.argument_context('horizondb delete') as c:
c.argument('yes', arg_type=yes_arg_type)

with self.argument_context('horizondb parameter-group') as c:
c.argument('resource_group_name', arg_type=resource_group_name_type)
c.argument('parameter_group_name', arg_type=parameter_group_name_arg_type)

with self.argument_context('horizondb parameter-group create') as c:
c.argument('location', arg_type=get_location_type(self.cli_ctx), required=False)
c.argument('tags', tags_type)
c.argument('parameters', arg_type=parameters_arg_type)
c.argument('description', arg_type=description_arg_type)
c.argument('pg_version', arg_type=version_arg_type, type=int)
c.argument('apply_immediately', arg_type=apply_immediately_arg_type)

with self.argument_context('horizondb parameter-group delete') as c:
c.argument('yes', arg_type=yes_arg_type)

_horizondb_params()
22 changes: 22 additions & 0 deletions src/horizondb/azext_horizondb/_validators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# --------------------------------------------------------------------------------------------
# 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.azclierror import ArgumentUsageError


def validate_parameters(cmd, namespace): # pylint: disable=unused-argument
if not namespace.parameters:
return

from azext_horizondb.vendored_sdks.models import ParameterProperties

parameter_list = []
for item in namespace.parameters:
if '=' not in item:
raise ArgumentUsageError("Parameter '{}' must be in the format name=value.".format(item))
name, value = item.split('=', 1)
parameter_list.append(ParameterProperties(name=name, value=value))

namespace.parameters = parameter_list
19 changes: 18 additions & 1 deletion src/horizondb/azext_horizondb/cluster_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

from azure.cli.core.commands import CliCommandType
from azext_horizondb._client_factory import (
cf_horizondb_clusters)
cf_horizondb_clusters,
cf_horizondb_parameter_groups)
from azext_horizondb.utils._transformers import (
table_transform_output)

Expand All @@ -17,8 +18,16 @@ def load_command_table(self, _):
client_factory=cf_horizondb_clusters
)

horizondb_parameter_groups_sdk = CliCommandType(
operations_tmpl='azext_horizondb.vendored_sdks.operations#HorizonDbParameterGroupsOperations.{}',
client_factory=cf_horizondb_parameter_groups
)

custom_commands = CliCommandType(
operations_tmpl='azext_horizondb.commands.custom_commands#{}')

parameter_group_commands = CliCommandType(
operations_tmpl='azext_horizondb.commands.parameter_group_commands#{}')
with self.command_group('horizondb', horizondb_clusters_sdk,
custom_command_type=custom_commands,
client_factory=cf_horizondb_clusters) as g:
Expand All @@ -27,3 +36,11 @@ def load_command_table(self, _):
g.custom_command('delete', 'horizondb_cluster_delete')
g.custom_command('list', 'horizondb_cluster_list')
g.show_command('show', 'get')

with self.command_group('horizondb parameter-group', horizondb_parameter_groups_sdk,
custom_command_type=parameter_group_commands,
client_factory=cf_horizondb_parameter_groups) as g:
g.custom_command('create', 'horizondb_parameter_group_create', supports_no_wait=True)
g.custom_command('delete', 'horizondb_parameter_group_delete', supports_no_wait=True)
g.custom_command('list', 'horizondb_parameter_group_list')
g.show_command('show', 'get')
51 changes: 51 additions & 0 deletions src/horizondb/azext_horizondb/commands/parameter_group_commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# --------------------------------------------------------------------------------------------
# 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 azure.cli.core.util import sdk_no_wait, user_confirmation


def horizondb_parameter_group_create(client, resource_group_name, parameter_group_name, location,
parameters=None, description=None, pg_version=None,
apply_immediately=None, tags=None, no_wait=False):
from azext_horizondb.vendored_sdks.models import (
HorizonDbParameterGroup,
HorizonDbParameterGroupProperties,
)

properties = HorizonDbParameterGroupProperties(
parameters=parameters,
description=description,
pg_version=pg_version,
apply_immediately=apply_immediately,
)

resource = HorizonDbParameterGroup(
location=location,
tags=tags,
properties=properties,
)

return sdk_no_wait(no_wait, client.begin_create_or_update,
resource_group_name=resource_group_name,
parameter_group_name=parameter_group_name,
resource=resource)


def horizondb_parameter_group_delete(client, resource_group_name, parameter_group_name, no_wait=False, yes=False):
if not yes:
user_confirmation(
"Are you sure you want to delete the parameter group '{0}' in resource group '{1}'".format(
parameter_group_name, resource_group_name), yes=yes)
return sdk_no_wait(no_wait, client.begin_delete,
resource_group_name=resource_group_name,
parameter_group_name=parameter_group_name)


def horizondb_parameter_group_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()
2 changes: 2 additions & 0 deletions src/horizondb/azext_horizondb/tests/latest/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

# Constants
CLUSTER_NAME_PREFIX = 'horizondbclitest-'
PARAMETER_GROUP_NAME_PREFIX = 'horizondbpgclitest-'
PASSWORD_PREFIX = 'passwordHorizon%'
CLUSTER_NAME_MAX_LENGTH = 40
PARAMETER_GROUP_NAME_MAX_LENGTH = 40
DEFAULT_LOCATION = 'centralus'
Loading