Skip to content

Commit aeee555

Browse files
authored
{POSTGRESQL} Split postgres flexible server commands from RDBMS (#32598)
1 parent ad78421 commit aeee555

File tree

127 files changed

+95581
-232873
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+95581
-232873
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
/src/azure-cli/azure/cli/command_modules/natgateway/ @jsntcy @kairu-ms @necusjz @khannarheams
5353
/src/azure-cli/azure/cli/command_modules/network/ @jsntcy @kairu-ms @wangzelin007 @necusjz
5454
/src/azure-cli/azure/cli/command_modules/policyinsights/ @jsntcy @cheggert
55+
/src/azure-cli/azure/cli/command_modules/postgresql/ @evelyn-ys @calvinhzy @arde0708
5556
/src/azure-cli/azure/cli/command_modules/privatedns/ @jsntcy @kairu-ms @necusjz
5657
/src/azure-cli/azure/cli/command_modules/profile/ @jiasli @evelyn-ys @bebound
5758
/src/azure-cli/azure/cli/command_modules/rdbms/ @evelyn-ys @calvinhzy @arde0708 @alanenriqueo

doc/sphinx/azhelpgen/doc_source_map.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"network": "src/azure-cli/azure/cli/command_modules/network/_help.py",
5757
"policy": "src/azure-cli/azure/cli/command_modules/resource/_help.py",
5858
"policyinsights": "src/azure-cli/azure/cli/command_modules/policyinsights/_help.py",
59+
"postgresql": "src/azure-cli/azure/cli/command_modules/postgresql/_help.py",
5960
"privatedns": "src/azure-cli/azure/cli/command_modules/privatedns/_help.py",
6061
"provider": "src/azure-cli/azure/cli/command_modules/resource/_help.py",
6162
"rdbms": "src/azure-cli/azure/cli/command_modules/rdbms/_help.py",

scripts/live_test/CLITest.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ stages:
178178
Target: network
179179
policyinsights:
180180
Target: policyinsights
181+
postgresql:
182+
Target: postgresql
181183
privatedns:
182184
Target: privatedns
183185
profile:
@@ -754,6 +756,8 @@ stages:
754756
Target: network
755757
policyinsights:
756758
Target: policyinsights
759+
postgresql:
760+
Target: postgresql
757761
privatedns:
758762
Target: privatedns
759763
profile:
@@ -1329,6 +1333,8 @@ stages:
13291333
Target: network
13301334
policyinsights:
13311335
Target: policyinsights
1336+
postgresql:
1337+
Target: postgresql
13321338
privatedns:
13331339
Target: privatedns
13341340
profile:

src/azure-cli-core/azure/cli/core/profiles/_shared.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class ResourceType(Enum): # pylint: disable=too-few-public-methods
107107
MGMT_MAPS = ('azure.mgmt.maps', None)
108108
MGMT_POLICYINSIGHTS = ('azure.mgmt.policyinsights', None)
109109
MGMT_RDBMS = ('azure.mgmt.rdbms', None)
110+
MGMT_POSTGRESQL = ('azure.mgmt.postgresql', None)
110111
MGMT_REDIS = ('azure.mgmt.redis', None)
111112
MGMT_SEARCH = ('azure.mgmt.search', None)
112113
MGMT_SERVICEFABRIC = ('azure.mgmt.servicefabric', None)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
from azure.cli.core import AzCommandsLoader
7+
from azure.cli.core import ModExtensionSuppress
8+
from azure.cli.core.commands import CliCommandType
9+
from azure.cli.core.profiles import ResourceType
10+
from azure.cli.command_modules.postgresql._util import PostgreSQLArgumentContext
11+
from azure.cli.command_modules.postgresql.flexible_server_commands import load_flexibleserver_command_table
12+
from azure.cli.command_modules.postgresql._params import load_arguments
13+
import azure.cli.command_modules.postgresql._help # pylint: disable=unused-import
14+
15+
16+
# pylint: disable=import-outside-toplevel
17+
class PostgreSQLCommandsLoader(AzCommandsLoader):
18+
19+
def __init__(self, cli_ctx=None):
20+
21+
postgresql_custom = CliCommandType(operations_tmpl='azure.cli.command_modules.postgresql.custom#{}')
22+
super().__init__(
23+
cli_ctx=cli_ctx,
24+
resource_type=ResourceType.MGMT_POSTGRESQL,
25+
custom_command_type=postgresql_custom,
26+
argument_context_cls=PostgreSQLArgumentContext,
27+
suppress_extension=ModExtensionSuppress(
28+
__name__,
29+
'postgresql-vnet',
30+
'10.0.1',
31+
reason='These commands are now in the CLI.',
32+
recommend_remove=True))
33+
34+
def load_command_table(self, args):
35+
from azure.cli.core.aaz import load_aaz_command_table
36+
try:
37+
from . import aaz
38+
except ImportError:
39+
aaz = None
40+
if aaz:
41+
load_aaz_command_table(
42+
loader=self,
43+
aaz_pkg_name=aaz.__name__,
44+
args=args
45+
)
46+
47+
load_flexibleserver_command_table(self, args)
48+
return self.command_table
49+
50+
def load_arguments(self, command):
51+
load_arguments(self, command)
52+
53+
54+
COMMAND_LOADER_CLS = PostgreSQLCommandsLoader

src/azure-cli/azure/cli/command_modules/rdbms/_breaking_change.py renamed to src/azure-cli/azure/cli/command_modules/postgresql/_breaking_change.py

File renamed without changes.
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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+
from azure.cli.core.commands.client_factory import get_mgmt_service_client
7+
from azure.cli.core.profiles import ResourceType
8+
from azure.cli.core.auth.identity import get_environment_credential, AZURE_CLIENT_ID
9+
10+
# pylint: disable=import-outside-toplevel
11+
12+
RM_URI_OVERRIDE = 'AZURE_CLI_POSTGRESQL_FLEXIBLE_RM_URI'
13+
SUB_ID_OVERRIDE = 'AZURE_CLI_POSTGRESQL_FLEXIBLE_SUB_ID'
14+
15+
16+
def get_postgresql_flexible_management_client(cli_ctx, subscription_id=None, **_):
17+
from os import getenv
18+
from azure.mgmt.postgresqlflexibleservers import PostgreSQLManagementClient
19+
# Allow overriding resource manager URI using environment variable
20+
# for testing purposes. Subscription id is also determined by environment
21+
# variable.
22+
rm_uri_override = getenv(RM_URI_OVERRIDE)
23+
subscription = subscription_id if subscription_id is not None else getenv(SUB_ID_OVERRIDE)
24+
if rm_uri_override:
25+
client_id = getenv(AZURE_CLIENT_ID)
26+
if client_id:
27+
credentials = get_environment_credential()
28+
else:
29+
from msrest.authentication import Authentication # pylint: disable=import-error
30+
credentials = Authentication()
31+
32+
return PostgreSQLManagementClient(
33+
subscription_id=subscription,
34+
base_url=rm_uri_override,
35+
credential=credentials)
36+
# Normal production scenario.
37+
return get_mgmt_service_client(cli_ctx, PostgreSQLManagementClient, subscription_id=subscription)
38+
39+
40+
def cf_postgres_flexible_servers(cli_ctx, _):
41+
return get_postgresql_flexible_management_client(cli_ctx).servers
42+
43+
44+
def cf_postgres_flexible_firewall_rules(cli_ctx, _):
45+
return get_postgresql_flexible_management_client(cli_ctx).firewall_rules
46+
47+
48+
def cf_postgres_flexible_virtual_endpoints(cli_ctx, _):
49+
return get_postgresql_flexible_management_client(cli_ctx).virtual_endpoints
50+
51+
52+
def cf_postgres_flexible_config(cli_ctx, _):
53+
return get_postgresql_flexible_management_client(cli_ctx).configurations
54+
55+
56+
def cf_postgres_flexible_replica(cli_ctx, _):
57+
return get_postgresql_flexible_management_client(cli_ctx).replicas
58+
59+
60+
def cf_postgres_flexible_location_capabilities(cli_ctx, _):
61+
return get_postgresql_flexible_management_client(cli_ctx).capabilities_by_location
62+
63+
64+
def cf_postgres_flexible_server_capabilities(cli_ctx, _):
65+
return get_postgresql_flexible_management_client(cli_ctx).capabilities_by_server
66+
67+
68+
def cf_postgres_flexible_backups(cli_ctx, _):
69+
return get_postgresql_flexible_management_client(cli_ctx).backups_automatic_and_on_demand
70+
71+
72+
def cf_postgres_flexible_ltr_backups(cli_ctx, _):
73+
return get_postgresql_flexible_management_client(cli_ctx).backups_long_term_retention
74+
75+
76+
def cf_postgres_flexible_operations(cli_ctx, _):
77+
return get_postgresql_flexible_management_client(cli_ctx).operations
78+
79+
80+
def cf_postgres_flexible_admin(cli_ctx, _):
81+
return get_postgresql_flexible_management_client(cli_ctx).administrators_microsoft_entra
82+
83+
84+
def cf_postgres_flexible_migrations(cli_ctx, _):
85+
return get_postgresql_flexible_management_client(cli_ctx).migrations
86+
87+
88+
def cf_postgres_flexible_server_threat_protection_settings(cli_ctx, _):
89+
return get_postgresql_flexible_management_client(cli_ctx).server_threat_protection_settings
90+
91+
92+
def cf_postgres_flexible_advanced_threat_protection_settings(cli_ctx, _):
93+
return get_postgresql_flexible_management_client(cli_ctx).advanced_threat_protection_settings
94+
95+
96+
def cf_postgres_flexible_server_log_files(cli_ctx, _):
97+
return get_postgresql_flexible_management_client(cli_ctx).captured_logs
98+
99+
100+
def cf_postgres_check_resource_availability(cli_ctx, _):
101+
return get_postgresql_flexible_management_client(cli_ctx).name_availability
102+
103+
104+
def cf_postgres_flexible_db(cli_ctx, _):
105+
return get_postgresql_flexible_management_client(cli_ctx).databases
106+
107+
108+
def cf_postgres_flexible_private_dns_zone_suffix_operations(cli_ctx, _):
109+
return get_postgresql_flexible_management_client(cli_ctx).private_dns_zone_suffix
110+
111+
112+
def cf_postgres_flexible_private_endpoint_connections(cli_ctx, _):
113+
return get_postgresql_flexible_management_client(cli_ctx).private_endpoint_connections
114+
115+
116+
def cf_postgres_flexible_private_link_resources(cli_ctx, _):
117+
return get_postgresql_flexible_management_client(cli_ctx).private_link_resources
118+
119+
120+
def cf_postgres_flexible_tuning_options(cli_ctx, _):
121+
return get_postgresql_flexible_management_client(cli_ctx).tuning_options
122+
123+
124+
def resource_client_factory(cli_ctx, subscription_id=None):
125+
return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES, subscription_id=subscription_id)
126+
127+
128+
def private_dns_client_factory(cli_ctx, subscription_id=None):
129+
from azure.mgmt.privatedns import PrivateDnsManagementClient
130+
return get_mgmt_service_client(cli_ctx, PrivateDnsManagementClient, subscription_id=subscription_id).private_zones
131+
132+
133+
def private_dns_link_client_factory(cli_ctx, subscription_id=None):
134+
from azure.mgmt.privatedns import PrivateDnsManagementClient
135+
return get_mgmt_service_client(cli_ctx, PrivateDnsManagementClient,
136+
subscription_id=subscription_id).virtual_network_links
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
import json
7+
import os
8+
from azure.cli.core.azclierror import BadRequestError
9+
10+
_config = None
11+
12+
13+
def get_config_json():
14+
global _config # pylint:disable=global-statement
15+
if _config is not None:
16+
return _config
17+
script_dir = os.path.dirname(os.path.realpath(__file__))
18+
with open(os.path.join(script_dir, "config.json"), "r") as f:
19+
try:
20+
_config = json.load(f)
21+
return _config
22+
except ValueError:
23+
raise BadRequestError("Invalid json file. Make sure that the json file content is properly formatted.")
24+
25+
26+
def get_cloud(cmd):
27+
config = get_config_json()
28+
return config[cmd.cli_ctx.cloud.name]
29+
30+
31+
def get_cloud_cluster(cmd, location, subscription_id):
32+
try:
33+
cloud = get_cloud(cmd)
34+
clusters = cloud[location]
35+
except KeyError:
36+
clusters = None
37+
if clusters is not None:
38+
for cluster in clusters:
39+
if cloud[cluster] is not None:
40+
if subscription_id in cloud[cluster]["subscriptions"]:
41+
return cloud[cluster]
42+
return

0 commit comments

Comments
 (0)