Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
1. Added a confirmation for migration delete, 2. Deleted unused code,…
… 3. Return instead of just the migration_id from update
  • Loading branch information
Rajesh1Ganesan committed May 27, 2021
commit 9b94286b346e59bcc22e11e6078a2f14896d9bcb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 2 additions & 4 deletions src/azure-cli/azure/cli/command_modules/rdbms/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()