Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DMS - Adding PG and MySQL extension #207

Merged
merged 14 commits into from
Jun 20, 2018
7 changes: 7 additions & 0 deletions src/datamigration/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Microsoft Azure CLI 'Database Migration Service' Command Module
===============================================================

This package is for the 'Database Migration Service' module.
i.e. 'az dms'


31 changes: 31 additions & 0 deletions src/datamigration/azext_dms/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# --------------------------------------------------------------------------------------------
# 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 import AzCommandsLoader

import azext_dms._help # pylint: disable=unused-import

class DmsCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
from azure.cli.command_modules.dms.commands import dms_api_exception_handler
dms_custom = CliCommandType(operations_tmpl='azext_dms.custom#{}',
exception_handler=dms_api_exception_handler)
super(DmsCommandsLoader, self).__init__(cli_ctx=cli_ctx,
min_profile='2017-03-10-profile',
custom_command_type=dms_custom)

def load_command_table(self, args):
from azext_dms.commands import load_command_table
load_command_table(self, args)
return self.command_table

def load_arguments(self, command):
from azext_dms._params import load_arguments
load_arguments(self, command)


COMMAND_LOADER_CLS = DmsCommandsLoader
15 changes: 15 additions & 0 deletions src/datamigration/azext_dms/_client_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

def dms_client_factory(cli_ctx, **_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azext_dms.mgmt.datamigration import DataMigrationServiceClient
return get_mgmt_service_client(cli_ctx, DataMigrationServiceClient)

def dms_cf_projects(cli_ctx, *_):
return dms_client_factory(cli_ctx).projects

def dms_cf_tasks(cli_ctx, *_):
return dms_client_factory(cli_ctx).tasks
140 changes: 140 additions & 0 deletions src/datamigration/azext_dms/_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from knack.help_files import helps

helps['dms project create'] = """
type: command
short-summary: Create a migration Project which can contain multiple Tasks.
long-summary: |
This extension currently supports the following project configurations.
-) source -> target :: data movement type
1) SQL -> SQLDB :: One time
2) PostgreSQL -> AzureDbForPostgreSql :: Continuous
3) MySQL -> AzureDbForMySql :: Continuous

parameters:
- name: --source-platform
type: string
short-summary: >
The type of server for the source database. The supported types are: SQL, PostgreSQL, MySQL
- name: --target-platform
type: string
short-summary: >
The type of service for the target database. The supported types are: SQLDB, AzureDbForPostgreSql, AzureDbForMySql.
examples:
- name: Create a SQL Project for a DMS instance.
text: >
az dms project create -l westus -n myproject -g myresourcegroup --service-name mydms --source-platform SQL--target-platform SQLDB --tags tagName1=tagValue1 tagWithNoValue
"""

helps['dms project task create'] = """
type: command
short-summary: Create a migration Project which can contain multiple Tasks.
parameters:
- name: --source-platform
type: string
short-summary: >
The type of server for the source database. The supported types are: SQL, PostgreSQL, MySQL
- name: --target-platform
type: string
short-summary: >
The type of service for the target database. The supported types are: SQLDB, AzureDbForPostgreSql, AzureDbForMySql.
- name: --database-options-json
type: string
short-summary: >
Database and table information. This can be either a JSON-formatted string or the location to a file containing the JSON object. See example below for the format.
- name: --source-connection-json
type: string
short-summary: >
The connection information to the source server. This can be either a JSON-formatted string or the location to a file containing the JSON object. See example below for the format.
- name: --target-connection-json
type: string
short-summary: >
The connection information to the target server. This can be either a JSON-formatted string or the location to a file containing the JSON object. See example below for the format.
- name: --enable-data-integrity-validation
type: bool
short-summary: >
(For SQL only) Whether to perform a checksum based data integrity validation between source and target for the selected database and tables.
- name: --enable-query-analysis-validation
type: bool
short-summary: >
(For SQL only) Whether to perform a quick and intelligent query analysis by retrieving queries from the source database and executing them in the target. The result will have execution statistics for executions in source and target databases for the extracted queries.
- name: --enable-schema-validation
type: bool
short-summary: >
(For SQL only) Whether to compare the schema information between source and target.
examples:
- name: Create and start a SQL Task which performs no validation checks.
text: >
az dms project task create --database-options-json C:\\CLI Files\\databaseOptions.json -n mytask --project-name myproject -g myresourcegroup --service-name mydms --source-connection-json '{'dataSource': 'myserver', 'authentication': 'SqlAuthentication', 'encryptConnection': 'true', 'trustServerCertificate': 'true'}' --target-connection-json C:\\CLI Files\\targetConnection.json
- name: Create and start a SQL Task which performs all validation checks.
text: >
az dms project task create --database-options-json C:\\CLI Files\\databaseOptions.json -n mytask --project-name myproject -g myresourcegroup --service-name mydms --source-connection-json C:\\CLI Files\\sourceConnection.json --target-connection-json C:\\CLI Files\\targetConnection.json --enable-data-integrity-validation=True --enable-query-analysis-validation --enable-schema-validation
- name: For SQL, the format of the database options JSON object.
long-summary: |
For SQL we support per table migrations. To use this, specify the tables names in the 'table_map' as below.
YOu can aslo set the source as read only.
text: >
[
{
"name": "source database",
"target_database_name": "target database",
"make_source_db_read_only": false|true,
"table_map": {
"schema.SourceTableName1": "schema.TargetTableName1",
"schema.SourceTableName2": "schema.TargetTableName2",
...n
}
},
...n
]
- name: For PostgreSQL and MySQL, the format of the database options JSON object.
text: >
[
{
"name": "source database",
"target_database_name": "target database",
},
...n
]
- name: The format of the connection JSON object for SQL connections.
text: >
{
"userName": "user name", // if this is missing or null, you will be prompted
"password": null, // if this is missing or null (highly recommended) you will be prompted
"dataSource": "server name[,port]",
"authentication": "SqlAuthentication|WindowsAuthentication",
"encryptConnection": true, // highly recommended to leave as true
"trustServerCertificate": true // highly recommended to leave as true
}
- name: The format of the connection JSON object for MySql connections.
text: >
{
"userName": "user name", // if this is missing or null, you will be prompted
"password": null, // if this is missing or null (highly recommended) you will be prompted
"serverName": "server name",
"port": 3306 // if this is missing, it will default to 3306
}
- name: The format of the connection JSON object for PostgreSql connections.
text: >
{
"userName": "user name", // if this is missing or null, you will be prompted
"password": null, // if this is missing or null (highly recommended) you will be prompted
"serverName": "server name",
"databaseName": "database name", // if this is missing, it will default to the 'postgre' server
"port": 5432 // if this is missing, it will default to 5432
}
"""

helps['dms project task cutover'] = """
type: command
short-summary: For a continuous task, complete the migration by performing a cutover.
parameters:
- name: --database-name
type: string
short-summary: >
The name of the database on the source you wish to cutover.
"""
21 changes: 21 additions & 0 deletions src/datamigration/azext_dms/_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from knack.arguments import CLIArgumentType

from azure.cli.core.commands.parameters import tags_type

def load_arguments(self, _):
name_arg_type = CLIArgumentType(options_list=['--name', '-n'], metavar='NAME')

with self.argument_context('dms project') as c:
c.argument('service_name', options_list=['--service-name'], help="The name of the Service.")
c.argument('project_name', name_arg_type, help='The name of the Project.')
c.argument('tags', tags_type, help='A space-delimited list of tags in tag1[=value1]" format.')

with self.argument_context('dms project task') as c:
c.argument('service_name', options_list=['--service-name'], help="The name of the Service.")
c.argument('project_name', options_list=['--project-name'])
c.argument('task_name', name_arg_type, help='The name of the Task.')
28 changes: 28 additions & 0 deletions src/datamigration/azext_dms/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# --------------------------------------------------------------------------------------------
# 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.commands import CliCommandType

from azext_dms._client_factory import (dms_client_factory,
dms_cf_projects,
dms_cf_tasks)

def load_command_table(self, _):
dms_projects_sdk = CliCommandType(
operations_tmpl='azext_dms.mgmt.datamigration.operations.projects_operations#ProjectsOperations.{}',
client_factory=dms_client_factory
)

dms_tasks_sdk = CliCommandType(
operations_tmpl='azext_dms.mgmt.datamigration.operations.tasks_operations#TasksOperations.{}',
client_factory=dms_client_factory
)

with self.command_group('dms project', dms_projects_sdk, client_factory=dms_cf_projects) as g:
g.custom_command('create', 'create_or_update_project')

with self.command_group('dms project task', dms_tasks_sdk, client_factory=dms_cf_tasks) as g:
g.custom_command('create', 'create_task')
g.custom_command('cutover', 'cutover_sync_task')
Loading