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. Remove the --subscription-id parameter. Use the CLI command param …
…--subscription instead
  • Loading branch information
Rajesh1Ganesan committed May 24, 2021
commit 4d614e47ca3df59d8fadfefc14d7dc3a27ab4575
40 changes: 17 additions & 23 deletions src/azure-cli/azure/cli/command_modules/rdbms/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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))

Expand Down
Loading