Skip to content

Commit ab5124c

Browse files
temandrtemandr
andauthored
[DMS] az dms project create: Change location parameter to be optional (#31465)
Co-authored-by: temandr <[email protected]>
1 parent 27f4437 commit ab5124c

File tree

9 files changed

+4727
-1986
lines changed

9 files changed

+4727
-1986
lines changed

src/azure-cli/azure/cli/command_modules/dms/_breaking_change.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/azure-cli/azure/cli/command_modules/dms/_client_factory.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
55

6-
76
def dms_client_factory(cli_ctx, *_):
87
from azure.cli.core.commands.client_factory import get_mgmt_service_client
98
from azure.mgmt.datamigration import DataMigrationManagementClient
@@ -24,3 +23,10 @@ def dms_cf_projects(cli_ctx, *_):
2423

2524
def dms_cf_tasks(cli_ctx, *_):
2625
return dms_client_factory(cli_ctx).tasks
26+
27+
28+
def get_resource_groups_client(cli_ctx, subscription_id=None):
29+
from azure.cli.core.commands.client_factory import get_mgmt_service_client
30+
from azure.cli.core.profiles import ResourceType
31+
return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES,
32+
subscription_id=subscription_id).resource_groups

src/azure-cli/azure/cli/command_modules/dms/_help.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
examples:
5252
- name: Create an instance of DMS.
5353
text: >
54-
az dms create -l westus -n mydms -g myresourcegroup --sku-name Basic_2vCores --subnet /subscriptions/{vnetSubscriptionId}/resourceGroups/{vnetResourceGroup}/providers/Microsoft.Network/virtualNetworks/{vnetName}/subnets/{subnetName} --tags tagName1=tagValue1 tagWithNoValue
54+
az dms create -n mydms -g myresourcegroup --sku-name Basic_2vCores --subnet /subscriptions/{vnetSubscriptionId}/resourceGroups/{vnetResourceGroup}/providers/Microsoft.Network/virtualNetworks/{vnetName}/subnets/{subnetName} --tags tagName1=tagValue1 tagWithNoValue
5555
"""
5656

5757
helps['dms delete'] = """
@@ -122,13 +122,13 @@
122122
examples:
123123
- name: Create a SQL to SQLDB project for a DMS instance.
124124
text: >
125-
az dms project create -l westus -n sqlproject -g myresourcegroup --service-name mydms --source-platform SQL --target-platform SQLDB --tags tagName1=tagValue1 tagWithNoValue
125+
az dms project create -n sqlproject -g myresourcegroup --service-name mydms --source-platform SQL --target-platform SQLDB --tags tagName1=tagValue1 tagWithNoValue
126126
- name: Create a PostgreSql to AzureDbForPostgreSql project for a DMS instance.
127127
text: >
128-
az dms project create -l westus -n pgproject -g myresourcegroup --service-name mydms --source-platform PostgreSQL --target-platform AzureDbForPostgreSQL --tags tagName1=tagValue1 tagWithNoValue
128+
az dms project create -n pgproject -g myresourcegroup --service-name mydms --source-platform PostgreSQL --target-platform AzureDbForPostgreSQL --tags tagName1=tagValue1 tagWithNoValue
129129
- name: Create a MySQL to AzureDbForMySQL project for a DMS instance.
130130
text: >
131-
az dms project create -l westus -n mysqlproject -g myresourcegroup --service-name mydms --source-platform MySQL --target-platform AzureDbForMySQL --tags tagName1=tagValue1 tagWithNoValue
131+
az dms project create -n mysqlproject -g myresourcegroup --service-name mydms --source-platform MySQL --target-platform AzureDbForMySQL --tags tagName1=tagValue1 tagWithNoValue
132132
"""
133133

134134
helps['dms project delete'] = """
@@ -320,6 +320,8 @@
320320
// Optional setting that configures the delay between updates of result objects in Azure Table Storage.
321321
"DelayProgressUpdatesInStorageInterval": "00:00:30",
322322
},
323+
// Optional setting to migrate the full server.
324+
"migrate_full_server": "true|false",
323325
// Optional setting to set the source server read only.
324326
"make_source_server_read_only": "true|false",
325327
// Optional setting to enable consistent backup. True by default for the sync migration, unless lockless is enabled.
@@ -339,7 +341,7 @@
339341
// Optional. If true, all users/grants will be migrated.
340342
"migrate_user_system_tables": "true|false",
341343
// Binlog position to start the migration from. Only applicable for the ReplicateChanges migration.
342-
"binLogInfo": {
344+
"binlog_info": {
343345
"filename": "binlog.0004523",
344346
"position": 283287
345347
}
@@ -376,7 +378,9 @@
376378
"userName": "user name", // if this is missing or null, you will be prompted
377379
"password": null, // if this is missing or null (highly recommended) you will be prompted
378380
"serverName": "server name",
379-
"port": 3306 // if this is missing, it will default to 3306
381+
"port": 3306, // if this is missing, it will default to 3306
382+
"encryptConnection": true, // highly recommended to leave as true
383+
"trustServerCertificate": false // highly recommended to leave as false
380384
}
381385
- name: --target-connection-json
382386
type: string

src/azure-cli/azure/cli/command_modules/dms/custom.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525

2626
from azure.cli.core.azclierror import RequiredArgumentMissingError
2727
from azure.cli.core.util import sdk_no_wait, get_file_json, shell_safe_json_parse
28-
from azure.cli.command_modules.dms._client_factory import dms_cf_projects
28+
from azure.cli.command_modules.dms._client_factory import (dms_cf_projects,
29+
get_resource_groups_client,
30+
dms_cf_services)
2931
from azure.cli.command_modules.dms.scenario_inputs import (get_migrate_sql_to_sqldb_offline_input,
3032
get_migrate_postgresql_to_azuredbforpostgresql_sync_input,
3133
get_migrate_mysql_to_azuredbformysql_offline_input,
@@ -42,14 +44,17 @@ def check_service_name_availability(client, service_name, location):
4244
parameters=parameters)
4345

4446

45-
def create_service(client,
47+
def create_service(cmd,
48+
client,
4649
service_name,
4750
resource_group_name,
48-
location,
4951
subnet,
5052
sku_name,
53+
location=None,
5154
tags=None,
5255
no_wait=False):
56+
if location is None:
57+
location = get_rg_location(cmd.cli_ctx, resource_group_name)
5358
parameters = DataMigrationService(location=location,
5459
virtual_subnet_id=subnet,
5560
sku=ServiceSku(name=sku_name),
@@ -102,11 +107,11 @@ def check_project_name_availability(client, resource_group_name, service_name, p
102107
parameters=parameters)
103108

104109

105-
def create_or_update_project(client,
110+
def create_or_update_project(cmd,
111+
client,
106112
project_name,
107113
service_name,
108114
resource_group_name,
109-
location,
110115
source_platform,
111116
target_platform,
112117
tags=None):
@@ -115,6 +120,8 @@ def create_or_update_project(client,
115120
necessary at the Task level, there is no need to include it at the Project level where for CLI it is more of a
116121
useless redundancy."""
117122

123+
location = get_dms_location(cmd.cli_ctx, resource_group_name, service_name)
124+
118125
# Set inputs to lowercase
119126
source_platform = source_platform.lower()
120127
target_platform = target_platform.lower()
@@ -474,6 +481,24 @@ def get_scenario_type(source_platform, target_platform, task_type=""):
474481
return scenario_type
475482

476483

484+
def get_rg_location(ctx, resource_group_name, subscription_id=None):
485+
groups = get_resource_groups_client(ctx, subscription_id=subscription_id)
486+
# Just do the get, we don't need the result, it will error out if the group doesn't exist.
487+
rg = groups.get(resource_group_name)
488+
if rg is None:
489+
raise CLIError('Resource group {} not found.'.format(resource_group_name))
490+
return rg.location
491+
492+
493+
def get_dms_location(ctx, resource_group_name, dms_name):
494+
services = dms_cf_services(ctx)
495+
# Just do the get, we don't need the result, it will error out if the group doesn't exist.
496+
service = services.get(group_name=resource_group_name, service_name=dms_name)
497+
if service is None:
498+
raise CLIError('Service {} not found.'.format(dms_name))
499+
return service.location
500+
501+
477502
class ScenarioType(Enum):
478503
unknown = 0
479504
# SQL to SQLDB

src/azure-cli/azure/cli/command_modules/dms/scenario_inputs.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,28 +105,35 @@ def get_migrate_mysql_to_azuredbformysql_input(database_options_json,
105105
migration_level_settings = {}
106106
make_source_server_read_only = False
107107
migration_properties = {}
108+
migrate_full_server = False
108109

109110
if not isinstance(database_options_json, dict):
110111
raise ValidationError('Format of the database option file is wrong')
111112

112-
if 'selected_databases' not in database_options_json:
113+
migrate_full_server = database_options_json.get('migrate_full_server', False)
114+
if migrate_full_server:
115+
set_optional(migration_properties, 'migrateFullServer', database_options_json, 'migrate_full_server')
116+
117+
if ('selected_databases' not in database_options_json) and (not migrate_full_server):
113118
raise ValidationError('Database option file should contain at least one selected database for migration')
114119

115120
selected_databases = database_options_json.get('selected_databases')
116121

117-
for database in selected_databases:
118-
if not isinstance(database, dict):
119-
raise ValidationError('Format of the selected database file is wrong')
120-
if 'name' not in database:
121-
raise ValidationError('Selected database should have a name')
122-
if 'target_database_name' not in database:
123-
raise ValidationError('Selected database should have a target_database_name')
124-
if 'table_map' in database and (not isinstance(database.get('table_map'), dict) or
125-
len(database.get('table_map')) == 0):
126-
raise ValidationError('table_map should be dictionary and non empty, to select all tables remove table_map')
127-
128-
db_input = create_db_input(database, has_schema_migration_options)
129-
database_options.append(db_input)
122+
if selected_databases is not None:
123+
for database in selected_databases:
124+
if not isinstance(database, dict):
125+
raise ValidationError('Format of the selected database file is wrong')
126+
if 'name' not in database:
127+
raise ValidationError('Selected database should have a name')
128+
if 'target_database_name' not in database:
129+
raise ValidationError('Selected database should have a target_database_name')
130+
if 'table_map' in database and (not isinstance(database.get('table_map'), dict) or
131+
len(database.get('table_map')) == 0):
132+
raise ValidationError(
133+
'table_map should be dictionary and non empty, to select all tables remove table_map')
134+
135+
db_input = create_db_input(database, has_schema_migration_options)
136+
database_options.append(db_input)
130137

131138
set_optional(migration_properties, 'sourceServerResourceId', database_options_json, 'source_server_resource_id')
132139
set_optional(migration_properties, 'targetServerResourceId', database_options_json, 'target_server_resource_id')

0 commit comments

Comments
 (0)