Skip to content

Commit 771ca37

Browse files
authored
[HorizonDB] Add parameter-group commands (#10046)
1 parent 4fa8063 commit 771ca37

12 files changed

Lines changed: 14719 additions & 4 deletions

‎src/horizondb/HISTORY.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
Release History
44
===============
55

6+
1.0.0b7
7+
+++++++
8+
* Add `az horizondb parameter-group` commands to create, delete, list, show, and list connections for HorizonDB parameter groups.
9+
610
1.0.0b6
711
+++++++
812
* Add private endpoint connection commands: `az horizondb private-endpoint-connection list/show/approve/reject/delete`.

‎src/horizondb/azext_horizondb/_client_factory.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ def cf_horizondb_clusters(cli_ctx, _):
3838
return get_horizondb_management_client(cli_ctx).horizon_db_clusters
3939

4040

41+
def cf_horizondb_parameter_groups(cli_ctx, _):
42+
return get_horizondb_management_client(cli_ctx).horizon_db_parameter_groups
43+
44+
4145
def cf_horizondb_firewall_rules(cli_ctx, _):
4246
return get_horizondb_management_client(cli_ctx).horizon_db_firewall_rules
4347

‎src/horizondb/azext_horizondb/_help.py‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,61 @@
7474
"""
7575

7676

77+
helps['horizondb parameter-group'] = """
78+
type: group
79+
short-summary: Manage Azure HorizonDB parameter groups.
80+
"""
81+
82+
83+
helps['horizondb parameter-group create'] = """
84+
type: command
85+
short-summary: Create a new Azure HorizonDB parameter group.
86+
examples:
87+
- name: Create an Azure HorizonDB parameter group with custom parameter values. Unspecified parameters inherit the default PostgreSQL values.
88+
text: az horizondb parameter-group create --name exampleparametergroup --resource-group exampleresourcegroup --location westus2 --version 17 --parameters max_connections=200 log_min_error_statement=error shared_buffers=2000
89+
- name: Create an Azure HorizonDB parameter group that applies parameters immediately and includes a description.
90+
text: az horizondb parameter-group create --name exampleparametergroup --resource-group exampleresourcegroup --location westus2 --version 17 --parameters max_connections=200 log_min_error_statement=error shared_buffers=2000 --apply-immediately true --description "Parameter group for high-throughput workloads"
91+
"""
92+
93+
94+
helps['horizondb parameter-group delete'] = """
95+
type: command
96+
short-summary: Delete an Azure HorizonDB parameter group.
97+
examples:
98+
- name: Delete an Azure HorizonDB parameter group.
99+
text: az horizondb parameter-group delete --name exampleparametergroup --resource-group exampleresourcegroup
100+
"""
101+
102+
103+
helps['horizondb parameter-group show'] = """
104+
type: command
105+
short-summary: Show details of an Azure HorizonDB parameter group.
106+
examples:
107+
- name: Show details of an Azure HorizonDB parameter group.
108+
text: az horizondb parameter-group show --name exampleparametergroup --resource-group exampleresourcegroup
109+
"""
110+
111+
112+
helps['horizondb parameter-group list'] = """
113+
type: command
114+
short-summary: List Azure HorizonDB parameter groups.
115+
examples:
116+
- name: List all Azure HorizonDB parameter groups in the current subscription.
117+
text: az horizondb parameter-group list
118+
- name: List Azure HorizonDB parameter groups in a resource group.
119+
text: az horizondb parameter-group list --resource-group exampleresourcegroup
120+
"""
121+
122+
123+
helps['horizondb parameter-group list-connections'] = """
124+
type: command
125+
short-summary: List Azure HorizonDB clusters connected to a parameter group.
126+
examples:
127+
- name: List Azure HorizonDB clusters connected to a parameter group.
128+
text: az horizondb parameter-group list-connections --resource-group exampleresourcegroup --name exampleparametergroup
129+
"""
130+
131+
77132
helps['horizondb firewall-rule'] = """
78133
type: group
79134
short-summary: Manage firewall rules for an Azure HorizonDB cluster.

‎src/horizondb/azext_horizondb/_params.py‎

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
resource_group_name_type,
1212
get_location_type,
1313
tags_type,
14+
get_three_state_flag,
1415
get_enum_type)
1516
from azure.cli.core.local_context import LocalContextAttribute, LocalContextAction
1617
from .utils.validators import (
18+
validate_parameters,
1719
validate_replica_count,
1820
public_access_validator,
1921
ip_address_validator)
@@ -51,7 +53,7 @@ def _horizondb_params():
5153

5254
version_arg_type = CLIArgumentType(
5355
options_list=['--version', '-v'],
54-
help='The version of the HorizonDb cluster.')
56+
help='Specifies the PostgreSQL major version.')
5557

5658
replica_count_arg_type = CLIArgumentType(
5759
options_list=['--replica-count', '-r'],
@@ -71,7 +73,32 @@ def _horizondb_params():
7173

7274
parameter_group_arg_type = CLIArgumentType(
7375
options_list=['--parameter-group'],
74-
help='The resource ID of the parameter group.')
76+
help='The resource identifier of the parameter group.')
77+
78+
parameter_group_name_arg_type = CLIArgumentType(
79+
metavar='NAME',
80+
options_list=['--name', '-n'],
81+
id_part='name',
82+
help='Name of the parameter group.')
83+
84+
parameters_arg_type = CLIArgumentType(
85+
options_list=['--parameters'],
86+
nargs='+',
87+
required=True,
88+
validator=validate_parameters,
89+
help="Space-separated list of parameters in 'name=value' format. "
90+
"At least one parameter is required; any parameters you do not "
91+
"specify inherit the PostgreSQL defaults for the parameter group.")
92+
93+
description_arg_type = CLIArgumentType(
94+
options_list=['--description'],
95+
help='Description of the parameter group.')
96+
97+
apply_immediately_arg_type = CLIArgumentType(
98+
options_list=['--apply-immediately'],
99+
arg_type=get_three_state_flag(),
100+
help='Indicates whether the parameters should be applied immediately.')
101+
75102
cluster_name_resource_arg_type = CLIArgumentType(
76103
metavar='NAME',
77104
options_list=['--cluster-name', '-c'],
@@ -81,17 +108,21 @@ def _horizondb_params():
81108
name='cluster_name',
82109
actions=[LocalContextAction.SET, LocalContextAction.GET],
83110
scopes=['horizondb']))
111+
84112
private_endpoint_connection_name_arg_type = CLIArgumentType(
85113
options_list=['--name', '-n'],
86114
help='The name of the private endpoint connection associated with the HorizonDB cluster. '
87115
'Required if --id is not specified.')
116+
88117
private_endpoint_connection_id_arg_type = CLIArgumentType(
89118
options_list=['--id'],
90119
help='The resource ID of the private endpoint connection associated with the HorizonDB cluster. '
91120
'If specified --cluster-name/-c and --name/-n, this should be omitted.')
121+
92122
private_endpoint_connection_description_arg_type = CLIArgumentType(
93123
options_list=['--description', '-d'],
94124
help='Comments for the approval or rejection.')
125+
95126
private_link_resource_group_name_arg_type = CLIArgumentType(
96127
options_list=['--group-name'],
97128
help='The private link resource group name. For HorizonDB this is the pool name, for example DefaultPool.')
@@ -165,6 +196,21 @@ def _horizondb_params():
165196
with self.argument_context('horizondb delete') as c:
166197
c.argument('yes', arg_type=yes_arg_type)
167198

199+
with self.argument_context('horizondb parameter-group') as c:
200+
c.argument('resource_group_name', arg_type=resource_group_name_type)
201+
c.argument('parameter_group_name', arg_type=parameter_group_name_arg_type)
202+
203+
with self.argument_context('horizondb parameter-group create') as c:
204+
c.argument('location', arg_type=get_location_type(self.cli_ctx), required=False)
205+
c.argument('tags', tags_type)
206+
c.argument('parameters', arg_type=parameters_arg_type)
207+
c.argument('description', arg_type=description_arg_type)
208+
c.argument('pg_version', arg_type=version_arg_type, type=int)
209+
c.argument('apply_immediately', arg_type=apply_immediately_arg_type)
210+
211+
with self.argument_context('horizondb parameter-group delete') as c:
212+
c.argument('yes', arg_type=yes_arg_type)
213+
168214
with self.argument_context('horizondb firewall-rule') as c:
169215
c.argument('resource_group_name', arg_type=resource_group_name_type)
170216
c.argument('cluster_name', arg_type=firewall_cluster_name_arg_type)

‎src/horizondb/azext_horizondb/cluster_commands.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from azure.cli.core.commands import CliCommandType
77
from azext_horizondb._client_factory import (
88
cf_horizondb_clusters,
9+
cf_horizondb_parameter_groups,
910
cf_horizondb_firewall_rules,
1011
cf_horizondb_private_endpoint_connections,
1112
cf_horizondb_private_link_resources)
@@ -22,9 +23,17 @@ def load_command_table(self, _):
2223
client_factory=cf_horizondb_clusters
2324
)
2425

26+
horizondb_parameter_groups_sdk = CliCommandType(
27+
operations_tmpl='azext_horizondb.vendored_sdks.operations#HorizonDbParameterGroupsOperations.{}',
28+
client_factory=cf_horizondb_parameter_groups
29+
)
30+
2531
custom_commands = CliCommandType(
2632
operations_tmpl='azext_horizondb.commands.custom_commands#{}')
2733

34+
parameter_group_commands = CliCommandType(
35+
operations_tmpl='azext_horizondb.commands.parameter_group_commands#{}')
36+
2837
firewall_rule_custom = CliCommandType(
2938
operations_tmpl='azext_horizondb.commands.firewall_rule_commands#{}',
3039
client_factory=cf_horizondb_firewall_rules)
@@ -48,6 +57,15 @@ def load_command_table(self, _):
4857
g.custom_command('list', 'horizondb_cluster_list')
4958
g.show_command('show', 'get')
5059

60+
with self.command_group('horizondb parameter-group', horizondb_parameter_groups_sdk,
61+
custom_command_type=parameter_group_commands,
62+
client_factory=cf_horizondb_parameter_groups) as g:
63+
g.custom_command('create', 'horizondb_parameter_group_create', supports_no_wait=True)
64+
g.custom_command('delete', 'horizondb_parameter_group_delete', supports_no_wait=True)
65+
g.custom_command('list', 'horizondb_parameter_group_list')
66+
g.custom_command('list-connections', 'horizondb_parameter_group_list_connections')
67+
g.show_command('show', 'get')
68+
5169
with self.command_group('horizondb firewall-rule', firewall_rule_custom,
5270
custom_command_type=firewall_rule_custom,
5371
client_factory=cf_horizondb_firewall_rules) as g:
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
# pylint: disable=line-too-long, too-many-locals
7+
8+
from azure.cli.core.util import sdk_no_wait, user_confirmation
9+
10+
11+
def horizondb_parameter_group_create(client, resource_group_name, parameter_group_name, location,
12+
parameters=None, description=None, pg_version=None,
13+
apply_immediately=None, tags=None, no_wait=False):
14+
from azext_horizondb.vendored_sdks.models import (
15+
HorizonDbParameterGroup,
16+
HorizonDbParameterGroupProperties,
17+
)
18+
19+
properties = HorizonDbParameterGroupProperties(
20+
parameters=parameters,
21+
description=description,
22+
pg_version=pg_version,
23+
apply_immediately=apply_immediately,
24+
)
25+
26+
resource = HorizonDbParameterGroup(
27+
location=location,
28+
tags=tags,
29+
properties=properties,
30+
)
31+
32+
return sdk_no_wait(no_wait, client.begin_create_or_update,
33+
resource_group_name=resource_group_name,
34+
parameter_group_name=parameter_group_name,
35+
resource=resource)
36+
37+
38+
def horizondb_parameter_group_delete(client, resource_group_name, parameter_group_name, no_wait=False, yes=False):
39+
if not yes:
40+
user_confirmation(
41+
"Are you sure you want to delete the parameter group '{0}' in resource group '{1}'".format(
42+
parameter_group_name, resource_group_name), yes=yes)
43+
return sdk_no_wait(no_wait, client.begin_delete,
44+
resource_group_name=resource_group_name,
45+
parameter_group_name=parameter_group_name)
46+
47+
48+
def horizondb_parameter_group_list(client, resource_group_name=None):
49+
if resource_group_name:
50+
return client.list_by_resource_group(resource_group_name=resource_group_name)
51+
return client.list_by_subscription()
52+
53+
54+
def horizondb_parameter_group_list_connections(client, resource_group_name, parameter_group_name):
55+
return client.list_connections(resource_group_name=resource_group_name, parameter_group_name=parameter_group_name)

‎src/horizondb/azext_horizondb/tests/latest/constants.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
# Constants
77
CLUSTER_NAME_PREFIX = 'horizondbclitest-'
8+
PARAMETER_GROUP_NAME_PREFIX = 'horizondbpgclitest-'
89
PASSWORD_PREFIX = 'passwordHorizon%'
910
CLUSTER_NAME_MAX_LENGTH = 40
11+
PARAMETER_GROUP_NAME_MAX_LENGTH = 40
1012
DEFAULT_LOCATION = 'centralus'

0 commit comments

Comments
 (0)