From 2da175195511e5098c8098d32ddde98bd6f68ffc Mon Sep 17 00:00:00 2001 From: Rajesh1Ganesan <58494385+Rajesh1Ganesan@users.noreply.github.com> Date: Thu, 20 May 2021 15:12:38 -0700 Subject: [PATCH 01/13] Support for "az postgres flexible-server migration" commands --- .../cli/command_modules/rdbms/_helptext_pg.py | 52 ++++ .../cli/command_modules/rdbms/_params.py | 58 ++++ .../rdbms/flexible_server_commands.py | 10 + .../rdbms/flexible_server_custom_common.py | 102 +++++++ .../rdbms/tests/latest/migrationPublic.json | 30 ++ .../rdbms/tests/latest/migrationVNet.json | 31 +++ .../test_postgres_server_migration.yaml | 260 ++++++++++++++++++ ...ms_flexible_commands_postgres_migration.py | 101 +++++++ 8 files changed, 644 insertions(+) create mode 100644 src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/migrationPublic.json create mode 100644 src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/migrationVNet.json create mode 100644 src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/recordings/test_postgres_server_migration.yaml create mode 100644 src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_flexible_commands_postgres_migration.py diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py b/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py index 9eb16692d88..552d7f9fcbc 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py @@ -170,6 +170,58 @@ text: az postgres flexible-server list --resource-group testGroup """ +helps['postgres flexible-server migration create'] = """ +type: command +short-summary: Create a new migration workflow for a flexible server. +examples: + - name: Start a migration workflow on the target server identified by the parameters. The configurations of the migration should be specified in the migrationConfig.json file. + text: az postgres flexible-server migration create --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --body @"migrationConfig.json" +""" + +helps['postgres flexible-server migration list'] = """ +type: command +short-summary: List the migrations of a flexible server. +examples: + - name: List the currently active migrations of a target flexible server. + text: az postgres flexible-server migration list --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --filter Active" + - name: List all (Active/Completed) migrations of a target flexible server. + text: az postgres flexible-server migration list --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --filter All" +""" + +helps['postgres flexible-server migration show'] = """ +type: command +short-summary: Get the details of a specific migration. +examples: + - name: Get the details of a specific migration of a target flexible server. + text: az postgres flexible-server migration show --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" +""" + +helps['postgres flexible-server migration update'] = """ +type: command +short-summary: Update a specific migration. +examples: + - name: Allow the migration workflow to setup logical replication on the source. Note that this command will restart the source server. + text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --setup-logical-replication" + - name: Specify the list of DBs to migrate. A minimum of 1 and a maximum of 8 DBs can be specified. You can migrate additional DBs concurrently using new migrations. Note that each additional DB affects the performance of the source server. + text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --db1 dbName1 --db2 dbName2 --db3 dbName3" + - name: Allow the migration workflow to overwrite the DB on the target. + text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --overwrite-dbs" + - name: Specify the start time for the data migration to start. This should be within 2 weeks from the current time. + text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --start-time-utc '2021-12-28T17:06:03.4669999-07:00'" + - name: Start the data migration now, rather than wait for the migration window start time. + text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --initiate-data-migration" + - name: Cutover the data migration. After this is complete, subsequent updates to the source DB will not be migrated to the target. + text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --cutover" +""" + +helps['postgres flexible-server migration delete'] = """ +type: command +short-summary: Delete a specific migration. +examples: + - name: Cancel/delete the migration workflow. The migration workflows can be canceled/deleted at any point. + text: az postgres flexible-server migration delete --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" +""" + helps['postgres flexible-server parameter'] = """ type: group short-summary: Commands for managing server parameter values for flexible server. diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/_params.py b/src/azure-cli/azure/cli/command_modules/rdbms/_params.py index 28c1298fc62..b87e77fa346 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/_params.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/_params.py @@ -228,6 +228,14 @@ def _flexible_server_params(command_group): help="Name of the server. The name can contain only lowercase letters, numbers, and the hyphen (-) character. Minimum 3 characters and maximum 63 characters.", local_context_attribute=LocalContextAttribute(name='server_name', actions=[LocalContextAction.SET, LocalContextAction.GET], scopes=['{} flexible-server'.format(command_group)])) + subscription_arg_type = CLIArgumentType(metavar='NAME', + help="ID of subscription. You can configure the default subscription using `az account set -s NAME_OR_ID`", + local_context_attribute=LocalContextAttribute(name='subscription_id', actions=[LocalContextAction.SET, LocalContextAction.GET], scopes=['{} flexible-server'.format(command_group)])) + + migration_id_arg_type = CLIArgumentType(metavar='NAME', + help="ID of the migration.", + local_context_attribute=LocalContextAttribute(name='migration_id', actions=[LocalContextAction.SET, LocalContextAction.GET], scopes=['{} flexible-server'.format(command_group)])) + administrator_login_setter_arg_type = CLIArgumentType(metavar='NAME', local_context_attribute=LocalContextAttribute(name='administrator_login', actions=[LocalContextAction.SET], scopes=['{} flexible-server'.format(command_group)])) @@ -399,6 +407,8 @@ def _flexible_server_params(command_group): else: c.argument('server_name', id_part='name', options_list=['--name', '-n'], arg_type=server_name_arg_type) + handle_migration_parameters(command_group, server_name_arg_type, subscription_arg_type, migration_id_arg_type) + for scope in ['create', 'delete', 'show', 'update']: argument_context_string = '{} flexible-server firewall-rule {}'.format(command_group, scope) with self.argument_context(argument_context_string) as c: @@ -464,5 +474,53 @@ def _flexible_server_params(command_group): with self.argument_context('{} flexible-server replica stop-replication'.format(command_group)) as c: c.argument('server_name', options_list=['--name', '-n'], help='Name of the replica server.') + def handle_migration_parameters(command_group, server_name_arg_type, subscription_arg_type, migration_id_arg_type): + for scope in ['create', 'show', 'list', 'update', 'delete']: + argument_context_string = '{} flexible-server migration {}'.format(command_group, scope) + with self.argument_context(argument_context_string) as c: + c.argument('subscription_id', arg_type=subscription_arg_type, options_list=['--subscription-id'], + help='Subscription ID of the migration target server.') + c.argument('resource_group_name', arg_type=resource_group_name_type, + help='Resource Group Name of the migration target server.') + c.argument('server_name', id_part='name', options_list=['--name', '-n'], arg_type=server_name_arg_type, + help='Migration target server name.') + if scope == "create": + c.argument('body', options_list=['--body', '-b'], + help='Request body. Use @{file} to load from a file. For quoting issues in different terminals, ' + 'see https://github.com/Azure/azure-cli/blob/dev/doc/use_cli_effectively.md#quoting-issues') + c.argument('migration_id', arg_type=migration_id_arg_type, options_list=['--migration-id'], + help='Name or ID of the migration.') + elif scope == "show": + c.argument('migration_id', arg_type=migration_id_arg_type, options_list=['--migration-id'], + help='Name or ID of the migration.') + elif scope == "list": + c.argument('migration_filter', options_list=['--filter'], required=False, + help='Indicates whether all the migrations or just the Active migrations are returned. Active is the default. Valid values are: Active, All.') + elif scope == "update": + c.argument('migration_id', arg_type=migration_id_arg_type, options_list=['--migration-id'], + help='Name or ID of the migration.') + c.argument('setup-logical_replication', options_list=['--setup-logical-replication'], action='store_true', required=False, + help='Allows the migration workflow to setup logical replication on the source. Note that this command will restart the source server.') + c.argument('db1', options_list=['--db1', '--db'], required=False, + help='Specifies the first DB to migrate. A minimum of 1 and a maximum of 8 DBs can be specified using --db1, --db2, --db3... You can migrate additional DBs concurrently using new migrations. Note that each additional DB affects the performance of the source server.') + c.argument('db2', options_list=['--db2'], required=False) + c.argument('db3', options_list=['--db3'], required=False) + c.argument('db4', options_list=['--db4'], required=False) + c.argument('db5', options_list=['--db5'], required=False) + c.argument('db6', options_list=['--db6'], required=False) + c.argument('db7', options_list=['--db7'], required=False) + c.argument('db8', options_list=['--db8'], required=False) + c.argument('overwrite_dbs', options_list=['--overwrite-dbs'], action='store_true', required=False, + help='Allows the migration workflow to overwrite the DB on the target.') + # c.argument('start_time_utc', options_list=['--start-time-utc'], required=False, + # help='Specifies the start time for the data migration to start. This should be within 2 weeks from the current time.') + # c.argument('initiate_data_migration', options_list=['--initiate-data-migration'], action='store_true', required=False, + # help='Starts the data migration now, rather than wait for the migration window start time.') + c.argument('cutover', options_list=['--cutover'], action='store_true', required=False, + help='Cuts over the data migration. After this is complete, subsequent updates to the source DB will not be migrated to the target.') + elif scope == "delete": + c.argument('migration_id', arg_type=migration_id_arg_type, options_list=['--migration-id'], + help='Name or ID of the migration.') + _flexible_server_params('postgres') _flexible_server_params('mysql') diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_commands.py b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_commands.py index e755dac9245..9074c977d4a 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_commands.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_commands.py @@ -128,6 +128,16 @@ def load_flexibleserver_command_table(self, _): custom_func_name='flexible_firewall_rule_update_custom_func', custom_func_type=flexible_server_custom_common) + with self.command_group('postgres flexible-server migration', postgres_flexible_firewall_rule_sdk, + custom_command_type=flexible_servers_custom_postgres, + client_factory=cf_postgres_flexible_firewall_rules, + is_preview=True) as g: + g.custom_command('create', 'migration_create_func', custom_command_type=flexible_server_custom_common) + g.custom_command('show', 'migration_show_func', custom_command_type=flexible_server_custom_common) + g.custom_command('list', 'migration_list_func', custom_command_type=flexible_server_custom_common) + g.custom_command('update', 'migration_update_func', custom_command_type=flexible_server_custom_common) + g.custom_command('delete', 'migration_delete_func', custom_command_type=flexible_server_custom_common) + with self.command_group('postgres flexible-server parameter', postgres_flexible_config_sdk, custom_command_type=flexible_servers_custom_postgres, client_factory=cf_postgres_flexible_config, diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py index 2f3d9b876c7..62271e74049 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py @@ -5,8 +5,12 @@ # pylint: disable=unused-argument, line-too-long +import uuid from knack.log import get_logger from knack.util import CLIError +from azure.cli.core.azclierror import RequiredArgumentMissingError +from azure.cli.core.azclierror import MutuallyExclusiveArgumentError +from azure.cli.core.util import send_raw_request logger = get_logger(__name__) @@ -70,6 +74,104 @@ def firewall_rule_create_func(client, resource_group_name, server_name, firewall parameters) +def migration_create_func(cmd, client, subscription_id, resource_group_name, server_name, body, migration_id=None): + + if migration_id is None: + # Convert a UUID to a string of hex digits in standard form + migration_id = str(uuid.uuid4()) + + r = send_raw_request(cmd.cli_ctx, "put", "https://management.azure.com/subscriptions/{}/resourceGroups/{}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{}/migrations/{}?api-version=2020-02-14-privatepreview".format(subscription_id, resource_group_name, server_name, migration_id), None, None, body) + + return r.json() + + +def migration_show_func(cmd, client, subscription_id, resource_group_name, server_name, migration_id, level="Default"): + + r = send_raw_request(cmd.cli_ctx, "get", "https://management.azure.com/subscriptions/{}/resourceGroups/{}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{}/migrations/{}?level={}&api-version=2020-02-14-privatepreview".format(subscription_id, resource_group_name, server_name, migration_id, level)) + + return r.json() + + +def migration_list_func(cmd, client, subscription_id, resource_group_name, server_name, migration_filter="Active"): + + r = send_raw_request(cmd.cli_ctx, "get", "https://management.azure.com/subscriptions/{}/resourceGroups/{}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{}/migrations?migrationListFilter={}&api-version=2020-02-14-privatepreview".format(subscription_id, resource_group_name, server_name, migration_filter)) + + return r.json() + + +def migration_update_func(cmd, client, subscription_id, resource_group_name, server_name, migration_id, setup_logical_replication=None, db1=None, db2=None, db3=None, db4=None, db5=None, db6=None, db7=None, db8=None, overwrite_dbs=None, start_time_utc=None, initiate_data_migration=None, cutover=None, cancel=None): + + operationSpecified = False + if setup_logical_replication is True: + operationSpecified = True + body = "{\"properties\": {\"setupLogicalReplicationOnSourceDBIfNeeded\": \"true\"} }" + + db_names = None + db_names = db_names_concat_func(db_names, db1) + db_names = db_names_concat_func(db_names, db2) + db_names = db_names_concat_func(db_names, db3) + db_names = db_names_concat_func(db_names, db4) + db_names = db_names_concat_func(db_names, db5) + db_names = db_names_concat_func(db_names, db6) + db_names = db_names_concat_func(db_names, db7) + db_names = db_names_concat_func(db_names, db8) + + if db_names is not None: + if operationSpecified is True: + raise MutuallyExclusiveArgumentError("Incorrect Usage: Can only specify one update operation.") + operationSpecified = True + prefix = "{ \"properties\": { \"dBsToMigrate\": [" + suffix = "] } }" + body = prefix + db_names + suffix + + if overwrite_dbs is True: + if operationSpecified is True: + raise MutuallyExclusiveArgumentError("Incorrect Usage: Can only specify one update operation.") + operationSpecified = True + body = "{\"properties\": {\"overwriteDBsInTarget\": \"true\"} }" + + # if start_time_utc is not None: + # if operationSpecified is True: + # raise MutuallyExclusiveArgumentError("Incorrect Usage: Can only specify one update operation.") + # operationSpecified = True + # body = "{\"properties\": {\"MigrationWindowStartTimeInUtc\": \"{}\"} }".format(start_time_utc) + + # if initiate_data_migration is True: + # if operationSpecified is True: + # raise MutuallyExclusiveArgumentError("Incorrect Usage: Can only specify one update operation.") + # operationSpecified = True + # body = "{\"properties\": {\"startDataMigration\": \"true\"} }" + + if cutover is True: + if operationSpecified is True: + raise MutuallyExclusiveArgumentError("Incorrect Usage: Can only specify one update operation.") + operationSpecified = True + body = "{\"properties\": {\"triggerCutover\": \"true\"} }" + + if operationSpecified is False: + raise RequiredArgumentMissingError("Incorrect Usage: Atleast one update operation needs to be specified.") + + send_raw_request(cmd.cli_ctx, "patch", "https://management.azure.com/subscriptions/{}/resourceGroups/{}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{}/migrations/{}?api-version=2020-02-14-privatepreview".format(subscription_id, resource_group_name, server_name, migration_id), None, None, body) + + return migration_id + + +def migration_delete_func(cmd, client, subscription_id, resource_group_name, server_name, migration_id): + + r = send_raw_request(cmd.cli_ctx, "delete", "https://management.azure.com/subscriptions/{}/resourceGroups/{}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{}/migrations/{}?api-version=2020-02-14-privatepreview".format(subscription_id, resource_group_name, server_name, migration_id)) + + return r.json() + + +def db_names_concat_func(current_db_names, new_db_name): + + if new_db_name is not None: + db = "\"{}\"".format(new_db_name) + current_db_names = db if current_db_names is None else current_db_names + ", " + db + + return current_db_names + + def firewall_rule_delete_func(client, resource_group_name, server_name, firewall_rule_name, yes=None): confirm = yes result = None diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/migrationPublic.json b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/migrationPublic.json new file mode 100644 index 00000000000..3848c875230 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/migrationPublic.json @@ -0,0 +1,30 @@ +{ + "properties": { + "SourceDBServerResourceId": "subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.DBforPostgreSQL/servers/raganesa-s-s-pg-1", + "SecretParameters": + { + "AdminCredentials": + { + "SourceServerPassword": "xxxx", + "TargetServerPassword": "xxxx" + }, + "AADApp": + { + "ClientId": "xxxxxx", + "TenantId": "72f988bf-86f1-41af-91ab-2d7cd011db47", + "AadSecret": "xxxxx" + } + }, + "DBsToMigrate": [ + "dvdrental" + ], + "MigrationResourceGroup": + { + "ResourceId": "subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-DMSBuddy-Demo", + "Location": "West US 2" + }, + "SetupLogicalReplicationOnSourceDBIfNeeded": "true", + "OverwriteDBsinTarget": "true", + "TriggerCutover": "true" + } +} diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/migrationVNet.json b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/migrationVNet.json new file mode 100644 index 00000000000..d427f9b9b3a --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/migrationVNet.json @@ -0,0 +1,31 @@ +{ + "properties": { + "SourceDBServerResourceId": "subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.DBforPostgreSQL/servers/raganesa-s-s-pg-1-vnet-1", + "SecretParameters": + { + "AdminCredentials": + { + "SourceServerPassword": "xxxx", + "TargetServerPassword": "xxxx" + }, + "AADApp": + { + "ClientId": "xxxxxx", + "TenantId": "72f988bf-86f1-41af-91ab-2d7cd011db47", + "AadSecret": "xxxxx" + } + }, + "DBsToMigrate": [ + "dvdrental" + ], + "MigrationResourceGroup": + { + "ResourceId": "subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-DMSBuddy-Demo", + "Location": "West US 2" + }, + "TargetDBServerSubnetResourceId": "subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.Network/virtualNetworks/raganesa-s-s-pg-1-vnet/subnets/raganesa-s-s-pg-1-vnet-s-s-subnet", + "SetupLogicalReplicationOnSourceDBIfNeeded": "true", + "OverwriteDBsInTarget": "true", + "TriggerCutover": "true" + } +} diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/recordings/test_postgres_server_migration.yaml b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/recordings/test_postgres_server_migration.yaml new file mode 100644 index 00000000000..3dcf3736805 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/recordings/test_postgres_server_migration.yaml @@ -0,0 +1,260 @@ +interactions: +- request: + body: "{\r\n \"properties\": {\r\n \"SourceDBServerResourceId\": \"\ + subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.DBforPostgreSQL/servers/raganesa-s-s-pg-1-vnet-1\"\ + ,\r\n \"SecretParameters\":\r\n {\r\n \"AdminCredentials\"\ + :\r\n {\r\n \"SourceServerPassword\": \"xxxx\"\ + ,\r\n \"TargetServerPassword\": \"xxxx\"\r\n \ + \ },\r\n \"AADApp\":\r\n {\r\n \"ClientId\"\ + : \"xxxxxx\",\r\n \"TenantId\"\ + : \"72f988bf-86f1-41af-91ab-2d7cd011db47\",\r\n \"AadSecret\"\ + : \"xxxxx\"\r\n }\r\n },\r\n\ + \ \"DBsToMigrate\": [\r\n \"dvdrental\"\r\n ],\r\n\ + \ \"MigrationResourceGroup\":\r\n {\r\n \"ResourceId\"\ + : \"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-DMSBuddy-Demo\"\ + ,\r\n \"Location\": \"West US 2\"\r\n },\r\n \"TargetDBServerSubnetResourceId\"\ + : \"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.Network/virtualNetworks/raganesa-s-s-pg-1-vnet/subnets/raganesa-s-s-pg-1-vnet-s-s-subnet\"\ + ,\r\n \"SetupLogicalReplicationOnSourceDBIfNeeded\": \"true\",\r\n \ + \ \"OverwriteDBsInTarget\": \"true\",\r\n \"TriggerCutover\": \"\ + true\"\r\n }\r\n}" + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - postgres flexible-server migration create + Connection: + - keep-alive + Content-Length: + - '1360' + Content-Type: + - application/json + ParameterSetName: + - --subscription-id --resource-group --name --migration-id --body + User-Agent: + - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.22.1 + method: PUT + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000?api-version=2020-02-14-privatepreview + response: + body: + string: '{"properties":{"sourceDBServerResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.DBforPostgreSQL/servers/raganesa-s-s-pg-1-vnet-1","targetDBServerSubnetResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.Network/virtualNetworks/raganesa-s-s-pg-1-vnet/subnets/raganesa-s-s-pg-1-vnet-s-s-subnet","dBsToMigrate":["dvdrental"],"migrationResourceGroup":{"resourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-DMSBuddy-Demo","location":"West + US 2"},"setupLogicalReplicationOnSourceDBIfNeeded":true,"overwriteDBsInTarget":true,"triggerCutover":true},"location":"West + US 2","id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000","name":"00000000-0000-0000-0000-000000000000","type":"Microsoft.DBforPostgreSQL/flexibleServers/migrations"}' + headers: + cache-control: + - no-cache + content-length: + - '1054' + content-type: + - application/json; charset=utf-8 + date: + - Thu, 20 May 2021 20:21:00 GMT + expires: + - '-1' + pragma: + - no-cache + server: + - Microsoft-HTTPAPI/2.0 + strict-transport-security: + - max-age=31536000; includeSubDomains + x-content-type-options: + - nosniff + x-ms-ratelimit-remaining-subscription-writes: + - '1199' + status: + code: 201 + message: Created +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - postgres flexible-server migration list + Connection: + - keep-alive + ParameterSetName: + - --subscription-id --resource-group --name --filter + User-Agent: + - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.22.1 + method: GET + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations?migrationListFilter=Active&api-version=2020-02-14-privatepreview + response: + body: + string: '[{"properties":{"migrationId":"00000000-0000-0000-0000-000000000000","migrationDetailsLevel":"Full","currentStatus":{"state":"InProgress","currentSubStateDetails":{"currentSubState":"PerformingPreRequisiteSteps"}}},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000","name":"00000000-0000-0000-0000-000000000000","type":"Microsoft.DBforPostgreSQL/flexibleServers/migrations"}]' + headers: + cache-control: + - no-cache + content-length: + - '539' + content-type: + - application/json; charset=utf-8 + date: + - Thu, 20 May 2021 20:21:01 GMT + expires: + - '-1' + pragma: + - no-cache + server: + - Microsoft-HTTPAPI/2.0 + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding + x-content-type-options: + - nosniff + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - postgres flexible-server migration list + Connection: + - keep-alive + ParameterSetName: + - --subscription-id --resource-group --name + User-Agent: + - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.22.1 + method: GET + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations?migrationListFilter=Active&api-version=2020-02-14-privatepreview + response: + body: + string: '[{"properties":{"migrationId":"00000000-0000-0000-0000-000000000000","migrationDetailsLevel":"Full","currentStatus":{"state":"InProgress","currentSubStateDetails":{"currentSubState":"PerformingPreRequisiteSteps"}}},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000","name":"00000000-0000-0000-0000-000000000000","type":"Microsoft.DBforPostgreSQL/flexibleServers/migrations"}]' + headers: + cache-control: + - no-cache + content-length: + - '539' + content-type: + - application/json; charset=utf-8 + date: + - Thu, 20 May 2021 20:21:01 GMT + expires: + - '-1' + pragma: + - no-cache + server: + - Microsoft-HTTPAPI/2.0 + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding + x-content-type-options: + - nosniff + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - postgres flexible-server migration show + Connection: + - keep-alive + ParameterSetName: + - --subscription-id --resource-group --name --migration-id + User-Agent: + - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.22.1 + method: GET + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000?level=Default&api-version=2020-02-14-privatepreview + response: + body: + string: '{"properties":{"migrationId":"00000000-0000-0000-0000-000000000000","migrationDetailsLevel":"Default","currentStatus":{"state":"InProgress","currentSubStateDetails":{"currentSubState":"PerformingPreRequisiteSteps"}},"sourceDBServerMetadata":{"location":"westus2","version":"10","storageMB":102400,"sku":{"name":"GP_Gen5_4","tier":"GeneralPurpose"}},"targetDBServerMetadata":{"location":"West + US 2","version":"12","storageMB":32768,"sku":{"name":"Standard_B1ms","tier":"Burstable"}},"migrationCreateFullRequest":{"sourceDBServerResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.DBforPostgreSQL/servers/raganesa-s-s-pg-1-vnet-1","targetDBServerResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet","targetDBServerSubnetResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.Network/virtualNetworks/raganesa-s-s-pg-1-vnet/subnets/raganesa-s-s-pg-1-vnet-s-s-subnet","dBsToMigrate":["dvdrental"],"migrationResourceGroup":{"resourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-DMSBuddy-Demo","location":"West + US 2"},"setupLogicalReplicationOnSourceDBIfNeeded":true,"overwriteDBsInTarget":true,"migrationWindowStartTimeInUtc":"2021-05-20T20:21:01.4138988Z","triggerCutover":true}},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000","name":"00000000-0000-0000-0000-000000000000","type":"Microsoft.DBforPostgreSQL/flexibleServers/migrations"}' + headers: + cache-control: + - no-cache + content-length: + - '1780' + content-type: + - application/json; charset=utf-8 + date: + - Thu, 20 May 2021 20:21:01 GMT + expires: + - '-1' + pragma: + - no-cache + server: + - Microsoft-HTTPAPI/2.0 + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding + x-content-type-options: + - nosniff + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - postgres flexible-server migration delete + Connection: + - keep-alive + Content-Length: + - '0' + ParameterSetName: + - --subscription-id --resource-group --name --migration-id + User-Agent: + - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.22.1 + method: DELETE + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000?api-version=2020-02-14-privatepreview + response: + body: + string: '{"properties":{"sourceDBServerResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.DBforPostgreSQL/servers/raganesa-s-s-pg-1-vnet-1","targetDBServerSubnetResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.Network/virtualNetworks/raganesa-s-s-pg-1-vnet/subnets/raganesa-s-s-pg-1-vnet-s-s-subnet","dBsToMigrate":["dvdrental"],"migrationResourceGroup":{"resourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-DMSBuddy-Demo","location":"West + US 2"},"setupLogicalReplicationOnSourceDBIfNeeded":true,"overwriteDBsInTarget":true,"migrationWindowStartTimeInUtc":"2021-05-20T20:21:01.4138988Z","triggerCutover":true},"location":"West + US 2","id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000","name":"00000000-0000-0000-0000-000000000000","type":"Microsoft.DBforPostgreSQL/flexibleServers/migrations"}' + headers: + cache-control: + - no-cache + content-length: + - '1117' + content-type: + - application/json; charset=utf-8 + date: + - Thu, 20 May 2021 20:21:02 GMT + expires: + - '-1' + pragma: + - no-cache + server: + - Microsoft-HTTPAPI/2.0 + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding + x-content-type-options: + - nosniff + x-ms-ratelimit-remaining-subscription-deletes: + - '14999' + status: + code: 200 + message: OK +version: 1 diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_flexible_commands_postgres_migration.py b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_flexible_commands_postgres_migration.py new file mode 100644 index 00000000000..efe19dba770 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_flexible_commands_postgres_migration.py @@ -0,0 +1,101 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- +import time +import getopt +import uuid +import sys +from knack.log import get_logger + +from datetime import datetime +from time import sleep +from dateutil.tz import tzutc # pylint: disable=import-error +from azure_devtools.scenario_tests import AllowLargeResponse +from msrestazure.azure_exceptions import CloudError +from azure.cli.core.util import CLIError +from azure.cli.core.util import parse_proxy_resource_id +from azure.cli.testsdk.base import execute +from azure.cli.testsdk.exceptions import CliTestError # pylint: disable=unused-import +from azure.cli.testsdk import ( + JMESPathCheck, + NoneCheck, + ResourceGroupPreparer, + ScenarioTest, + StringContainCheck, + live_only) +from azure.cli.testsdk.preparers import ( + AbstractPreparer, + SingleValueReplacer) + +logger = get_logger(__name__) + + +class MigrationScenarioTest(ScenarioTest): + + @AllowLargeResponse() + def test_postgres_server_migration(self): + self._test_server_migration('postgres') + + def _test_server_migration(self, database_engine): + # Set this to True or False depending on whether we are in live mode or test mode + # livemode = True + livemode = False + + if livemode: + # Live mode values + target_subscription_id = "6a37df99-a9de-48c4-91e5-7e6ab00b2362" + migration_id = str(uuid.uuid4()) + else: + # Mock test mode values + target_subscription_id = "00000000-0000-0000-0000-000000000000" + migration_id = "00000000-0000-0000-0000-000000000000" + + target_resource_group_name = "raganesa-t-m-pg-1" + target_server_name = "raganesa-t-m-pg-1-vnet" + + # # test create migration - error - no param + # result = self.cmd('{} flexible-server migration create' + # .format(database_engine), expect_failure=True) + + # # test create migration - error - no sub + # result = self.cmd('{} flexible-server migration create --resource-group {} --name {} --body @migrationPublic.json' + # .format(database_engine, target_resource_group_name, target_server_name), expect_failure=True) + + # # test create migration - error - no resource-group + # result = self.cmd('{} flexible-server migration create --subscription-id {} --name {} --body @migrationPublic.json' + # .format(database_engine, target_subscription_id, target_server_name), expect_failure=True) + + # # test create migration - error - no server name + # result = self.cmd('{} flexible-server migration create --subscription-id {} --resource-group {} --body @migrationPublic.json' + # .format(database_engine, target_subscription_id, target_resource_group_name), expect_failure=True) + + # # test create migration - error - no body + # result = self.cmd('{} flexible-server migration create --subscription-id {} --resource-group {} --name {}' + # .format(database_engine, target_subscription_id, target_resource_group_name, target_server_name), expect_failure=True) + + # test create migration - success + result = self.cmd('{} flexible-server migration create --subscription-id {} --resource-group {} --name {} --migration-id {} --body @migrationVNet.json' + .format(database_engine, target_subscription_id, target_resource_group_name, target_server_name, migration_id)).get_output_in_json() + + migration_id = result['name'] + + # test list migrations - success, with filter + result = self.cmd('{} flexible-server migration list --subscription-id {} --resource-group {} --name {} --filter Active' + .format(database_engine, target_subscription_id, target_resource_group_name, target_server_name)).get_output_in_json() + + # test list migrations - success, without filter + result = self.cmd('{} flexible-server migration list --subscription-id {} --resource-group {} --name {}' + .format(database_engine, target_subscription_id, target_resource_group_name, target_server_name)).get_output_in_json() + + # test show migration - success + result = self.cmd('{} flexible-server migration show --subscription-id {} --resource-group {} --name {} --migration-id {}' + .format(database_engine, target_subscription_id, target_resource_group_name, target_server_name, migration_id)).get_output_in_json() + + # test update migration - error - no param + result = self.cmd('{} flexible-server migration update --subscription-id {} --resource-group {} --name {} --migration-id {}' + .format(database_engine, target_subscription_id, target_resource_group_name, target_server_name, migration_id), expect_failure=True) + + # test delete migration - success + result = self.cmd('{} flexible-server migration delete --subscription-id {} --resource-group {} --name {} --migration-id {}' + .format(database_engine, target_subscription_id, target_resource_group_name, target_server_name, migration_id)).get_output_in_json() From 67a98b95033cfce30e69f0000e65b2027e71936d Mon Sep 17 00:00:00 2001 From: Rajesh1Ganesan <58494385+Rajesh1Ganesan@users.noreply.github.com> Date: Thu, 20 May 2021 20:36:34 -0700 Subject: [PATCH 02/13] Fix a linter error caused by copy-paste. --- .../cli/command_modules/rdbms/_helptext_pg.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py b/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py index 69f4dbbdba2..cb9cab5a23e 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py @@ -189,9 +189,9 @@ short-summary: List the migrations of a flexible server. examples: - name: List the currently active migrations of a target flexible server. - text: az postgres flexible-server migration list --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --filter Active" + text: az postgres flexible-server migration list --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --filter Active - name: List all (Active/Completed) migrations of a target flexible server. - text: az postgres flexible-server migration list --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --filter All" + text: az postgres flexible-server migration list --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --filter All """ helps['postgres flexible-server migration show'] = """ @@ -199,7 +199,7 @@ short-summary: Get the details of a specific migration. examples: - name: Get the details of a specific migration of a target flexible server. - text: az postgres flexible-server migration show --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + text: az postgres flexible-server migration show --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx """ helps['postgres flexible-server migration update'] = """ @@ -207,17 +207,17 @@ short-summary: Update a specific migration. examples: - name: Allow the migration workflow to setup logical replication on the source. Note that this command will restart the source server. - text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --setup-logical-replication" + text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --setup-logical-replication - name: Specify the list of DBs to migrate. A minimum of 1 and a maximum of 8 DBs can be specified. You can migrate additional DBs concurrently using new migrations. Note that each additional DB affects the performance of the source server. - text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --db1 dbName1 --db2 dbName2 --db3 dbName3" + text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --db1 dbName1 --db2 dbName2 --db3 dbName3 - name: Allow the migration workflow to overwrite the DB on the target. - text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --overwrite-dbs" + text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --overwrite-dbs - name: Specify the start time for the data migration to start. This should be within 2 weeks from the current time. - text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --start-time-utc '2021-12-28T17:06:03.4669999-07:00'" + text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --start-time-utc '2021-12-28T17:06:03.4669999-07:00' - name: Start the data migration now, rather than wait for the migration window start time. - text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --initiate-data-migration" + text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --initiate-data-migration - name: Cutover the data migration. After this is complete, subsequent updates to the source DB will not be migrated to the target. - text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --cutover" + text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --cutover """ helps['postgres flexible-server migration delete'] = """ @@ -225,7 +225,7 @@ short-summary: Delete a specific migration. examples: - name: Cancel/delete the migration workflow. The migration workflows can be canceled/deleted at any point. - text: az postgres flexible-server migration delete --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + text: az postgres flexible-server migration delete --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx """ helps['postgres flexible-server parameter'] = """ From eed3e86f5ad25e746e2fbee622c68f702e6e078f Mon Sep 17 00:00:00 2001 From: Rajesh1Ganesan <58494385+Rajesh1Ganesan@users.noreply.github.com> Date: Thu, 20 May 2021 21:14:32 -0700 Subject: [PATCH 03/13] Fix more linter errors --- .../cli/command_modules/rdbms/_helptext_pg.py | 16 +++++++---- .../cli/command_modules/rdbms/_params.py | 27 ++++++++++++------- .../rdbms/flexible_server_custom_common.py | 2 +- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py b/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py index cb9cab5a23e..332d4cff0e5 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py @@ -176,6 +176,11 @@ text: az postgres flexible-server list --resource-group testGroup """ +helps['postgres flexible-server migration'] = """ +type: group +short-summary: Manage migration workflows for PostgreSQL Flexible Servers. +""" + helps['postgres flexible-server migration create'] = """ type: command short-summary: Create a new migration workflow for a flexible server. @@ -207,19 +212,20 @@ short-summary: Update a specific migration. examples: - name: Allow the migration workflow to setup logical replication on the source. Note that this command will restart the source server. - text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --setup-logical-replication + text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --setup-replication - name: Specify the list of DBs to migrate. A minimum of 1 and a maximum of 8 DBs can be specified. You can migrate additional DBs concurrently using new migrations. Note that each additional DB affects the performance of the source server. text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --db1 dbName1 --db2 dbName2 --db3 dbName3 - name: Allow the migration workflow to overwrite the DB on the target. text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --overwrite-dbs - - name: Specify the start time for the data migration to start. This should be within 2 weeks from the current time. - text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --start-time-utc '2021-12-28T17:06:03.4669999-07:00' - - name: Start the data migration now, rather than wait for the migration window start time. - text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --initiate-data-migration - name: Cutover the data migration. After this is complete, subsequent updates to the source DB will not be migrated to the target. text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --cutover """ +# - name: Specify the start time for the data migration to start. This should be within 2 weeks from the current time. +# text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --start-time-utc '2021-12-28T17:06:03.4669999-07:00' +# - name: Start the data migration now, rather than wait for the migration window start time. +# text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --init-data-migration + helps['postgres flexible-server migration delete'] = """ type: command short-summary: Delete a specific migration. diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/_params.py b/src/azure-cli/azure/cli/command_modules/rdbms/_params.py index 33d4e080bd4..e57ee37c600 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/_params.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/_params.py @@ -494,28 +494,37 @@ def handle_migration_parameters(command_group, server_name_arg_type, subscriptio elif scope == "show": c.argument('migration_id', arg_type=migration_id_arg_type, options_list=['--migration-id'], help='Name or ID of the migration.') + c.argument('level', options_list=['--level'], required=False, + help='Specifies the level of migration details requested. Valid values are Active and All. Active is the default.') elif scope == "list": c.argument('migration_filter', options_list=['--filter'], required=False, help='Indicates whether all the migrations or just the Active migrations are returned. Active is the default. Valid values are: Active, All.') elif scope == "update": c.argument('migration_id', arg_type=migration_id_arg_type, options_list=['--migration-id'], help='Name or ID of the migration.') - c.argument('setup-logical_replication', options_list=['--setup-logical-replication'], action='store_true', required=False, + c.argument('setup_logical_replication', options_list=['--setup-replication'], action='store_true', required=False, help='Allows the migration workflow to setup logical replication on the source. Note that this command will restart the source server.') c.argument('db1', options_list=['--db1', '--db'], required=False, help='Specifies the first DB to migrate. A minimum of 1 and a maximum of 8 DBs can be specified using --db1, --db2, --db3... You can migrate additional DBs concurrently using new migrations. Note that each additional DB affects the performance of the source server.') - c.argument('db2', options_list=['--db2'], required=False) - c.argument('db3', options_list=['--db3'], required=False) - c.argument('db4', options_list=['--db4'], required=False) - c.argument('db5', options_list=['--db5'], required=False) - c.argument('db6', options_list=['--db6'], required=False) - c.argument('db7', options_list=['--db7'], required=False) - c.argument('db8', options_list=['--db8'], required=False) + c.argument('db2', options_list=['--db2'], required=False, + help='Specifies the second DB to migrate.') + c.argument('db3', options_list=['--db3'], required=False, + help='Specifies the third DB to migrate.') + c.argument('db4', options_list=['--db4'], required=False, + help='Specifies the fourth DB to migrate.') + c.argument('db5', options_list=['--db5'], required=False, + help='Specifies the fifth DB to migrate.') + c.argument('db6', options_list=['--db6'], required=False, + help='Specifies the sixth DB to migrate.') + c.argument('db7', options_list=['--db7'], required=False, + help='Specifies the seventh DB to migrate.') + c.argument('db8', options_list=['--db8'], required=False, + help='Specifies the eigth DB to migrate.') c.argument('overwrite_dbs', options_list=['--overwrite-dbs'], action='store_true', required=False, help='Allows the migration workflow to overwrite the DB on the target.') # c.argument('start_time_utc', options_list=['--start-time-utc'], required=False, # help='Specifies the start time for the data migration to start. This should be within 2 weeks from the current time.') - # c.argument('initiate_data_migration', options_list=['--initiate-data-migration'], action='store_true', required=False, + # c.argument('initiate_data_migration', options_list=['--init-data-migration'], action='store_true', required=False, # help='Starts the data migration now, rather than wait for the migration window start time.') c.argument('cutover', options_list=['--cutover'], action='store_true', required=False, help='Cuts over the data migration. After this is complete, subsequent updates to the source DB will not be migrated to the target.') diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py index 707b1734bfa..70cce3f3536 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py @@ -101,7 +101,7 @@ def migration_list_func(cmd, client, subscription_id, resource_group_name, serve return r.json() -def migration_update_func(cmd, client, subscription_id, resource_group_name, server_name, migration_id, setup_logical_replication=None, db1=None, db2=None, db3=None, db4=None, db5=None, db6=None, db7=None, db8=None, overwrite_dbs=None, start_time_utc=None, initiate_data_migration=None, cutover=None, cancel=None): +def migration_update_func(cmd, client, subscription_id, resource_group_name, server_name, migration_id, setup_logical_replication=None, db1=None, db2=None, db3=None, db4=None, db5=None, db6=None, db7=None, db8=None, overwrite_dbs=None, cutover=None): operationSpecified = False if setup_logical_replication is True: From c641916da309337d951d6968523085eeb3cf3078 Mon Sep 17 00:00:00 2001 From: Rajesh1Ganesan <58494385+Rajesh1Ganesan@users.noreply.github.com> Date: Fri, 21 May 2021 10:22:22 -0700 Subject: [PATCH 04/13] Use custom_show_command instead of custom_command for 'show' to fix a linter finding. --- .../azure/cli/command_modules/rdbms/flexible_server_commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_commands.py b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_commands.py index 9074c977d4a..67916ecaa98 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_commands.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_commands.py @@ -133,7 +133,7 @@ def load_flexibleserver_command_table(self, _): client_factory=cf_postgres_flexible_firewall_rules, is_preview=True) as g: g.custom_command('create', 'migration_create_func', custom_command_type=flexible_server_custom_common) - g.custom_command('show', 'migration_show_func', custom_command_type=flexible_server_custom_common) + g.custom_show_command('show', 'migration_show_func', custom_command_type=flexible_server_custom_common) g.custom_command('list', 'migration_list_func', custom_command_type=flexible_server_custom_common) g.custom_command('update', 'migration_update_func', custom_command_type=flexible_server_custom_common) g.custom_command('delete', 'migration_delete_func', custom_command_type=flexible_server_custom_common) From 4d614e47ca3df59d8fadfefc14d7dc3a27ab4575 Mon Sep 17 00:00:00 2001 From: Rajesh1Ganesan <58494385+Rajesh1Ganesan@users.noreply.github.com> Date: Mon, 24 May 2021 09:20:36 -0700 Subject: [PATCH 05/13] 1. Remove the --subscription-id parameter. Use the CLI command param --subscription instead --- .../cli/command_modules/rdbms/_params.py | 40 ++++++++----------- .../rdbms/flexible_server_custom_common.py | 21 +++++++--- .../test_postgres_server_migration.yaml | 39 +++++++++--------- ...ms_flexible_commands_postgres_migration.py | 18 ++++----- 4 files changed, 61 insertions(+), 57 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/_params.py b/src/azure-cli/azure/cli/command_modules/rdbms/_params.py index e57ee37c600..4a84414eda5 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/_params.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/_params.py @@ -228,10 +228,6 @@ def _flexible_server_params(command_group): help="Name of the server. The name can contain only lowercase letters, numbers, and the hyphen (-) character. Minimum 3 characters and maximum 63 characters.", local_context_attribute=LocalContextAttribute(name='server_name', actions=[LocalContextAction.SET, LocalContextAction.GET], scopes=['{} flexible-server'.format(command_group)])) - subscription_arg_type = CLIArgumentType(metavar='NAME', - help="ID of subscription. You can configure the default subscription using `az account set -s NAME_OR_ID`", - local_context_attribute=LocalContextAttribute(name='subscription_id', actions=[LocalContextAction.SET, LocalContextAction.GET], scopes=['{} flexible-server'.format(command_group)])) - migration_id_arg_type = CLIArgumentType(metavar='NAME', help="ID of the migration.", local_context_attribute=LocalContextAttribute(name='migration_id', actions=[LocalContextAction.SET, LocalContextAction.GET], scopes=['{} flexible-server'.format(command_group)])) @@ -408,7 +404,7 @@ def _flexible_server_params(command_group): else: c.argument('server_name', id_part='name', options_list=['--name', '-n'], arg_type=server_name_arg_type) - handle_migration_parameters(command_group, server_name_arg_type, subscription_arg_type, migration_id_arg_type) + handle_migration_parameters(command_group, server_name_arg_type, migration_id_arg_type) for scope in ['create', 'delete', 'show', 'update']: argument_context_string = '{} flexible-server firewall-rule {}'.format(command_group, scope) @@ -475,12 +471,10 @@ def _flexible_server_params(command_group): with self.argument_context('{} flexible-server replica stop-replication'.format(command_group)) as c: c.argument('server_name', options_list=['--name', '-n'], help='Name of the replica server.') - def handle_migration_parameters(command_group, server_name_arg_type, subscription_arg_type, migration_id_arg_type): + def handle_migration_parameters(command_group, server_name_arg_type, migration_id_arg_type): for scope in ['create', 'show', 'list', 'update', 'delete']: argument_context_string = '{} flexible-server migration {}'.format(command_group, scope) with self.argument_context(argument_context_string) as c: - c.argument('subscription_id', arg_type=subscription_arg_type, options_list=['--subscription-id'], - help='Subscription ID of the migration target server.') c.argument('resource_group_name', arg_type=resource_group_name_type, help='Resource Group Name of the migration target server.') c.argument('server_name', id_part='name', options_list=['--name', '-n'], arg_type=server_name_arg_type, @@ -495,39 +489,39 @@ def handle_migration_parameters(command_group, server_name_arg_type, subscriptio c.argument('migration_id', arg_type=migration_id_arg_type, options_list=['--migration-id'], help='Name or ID of the migration.') c.argument('level', options_list=['--level'], required=False, - help='Specifies the level of migration details requested. Valid values are Active and All. Active is the default.') + help='Specify the level of migration details requested. Valid values are Active and All. Active is the default.') elif scope == "list": c.argument('migration_filter', options_list=['--filter'], required=False, - help='Indicates whether all the migrations or just the Active migrations are returned. Active is the default. Valid values are: Active, All.') + help='Indicate whether all the migrations or just the Active migrations are returned. Active is the default. Valid values are: Active, All.') elif scope == "update": c.argument('migration_id', arg_type=migration_id_arg_type, options_list=['--migration-id'], help='Name or ID of the migration.') c.argument('setup_logical_replication', options_list=['--setup-replication'], action='store_true', required=False, - help='Allows the migration workflow to setup logical replication on the source. Note that this command will restart the source server.') + help='Allow the migration workflow to setup logical replication on the source. Note that this command will restart the source server.') c.argument('db1', options_list=['--db1', '--db'], required=False, - help='Specifies the first DB to migrate. A minimum of 1 and a maximum of 8 DBs can be specified using --db1, --db2, --db3... You can migrate additional DBs concurrently using new migrations. Note that each additional DB affects the performance of the source server.') + help='Specify the first DB to migrate. A minimum of 1 and a maximum of 8 DBs can be specified using --db1, --db2, --db3... You can migrate additional DBs concurrently using new migrations. Note that each additional DB affects the performance of the source server.') c.argument('db2', options_list=['--db2'], required=False, - help='Specifies the second DB to migrate.') + help='Specify the second DB to migrate.') c.argument('db3', options_list=['--db3'], required=False, - help='Specifies the third DB to migrate.') + help='Specify the third DB to migrate.') c.argument('db4', options_list=['--db4'], required=False, - help='Specifies the fourth DB to migrate.') + help='Specify the fourth DB to migrate.') c.argument('db5', options_list=['--db5'], required=False, - help='Specifies the fifth DB to migrate.') + help='Specify the fifth DB to migrate.') c.argument('db6', options_list=['--db6'], required=False, - help='Specifies the sixth DB to migrate.') + help='Specify the sixth DB to migrate.') c.argument('db7', options_list=['--db7'], required=False, - help='Specifies the seventh DB to migrate.') + help='Specify the seventh DB to migrate.') c.argument('db8', options_list=['--db8'], required=False, - help='Specifies the eigth DB to migrate.') + help='Specify the eigth DB to migrate.') c.argument('overwrite_dbs', options_list=['--overwrite-dbs'], action='store_true', required=False, - help='Allows the migration workflow to overwrite the DB on the target.') + help='Allow the migration workflow to overwrite the DB on the target.') # c.argument('start_time_utc', options_list=['--start-time-utc'], required=False, - # help='Specifies the start time for the data migration to start. This should be within 2 weeks from the current time.') + # help='Specify the start time for the data migration to start. This should be within 2 weeks from the current time.') # c.argument('initiate_data_migration', options_list=['--init-data-migration'], action='store_true', required=False, - # help='Starts the data migration now, rather than wait for the migration window start time.') + # help='Start the data migration now, rather than wait for the migration window start time.') c.argument('cutover', options_list=['--cutover'], action='store_true', required=False, - help='Cuts over the data migration. After this is complete, subsequent updates to the source DB will not be migrated to the target.') + help='Cut-over the data migration. After this is complete, subsequent updates to the source DB will not be migrated to the target.') elif scope == "delete": c.argument('migration_id', arg_type=migration_id_arg_type, options_list=['--migration-id'], help='Name or ID of the migration.') diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py index 70cce3f3536..524562ae64d 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py @@ -11,6 +11,7 @@ from knack.util import CLIError from azure.cli.core.azclierror import RequiredArgumentMissingError from azure.cli.core.azclierror import MutuallyExclusiveArgumentError +from azure.cli.core.commands.client_factory import get_subscription_id from azure.cli.core.util import send_raw_request from azure.cli.core.util import user_confirmation @@ -76,7 +77,9 @@ def firewall_rule_create_func(client, resource_group_name, server_name, firewall parameters) -def migration_create_func(cmd, client, subscription_id, resource_group_name, server_name, body, migration_id=None): +def migration_create_func(cmd, client, resource_group_name, server_name, body, migration_id=None): + + subscription_id=get_subscription_id(cmd.cli_ctx) if migration_id is None: # Convert a UUID to a string of hex digits in standard form @@ -87,21 +90,27 @@ def migration_create_func(cmd, client, subscription_id, resource_group_name, ser return r.json() -def migration_show_func(cmd, client, subscription_id, resource_group_name, server_name, migration_id, level="Default"): +def migration_show_func(cmd, client, resource_group_name, server_name, migration_id, level="Default"): + + subscription_id=get_subscription_id(cmd.cli_ctx) r = send_raw_request(cmd.cli_ctx, "get", "https://management.azure.com/subscriptions/{}/resourceGroups/{}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{}/migrations/{}?level={}&api-version=2020-02-14-privatepreview".format(subscription_id, resource_group_name, server_name, migration_id, level)) return r.json() -def migration_list_func(cmd, client, subscription_id, resource_group_name, server_name, migration_filter="Active"): +def migration_list_func(cmd, client, resource_group_name, server_name, migration_filter="Active"): + + subscription_id=get_subscription_id(cmd.cli_ctx) r = send_raw_request(cmd.cli_ctx, "get", "https://management.azure.com/subscriptions/{}/resourceGroups/{}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{}/migrations?migrationListFilter={}&api-version=2020-02-14-privatepreview".format(subscription_id, resource_group_name, server_name, migration_filter)) return r.json() -def migration_update_func(cmd, client, subscription_id, resource_group_name, server_name, migration_id, setup_logical_replication=None, db1=None, db2=None, db3=None, db4=None, db5=None, db6=None, db7=None, db8=None, overwrite_dbs=None, cutover=None): +def migration_update_func(cmd, client, resource_group_name, server_name, migration_id, setup_logical_replication=None, db1=None, db2=None, db3=None, db4=None, db5=None, db6=None, db7=None, db8=None, overwrite_dbs=None, cutover=None): + + subscription_id=get_subscription_id(cmd.cli_ctx) operationSpecified = False if setup_logical_replication is True: @@ -158,7 +167,9 @@ def migration_update_func(cmd, client, subscription_id, resource_group_name, ser return migration_id -def migration_delete_func(cmd, client, subscription_id, resource_group_name, server_name, migration_id): +def migration_delete_func(cmd, client, resource_group_name, server_name, migration_id): + + subscription_id=get_subscription_id(cmd.cli_ctx) r = send_raw_request(cmd.cli_ctx, "delete", "https://management.azure.com/subscriptions/{}/resourceGroups/{}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{}/migrations/{}?api-version=2020-02-14-privatepreview".format(subscription_id, resource_group_name, server_name, migration_id)) diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/recordings/test_postgres_server_migration.yaml b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/recordings/test_postgres_server_migration.yaml index 3dcf3736805..785d1bf75aa 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/recordings/test_postgres_server_migration.yaml +++ b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/recordings/test_postgres_server_migration.yaml @@ -31,9 +31,9 @@ interactions: Content-Type: - application/json ParameterSetName: - - --subscription-id --resource-group --name --migration-id --body + - --subscription --resource-group --name --migration-id --body User-Agent: - - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.22.1 + - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.23.0 method: PUT uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000?api-version=2020-02-14-privatepreview response: @@ -49,7 +49,7 @@ interactions: content-type: - application/json; charset=utf-8 date: - - Thu, 20 May 2021 20:21:00 GMT + - Mon, 24 May 2021 16:11:06 GMT expires: - '-1' pragma: @@ -77,9 +77,9 @@ interactions: Connection: - keep-alive ParameterSetName: - - --subscription-id --resource-group --name --filter + - --subscription --resource-group --name --filter User-Agent: - - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.22.1 + - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.23.0 method: GET uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations?migrationListFilter=Active&api-version=2020-02-14-privatepreview response: @@ -93,7 +93,7 @@ interactions: content-type: - application/json; charset=utf-8 date: - - Thu, 20 May 2021 20:21:01 GMT + - Mon, 24 May 2021 16:11:06 GMT expires: - '-1' pragma: @@ -123,9 +123,9 @@ interactions: Connection: - keep-alive ParameterSetName: - - --subscription-id --resource-group --name + - --subscription --resource-group --name User-Agent: - - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.22.1 + - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.23.0 method: GET uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations?migrationListFilter=Active&api-version=2020-02-14-privatepreview response: @@ -139,7 +139,7 @@ interactions: content-type: - application/json; charset=utf-8 date: - - Thu, 20 May 2021 20:21:01 GMT + - Mon, 24 May 2021 16:11:06 GMT expires: - '-1' pragma: @@ -169,25 +169,24 @@ interactions: Connection: - keep-alive ParameterSetName: - - --subscription-id --resource-group --name --migration-id + - --subscription --resource-group --name --migration-id User-Agent: - - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.22.1 + - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.23.0 method: GET uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000?level=Default&api-version=2020-02-14-privatepreview response: body: - string: '{"properties":{"migrationId":"00000000-0000-0000-0000-000000000000","migrationDetailsLevel":"Default","currentStatus":{"state":"InProgress","currentSubStateDetails":{"currentSubState":"PerformingPreRequisiteSteps"}},"sourceDBServerMetadata":{"location":"westus2","version":"10","storageMB":102400,"sku":{"name":"GP_Gen5_4","tier":"GeneralPurpose"}},"targetDBServerMetadata":{"location":"West - US 2","version":"12","storageMB":32768,"sku":{"name":"Standard_B1ms","tier":"Burstable"}},"migrationCreateFullRequest":{"sourceDBServerResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.DBforPostgreSQL/servers/raganesa-s-s-pg-1-vnet-1","targetDBServerResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet","targetDBServerSubnetResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.Network/virtualNetworks/raganesa-s-s-pg-1-vnet/subnets/raganesa-s-s-pg-1-vnet-s-s-subnet","dBsToMigrate":["dvdrental"],"migrationResourceGroup":{"resourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-DMSBuddy-Demo","location":"West - US 2"},"setupLogicalReplicationOnSourceDBIfNeeded":true,"overwriteDBsInTarget":true,"migrationWindowStartTimeInUtc":"2021-05-20T20:21:01.4138988Z","triggerCutover":true}},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000","name":"00000000-0000-0000-0000-000000000000","type":"Microsoft.DBforPostgreSQL/flexibleServers/migrations"}' + string: '{"properties":{"migrationId":"00000000-0000-0000-0000-000000000000","migrationDetailsLevel":"Default","currentStatus":{"state":"InProgress","currentSubStateDetails":{"currentSubState":"PerformingPreRequisiteSteps"}},"migrationCreateFullRequest":{"sourceDBServerResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.DBforPostgreSQL/servers/raganesa-s-s-pg-1-vnet-1","targetDBServerResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet","targetDBServerSubnetResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.Network/virtualNetworks/raganesa-s-s-pg-1-vnet/subnets/raganesa-s-s-pg-1-vnet-s-s-subnet","dBsToMigrate":["dvdrental"],"migrationResourceGroup":{"resourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-DMSBuddy-Demo","location":"West + US 2"},"setupLogicalReplicationOnSourceDBIfNeeded":true,"overwriteDBsInTarget":true,"migrationWindowStartTimeInUtc":"2021-05-24T16:11:06.4576202Z","triggerCutover":true}},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000","name":"00000000-0000-0000-0000-000000000000","type":"Microsoft.DBforPostgreSQL/flexibleServers/migrations"}' headers: cache-control: - no-cache content-length: - - '1780' + - '1514' content-type: - application/json; charset=utf-8 date: - - Thu, 20 May 2021 20:21:01 GMT + - Mon, 24 May 2021 16:11:07 GMT expires: - '-1' pragma: @@ -219,15 +218,15 @@ interactions: Content-Length: - '0' ParameterSetName: - - --subscription-id --resource-group --name --migration-id + - --subscription --resource-group --name --migration-id User-Agent: - - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.22.1 + - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.23.0 method: DELETE uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000?api-version=2020-02-14-privatepreview response: body: string: '{"properties":{"sourceDBServerResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.DBforPostgreSQL/servers/raganesa-s-s-pg-1-vnet-1","targetDBServerSubnetResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.Network/virtualNetworks/raganesa-s-s-pg-1-vnet/subnets/raganesa-s-s-pg-1-vnet-s-s-subnet","dBsToMigrate":["dvdrental"],"migrationResourceGroup":{"resourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-DMSBuddy-Demo","location":"West - US 2"},"setupLogicalReplicationOnSourceDBIfNeeded":true,"overwriteDBsInTarget":true,"migrationWindowStartTimeInUtc":"2021-05-20T20:21:01.4138988Z","triggerCutover":true},"location":"West + US 2"},"setupLogicalReplicationOnSourceDBIfNeeded":true,"overwriteDBsInTarget":true,"migrationWindowStartTimeInUtc":"2021-05-24T16:11:06.4576202Z","triggerCutover":true},"location":"West US 2","id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000","name":"00000000-0000-0000-0000-000000000000","type":"Microsoft.DBforPostgreSQL/flexibleServers/migrations"}' headers: cache-control: @@ -237,7 +236,7 @@ interactions: content-type: - application/json; charset=utf-8 date: - - Thu, 20 May 2021 20:21:02 GMT + - Mon, 24 May 2021 16:11:07 GMT expires: - '-1' pragma: diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_flexible_commands_postgres_migration.py b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_flexible_commands_postgres_migration.py index efe19dba770..2b8039796f4 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_flexible_commands_postgres_migration.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_flexible_commands_postgres_migration.py @@ -63,39 +63,39 @@ def _test_server_migration(self, database_engine): # .format(database_engine, target_resource_group_name, target_server_name), expect_failure=True) # # test create migration - error - no resource-group - # result = self.cmd('{} flexible-server migration create --subscription-id {} --name {} --body @migrationPublic.json' + # result = self.cmd('{} flexible-server migration create --subscription {} --name {} --body @migrationPublic.json' # .format(database_engine, target_subscription_id, target_server_name), expect_failure=True) # # test create migration - error - no server name - # result = self.cmd('{} flexible-server migration create --subscription-id {} --resource-group {} --body @migrationPublic.json' + # result = self.cmd('{} flexible-server migration create --subscription {} --resource-group {} --body @migrationPublic.json' # .format(database_engine, target_subscription_id, target_resource_group_name), expect_failure=True) # # test create migration - error - no body - # result = self.cmd('{} flexible-server migration create --subscription-id {} --resource-group {} --name {}' + # result = self.cmd('{} flexible-server migration create --subscription {} --resource-group {} --name {}' # .format(database_engine, target_subscription_id, target_resource_group_name, target_server_name), expect_failure=True) # test create migration - success - result = self.cmd('{} flexible-server migration create --subscription-id {} --resource-group {} --name {} --migration-id {} --body @migrationVNet.json' + result = self.cmd('{} flexible-server migration create --subscription {} --resource-group {} --name {} --migration-id {} --body @migrationVNet.json' .format(database_engine, target_subscription_id, target_resource_group_name, target_server_name, migration_id)).get_output_in_json() migration_id = result['name'] # test list migrations - success, with filter - result = self.cmd('{} flexible-server migration list --subscription-id {} --resource-group {} --name {} --filter Active' + result = self.cmd('{} flexible-server migration list --subscription {} --resource-group {} --name {} --filter Active' .format(database_engine, target_subscription_id, target_resource_group_name, target_server_name)).get_output_in_json() # test list migrations - success, without filter - result = self.cmd('{} flexible-server migration list --subscription-id {} --resource-group {} --name {}' + result = self.cmd('{} flexible-server migration list --subscription {} --resource-group {} --name {}' .format(database_engine, target_subscription_id, target_resource_group_name, target_server_name)).get_output_in_json() # test show migration - success - result = self.cmd('{} flexible-server migration show --subscription-id {} --resource-group {} --name {} --migration-id {}' + result = self.cmd('{} flexible-server migration show --subscription {} --resource-group {} --name {} --migration-id {}' .format(database_engine, target_subscription_id, target_resource_group_name, target_server_name, migration_id)).get_output_in_json() # test update migration - error - no param - result = self.cmd('{} flexible-server migration update --subscription-id {} --resource-group {} --name {} --migration-id {}' + result = self.cmd('{} flexible-server migration update --subscription {} --resource-group {} --name {} --migration-id {}' .format(database_engine, target_subscription_id, target_resource_group_name, target_server_name, migration_id), expect_failure=True) # test delete migration - success - result = self.cmd('{} flexible-server migration delete --subscription-id {} --resource-group {} --name {} --migration-id {}' + result = self.cmd('{} flexible-server migration delete --subscription {} --resource-group {} --name {} --migration-id {}' .format(database_engine, target_subscription_id, target_resource_group_name, target_server_name, migration_id)).get_output_in_json() From 7aa090450e691f82386391824149089467d2513e Mon Sep 17 00:00:00 2001 From: Rajesh1Ganesan <58494385+Rajesh1Ganesan@users.noreply.github.com> Date: Mon, 24 May 2021 16:13:12 -0700 Subject: [PATCH 06/13] Rename body to properties, which makes more sense in this context. --- .../cli/command_modules/rdbms/_params.py | 4 ++-- .../rdbms/flexible_server_custom_common.py | 18 ++++++++-------- .../test_postgres_server_migration.yaml | 21 ++++++++++--------- ...ms_flexible_commands_postgres_migration.py | 10 ++++----- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/_params.py b/src/azure-cli/azure/cli/command_modules/rdbms/_params.py index 4a84414eda5..cfde3f50adf 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/_params.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/_params.py @@ -480,8 +480,8 @@ def handle_migration_parameters(command_group, server_name_arg_type, migration_i c.argument('server_name', id_part='name', options_list=['--name', '-n'], arg_type=server_name_arg_type, help='Migration target server name.') if scope == "create": - c.argument('body', options_list=['--body', '-b'], - help='Request body. Use @{file} to load from a file. For quoting issues in different terminals, ' + c.argument('properties', options_list=['--properties', '-b'], + help='Request properties. Use @{file} to load from a file. For quoting issues in different terminals, ' 'see https://github.com/Azure/azure-cli/blob/dev/doc/use_cli_effectively.md#quoting-issues') c.argument('migration_id', arg_type=migration_id_arg_type, options_list=['--migration-id'], help='Name or ID of the migration.') diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py index 524562ae64d..3fb7ed03285 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py @@ -77,7 +77,7 @@ def firewall_rule_create_func(client, resource_group_name, server_name, firewall parameters) -def migration_create_func(cmd, client, resource_group_name, server_name, body, migration_id=None): +def migration_create_func(cmd, client, resource_group_name, server_name, properties, migration_id=None): subscription_id=get_subscription_id(cmd.cli_ctx) @@ -85,7 +85,7 @@ def migration_create_func(cmd, client, resource_group_name, server_name, body, m # Convert a UUID to a string of hex digits in standard form migration_id = str(uuid.uuid4()) - r = send_raw_request(cmd.cli_ctx, "put", "https://management.azure.com/subscriptions/{}/resourceGroups/{}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{}/migrations/{}?api-version=2020-02-14-privatepreview".format(subscription_id, resource_group_name, server_name, migration_id), None, None, body) + r = send_raw_request(cmd.cli_ctx, "put", "https://management.azure.com/subscriptions/{}/resourceGroups/{}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{}/migrations/{}?api-version=2020-02-14-privatepreview".format(subscription_id, resource_group_name, server_name, migration_id), None, None, properties) return r.json() @@ -115,7 +115,7 @@ def migration_update_func(cmd, client, resource_group_name, server_name, migrati operationSpecified = False if setup_logical_replication is True: operationSpecified = True - body = "{\"properties\": {\"setupLogicalReplicationOnSourceDBIfNeeded\": \"true\"} }" + properties = "{\"properties\": {\"setupLogicalReplicationOnSourceDBIfNeeded\": \"true\"} }" db_names = None db_names = db_names_concat_func(db_names, db1) @@ -133,36 +133,36 @@ def migration_update_func(cmd, client, resource_group_name, server_name, migrati operationSpecified = True prefix = "{ \"properties\": { \"dBsToMigrate\": [" suffix = "] } }" - body = prefix + db_names + suffix + properties = prefix + db_names + suffix if overwrite_dbs is True: if operationSpecified is True: raise MutuallyExclusiveArgumentError("Incorrect Usage: Can only specify one update operation.") operationSpecified = True - body = "{\"properties\": {\"overwriteDBsInTarget\": \"true\"} }" + properties = "{\"properties\": {\"overwriteDBsInTarget\": \"true\"} }" # if start_time_utc is not None: # if operationSpecified is True: # raise MutuallyExclusiveArgumentError("Incorrect Usage: Can only specify one update operation.") # operationSpecified = True - # body = "{\"properties\": {\"MigrationWindowStartTimeInUtc\": \"{}\"} }".format(start_time_utc) + # properties = "{\"properties\": {\"MigrationWindowStartTimeInUtc\": \"{}\"} }".format(start_time_utc) # if initiate_data_migration is True: # if operationSpecified is True: # raise MutuallyExclusiveArgumentError("Incorrect Usage: Can only specify one update operation.") # operationSpecified = True - # body = "{\"properties\": {\"startDataMigration\": \"true\"} }" + # properties = "{\"properties\": {\"startDataMigration\": \"true\"} }" if cutover is True: if operationSpecified is True: raise MutuallyExclusiveArgumentError("Incorrect Usage: Can only specify one update operation.") operationSpecified = True - body = "{\"properties\": {\"triggerCutover\": \"true\"} }" + properties = "{\"properties\": {\"triggerCutover\": \"true\"} }" if operationSpecified is False: raise RequiredArgumentMissingError("Incorrect Usage: Atleast one update operation needs to be specified.") - send_raw_request(cmd.cli_ctx, "patch", "https://management.azure.com/subscriptions/{}/resourceGroups/{}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{}/migrations/{}?api-version=2020-02-14-privatepreview".format(subscription_id, resource_group_name, server_name, migration_id), None, None, body) + send_raw_request(cmd.cli_ctx, "patch", "https://management.azure.com/subscriptions/{}/resourceGroups/{}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{}/migrations/{}?api-version=2020-02-14-privatepreview".format(subscription_id, resource_group_name, server_name, migration_id), None, None, properties) return migration_id diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/recordings/test_postgres_server_migration.yaml b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/recordings/test_postgres_server_migration.yaml index 785d1bf75aa..4ce0f7878b5 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/recordings/test_postgres_server_migration.yaml +++ b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/recordings/test_postgres_server_migration.yaml @@ -31,7 +31,7 @@ interactions: Content-Type: - application/json ParameterSetName: - - --subscription --resource-group --name --migration-id --body + - --subscription --resource-group --name --migration-id --properties User-Agent: - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.23.0 method: PUT @@ -49,7 +49,7 @@ interactions: content-type: - application/json; charset=utf-8 date: - - Mon, 24 May 2021 16:11:06 GMT + - Mon, 24 May 2021 23:06:26 GMT expires: - '-1' pragma: @@ -93,7 +93,7 @@ interactions: content-type: - application/json; charset=utf-8 date: - - Mon, 24 May 2021 16:11:06 GMT + - Mon, 24 May 2021 23:06:26 GMT expires: - '-1' pragma: @@ -139,7 +139,7 @@ interactions: content-type: - application/json; charset=utf-8 date: - - Mon, 24 May 2021 16:11:06 GMT + - Mon, 24 May 2021 23:06:26 GMT expires: - '-1' pragma: @@ -176,17 +176,18 @@ interactions: uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000?level=Default&api-version=2020-02-14-privatepreview response: body: - string: '{"properties":{"migrationId":"00000000-0000-0000-0000-000000000000","migrationDetailsLevel":"Default","currentStatus":{"state":"InProgress","currentSubStateDetails":{"currentSubState":"PerformingPreRequisiteSteps"}},"migrationCreateFullRequest":{"sourceDBServerResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.DBforPostgreSQL/servers/raganesa-s-s-pg-1-vnet-1","targetDBServerResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet","targetDBServerSubnetResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.Network/virtualNetworks/raganesa-s-s-pg-1-vnet/subnets/raganesa-s-s-pg-1-vnet-s-s-subnet","dBsToMigrate":["dvdrental"],"migrationResourceGroup":{"resourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-DMSBuddy-Demo","location":"West - US 2"},"setupLogicalReplicationOnSourceDBIfNeeded":true,"overwriteDBsInTarget":true,"migrationWindowStartTimeInUtc":"2021-05-24T16:11:06.4576202Z","triggerCutover":true}},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000","name":"00000000-0000-0000-0000-000000000000","type":"Microsoft.DBforPostgreSQL/flexibleServers/migrations"}' + string: '{"properties":{"migrationId":"00000000-0000-0000-0000-000000000000","migrationDetailsLevel":"Default","currentStatus":{"state":"InProgress","currentSubStateDetails":{"currentSubState":"PerformingPreRequisiteSteps"}},"sourceDBServerMetadata":{"location":"westus2","version":"10","storageMB":102400,"sku":{"name":"GP_Gen5_4","tier":"GeneralPurpose"}},"targetDBServerMetadata":{"location":"West + US 2","version":"12","storageMB":32768,"sku":{"name":"Standard_B1ms","tier":"Burstable"}},"migrationCreateFullRequest":{"sourceDBServerResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.DBforPostgreSQL/servers/raganesa-s-s-pg-1-vnet-1","targetDBServerSubnetResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.Network/virtualNetworks/raganesa-s-s-pg-1-vnet/subnets/raganesa-s-s-pg-1-vnet-s-s-subnet","dBsToMigrate":["dvdrental"],"migrationResourceGroup":{"resourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-DMSBuddy-Demo","location":"West + US 2"},"setupLogicalReplicationOnSourceDBIfNeeded":true,"overwriteDBsInTarget":true,"migrationWindowStartTimeInUtc":"2021-05-24T23:06:26.7533397Z","triggerCutover":true,"targetDBServerResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet"}},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000","name":"00000000-0000-0000-0000-000000000000","type":"Microsoft.DBforPostgreSQL/flexibleServers/migrations"}' headers: cache-control: - no-cache content-length: - - '1514' + - '1780' content-type: - application/json; charset=utf-8 date: - - Mon, 24 May 2021 16:11:07 GMT + - Mon, 24 May 2021 23:06:26 GMT expires: - '-1' pragma: @@ -226,7 +227,7 @@ interactions: response: body: string: '{"properties":{"sourceDBServerResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.DBforPostgreSQL/servers/raganesa-s-s-pg-1-vnet-1","targetDBServerSubnetResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.Network/virtualNetworks/raganesa-s-s-pg-1-vnet/subnets/raganesa-s-s-pg-1-vnet-s-s-subnet","dBsToMigrate":["dvdrental"],"migrationResourceGroup":{"resourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-DMSBuddy-Demo","location":"West - US 2"},"setupLogicalReplicationOnSourceDBIfNeeded":true,"overwriteDBsInTarget":true,"migrationWindowStartTimeInUtc":"2021-05-24T16:11:06.4576202Z","triggerCutover":true},"location":"West + US 2"},"setupLogicalReplicationOnSourceDBIfNeeded":true,"overwriteDBsInTarget":true,"migrationWindowStartTimeInUtc":"2021-05-24T23:06:26.7533397Z","triggerCutover":true},"location":"West US 2","id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000","name":"00000000-0000-0000-0000-000000000000","type":"Microsoft.DBforPostgreSQL/flexibleServers/migrations"}' headers: cache-control: @@ -236,7 +237,7 @@ interactions: content-type: - application/json; charset=utf-8 date: - - Mon, 24 May 2021 16:11:07 GMT + - Mon, 24 May 2021 23:06:28 GMT expires: - '-1' pragma: diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_flexible_commands_postgres_migration.py b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_flexible_commands_postgres_migration.py index 2b8039796f4..ca2b9569714 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_flexible_commands_postgres_migration.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_flexible_commands_postgres_migration.py @@ -59,23 +59,23 @@ def _test_server_migration(self, database_engine): # .format(database_engine), expect_failure=True) # # test create migration - error - no sub - # result = self.cmd('{} flexible-server migration create --resource-group {} --name {} --body @migrationPublic.json' + # result = self.cmd('{} flexible-server migration create --resource-group {} --name {} --properties @migrationPublic.json' # .format(database_engine, target_resource_group_name, target_server_name), expect_failure=True) # # test create migration - error - no resource-group - # result = self.cmd('{} flexible-server migration create --subscription {} --name {} --body @migrationPublic.json' + # result = self.cmd('{} flexible-server migration create --subscription {} --name {} --properties @migrationPublic.json' # .format(database_engine, target_subscription_id, target_server_name), expect_failure=True) # # test create migration - error - no server name - # result = self.cmd('{} flexible-server migration create --subscription {} --resource-group {} --body @migrationPublic.json' + # result = self.cmd('{} flexible-server migration create --subscription {} --resource-group {} --properties @migrationPublic.json' # .format(database_engine, target_subscription_id, target_resource_group_name), expect_failure=True) - # # test create migration - error - no body + # # test create migration - error - no properties # result = self.cmd('{} flexible-server migration create --subscription {} --resource-group {} --name {}' # .format(database_engine, target_subscription_id, target_resource_group_name, target_server_name), expect_failure=True) # test create migration - success - result = self.cmd('{} flexible-server migration create --subscription {} --resource-group {} --name {} --migration-id {} --body @migrationVNet.json' + result = self.cmd('{} flexible-server migration create --subscription {} --resource-group {} --name {} --migration-id {} --properties @migrationVNet.json' .format(database_engine, target_subscription_id, target_resource_group_name, target_server_name, migration_id)).get_output_in_json() migration_id = result['name'] From f9208224580666488938462adb13ed4da32b72e7 Mon Sep 17 00:00:00 2001 From: Rajesh1Ganesan <58494385+Rajesh1Ganesan@users.noreply.github.com> Date: Mon, 24 May 2021 22:46:18 -0700 Subject: [PATCH 07/13] Fix isses reported by "azdev style rdbms" --- .../rdbms/flexible_server_custom_common.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py index 3fb7ed03285..50d2fd9f558 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py @@ -79,7 +79,7 @@ def firewall_rule_create_func(client, resource_group_name, server_name, firewall def migration_create_func(cmd, client, resource_group_name, server_name, properties, migration_id=None): - subscription_id=get_subscription_id(cmd.cli_ctx) + subscription_id = get_subscription_id(cmd.cli_ctx) if migration_id is None: # Convert a UUID to a string of hex digits in standard form @@ -92,7 +92,7 @@ def migration_create_func(cmd, client, resource_group_name, server_name, propert def migration_show_func(cmd, client, resource_group_name, server_name, migration_id, level="Default"): - subscription_id=get_subscription_id(cmd.cli_ctx) + subscription_id = get_subscription_id(cmd.cli_ctx) r = send_raw_request(cmd.cli_ctx, "get", "https://management.azure.com/subscriptions/{}/resourceGroups/{}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{}/migrations/{}?level={}&api-version=2020-02-14-privatepreview".format(subscription_id, resource_group_name, server_name, migration_id, level)) @@ -101,7 +101,7 @@ def migration_show_func(cmd, client, resource_group_name, server_name, migration def migration_list_func(cmd, client, resource_group_name, server_name, migration_filter="Active"): - subscription_id=get_subscription_id(cmd.cli_ctx) + subscription_id = get_subscription_id(cmd.cli_ctx) r = send_raw_request(cmd.cli_ctx, "get", "https://management.azure.com/subscriptions/{}/resourceGroups/{}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{}/migrations?migrationListFilter={}&api-version=2020-02-14-privatepreview".format(subscription_id, resource_group_name, server_name, migration_filter)) @@ -110,7 +110,7 @@ def migration_list_func(cmd, client, resource_group_name, server_name, migration def migration_update_func(cmd, client, resource_group_name, server_name, migration_id, setup_logical_replication=None, db1=None, db2=None, db3=None, db4=None, db5=None, db6=None, db7=None, db8=None, overwrite_dbs=None, cutover=None): - subscription_id=get_subscription_id(cmd.cli_ctx) + subscription_id = get_subscription_id(cmd.cli_ctx) operationSpecified = False if setup_logical_replication is True: @@ -169,7 +169,7 @@ def migration_update_func(cmd, client, resource_group_name, server_name, migrati def migration_delete_func(cmd, client, resource_group_name, server_name, migration_id): - subscription_id=get_subscription_id(cmd.cli_ctx) + subscription_id = get_subscription_id(cmd.cli_ctx) r = send_raw_request(cmd.cli_ctx, "delete", "https://management.azure.com/subscriptions/{}/resourceGroups/{}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{}/migrations/{}?api-version=2020-02-14-privatepreview".format(subscription_id, resource_group_name, server_name, migration_id)) From 677e093f323ed2c42c8d77479a03b1756b96f7e5 Mon Sep 17 00:00:00 2001 From: Rajesh1Ganesan <58494385+Rajesh1Ganesan@users.noreply.github.com> Date: Mon, 24 May 2021 23:04:55 -0700 Subject: [PATCH 08/13] Fix linter issues --- .../cli/command_modules/rdbms/_helptext_pg.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py b/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py index 332d4cff0e5..207d5f7a5a7 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py @@ -186,7 +186,7 @@ short-summary: Create a new migration workflow for a flexible server. examples: - name: Start a migration workflow on the target server identified by the parameters. The configurations of the migration should be specified in the migrationConfig.json file. - text: az postgres flexible-server migration create --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --body @"migrationConfig.json" + text: az postgres flexible-server migration create --subscription xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --properties @"migrationConfig.json" """ helps['postgres flexible-server migration list'] = """ @@ -194,9 +194,9 @@ short-summary: List the migrations of a flexible server. examples: - name: List the currently active migrations of a target flexible server. - text: az postgres flexible-server migration list --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --filter Active + text: az postgres flexible-server migration list --subscription xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --filter Active - name: List all (Active/Completed) migrations of a target flexible server. - text: az postgres flexible-server migration list --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --filter All + text: az postgres flexible-server migration list --subscription xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --filter All """ helps['postgres flexible-server migration show'] = """ @@ -204,7 +204,7 @@ short-summary: Get the details of a specific migration. examples: - name: Get the details of a specific migration of a target flexible server. - text: az postgres flexible-server migration show --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx + text: az postgres flexible-server migration show --subscription xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx """ helps['postgres flexible-server migration update'] = """ @@ -212,26 +212,26 @@ short-summary: Update a specific migration. examples: - name: Allow the migration workflow to setup logical replication on the source. Note that this command will restart the source server. - text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --setup-replication + text: az postgres flexible-server migration update --subscription xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --setup-replication - name: Specify the list of DBs to migrate. A minimum of 1 and a maximum of 8 DBs can be specified. You can migrate additional DBs concurrently using new migrations. Note that each additional DB affects the performance of the source server. - text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --db1 dbName1 --db2 dbName2 --db3 dbName3 + text: az postgres flexible-server migration update --subscription xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --db1 dbName1 --db2 dbName2 --db3 dbName3 - name: Allow the migration workflow to overwrite the DB on the target. - text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --overwrite-dbs + text: az postgres flexible-server migration update --subscription xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --overwrite-dbs - name: Cutover the data migration. After this is complete, subsequent updates to the source DB will not be migrated to the target. - text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --cutover + text: az postgres flexible-server migration update --subscription xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --cutover """ # - name: Specify the start time for the data migration to start. This should be within 2 weeks from the current time. -# text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --start-time-utc '2021-12-28T17:06:03.4669999-07:00' +# text: az postgres flexible-server migration update --subscription xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --start-time-utc '2021-12-28T17:06:03.4669999-07:00' # - name: Start the data migration now, rather than wait for the migration window start time. -# text: az postgres flexible-server migration update --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --init-data-migration +# text: az postgres flexible-server migration update --subscription xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --init-data-migration helps['postgres flexible-server migration delete'] = """ type: command short-summary: Delete a specific migration. examples: - name: Cancel/delete the migration workflow. The migration workflows can be canceled/deleted at any point. - text: az postgres flexible-server migration delete --subscription-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx + text: az postgres flexible-server migration delete --subscription xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx """ helps['postgres flexible-server parameter'] = """ From ce8956626031dc584be9eada09fcf6271935ebed Mon Sep 17 00:00:00 2001 From: Rajesh1Ganesan <58494385+Rajesh1Ganesan@users.noreply.github.com> Date: Tue, 25 May 2021 21:14:28 -0700 Subject: [PATCH 09/13] Fix issues reported by azdev style check --- src/azure-cli/azure/cli/command_modules/rdbms/_params.py | 2 +- .../cli/command_modules/rdbms/flexible_server_custom_common.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/_params.py b/src/azure-cli/azure/cli/command_modules/rdbms/_params.py index 43033770f7e..ae8f32967d9 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/_params.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/_params.py @@ -542,6 +542,6 @@ def handle_migration_parameters(command_group, server_name_arg_type, migration_i elif scope == "delete": c.argument('migration_id', arg_type=migration_id_arg_type, options_list=['--migration-id'], help='Name or ID of the migration.') - + _flexible_server_params('postgres') _flexible_server_params('mysql') diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py index 6a13210f090..bdd160cdb5e 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py @@ -9,7 +9,6 @@ from datetime import datetime from knack.log import get_logger from knack.util import CLIError -from azure.cli.core.azclierror import RequiredArgumentMissingError from azure.cli.core.azclierror import MutuallyExclusiveArgumentError from azure.cli.core.commands.client_factory import get_subscription_id from azure.cli.core.util import send_raw_request From 6ef6109c8f7de39677be256ad950ba7b1bfd36b0 Mon Sep 17 00:00:00 2001 From: Rajesh1Ganesan <58494385+Rajesh1Ganesan@users.noreply.github.com> Date: Wed, 26 May 2021 10:51:28 -0700 Subject: [PATCH 10/13] Mark the migration command group as experimental --- .../cli/command_modules/rdbms/flexible_server_commands.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_commands.py b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_commands.py index 6ab0739c383..3c0bcb1eba7 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_commands.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_commands.py @@ -131,7 +131,8 @@ def load_flexibleserver_command_table(self, _): with self.command_group('postgres flexible-server migration', postgres_flexible_firewall_rule_sdk, custom_command_type=flexible_servers_custom_postgres, client_factory=cf_postgres_flexible_firewall_rules, - is_preview=True) as g: + is_preview=True, + is_experimental=True) as g: g.custom_command('create', 'migration_create_func', custom_command_type=flexible_server_custom_common) g.custom_show_command('show', 'migration_show_func', custom_command_type=flexible_server_custom_common) g.custom_command('list', 'migration_list_func', custom_command_type=flexible_server_custom_common) From b8c5f261f03fce91f47b4de280ae9e3b3b741eb7 Mon Sep 17 00:00:00 2001 From: Rajesh1Ganesan <58494385+Rajesh1Ganesan@users.noreply.github.com> Date: Wed, 26 May 2021 15:06:19 -0700 Subject: [PATCH 11/13] Cannot have is_preview and is_experimental at the same time. So removed is_preview. --- .../azure/cli/command_modules/rdbms/flexible_server_commands.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_commands.py b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_commands.py index 3c0bcb1eba7..eb528add833 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_commands.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_commands.py @@ -131,7 +131,6 @@ def load_flexibleserver_command_table(self, _): with self.command_group('postgres flexible-server migration', postgres_flexible_firewall_rule_sdk, custom_command_type=flexible_servers_custom_postgres, client_factory=cf_postgres_flexible_firewall_rules, - is_preview=True, is_experimental=True) as g: g.custom_command('create', 'migration_create_func', custom_command_type=flexible_server_custom_common) g.custom_show_command('show', 'migration_show_func', custom_command_type=flexible_server_custom_common) From 9b94286b346e59bcc22e11e6078a2f14896d9bcb Mon Sep 17 00:00:00 2001 From: Rajesh1Ganesan <58494385+Rajesh1Ganesan@users.noreply.github.com> Date: Thu, 27 May 2021 16:14:17 -0700 Subject: [PATCH 12/13] 1. Added a confirmation for migration delete, 2. Deleted unused code, 3. Return instead of just the migration_id from update --- .../cli/command_modules/rdbms/_helptext_pg.py | 5 --- .../cli/command_modules/rdbms/_params.py | 6 ++-- .../rdbms/flexible_server_custom_common.py | 23 +++++--------- .../test_postgres_server_migration.yaml | 31 +++++++++---------- ...ms_flexible_commands_postgres_migration.py | 22 +------------ 5 files changed, 26 insertions(+), 61 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py b/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py index 552bf0b7a85..2e3bcc34911 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py @@ -221,11 +221,6 @@ text: az postgres flexible-server migration update --subscription xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --cutover """ -# - name: Specify the start time for the data migration to start. This should be within 2 weeks from the current time. -# text: az postgres flexible-server migration update --subscription xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --start-time-utc '2021-12-28T17:06:03.4669999-07:00' -# - name: Start the data migration now, rather than wait for the migration window start time. -# text: az postgres flexible-server migration update --subscription xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --init-data-migration - helps['postgres flexible-server migration delete'] = """ type: command short-summary: Delete a specific migration. diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/_params.py b/src/azure-cli/azure/cli/command_modules/rdbms/_params.py index ae8f32967d9..d06a292e301 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/_params.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/_params.py @@ -533,15 +533,13 @@ def handle_migration_parameters(command_group, server_name_arg_type, migration_i help='Specify the eigth DB to migrate.') c.argument('overwrite_dbs', options_list=['--overwrite-dbs'], action='store_true', required=False, help='Allow the migration workflow to overwrite the DB on the target.') - # c.argument('start_time_utc', options_list=['--start-time-utc'], required=False, - # help='Specify the start time for the data migration to start. This should be within 2 weeks from the current time.') - # c.argument('initiate_data_migration', options_list=['--init-data-migration'], action='store_true', required=False, - # help='Start the data migration now, rather than wait for the migration window start time.') c.argument('cutover', options_list=['--cutover'], action='store_true', required=False, help='Cut-over the data migration. After this is complete, subsequent updates to the source DB will not be migrated to the target.') elif scope == "delete": c.argument('migration_id', arg_type=migration_id_arg_type, options_list=['--migration-id'], help='Name or ID of the migration.') + c.argument('yes', options_list=['--yes', '-y'], action='store_true', + help='Do not prompt for confirmation.') _flexible_server_params('postgres') _flexible_server_params('mysql') diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py index bdd160cdb5e..167896d00f1 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py @@ -144,18 +144,6 @@ def migration_update_func(cmd, client, resource_group_name, server_name, migrati operationSpecified = True properties = "{\"properties\": {\"overwriteDBsInTarget\": \"true\"} }" - # if start_time_utc is not None: - # if operationSpecified is True: - # raise MutuallyExclusiveArgumentError("Incorrect Usage: Can only specify one update operation.") - # operationSpecified = True - # properties = "{\"properties\": {\"MigrationWindowStartTimeInUtc\": \"{}\"} }".format(start_time_utc) - - # if initiate_data_migration is True: - # if operationSpecified is True: - # raise MutuallyExclusiveArgumentError("Incorrect Usage: Can only specify one update operation.") - # operationSpecified = True - # properties = "{\"properties\": {\"startDataMigration\": \"true\"} }" - if cutover is True: if operationSpecified is True: raise MutuallyExclusiveArgumentError("Incorrect Usage: Can only specify one update operation.") @@ -165,15 +153,20 @@ def migration_update_func(cmd, client, resource_group_name, server_name, migrati if operationSpecified is False: raise RequiredArgumentMissingError("Incorrect Usage: Atleast one update operation needs to be specified.") - send_raw_request(cmd.cli_ctx, "patch", "https://management.azure.com/subscriptions/{}/resourceGroups/{}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{}/migrations/{}?api-version=2020-02-14-privatepreview".format(subscription_id, resource_group_name, server_name, migration_id), None, None, properties) + r = send_raw_request(cmd.cli_ctx, "patch", "https://management.azure.com/subscriptions/{}/resourceGroups/{}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{}/migrations/{}?api-version=2020-02-14-privatepreview".format(subscription_id, resource_group_name, server_name, migration_id), None, None, properties) - return migration_id + return r.json() -def migration_delete_func(cmd, client, resource_group_name, server_name, migration_id): +def migration_delete_func(cmd, client, resource_group_name, server_name, migration_id, yes=None): subscription_id = get_subscription_id(cmd.cli_ctx) + if not yes: + user_confirmation( + "Are you sure you want to delete the migration '{0}' on target server '{1}', resource group '{2}'".format( + migration_id, server_name, resource_group_name)) + r = send_raw_request(cmd.cli_ctx, "delete", "https://management.azure.com/subscriptions/{}/resourceGroups/{}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{}/migrations/{}?api-version=2020-02-14-privatepreview".format(subscription_id, resource_group_name, server_name, migration_id)) return r.json() diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/recordings/test_postgres_server_migration.yaml b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/recordings/test_postgres_server_migration.yaml index 4ce0f7878b5..4090be38d3b 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/recordings/test_postgres_server_migration.yaml +++ b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/recordings/test_postgres_server_migration.yaml @@ -33,7 +33,7 @@ interactions: ParameterSetName: - --subscription --resource-group --name --migration-id --properties User-Agent: - - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.23.0 + - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.24.0 method: PUT uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000?api-version=2020-02-14-privatepreview response: @@ -49,7 +49,7 @@ interactions: content-type: - application/json; charset=utf-8 date: - - Mon, 24 May 2021 23:06:26 GMT + - Thu, 27 May 2021 23:06:59 GMT expires: - '-1' pragma: @@ -79,7 +79,7 @@ interactions: ParameterSetName: - --subscription --resource-group --name --filter User-Agent: - - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.23.0 + - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.24.0 method: GET uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations?migrationListFilter=Active&api-version=2020-02-14-privatepreview response: @@ -93,7 +93,7 @@ interactions: content-type: - application/json; charset=utf-8 date: - - Mon, 24 May 2021 23:06:26 GMT + - Thu, 27 May 2021 23:06:59 GMT expires: - '-1' pragma: @@ -125,7 +125,7 @@ interactions: ParameterSetName: - --subscription --resource-group --name User-Agent: - - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.23.0 + - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.24.0 method: GET uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations?migrationListFilter=Active&api-version=2020-02-14-privatepreview response: @@ -139,7 +139,7 @@ interactions: content-type: - application/json; charset=utf-8 date: - - Mon, 24 May 2021 23:06:26 GMT + - Thu, 27 May 2021 23:07:00 GMT expires: - '-1' pragma: @@ -171,23 +171,22 @@ interactions: ParameterSetName: - --subscription --resource-group --name --migration-id User-Agent: - - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.23.0 + - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.24.0 method: GET uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000?level=Default&api-version=2020-02-14-privatepreview response: body: - string: '{"properties":{"migrationId":"00000000-0000-0000-0000-000000000000","migrationDetailsLevel":"Default","currentStatus":{"state":"InProgress","currentSubStateDetails":{"currentSubState":"PerformingPreRequisiteSteps"}},"sourceDBServerMetadata":{"location":"westus2","version":"10","storageMB":102400,"sku":{"name":"GP_Gen5_4","tier":"GeneralPurpose"}},"targetDBServerMetadata":{"location":"West - US 2","version":"12","storageMB":32768,"sku":{"name":"Standard_B1ms","tier":"Burstable"}},"migrationCreateFullRequest":{"sourceDBServerResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.DBforPostgreSQL/servers/raganesa-s-s-pg-1-vnet-1","targetDBServerSubnetResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.Network/virtualNetworks/raganesa-s-s-pg-1-vnet/subnets/raganesa-s-s-pg-1-vnet-s-s-subnet","dBsToMigrate":["dvdrental"],"migrationResourceGroup":{"resourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-DMSBuddy-Demo","location":"West - US 2"},"setupLogicalReplicationOnSourceDBIfNeeded":true,"overwriteDBsInTarget":true,"migrationWindowStartTimeInUtc":"2021-05-24T23:06:26.7533397Z","triggerCutover":true,"targetDBServerResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet"}},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000","name":"00000000-0000-0000-0000-000000000000","type":"Microsoft.DBforPostgreSQL/flexibleServers/migrations"}' + string: '{"properties":{"migrationId":"00000000-0000-0000-0000-000000000000","migrationDetailsLevel":"Default","currentStatus":{"state":"InProgress","currentSubStateDetails":{"currentSubState":"PerformingPreRequisiteSteps"}},"migrationCreateFullRequest":{"sourceDBServerResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.DBforPostgreSQL/servers/raganesa-s-s-pg-1-vnet-1","targetDBServerResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet","targetDBServerSubnetResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.Network/virtualNetworks/raganesa-s-s-pg-1-vnet/subnets/raganesa-s-s-pg-1-vnet-s-s-subnet","dBsToMigrate":["dvdrental"],"migrationResourceGroup":{"resourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-DMSBuddy-Demo","location":"West + US 2"},"setupLogicalReplicationOnSourceDBIfNeeded":true,"overwriteDBsInTarget":true,"migrationWindowStartTimeInUtc":"2021-05-27T23:07:00.0345809Z","triggerCutover":true}},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000","name":"00000000-0000-0000-0000-000000000000","type":"Microsoft.DBforPostgreSQL/flexibleServers/migrations"}' headers: cache-control: - no-cache content-length: - - '1780' + - '1514' content-type: - application/json; charset=utf-8 date: - - Mon, 24 May 2021 23:06:26 GMT + - Thu, 27 May 2021 23:07:01 GMT expires: - '-1' pragma: @@ -219,15 +218,15 @@ interactions: Content-Length: - '0' ParameterSetName: - - --subscription --resource-group --name --migration-id + - --subscription --resource-group --name --migration-id --yes User-Agent: - - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.23.0 + - python/3.9.4 (Windows-10-10.0.19041-SP0) AZURECLI/2.24.0 method: DELETE uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000?api-version=2020-02-14-privatepreview response: body: string: '{"properties":{"sourceDBServerResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.DBforPostgreSQL/servers/raganesa-s-s-pg-1-vnet-1","targetDBServerSubnetResourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-s-s-pg-1/providers/Microsoft.Network/virtualNetworks/raganesa-s-s-pg-1-vnet/subnets/raganesa-s-s-pg-1-vnet-s-s-subnet","dBsToMigrate":["dvdrental"],"migrationResourceGroup":{"resourceId":"subscriptions/6a37df99-a9de-48c4-91e5-7e6ab00b2362/resourceGroups/raganesa-DMSBuddy-Demo","location":"West - US 2"},"setupLogicalReplicationOnSourceDBIfNeeded":true,"overwriteDBsInTarget":true,"migrationWindowStartTimeInUtc":"2021-05-24T23:06:26.7533397Z","triggerCutover":true},"location":"West + US 2"},"setupLogicalReplicationOnSourceDBIfNeeded":true,"overwriteDBsInTarget":true,"migrationWindowStartTimeInUtc":"2021-05-27T23:07:00.0345809Z","triggerCutover":true},"location":"West US 2","id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/raganesa-t-m-pg-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/raganesa-t-m-pg-1-vnet/migrations/00000000-0000-0000-0000-000000000000","name":"00000000-0000-0000-0000-000000000000","type":"Microsoft.DBforPostgreSQL/flexibleServers/migrations"}' headers: cache-control: @@ -237,7 +236,7 @@ interactions: content-type: - application/json; charset=utf-8 date: - - Mon, 24 May 2021 23:06:28 GMT + - Thu, 27 May 2021 23:07:01 GMT expires: - '-1' pragma: diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_flexible_commands_postgres_migration.py b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_flexible_commands_postgres_migration.py index ca2b9569714..dff68b2284b 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_flexible_commands_postgres_migration.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_rdbms_flexible_commands_postgres_migration.py @@ -54,26 +54,6 @@ def _test_server_migration(self, database_engine): target_resource_group_name = "raganesa-t-m-pg-1" target_server_name = "raganesa-t-m-pg-1-vnet" - # # test create migration - error - no param - # result = self.cmd('{} flexible-server migration create' - # .format(database_engine), expect_failure=True) - - # # test create migration - error - no sub - # result = self.cmd('{} flexible-server migration create --resource-group {} --name {} --properties @migrationPublic.json' - # .format(database_engine, target_resource_group_name, target_server_name), expect_failure=True) - - # # test create migration - error - no resource-group - # result = self.cmd('{} flexible-server migration create --subscription {} --name {} --properties @migrationPublic.json' - # .format(database_engine, target_subscription_id, target_server_name), expect_failure=True) - - # # test create migration - error - no server name - # result = self.cmd('{} flexible-server migration create --subscription {} --resource-group {} --properties @migrationPublic.json' - # .format(database_engine, target_subscription_id, target_resource_group_name), expect_failure=True) - - # # test create migration - error - no properties - # result = self.cmd('{} flexible-server migration create --subscription {} --resource-group {} --name {}' - # .format(database_engine, target_subscription_id, target_resource_group_name, target_server_name), expect_failure=True) - # test create migration - success result = self.cmd('{} flexible-server migration create --subscription {} --resource-group {} --name {} --migration-id {} --properties @migrationVNet.json' .format(database_engine, target_subscription_id, target_resource_group_name, target_server_name, migration_id)).get_output_in_json() @@ -97,5 +77,5 @@ def _test_server_migration(self, database_engine): .format(database_engine, target_subscription_id, target_resource_group_name, target_server_name, migration_id), expect_failure=True) # test delete migration - success - result = self.cmd('{} flexible-server migration delete --subscription {} --resource-group {} --name {} --migration-id {}' + result = self.cmd('{} flexible-server migration delete --subscription {} --resource-group {} --name {} --migration-id {} --yes' .format(database_engine, target_subscription_id, target_resource_group_name, target_server_name, migration_id)).get_output_in_json() From 57441c8a95edf55b44bdc1b91e9da88fc2907346 Mon Sep 17 00:00:00 2001 From: Rajesh1Ganesan <58494385+Rajesh1Ganesan@users.noreply.github.com> Date: Thu, 27 May 2021 17:45:32 -0700 Subject: [PATCH 13/13] Replace parameters db1, db2, ...db8 with an db-names parameter which takes a space-separated list of values --- .../cli/command_modules/rdbms/_helptext_pg.py | 4 ++-- .../cli/command_modules/rdbms/_params.py | 18 ++------------ .../rdbms/flexible_server_custom_common.py | 24 +++---------------- 3 files changed, 7 insertions(+), 39 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py b/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py index 2e3bcc34911..02b2deca37d 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py @@ -213,8 +213,8 @@ examples: - name: Allow the migration workflow to setup logical replication on the source. Note that this command will restart the source server. text: az postgres flexible-server migration update --subscription xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --setup-replication - - name: Specify the list of DBs to migrate. A minimum of 1 and a maximum of 8 DBs can be specified. You can migrate additional DBs concurrently using new migrations. Note that each additional DB affects the performance of the source server. - text: az postgres flexible-server migration update --subscription xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --db1 dbName1 --db2 dbName2 --db3 dbName3 + - name: Space-separated list of DBs to migrate. A minimum of 1 and a maximum of 8 DBs can be specified. You can migrate more DBs concurrently using additional migrations. Note that each additional DB affects the performance of the source server. + text: az postgres flexible-server migration update --subscription xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --db-names db1 db2 - name: Allow the migration workflow to overwrite the DB on the target. text: az postgres flexible-server migration update --subscription xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --resource-group testGroup --name testServer --migration-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --overwrite-dbs - name: Cutover the data migration. After this is complete, subsequent updates to the source DB will not be migrated to the target. diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/_params.py b/src/azure-cli/azure/cli/command_modules/rdbms/_params.py index d06a292e301..aa6884ad348 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/_params.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/_params.py @@ -515,22 +515,8 @@ def handle_migration_parameters(command_group, server_name_arg_type, migration_i help='Name or ID of the migration.') c.argument('setup_logical_replication', options_list=['--setup-replication'], action='store_true', required=False, help='Allow the migration workflow to setup logical replication on the source. Note that this command will restart the source server.') - c.argument('db1', options_list=['--db1', '--db'], required=False, - help='Specify the first DB to migrate. A minimum of 1 and a maximum of 8 DBs can be specified using --db1, --db2, --db3... You can migrate additional DBs concurrently using new migrations. Note that each additional DB affects the performance of the source server.') - c.argument('db2', options_list=['--db2'], required=False, - help='Specify the second DB to migrate.') - c.argument('db3', options_list=['--db3'], required=False, - help='Specify the third DB to migrate.') - c.argument('db4', options_list=['--db4'], required=False, - help='Specify the fourth DB to migrate.') - c.argument('db5', options_list=['--db5'], required=False, - help='Specify the fifth DB to migrate.') - c.argument('db6', options_list=['--db6'], required=False, - help='Specify the sixth DB to migrate.') - c.argument('db7', options_list=['--db7'], required=False, - help='Specify the seventh DB to migrate.') - c.argument('db8', options_list=['--db8'], required=False, - help='Specify the eigth DB to migrate.') + c.argument('db_names', nargs='+', options_list=['--db-names', '--dbs'], required=False, + help='Space-separated list of DBs to migrate. A minimum of 1 and a maximum of 8 DBs can be specified. You can migrate more DBs concurrently using additional migrations. Note that each additional DB affects the performance of the source server.') c.argument('overwrite_dbs', options_list=['--overwrite-dbs'], action='store_true', required=False, help='Allow the migration workflow to overwrite the DB on the target.') c.argument('cutover', options_list=['--cutover'], action='store_true', required=False, diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py index 167896d00f1..c71520b58c0 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py @@ -111,7 +111,7 @@ def migration_list_func(cmd, client, resource_group_name, server_name, migration return r.json() -def migration_update_func(cmd, client, resource_group_name, server_name, migration_id, setup_logical_replication=None, db1=None, db2=None, db3=None, db4=None, db5=None, db6=None, db7=None, db8=None, overwrite_dbs=None, cutover=None): +def migration_update_func(cmd, client, resource_group_name, server_name, migration_id, setup_logical_replication=None, db_names=None, overwrite_dbs=None, cutover=None): subscription_id = get_subscription_id(cmd.cli_ctx) @@ -120,23 +120,14 @@ def migration_update_func(cmd, client, resource_group_name, server_name, migrati operationSpecified = True properties = "{\"properties\": {\"setupLogicalReplicationOnSourceDBIfNeeded\": \"true\"} }" - db_names = None - db_names = db_names_concat_func(db_names, db1) - db_names = db_names_concat_func(db_names, db2) - db_names = db_names_concat_func(db_names, db3) - db_names = db_names_concat_func(db_names, db4) - db_names = db_names_concat_func(db_names, db5) - db_names = db_names_concat_func(db_names, db6) - db_names = db_names_concat_func(db_names, db7) - db_names = db_names_concat_func(db_names, db8) - if db_names is not None: if operationSpecified is True: raise MutuallyExclusiveArgumentError("Incorrect Usage: Can only specify one update operation.") operationSpecified = True prefix = "{ \"properties\": { \"dBsToMigrate\": [" + db_names_str = "\"" + "\", \"".join(db_names) + "\"" suffix = "] } }" - properties = prefix + db_names + suffix + properties = prefix + db_names_str + suffix if overwrite_dbs is True: if operationSpecified is True: @@ -172,15 +163,6 @@ def migration_delete_func(cmd, client, resource_group_name, server_name, migrati return r.json() -def db_names_concat_func(current_db_names, new_db_name): - - if new_db_name is not None: - db = "\"{}\"".format(new_db_name) - current_db_names = db if current_db_names is None else current_db_names + ", " + db - - return current_db_names - - def firewall_rule_delete_func(client, resource_group_name, server_name, firewall_rule_name, yes=None): result = None if not yes: