зеркало из https://github.com/microsoft/azure-cli.git
Import/Export CLI changes for SAS key (#2584)
* Add examples, custom code handling, and testing for Import/Export using SAS key * Fix help section * Change test to be Python 2 compatible, re-do recording * Addressed comments, fix linter issues * Update dependency to azure-mgmt-sql==0.4.0 * Fixed Import/Export examples * Fixed auth_type param in db export
This commit is contained in:
Родитель
2674d5f5db
Коммит
afee409b33
|
@ -651,6 +651,7 @@
|
|||
<Folder Include="command_modules\azure-cli-vm\azure\cli\" />
|
||||
<Folder Include="command_modules\azure-cli-vm\azure\cli\command_modules\" />
|
||||
<Folder Include="command_modules\azure-cli-vm\azure\cli\command_modules\vm\" />
|
||||
<Folder Include="command_modules\azure-cli-vm\azure\cli\command_modules\vm\tests\" />
|
||||
<Folder Include="command_modules\azure-cli-vm\tests\" />
|
||||
<Folder Include="command_modules\azure-cli-vm\tests\keyvault\" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -16,15 +16,19 @@ def get_sql_management_client(_):
|
|||
return get_mgmt_service_client(SqlManagementClient)
|
||||
|
||||
|
||||
def get_sql_servers_operation(kwargs):
|
||||
def get_sql_servers_operations(kwargs):
|
||||
return get_sql_management_client(kwargs).servers
|
||||
|
||||
|
||||
def get_sql_database_operations(kwargs):
|
||||
def get_sql_firewall_rules_operations(kwargs):
|
||||
return get_sql_management_client(kwargs).firewall_rules
|
||||
|
||||
|
||||
def get_sql_databases_operations(kwargs):
|
||||
return get_sql_management_client(kwargs).databases
|
||||
|
||||
|
||||
def get_sql_elasticpools_operations(kwargs):
|
||||
def get_sql_elastic_pools_operations(kwargs):
|
||||
return get_sql_management_client(kwargs).elastic_pools
|
||||
|
||||
|
||||
|
@ -32,14 +36,6 @@ def get_sql_recommended_elastic_pools_operations(kwargs):
|
|||
return get_sql_management_client(kwargs).recommended_elastic_pools
|
||||
|
||||
|
||||
def get_sql_database_blob_auditing_policies_operations(kwargs):
|
||||
return get_sql_management_client(kwargs).database_blob_auditing_policies
|
||||
|
||||
|
||||
def get_sql_database_threat_detection_policies_operations(kwargs):
|
||||
return get_sql_management_client(kwargs).database_threat_detection_policies
|
||||
|
||||
|
||||
# COMMANDS UTILITIES
|
||||
|
||||
def create_service_adapter(service_model, service_class):
|
||||
|
|
|
@ -4,11 +4,10 @@
|
|||
# --------------------------------------------------------------------------------------------
|
||||
|
||||
from ._util import (
|
||||
get_sql_servers_operation,
|
||||
get_sql_database_operations,
|
||||
get_sql_database_blob_auditing_policies_operations,
|
||||
get_sql_database_threat_detection_policies_operations,
|
||||
get_sql_elasticpools_operations,
|
||||
get_sql_servers_operations,
|
||||
get_sql_firewall_rules_operations,
|
||||
get_sql_databases_operations,
|
||||
get_sql_elastic_pools_operations,
|
||||
create_service_adapter,
|
||||
ServiceGroup)
|
||||
|
||||
|
@ -19,7 +18,7 @@ from ._util import (
|
|||
database_operations = create_service_adapter('azure.mgmt.sql.operations.databases_operations',
|
||||
'DatabasesOperations')
|
||||
|
||||
with ServiceGroup(__name__, get_sql_database_operations, database_operations) as s:
|
||||
with ServiceGroup(__name__, get_sql_databases_operations, database_operations) as s:
|
||||
with s.group('sql db') as c:
|
||||
c.custom_command('create', 'db_create')
|
||||
c.custom_command('copy', 'db_copy')
|
||||
|
@ -30,8 +29,8 @@ with ServiceGroup(__name__, get_sql_database_operations, database_operations) as
|
|||
# c.command('show-usage', 'list_usages')
|
||||
c.command('delete', 'delete', confirmation=True)
|
||||
c.generic_update_command('update', 'get', 'create_or_update', custom_func_name='db_update')
|
||||
c.command('import', 'import_method')
|
||||
c.command('export', 'export')
|
||||
c.custom_command('import', 'db_import')
|
||||
c.custom_command('export', 'db_export')
|
||||
|
||||
with s.group('sql db replica') as c:
|
||||
c.custom_command('create', 'db_create_replica')
|
||||
|
@ -44,8 +43,8 @@ with ServiceGroup(__name__, get_sql_database_operations, database_operations) as
|
|||
c.command('show', 'get')
|
||||
c.custom_command('list', 'dw_list')
|
||||
c.command('delete', 'delete', confirmation=True)
|
||||
c.command('pause', 'pause_data_warehouse')
|
||||
c.command('resume', 'resume_data_warehouse')
|
||||
c.command('pause', 'pause')
|
||||
c.command('resume', 'resume')
|
||||
c.generic_update_command('update', 'get', 'create_or_update', custom_func_name='dw_update')
|
||||
|
||||
# Data Warehouse restore will not be included in the first batch of GA commands
|
||||
|
@ -65,41 +64,26 @@ with ServiceGroup(__name__, get_sql_database_operations, database_operations) as
|
|||
# c.command('list', 'list_service_tier_advisors')
|
||||
# c.command('show', 'get_service_tier_advisor')
|
||||
|
||||
database_blob_auditing_policy_operations = create_service_adapter(
|
||||
'azure.mgmt.sql.operations.database_blob_auditing_policies_operations',
|
||||
'DatabaseBlobAuditingPoliciesOperations')
|
||||
|
||||
with ServiceGroup(__name__,
|
||||
get_sql_database_blob_auditing_policies_operations,
|
||||
database_blob_auditing_policy_operations) as s:
|
||||
with s.group('sql db audit-policy') as c:
|
||||
c.command('show', 'get')
|
||||
c.command('show', 'get_blob_auditing_policy')
|
||||
c.generic_update_command(
|
||||
'update', 'get', 'create_or_update',
|
||||
custom_func_name='db_audit_policy_update',
|
||||
setter_arg_name='database_blob_auditing_policy')
|
||||
'update', 'get_blob_auditing_policy', 'create_or_update_blob_auditing_policy',
|
||||
custom_func_name='db_audit_policy_update')
|
||||
|
||||
database_threat_detection_policy_operations = create_service_adapter(
|
||||
'azure.mgmt.sql.operations.database_threat_detection_policies_operations',
|
||||
'DatabaseThreatDetectionPoliciesOperations')
|
||||
|
||||
with ServiceGroup(__name__,
|
||||
get_sql_database_threat_detection_policies_operations,
|
||||
database_threat_detection_policy_operations) as s:
|
||||
with s.group('sql db threat-policy') as c:
|
||||
c.command('show', 'get')
|
||||
c.generic_update_command('update', 'get', 'create_or_update',
|
||||
custom_func_name='db_threat_detection_policy_update',
|
||||
setter_arg_name='database_security_alert_policy')
|
||||
c.command('show', 'get_threat_detection_policy')
|
||||
c.generic_update_command('update', 'get_threat_detection_policy',
|
||||
'create_or_update_threat_detection_policy',
|
||||
custom_func_name='db_threat_detection_policy_update')
|
||||
|
||||
###############################################
|
||||
# sql elastic-pool #
|
||||
###############################################
|
||||
|
||||
elasticpools_ops = create_service_adapter('azure.mgmt.sql.operations.elastic_pools_operations',
|
||||
'ElasticPoolsOperations')
|
||||
elastic_pools_ops = create_service_adapter('azure.mgmt.sql.operations.elastic_pools_operations',
|
||||
'ElasticPoolsOperations')
|
||||
|
||||
with ServiceGroup(__name__, get_sql_elasticpools_operations, elasticpools_ops) as s:
|
||||
with ServiceGroup(__name__, get_sql_elastic_pools_operations, elastic_pools_ops) as s:
|
||||
with s.group('sql elastic-pool') as c:
|
||||
c.custom_command('create', 'elastic_pool_create')
|
||||
c.command('delete', 'delete')
|
||||
|
@ -130,27 +114,31 @@ recommanded_elastic_pools_ops = \
|
|||
# sql server #
|
||||
###############################################
|
||||
|
||||
server_operations = create_service_adapter('azure.mgmt.sql.operations.servers_operations',
|
||||
'ServersOperations')
|
||||
|
||||
with ServiceGroup(__name__, get_sql_servers_operation, server_operations) as s:
|
||||
servers_operations = create_service_adapter('azure.mgmt.sql.operations.servers_operations',
|
||||
'ServersOperations')
|
||||
|
||||
with ServiceGroup(__name__, get_sql_servers_operations, servers_operations) as s:
|
||||
with s.group('sql server') as c:
|
||||
c.command('create', 'create_or_update')
|
||||
c.command('delete', 'delete', confirmation=True)
|
||||
c.command('show', 'get_by_resource_group')
|
||||
c.command('show', 'get')
|
||||
# Usages will not be included in the first batch of GA commands
|
||||
# c.command('show-usage', 'list_usages')
|
||||
c.command('list', 'list_by_resource_group')
|
||||
c.generic_update_command('update', 'get_by_resource_group', 'create_or_update',
|
||||
c.generic_update_command('update', 'get', 'create_or_update',
|
||||
custom_func_name='server_update')
|
||||
|
||||
firewall_rules_operations = create_service_adapter(
|
||||
'azure.mgmt.sql.operations.firewall_rules_operations',
|
||||
'FirewallRulesOperations')
|
||||
|
||||
with ServiceGroup(__name__, get_sql_firewall_rules_operations, firewall_rules_operations) as s:
|
||||
with s.group('sql server firewall-rule') as c:
|
||||
c.command('create', 'create_or_update_firewall_rule')
|
||||
c.command('create', 'create_or_update')
|
||||
c.custom_command('update', 'firewall_rule_update')
|
||||
c.command('delete', 'delete_firewall_rule')
|
||||
c.command('show', 'get_firewall_rule')
|
||||
c.command('list', 'list_firewall_rules')
|
||||
c.command('delete', 'delete')
|
||||
c.command('show', 'get')
|
||||
c.command('list', 'list_by_server')
|
||||
# Keeping this command hidden for now. `firewall-rule create` will explain the special
|
||||
# 0.0.0.0 rule.
|
||||
# c.custom_command('allow-all-azure-ips', 'firewall_rule_allow_all_azure_ips')
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
# --------------------------------------------------------------------------------------------
|
||||
|
||||
from ._util import (
|
||||
get_sql_servers_operation,
|
||||
get_sql_elasticpools_operations
|
||||
get_sql_servers_operations,
|
||||
get_sql_elastic_pools_operations
|
||||
)
|
||||
|
||||
from azure.cli.core.commands.client_factory import (
|
||||
|
@ -15,10 +15,11 @@ from azure.cli.core._util import CLIError
|
|||
from azure.mgmt.sql.models.sql_management_client_enums import (
|
||||
BlobAuditingPolicyState,
|
||||
CreateMode,
|
||||
DatabaseEditions,
|
||||
DatabaseEdition,
|
||||
ReplicationRole,
|
||||
SecurityAlertPolicyState,
|
||||
ServiceObjectiveName
|
||||
ServiceObjectiveName,
|
||||
StorageKeyType
|
||||
)
|
||||
from azure.mgmt.resource.resources import ResourceManagementClient
|
||||
from azure.mgmt.storage import StorageManagementClient
|
||||
|
@ -33,9 +34,9 @@ from six.moves.urllib.parse import (quote, urlparse) # pylint: disable=import-e
|
|||
|
||||
# Determines server location
|
||||
def get_server_location(server_name, resource_group_name):
|
||||
server_client = get_sql_servers_operation(None)
|
||||
server_client = get_sql_servers_operations(None)
|
||||
# pylint: disable=no-member
|
||||
return server_client.get_by_resource_group(
|
||||
return server_client.get(
|
||||
server_name=server_name,
|
||||
resource_group_name=resource_group_name).location
|
||||
|
||||
|
@ -84,7 +85,7 @@ def db_create(
|
|||
|
||||
# Verify edition
|
||||
edition = kwargs.get('edition') # kwags['edition'] throws KeyError if not in dictionary
|
||||
if edition and edition.lower() == DatabaseEditions.data_warehouse.value.lower():
|
||||
if edition and edition.lower() == DatabaseEdition.data_warehouse.value.lower():
|
||||
raise CLIError('Azure SQL Data Warehouse can be created with the command'
|
||||
' `az sql dw create`.')
|
||||
|
||||
|
@ -272,6 +273,61 @@ def db_delete_replica_link( # pylint: disable=too-many-arguments
|
|||
link_id=link.name)
|
||||
|
||||
|
||||
def db_export( # pylint: disable=too-many-arguments
|
||||
client,
|
||||
database_name,
|
||||
server_name,
|
||||
resource_group_name,
|
||||
storage_key_type,
|
||||
storage_key,
|
||||
**kwargs):
|
||||
storage_key = pad_sas_key(storage_key_type, storage_key)
|
||||
|
||||
kwargs['storage_key_type'] = storage_key_type
|
||||
kwargs['storage_key'] = storage_key
|
||||
|
||||
return client.export(
|
||||
database_name=database_name,
|
||||
server_name=server_name,
|
||||
resource_group_name=resource_group_name,
|
||||
storage_key_type=storage_key_type,
|
||||
storage_key=storage_key,
|
||||
parameters=kwargs)
|
||||
|
||||
|
||||
def db_import( # pylint: disable=too-many-arguments
|
||||
client,
|
||||
database_name,
|
||||
server_name,
|
||||
resource_group_name,
|
||||
storage_key_type,
|
||||
storage_key,
|
||||
**kwargs):
|
||||
storage_key = pad_sas_key(storage_key_type, storage_key)
|
||||
|
||||
kwargs['storage_key_type'] = storage_key_type
|
||||
kwargs['storage_key'] = storage_key
|
||||
|
||||
return client.create_import_operation(
|
||||
database_name=database_name,
|
||||
server_name=server_name,
|
||||
resource_group_name=resource_group_name,
|
||||
storage_key_type=storage_key_type,
|
||||
storage_key=storage_key,
|
||||
parameters=kwargs)
|
||||
|
||||
|
||||
def pad_sas_key(
|
||||
storage_key_type,
|
||||
storage_key):
|
||||
# Import/Export API requires that "?" precede SAS key as an argument.
|
||||
# Add ? prefix if it wasn't included.
|
||||
if storage_key_type.lower() == StorageKeyType.shared_access_key.value.lower():
|
||||
if storage_key[0] != '?':
|
||||
storage_key = '?' + storage_key
|
||||
return storage_key
|
||||
|
||||
|
||||
# Lists databases in a server or elastic pool.
|
||||
def db_list(
|
||||
client,
|
||||
|
@ -281,7 +337,7 @@ def db_list(
|
|||
|
||||
if elastic_pool_name:
|
||||
# List all databases in the elastic pool
|
||||
pool_client = get_sql_elasticpools_operations(None)
|
||||
pool_client = get_sql_elastic_pools_operations(None)
|
||||
return pool_client.list_databases(
|
||||
server_name=server_name,
|
||||
resource_group_name=resource_group_name,
|
||||
|
@ -302,7 +358,7 @@ def db_update(
|
|||
requested_service_objective_name=None):
|
||||
|
||||
# Verify edition
|
||||
if instance.edition.lower() == DatabaseEditions.data_warehouse.value.lower():
|
||||
if instance.edition.lower() == DatabaseEdition.data_warehouse.value.lower():
|
||||
raise CLIError('Azure SQL Data Warehouse can be updated with the command'
|
||||
' `az sql dw update`.')
|
||||
|
||||
|
@ -559,7 +615,7 @@ def dw_create(
|
|||
**kwargs):
|
||||
|
||||
# Set edition
|
||||
kwargs['edition'] = DatabaseEditions.data_warehouse.value
|
||||
kwargs['edition'] = DatabaseEdition.data_warehouse.value
|
||||
|
||||
# Create
|
||||
return _db_dw_create(
|
||||
|
@ -578,7 +634,7 @@ def dw_list(
|
|||
resource_group_name=resource_group_name,
|
||||
server_name=server_name,
|
||||
# OData filter to include only DW's
|
||||
filter="properties/edition eq '{}'".format(DatabaseEditions.data_warehouse.value))
|
||||
filter="properties/edition eq '{}'".format(DatabaseEdition.data_warehouse.value))
|
||||
|
||||
|
||||
# Update data warehouse. Custom update function to apply parameters to instance.
|
||||
|
@ -678,7 +734,7 @@ def firewall_rule_allow_all_azure_ips(
|
|||
# Special start/end IP that represents allowing all azure ips
|
||||
azure_ip_addr = '0.0.0.0'
|
||||
|
||||
return client.create_or_update_firewall_rule(
|
||||
return client.create_or_update(
|
||||
resource_group_name=resource_group_name,
|
||||
server_name=server_name,
|
||||
firewall_rule_name=rule_name,
|
||||
|
@ -697,13 +753,13 @@ def firewall_rule_update( # pylint: disable=too-many-arguments
|
|||
end_ip_address=None):
|
||||
|
||||
# Get existing instance
|
||||
instance = client.get_firewall_rule(
|
||||
instance = client.get(
|
||||
firewall_rule_name=firewall_rule_name,
|
||||
server_name=server_name,
|
||||
resource_group_name=resource_group_name)
|
||||
|
||||
# Send update
|
||||
return client.create_or_update_firewall_rule(
|
||||
return client.create_or_update(
|
||||
firewall_rule_name=firewall_rule_name,
|
||||
server_name=server_name,
|
||||
resource_group_name=resource_group_name,
|
||||
|
|
|
@ -89,13 +89,31 @@ helps['sql db replica delete-link'] = """
|
|||
type: command
|
||||
short-summary: Permanently stops data replication between two database replicas.
|
||||
"""
|
||||
helps['sql db restore'] = """
|
||||
helps['sql db export'] = """
|
||||
type: command
|
||||
short-summary: Creates a new database by restoring from a database backup.
|
||||
short-summary: Exports a database to a bacpac.
|
||||
examples:
|
||||
- name: Get SAS key for use in export operation
|
||||
text: az storage blob generate-sas --account-name myAccountName -c myContainer -n myBacpac.bacpac --permissions w --expiry 2018-01-01T00:00:00Z
|
||||
- name: Export bacpac using SAS key
|
||||
text: az sql db export -s myserver -n mydatabase -g mygroup -p password -u login --storage-key "?sr=b&sp=rw&se=2018-01-01T00%3A00%3A00Z&sig=mysignature&sv=2015-07-08" --storage-key-type SharedAccessKey --storage-uri https://mystorageaccount.blob.core.windows.net/bacpacs/mybacpac.bacpac
|
||||
- name: Export bacpac using storage account Key
|
||||
text: az sql db export -s myserver -n mydatabase -g mygroup -p password -u login --storage-key MYKEY== --storage-key-type StorageAccessKey --storage-uri https://mystorageaccount.blob.core.windows.net/bacpacs/mybacpac.bacpac
|
||||
"""
|
||||
helps['sql db import'] = """
|
||||
type: command
|
||||
short-summary: Imports a bacpac into an existing database.
|
||||
examples:
|
||||
- name: Get SAS key for use in import operation
|
||||
text: az storage blob generate-sas --account-name myAccountName -c myContainer -n myBacpac.bacpac --permissions r --expiry 2018-01-01T00:00:00Z
|
||||
- name: Import bacpac into an existing database using SAS key
|
||||
text: az sql db import -s myserver -n mydatabase -g mygroup -p password -u login --storage-key "?sr=b&sp=rw&se=2018-01-01T00%3A00%3A00Z&sig=mysignature&sv=2015-07-08" --storage-key-type SharedAccessKey --storage-uri https://mystorageaccount.blob.core.windows.net/bacpacs/mybacpac.bacpac
|
||||
- name: Import bacpac into an existing database using storage account key
|
||||
text: az sql db import -s myserver -n mydatabase -g mygroup -p password -u login --storage-key MYKEY== --storage-key-type StorageAccessKey --storage-uri https://mystorageaccount.blob.core.windows.net/bacpacs/mybacpac.bacpac
|
||||
"""
|
||||
helps['sql db restore'] = """
|
||||
type: command
|
||||
short-summary: Creates a new database by restoring from a database backup.
|
||||
"""
|
||||
helps['sql db threat-policy'] = """
|
||||
type: group
|
||||
|
@ -138,29 +156,29 @@ helps['sql db threat-policy update'] = """
|
|||
# short-summary: Manage database service tier advisors.
|
||||
# """
|
||||
helps['sql dw'] = """
|
||||
type: group
|
||||
short-summary: Manage data warehouses.
|
||||
"""
|
||||
type: group
|
||||
short-summary: Manage data warehouses.
|
||||
"""
|
||||
helps['sql dw create'] = """
|
||||
type: command
|
||||
short-summary: Creates a data warehouse.
|
||||
"""
|
||||
type: command
|
||||
short-summary: Creates a data warehouse.
|
||||
"""
|
||||
helps['sql dw delete'] = """
|
||||
type: command
|
||||
short-summary: Deletes a database or data warehouse.
|
||||
"""
|
||||
type: command
|
||||
short-summary: Deletes a database or data warehouse.
|
||||
"""
|
||||
helps['sql dw list'] = """
|
||||
type: command
|
||||
short-summary: Lists all data warehouses in a server.
|
||||
"""
|
||||
type: command
|
||||
short-summary: Lists all data warehouses in a server.
|
||||
"""
|
||||
helps['sql dw show'] = """
|
||||
type: command
|
||||
short-summary: Gets a database or data warehouse.
|
||||
"""
|
||||
type: command
|
||||
short-summary: Gets a database or data warehouse.
|
||||
"""
|
||||
helps['sql dw update'] = """
|
||||
type: command
|
||||
short-summary: Updates a data warehouse.
|
||||
"""
|
||||
type: command
|
||||
short-summary: Updates a data warehouse.
|
||||
"""
|
||||
helps['sql elastic-pool'] = """
|
||||
type: group
|
||||
short-summary: Manage elastic pools. An elastic pool is an allocation of CPU, IO, and memory resources. Databases inside the pool share these resources.
|
||||
|
|
|
@ -12,9 +12,9 @@ from azure.cli.core.commands.parameters import (
|
|||
ignore_type)
|
||||
from azure.mgmt.sql.models.database import Database
|
||||
from azure.mgmt.sql.models.elastic_pool import ElasticPool
|
||||
from azure.mgmt.sql.models.import_extension_request_parameters \
|
||||
import ImportExtensionRequestParameters
|
||||
from azure.mgmt.sql.models.export_request_parameters import ExportRequestParameters
|
||||
from azure.mgmt.sql.models.import_extension_request \
|
||||
import ImportExtensionRequest
|
||||
from azure.mgmt.sql.models.export_request import ExportRequest
|
||||
from azure.mgmt.sql.models.server import Server
|
||||
from azure.mgmt.sql.models.sql_management_client_enums import (
|
||||
AuthenticationType,
|
||||
|
@ -281,25 +281,27 @@ with ParametersContext(command='sql db update') as c:
|
|||
c.argument('max_size_bytes', help='The new maximum size of the database expressed in bytes.')
|
||||
|
||||
with ParametersContext(command='sql db export') as c:
|
||||
c.expand('parameters', ExportRequestParameters)
|
||||
c.expand('parameters', ExportRequest)
|
||||
c.register_alias('administrator_login', ('--admin-user', '-u'))
|
||||
c.register_alias('administrator_login_password', ('--admin-password', '-p'))
|
||||
c.argument('authentication_type', options_list=('--auth_type',),
|
||||
c.argument('authentication_type', options_list=('--auth-type',),
|
||||
**enum_choice_list(AuthenticationType))
|
||||
c.argument('storage_key_type', **enum_choice_list(StorageKeyType))
|
||||
|
||||
with ParametersContext(command='sql db import') as c:
|
||||
c.expand('parameters', ImportExtensionRequestParameters)
|
||||
c.expand('parameters', ImportExtensionRequest)
|
||||
c.register_alias('administrator_login', ('--admin-user', '-u'))
|
||||
c.register_alias('administrator_login_password', ('--admin-password', '-p'))
|
||||
c.argument('authentication_type', options_list=('--auth_type',),
|
||||
c.argument('authentication_type', options_list=('--auth-type',),
|
||||
**enum_choice_list(AuthenticationType))
|
||||
c.argument('storage_key_type', **enum_choice_list(StorageKeyType))
|
||||
|
||||
c.ignore('type')
|
||||
|
||||
# The parameter name '--name' is used for 'database_name', so we need to give a different name
|
||||
# for the import extension 'name' parameter to avoid conflicts. This parameter is actually not
|
||||
# needed, but we still need to avoid this conflict.
|
||||
c.argument('name', options_list=('--unused-extension-name',), arg_type=ignore_type)
|
||||
c.argument('name', options_list=('--not-name',), arg_type=ignore_type)
|
||||
|
||||
|
||||
#####
|
||||
|
|
|
@ -24,7 +24,7 @@ CLASSIFIERS = [
|
|||
|
||||
DEPENDENCIES = [
|
||||
'azure-cli-core',
|
||||
'azure-mgmt-sql==0.3.3',
|
||||
'azure-mgmt-sql==0.4.0',
|
||||
'azure-mgmt-storage==0.31.0',
|
||||
'six'
|
||||
]
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1018,72 +1018,132 @@ class SqlServerImportExportMgmtScenarioTest(ScenarioTest):
|
|||
admin_password = 'SecretPassword123'
|
||||
db_name = 'cliautomationdb01'
|
||||
db_name2 = 'cliautomationdb02'
|
||||
db_name3 = 'cliautomationdb03'
|
||||
blob = 'testbacpac.bacpac'
|
||||
blob2 = 'testbacpac2.bacpac'
|
||||
|
||||
container = 'bacpacs'
|
||||
|
||||
firewall_rule_1 = 'allowAllIps'
|
||||
start_ip_address_1 = '0.0.0.0'
|
||||
end_ip_address_1 = '255.255.255.255'
|
||||
|
||||
loc_long = location_long_name
|
||||
rg = resource_group
|
||||
sa = storage_account
|
||||
end_ip_address_1 = '0.0.0.0'
|
||||
|
||||
# create server firewall rule
|
||||
self.cmd('sql server firewall-rule create --name {} -g {} --server {} '
|
||||
'--start-ip-address {} --end-ip-address {}'
|
||||
.format(firewall_rule_1, rg, server,
|
||||
.format(firewall_rule_1, resource_group, server,
|
||||
start_ip_address_1, end_ip_address_1),
|
||||
checks=[
|
||||
JMESPathCheck('name', firewall_rule_1),
|
||||
JMESPathCheck('resourceGroup', rg),
|
||||
JMESPathCheck('resourceGroup', resource_group),
|
||||
JMESPathCheck('startIpAddress', start_ip_address_1),
|
||||
JMESPathCheck('endIpAddress', end_ip_address_1)])
|
||||
|
||||
# create db
|
||||
# create dbs
|
||||
self.cmd('sql db create -g {} --server {} --name {}'
|
||||
.format(rg, server, db_name),
|
||||
.format(resource_group, server, db_name),
|
||||
checks=[
|
||||
JMESPathCheck('resourceGroup', rg),
|
||||
JMESPathCheck('resourceGroup', resource_group),
|
||||
JMESPathCheck('name', db_name),
|
||||
JMESPathCheck('location', loc_long),
|
||||
JMESPathCheck('location', location_long_name),
|
||||
JMESPathCheck('elasticPoolName', None),
|
||||
JMESPathCheck('status', 'Online')])
|
||||
|
||||
self.cmd('sql db create -g {} --server {} --name {}'
|
||||
.format(rg, server, db_name2),
|
||||
.format(resource_group, server, db_name2),
|
||||
checks=[
|
||||
JMESPathCheck('resourceGroup', rg),
|
||||
JMESPathCheck('resourceGroup', resource_group),
|
||||
JMESPathCheck('name', db_name2),
|
||||
JMESPathCheck('location', loc_long),
|
||||
JMESPathCheck('location', location_long_name),
|
||||
JMESPathCheck('elasticPoolName', None),
|
||||
JMESPathCheck('status', 'Online')])
|
||||
|
||||
self.cmd('sql db create -g {} --server {} --name {}'
|
||||
.format(resource_group, server, db_name3),
|
||||
checks=[
|
||||
JMESPathCheck('resourceGroup', resource_group),
|
||||
JMESPathCheck('name', db_name3),
|
||||
JMESPathCheck('location', location_long_name),
|
||||
JMESPathCheck('elasticPoolName', None),
|
||||
JMESPathCheck('status', 'Online')])
|
||||
|
||||
# Backup to new dacpac
|
||||
# get storage account endpoint
|
||||
storage_endpoint = self.cmd('storage account show -g {} -n {}'
|
||||
' --query primaryEndpoints.blob'
|
||||
.format(rg, storage_account)).get_output_in_json()
|
||||
.format(resource_group, storage_account)).get_output_in_json()
|
||||
bacpacUri = '{}{}/{}'.format(storage_endpoint, container, blob)
|
||||
bacpacUri2 = '{}{}/{}'.format(storage_endpoint, container, blob2)
|
||||
|
||||
# get storage account key
|
||||
key = self.cmd('storage account keys list -g {} -n {} --query [0].value'
|
||||
.format(rg, storage_account)).get_output_in_json()
|
||||
storageKey = self.cmd('storage account keys list -g {} -n {} --query [0].value'
|
||||
.format(resource_group, storage_account)).get_output_in_json()
|
||||
|
||||
# Set Expiry
|
||||
expiryString = '9999-12-25T00:00:00Z'
|
||||
|
||||
# Get sas key
|
||||
sasKey = self.cmd('storage blob generate-sas --account-name {} -c {} -n {} --permissions rw --expiry {}'.format(
|
||||
storage_account, container, blob2, expiryString)).get_output_in_json()
|
||||
|
||||
# create storage account blob container
|
||||
self.cmd('storage container create -n {} --account-name {} --account-key {} '
|
||||
.format(container, sa, key),
|
||||
.format(container, storage_account, storageKey),
|
||||
checks=[
|
||||
JMESPathCheck('created', True)])
|
||||
|
||||
# export database to blob container
|
||||
# export database to blob container using both keys
|
||||
self.cmd('sql db export -s {} -n {} -g {} -p {} -u {}'
|
||||
' --storage-key {} --storage-key-type StorageAccessKey'
|
||||
' --storage-uri {}{}/testbacpac.bacpac'
|
||||
.format(server, db_name, rg, admin_password, admin_login, key,
|
||||
storage_endpoint, container))
|
||||
' --storage-uri {}'
|
||||
.format(server, db_name, resource_group, admin_password, admin_login, storageKey,
|
||||
bacpacUri),
|
||||
checks=[
|
||||
JMESPathCheck('blobUri', bacpacUri),
|
||||
JMESPathCheck('databaseName', db_name),
|
||||
JMESPathCheck('requestType', 'Export'),
|
||||
JMESPathCheck('resourceGroup', resource_group),
|
||||
JMESPathCheck('serverName', server),
|
||||
JMESPathCheck('status', 'Completed')])
|
||||
|
||||
# import bacpac to second database
|
||||
self.cmd('sql db export -s {} -n {} -g {} -p {} -u {}'
|
||||
' --storage-key {} --storage-key-type SharedAccessKey'
|
||||
' --storage-uri {}'
|
||||
.format(server, db_name, resource_group, admin_password, admin_login, sasKey,
|
||||
bacpacUri2),
|
||||
checks=[
|
||||
JMESPathCheck('blobUri', bacpacUri2),
|
||||
JMESPathCheck('databaseName', db_name),
|
||||
JMESPathCheck('requestType', 'Export'),
|
||||
JMESPathCheck('resourceGroup', resource_group),
|
||||
JMESPathCheck('serverName', server),
|
||||
JMESPathCheck('status', 'Completed')])
|
||||
|
||||
# import bacpac to second database using Storage Key
|
||||
self.cmd('sql db import -s {} -n {} -g {} -p {} -u {}'
|
||||
' --storage-key {} --storage-key-type StorageAccessKey'
|
||||
' --storage-uri {}{}/testbacpac.bacpac'
|
||||
.format(server, db_name2, rg, admin_password, admin_login, key,
|
||||
storage_endpoint, container))
|
||||
' --storage-uri {}'
|
||||
.format(server, db_name2, resource_group, admin_password, admin_login, storageKey,
|
||||
bacpacUri),
|
||||
checks=[
|
||||
JMESPathCheck('blobUri', bacpacUri),
|
||||
JMESPathCheck('databaseName', db_name2),
|
||||
JMESPathCheck('name', 'import'),
|
||||
JMESPathCheck('requestType', 'Import'),
|
||||
JMESPathCheck('resourceGroup', resource_group),
|
||||
JMESPathCheck('serverName', server),
|
||||
JMESPathCheck('status', 'Completed')])
|
||||
|
||||
# import bacpac to third database using SAS key
|
||||
self.cmd('sql db import -s {} -n {} -g {} -p {} -u {}'
|
||||
' --storage-key {} --storage-key-type SharedAccessKey'
|
||||
' --storage-uri {}'
|
||||
.format(server, db_name3, resource_group, admin_password, admin_login, sasKey,
|
||||
bacpacUri2),
|
||||
checks=[
|
||||
JMESPathCheck('blobUri', bacpacUri2),
|
||||
JMESPathCheck('databaseName', db_name3),
|
||||
JMESPathCheck('name', 'import'),
|
||||
JMESPathCheck('requestType', 'Import'),
|
||||
JMESPathCheck('resourceGroup', resource_group),
|
||||
JMESPathCheck('serverName', server),
|
||||
JMESPathCheck('status', 'Completed')])
|
||||
|
|
Загрузка…
Ссылка в новой задаче