Skip to content

Commit 9b3b244

Browse files
authored
{RDBMS} Add support for osshf cluster (#28310)
* Add support for osshf cluster * Fix pylint errors * Fix missing cluster in json error * Fix CLI errors * Fix too generic exception error * Add osshf support for CLI in northcentralus * Avoid key error in case of reading for cloud from json file
1 parent 48d06b2 commit 9b3b244

File tree

3 files changed

+83
-8
lines changed

3 files changed

+83
-8
lines changed
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"AzureCloud": {
3+
"southcentralus": ["ossdev", "osshf", "ossmc"],
4+
"northcentralus": ["ossdev", "osshf", "ossmc"],
5+
"osshf": {
6+
"subscriptions": ["4a5d02ab-e0c3-4d39-8031-293ddd4e1875"],
7+
"privateDnsZoneDomain": "pg.osshf-scus1-a.mscds.com"
8+
},
9+
"ossdev": {
10+
"subscriptions": ["4a739919-f590-44f7-9eb8-0b84cde3bac8"],
11+
"privateDnsZoneDomain": "pg.ossdev-scus1-a.mscds.com"
12+
},
13+
"ossmc": {
14+
"subscriptions": ["d4fbfa87-b94d-4b13-906f-97361388c5e4"],
15+
"privateDnsZoneDomain": "pg.ossmc-scus1-a.mscds.com"
16+
}
17+
},
18+
"AzureChinaCloud": {
19+
},
20+
"AzureUSGovernment": {
21+
},
22+
"AzureGermanCloud": {
23+
},
24+
"Stage": {
25+
}
26+
}

src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_virtual_network.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from azure.mgmt.privatedns.models import SubResource
1616
from azure.mgmt.privatedns.models import VirtualNetworkLink
1717
from ._client_factory import resource_client_factory, private_dns_client_factory, private_dns_link_client_factory
18+
from ._config_reader import get_cloud_cluster
1819
from ._flexible_server_util import get_id_components, check_existence, _is_resource_name, parse_public_access_input, get_user_confirmation, _check_resource_group_existence
1920
from .validators import validate_private_dns_zone, validate_vnet_location
2021

@@ -338,14 +339,6 @@ def prepare_mysql_exist_private_dns_zone(cmd, resource_group, private_dns_zone,
338339

339340
def prepare_private_dns_zone(db_context, resource_group, server_name, private_dns_zone, subnet_id, location, yes):
340341
cmd = db_context.cmd
341-
dns_suffix_client = db_context.cf_private_dns_zone_suffix(cmd.cli_ctx, '_')
342-
private_dns_zone_suffix = dns_suffix_client.execute()
343-
if db_context.command_group == 'mysql':
344-
private_dns_zone_suffix = private_dns_zone_suffix.private_dns_zone_suffix
345-
346-
# suffix should start with .
347-
if private_dns_zone_suffix[0] != '.':
348-
private_dns_zone_suffix = '.' + private_dns_zone_suffix
349342

350343
# Get Vnet Components
351344
vnet_subscription, vnet_rg, vnet_name, _ = get_id_components(subnet_id)
@@ -360,6 +353,20 @@ def prepare_private_dns_zone(db_context, resource_group, server_name, private_dn
360353
"resource_group": vnet_rg
361354
})
362355

356+
cluster = get_cloud_cluster(cmd, location.replace('/ +/g', '').lower(), vnet_subscription)
357+
358+
if cluster is not None:
359+
private_dns_zone_suffix = cluster["privateDnsZoneDomain"]
360+
else:
361+
dns_suffix_client = db_context.cf_private_dns_zone_suffix(cmd.cli_ctx, '_')
362+
private_dns_zone_suffix = dns_suffix_client.execute()
363+
if db_context.command_group == 'mysql':
364+
private_dns_zone_suffix = private_dns_zone_suffix.private_dns_zone_suffix
365+
366+
# suffix should start with .
367+
if private_dns_zone_suffix[0] != '.':
368+
private_dns_zone_suffix = '.' + private_dns_zone_suffix
369+
363370
# Process private dns zone (no input or Id input)
364371
dns_rg = None
365372
dns_subscription = vnet_subscription

0 commit comments

Comments
 (0)