Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Georestore for MySQL and PostgreSQL. #117

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions src/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,9 @@
],
"rdbms": [
{
"filename": "rdbms-0.0.3-py2.py3-none-any.whl",
"sha256Digest": "3125d386c56599dd364534988ebc7cac35d79de58bb6e89af04bc48569da9522",
"downloadUrl": "https://prodrdbmsclipackages.blob.core.windows.net/cliextensions/rdbms-0.0.3-py2.py3-none-any.whl",
"filename": "rdbms-0.0.4-py2.py3-none-any.whl",
"sha256Digest": "6e0f6d39c98c3a39c9664ed54576b2e0f1cd23b412b137f19815a276e7510350",
"downloadUrl": "https://prodrdbmsclipackages.blob.core.windows.net/cliextensions/rdbms-0.0.4-py2.py3-none-any.whl",
"metadata": {
"classifiers": [
"Development Status :: 4 - Beta",
Expand Down Expand Up @@ -454,7 +454,7 @@
"metadata_version": "2.0",
"name": "rdbms",
"summary": "An Azure CLI Extension to manage Azure MySQL and Azure PostgreSQL resources",
"version": "0.0.3"
"version": "0.0.4"
}
}
],
Expand Down
159 changes: 7 additions & 152 deletions src/rdbms/azext_rdbms/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,7 @@


def add_helps(command_group, server_type):
helps['{}'.format(command_group)] = """
type: group
short-summary: Manage Azure Database for {} servers.
""".format(server_type)
helps['{} server'.format(command_group)] = """
type: group
short-summary: Manage {} servers.
""".format(server_type)
helps['{} server create'.format(command_group)] = """
type: command
short-summary: Create a server.
examples:
- name: Create a {0} server with only required paramaters in North Europe.
Expand All @@ -31,153 +22,17 @@ def add_helps(command_group, server_type):
--sku-name B_Gen4_2 --ssl-enforcement Disabled \\
--storage-size 51200 --tags "key=value" --version {{server-version}}
""".format(server_type, command_group)
helps['{} server restore'.format(command_group)] = """
helps['{} server georestore'.format(command_group)] = """
type: command
short-summary: Restore a server from backup.
short-summary: Georestore a server from backup.
examples:
- name: Restore 'testsvr' as 'testsvrnew'.
text: az {0} server restore -g testgroup -n testsvrnew --source-server testsvr --restore-point-in-time "2017-06-15T13:10:00Z"
- name: Restore 'testsvr2' to 'testsvrnew', where 'testsvrnew' is in a different resource group than the backup.
- name: Georestore 'testsvr' as 'testsvrnew'.
text: az {0} server georestore -g testgroup -n testsvrnew --source-server testsvr -l westus2"
- name: Georestore 'testsvr2' to 'testsvrnew', where 'testsvrnew' is in the same resource group as the original server but in a different location.
text: |
az {0} server restore -g testgroup -n testsvrnew \\
-s "/subscriptions/${{SubID}}/resourceGroups/${{ResourceGroup}}/providers/Microsoft.DBfor{1}/servers/testsvr2" \\
--restore-point-in-time "2017-06-15T13:10:00Z"
az {0} server georestore -g testgroup -n testsvrnew \\
-s "/subscriptions/${{SubID}}/resourceGroups/${{ResourceGroup}}/providers/Microsoft.DBfor{1}/servers/testsvr2" -l westus2 --sku-name GP_Gen5_2 "
""".format(command_group, server_type)
helps['{} server update'.format(command_group)] = """
type: command
short-summary: Update a server.
examples:
- name: Update a server's vcore to 2.
text: az {0} server update -g testgroup -n testsvrnew --vcore 2
- name: Update a server's tags.
text: az {0} server update -g testgroup -n testsvrnew --tags "k1=v1" "k2=v2"
""".format(command_group)
helps['{} server delete'.format(command_group)] = """
type: command
short-summary: Delete a server.
"""
helps['{} server show'.format(command_group)] = """
type: command
short-summary: Get the details of a server.
"""
helps['{} server list'.format(command_group)] = """
type: command
short-summary: List available servers.
examples:
- name: List all {0} servers in a subscription.
text: az {1} server list
- name: List all {0} servers in a resource group.
text: az {1} server list -g testgroup
""".format(server_type, command_group)
helps['{} server firewall-rule'.format(command_group)] = """
type: group
short-summary: Manage firewall rules for a server.
"""
helps['{} server firewall-rule create'.format(command_group)] = """
type: command
short-summary: Create a new firewall rule for a server.
examples:
- name: Create a firewall rule allowing all connections from all IP addresses.
text: az {} server firewall-rule create -g testgroup -s testsvr -n allowall --start-ip-address 0.0.0.0 --end-ip-address 255.255.255.255
""".format(command_group)
helps['{} server firewall-rule update'.format(command_group)] = """
type: command
short-summary: Update a firewall rule.
examples:
- name: Update a firewall rule's start IP address.
text: az {0} server firewall-rule update -g testgroup -s testsvr -n allowall --start-ip-address 0.0.0.1
- name: Update a firewall rule's start and end IP address.
text: az {0} server firewall-rule update -g testgroup -s testsvr -n allowall --start-ip-address 0.0.0.1 --end-ip-address 255.255.255.254
""".format(command_group)
helps['{} server firewall-rule delete'.format(command_group)] = """
type: command
short-summary: Delete a firewall rule.
"""
helps['{} server firewall-rule show'.format(command_group)] = """
type: command
short-summary: Get the details of a firewall rule.
"""
helps['{} server firewall-rule list'.format(command_group)] = """
type: command
short-summary: List all firewall rules for a server.
"""
helps['{} server configuration'.format(command_group)] = """
type: group
short-summary: Manage configuration values for a server.
"""
helps['{} server configuration set'.format(command_group)] = """
type: command
short-summary: Update the configuration of a server.
examples:
- name: Set a new configuration value.
text: az {0} server configuration set -g testgroup -s testsvr -n {{config_name}} --value {{config_value}}
- name: Set a configuration value to its default.
text: az {0} server configuration set -g testgroup -s testsvr -n {{config_name}}
""".format(command_group)
helps['{} server configuration show'.format(command_group)] = """
type: command
short-summary: Get the configuration for a server."
"""
helps['{} server configuration list'.format(command_group)] = """
type: command
short-summary: List the configuration values for a server.
"""
helps['{} server-logs'.format(command_group)] = """
type: group
short-summary: Manage server logs.
"""
helps['{} server-logs list'.format(command_group)] = """
type: command
short-summary: List log files for a server.
examples:
- name: List log files for 'testsvr' modified in the last 72 hours (default value).
text: az {0} server-logs list -g testgroup -s testsvr
- name: List log files for 'testsvr' modified in the last 10 hours.
text: az {0} server-logs list -g testgroup -s testsvr --file-last-written 10
- name: List log files for 'testsvr' less than 30Kb in size.
text: az {0} server-logs list -g testgroup -s testsvr --max-file-size 30
""".format(command_group)
helps['{} server-logs download'.format(command_group)] = """
type: command
short-summary: Download log files.
examples:
- name: Download log files f1 and f2 to the current directory from the server 'testsvr'.
text: az {} server-logs download -g testgroup -s testsvr -n f1.log f2.log
""".format(command_group)
helps['{} db'.format(command_group)] = """
type: group
short-summary: Manage {0} databases on a server.
""".format(server_type)
helps['{} db create'.format(command_group)] = """
type: command
short-summary: Create a {0} database.
examples:
- name: Create database 'testdb' in the server 'testsvr' with the default parameters.
text: az {1} db create -g testgroup -s testsvr -n testdb
- name: Create database 'testdb' in server 'testsvr' with a given character set and collation rules.
text: az {1} db create -g testgroup -s testsvr -n testdb --charset {{valid_charset}} --collation {{valid_collation}}
""".format(server_type, command_group)
helps['{} db delete'.format(command_group)] = """
type: command
short-summary: Delete a database.
examples:
- name: Delete database 'testdb' in the server 'testsvr'.
text: az {0} db delete -g testgroup -s testsvr -n testdb
""".format(command_group)
helps['{} db show'.format(command_group)] = """
type: command
short-summary: Show the details of a database.
examples:
- name: Show database 'testdb' in the server 'testsvr'.
text: az {0} db show -g testgroup -s testsvr -n testdb
""".format(command_group)
helps['{} db list'.format(command_group)] = """
type: command
short-summary: List the databases for a server.
examples:
- name: List databases in the server 'testsvr'.
text: az {0} db list -g testgroup -s testsvr
""".format(command_group)


add_helps("mysql", "MySQL")
Expand Down
75 changes: 21 additions & 54 deletions src/rdbms/azext_rdbms/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
# pylint: disable=line-too-long

from azure.cli.core.commands.parameters import get_resource_name_completion_list, tags_type, get_location_type, get_enum_type # pylint: disable=line-too-long
from azext_rdbms import mysql, postgresql
from azext_rdbms.validators import configuration_value_validator


def load_arguments(self, _): # pylint: disable=too-many-statements
Expand All @@ -17,39 +15,31 @@ def load_arguments(self, _): # pylint: disable=too-many-statements
'postgres': get_resource_name_completion_list('Microsoft.DBForPostgreSQL/servers')
}

def _complex_params(command_group, engine):
def _complex_params(command_group):
with self.argument_context('{} server create'.format(command_group)) as c:
c.expand('sku', engine.models.Sku)
c.ignore('size', 'family', 'capacity', 'tier')
c.expand('storage_profile', engine.models.storage_profile.StorageProfile)
c.expand('properties', engine.models.ServerPropertiesForDefaultCreate)
c.argument('sku_name', options_list=['--sku-name'], required=True, help='The name of the sku, typically, tier + family + cores, e.g. B_Gen4_1, GP_Gen5_8.')

c.argument('backup_retention', type=int, options_list=['--backup-retention'], help='The number of days a backup is retained.')
c.argument('geo_redundant_backup', options_list=['--geo-redundant-backup'], help='Enable Geo-redundant or not for server backup.')
c.argument('storage_size', options_list=['--storage-size'], type=int, help='The max storage size of the server. Unit is megabytes.')

c.argument('administrator_login', required=True, arg_group='Authentication')
c.argument('administrator_login_password', arg_group='Authentication')

c.expand('parameters', engine.models.ServerForCreate)
c.argument('location', arg_type=get_location_type(self.cli_ctx), required=False)
c.argument('version', help='Server version')

with self.argument_context('{} server restore'. format(command_group)) as c:
c.ignore('sku', 'storage_profile')

c.expand('properties', engine.models.ServerPropertiesForRestore)
c.ignore('version', 'ssl_enforcement', 'storage_mb')

c.expand('parameters', engine.models.ServerForCreate)
c.ignore('tags', 'location')

c.argument('source_server_id', options_list=['--source-server', '-s'], help='The name or ID of the source server to restore from.')
c.argument('restore_point_in_time', help='The point in time to restore from (ISO8601 format), e.g., 2017-04-26T02:10:00+08:00')

with self.argument_context('{} server configuration set'.format(command_group)) as c:
c.argument('value', help='Value of the configuration. If not provided, configuration value will be set to default.', validator=configuration_value_validator)
c.ignore('source')
with self.argument_context('{} server georestore'. format(command_group)) as c:
c.argument('location', arg_type=get_location_type(self.cli_ctx), required=True)
c.argument('sku_name', options_list=['--sku-name'], required=False, help='The name of the sku, typically, tier + family + cores, e.g. B_Gen4_1, GP_Gen5_8.')
c.argument('source_server', options_list=['--source-server', '-s'], required=True, help='The name or ID of the source server to restore from.')
c.argument('backup_retention', options_list=['--backup-retention'], type=int, help='The max days of retention, unit is days.')

with self.argument_context('{} server wait'.format(command_group)) as c:
c.ignore('created', 'deleted', 'updated')

_complex_params('mysql', mysql)
_complex_params('postgres', postgresql)
_complex_params('mysql')
_complex_params('postgres')

for scope in ['mysql', 'postgres']:
with self.argument_context(scope) as c:
Expand All @@ -62,34 +52,11 @@ def _complex_params(command_group, engine):

c.argument('server_name', options_list=['--name', '-n'], id_part='name', help='Name of the server.')
c.argument('administrator_login', options_list=['--admin-user', '-u'])
c.argument('administrator_login_password', options_list=['--admin-password', '-p'], required=False, help='The password of the administrator login.')
c.argument('administrator_login_password', options_list=['--admin-password', '-p'], help='The password of the administrator login.')
c.argument('ssl_enforcement', arg_type=get_enum_type(['Enabled', 'Disabled']), options_list=['--ssl-enforcement'], help='Enable ssl enforcement or not when connect to server.')
c.argument('tier', arg_type=get_enum_type(['Basic', 'GeneralPurpose', 'MemoryOptimized']), required=False, options_list=['--performance-tier'], help='The performance tier of the server.')
c.argument('capacity', options_list=['--vcore'], type=int, required=False, help='Number of vcore.')
c.argument('family', options_list=['--family'], arg_type=get_enum_type(['Gen4', 'Gen5']), required=False, help='Hardware generation.')
c.argument('storage_mb', options_list=['--storage-size'], type=int, help='The max storage size of the server, unit is MB.')
c.argument('backup_retention_days', options_list=['--backup-retention'], type=int, help='The max days of retention, unit is days.')
c.argument('tier', arg_type=get_enum_type(['Basic', 'GeneralPurpose', 'MemoryOptimized']), options_list=['--performance-tier'], help='The performance tier of the server.')
c.argument('capacity', options_list=['--vcore'], type=int, help='Number of vcore.')
c.argument('family', options_list=['--family'], arg_type=get_enum_type(['Gen4', 'Gen5']), help='Hardware generation.')
c.argument('storage_mb', options_list=['--storage-size'], type=int, help='The max storage size of the server. Unit is megabytes.')
c.argument('backup_retention_days', options_list=['--backup-retention'], type=int, help='The number of days a backup is retained.')
c.argument('tags', tags_type)

for scope in ['mysql server-logs', 'postgres server-logs']:
with self.argument_context(scope) as c:
c.argument('file_name', options_list=['--name', '-n'], nargs='+', help='Space separated list of log filenames on the server to download.')
c.argument('max_file_size', type=int, help='The file size limitation to filter files.')
c.argument('file_last_written', type=int, help='Integer in hours to indicate file last modify time, default value is 72.')
c.argument('filename_contains', help='The pattern that file name should match.')

for scope in ['mysql db', 'postgres db']:
with self.argument_context(scope) as c:
c.argument('database_name', options_list=['--name', '-n'])

for scope in ['mysql server firewall-rule', 'postgres server firewall-rule']:
with self.argument_context(scope) as c:
c.argument('server_name', options_list=['--server-name', '-s'])
c.argument('firewall_rule_name', options_list=['--name', '-n'], id_part='child_name_1', help='The name of the firewall rule.')
c.argument('start_ip_address', options_list=['--start-ip-address'], help='The start IP address of the firewall rule. Must be IPv4 format. Use value \'0.0.0.0\' to represent all Azure-internal IP addresses.')
c.argument('end_ip_address', options_list=['--end-ip-address'], help='The end IP address of the firewall rule. Must be IPv4 format. Use value \'0.0.0.0\' to represent all Azure-internal IP addresses.')

for scope in ['mysql server configuration', 'postgres server configuration']:
with self.argument_context(scope) as c:
c.argument('server_name', options_list=['--server-name', '-s'])
c.argument('configuration_name', id_part='child_name_1', options_list=['--name', '-n'])
Loading