Skip to content
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
bf63231
flexible server migration
DaeunYim Feb 7, 2021
a018b7d
single server migration draft
DaeunYim Feb 8, 2021
65fe403
style fixed
DaeunYim Feb 8, 2021
5abef3c
allow large reponse for proxy test
DaeunYim Feb 8, 2021
8b16281
singles server test fixed
DaeunYim Feb 9, 2021
75cd854
minor bugs fixed
DaeunYim Feb 9, 2021
822c738
linter and style issues fixed
DaeunYim Feb 9, 2021
dfe3896
config files added
DaeunYim Feb 10, 2021
bdd876c
empty commit
DaeunYim Feb 10, 2021
7a144d7
empty commit
DaeunYim Feb 18, 2021
ecd6dd2
pulled dev repo
DaeunYim Mar 2, 2021
6d83a71
pulled from dev
DaeunYim Mar 3, 2021
221f2e4
fix recording files for the migration code
DaeunYim Mar 3, 2021
f037cac
fixed mariadb failing test case
DaeunYim Mar 3, 2021
8acc000
fix for failing test cases
DaeunYim Mar 4, 2021
8fd0fa0
fixed typo
DaeunYim Mar 4, 2021
0c25766
Merge branch 'dev' of https://github.com/Azure/azure-cli into python-…
DaeunYim Mar 5, 2021
fdce3c9
change datetime function to accomodate python 3.6
DaeunYim Mar 6, 2021
cc30375
takes care of two different time input
DaeunYim Mar 6, 2021
ab1eb2e
style fixed
DaeunYim Mar 6, 2021
2154e3a
restore source parameter added
DaeunYim Mar 9, 2021
7486023
bug fix auth, LRO polling commands, object create by dict
DaeunYim Mar 10, 2021
16aa866
Merge branch 'python-sdk-migration-2' of https://github.com/DaeunYim/…
DaeunYim Mar 10, 2021
dfe33e0
restore reverted to no source parameters
DaeunYim Mar 10, 2021
62d0d4c
db for pg
DaeunYim Mar 10, 2021
d317139
added pg db tests
DaeunYim Mar 10, 2021
dc9e44c
help text updated and recording files updated with the database change
DaeunYim Mar 11, 2021
0ef1240
empty commit
DaeunYim Mar 11, 2021
98b9265
Merge branch 'dev' into python-sdk-migration-2
DaeunYim Mar 11, 2021
e85714d
empty commit
DaeunYim Mar 11, 2021
f2e589f
Merge branch 'dev' into s184
DaeunYim Mar 11, 2021
5477413
revert resource module
DaeunYim Mar 11, 2021
61ce4e1
Merge branch 's184' of https://github.com/DaeunYim/azure-cli into s184
DaeunYim Mar 11, 2021
3d71790
id = child name fix
DaeunYim Mar 12, 2021
bb840b3
Merge branch 'python-sdk-migration-2' of https://github.com/DaeunYim/…
DaeunYim Mar 12, 2021
45703ac
Merge branch 'dev' of https://github.com/Azure/azure-cli into python-…
DaeunYim Mar 15, 2021
945de4d
network module test failure fixed
DaeunYim Mar 15, 2021
415d161
pulled migration branch
DaeunYim Mar 15, 2021
1953b87
pulled merged sdk migration
DaeunYim Mar 16, 2021
11cc8ea
remove and fix rdbms params file
DaeunYim Mar 16, 2021
52feb43
fix typo
DaeunYim Mar 17, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ def cf_postgres_check_resource_availability(cli_ctx, _):
return get_postgresql_flexible_management_client(cli_ctx).check_name_availability


def cf_postgres_flexible_db(cli_ctx, _):
return get_postgresql_flexible_management_client(cli_ctx).databases


def resource_client_factory(cli_ctx, **_):
return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
# --------------------------------------------------------------------------------------------

# pylint: disable=unused-argument, line-too-long

import datetime as dt
from datetime import datetime
import random
from knack.log import get_logger
from azure.core.paging import ItemPaged

from azure.cli.core.commands import LongRunningOperation, _is_poller
from azure.cli.core.util import CLIError
from azure.cli.core.azclierror import ValidationError
from azure.mgmt.resource.resources.models import ResourceGroup
from ._client_factory import resource_client_factory, cf_mysql_flexible_location_capabilities, cf_postgres_flexible_location_capabilities
from .flexible_server_custom_common import firewall_rule_create_func
Expand Down Expand Up @@ -78,7 +79,6 @@ def generate_password(administrator_login_password):


def create_firewall_rule(db_context, cmd, resource_group_name, server_name, start_ip, end_ip):
from datetime import datetime
# allow access to azure ip addresses
cf_firewall, logging_name = db_context.cf_firewall, db_context.logging_name # NOQA pylint: disable=unused-variable
now = datetime.now()
Expand Down Expand Up @@ -294,5 +294,14 @@ def _map_maintenance_window(day_of_week):


def get_current_time():
import datetime
return datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc, microsecond=0).isoformat()
return datetime.utcnow().replace(tzinfo=dt.timezone.utc, microsecond=0).isoformat()


def change_str_to_datetime(date_str):
for fmt in ("%Y-%m-%dT%H:%M:%S+00:00", "%Y-%m-%dT%H:%M:%S.%f+00:00"):
try:
return datetime.strptime(date_str, fmt)
except ValueError:
pass

raise ValidationError("The format of restore time should be %Y-%m-%dT%H:%M:%S+00:00")
2 changes: 1 addition & 1 deletion src/azure-cli/azure/cli/command_modules/rdbms/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@
az postgres server create -l northeurope -g testgroup -n testsvr -u username -p password \\
--sku-name B_Gen5_1 --ssl-enforcement Enabled --minimal-tls-version TLS1_0 --public-network-access Disabled \\
--backup-retention 10 --geo-redundant-backup Enabled --storage-size 51200 \\
--tags "key=value" --version 11.0
--tags "key=value" --version 11
"""

helps['postgres server delete'] = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,33 @@
- name: Create a MySQL flexible server with default params ( resource group, location, servername, username, password ) with public access without any firewall rules.
text: |
az mysql flexible-server create --public-access none
- name: Create a MySQL flexible server with public access and add client IP address to have access to the server
text: |
az mysql flexible-server create --public-access <my_client_ip>
- name: Create a MySQL flexible server with public access and add the range of IP address to have access to this server
text: |
az mysql flexible-server create --public-access <start_ip_address-end_ip_address>
- name: Create a MySQL flexible server with public access and allow applications from Azure IP addresses to connect to your flexible server
text: |
az mysql flexible-server create --public-access 0.0.0.0
- name: Create a MySQL flexible server with specified SKU and storage, using defaults from local context.
text: |
az mysql flexible-server create --name testServer --admin-password password
- name: Create a MySQL flexible server using already existing virtual network and subnet. If provided virtual network and subnet does not exists then virtual network and subnet with default address prefix will be created.
text: |
az mysql flexible-server create --vnet myVnet --subnet mySubnet
- name: Create a MySQL flexible server using already existing virtual network, subnet, and using the subnet ID. The provided subnet should not have any other resource deployed in it and this subnet will be delegated to Microsoft.DBforMySQL/flexibleServers, if not already delegated.
text: |
az mysql flexible-server create --subnet /subscriptions/{SubID}/resourceGroups/{ResourceGroup}/providers/Microsoft.Network/virtualNetworks/{VNetName}/subnets/{SubnetName}
- name: Create a MySQL flexible server using new virtual network, subnet with non-default address prefix.
text: |
az mysql flexible-server create --vnet myVnet --address-prefixes 10.0.0.0/24 --subnet mySubnet --subnet-prefixes 10.0.0.0/24
- name: Create a MySQL flexible server with parameters set.
text: |
az mysql flexible-server create --location northeurope --resource-group testGroup --name testServer --admin-user username \\
--admin-password password --sku-name Standard_B1ms --tier GeneralPurpose --public-access 0.0.0.0 \\
--storage-size 32 --tags "key=value" --version 5.7
az mysql flexible-server create --location northeurope --resource-group testGroup \\
--name testServer --admin-user username --admin-password password \\
--sku-name Standard-B1ms --tier Burstable --public-access 0.0.0.0 --storage-size 32 \\
--tags "key=value" --version 5.7
"""

helps['mysql flexible-server db'] = """
Expand All @@ -47,7 +66,7 @@
- name: Create database 'testDatabase' in the flexible server 'testServer' with the default parameters.
text: az mysql flexible-server db create --resource-group testGroup --server-name testServer --database-name testDatabase
- name: Create database 'testDatabase' in the flexible server 'testServer' with a given character set and collation rules.
text: az mysql flexible-server db create --resource-group testGroup --server-name testServer --database-name testDatabase//
text: az mysql flexible-server db create --resource-group testGroup --server-name testServer --database-name testDatabase \\
--charset validCharset --collation validCollation
"""

Expand Down Expand Up @@ -132,10 +151,10 @@
short-summary: Update a firewall rule.
examples:
- name: Update a firewall rule's start IP address.
text: az mysql flexible-server firewall-rule update --resource-group testGroup --name testServer
text: az mysql flexible-server firewall-rule update --resource-group testGroup --name testServer \\
--rule-name allowiprange --start-ip-address 107.46.14.1
- name: Update a firewall rule's start and end IP address.
text: az mysql flexible-server firewall-rule update --resource-group testGroup --name testServer
text: az mysql flexible-server firewall-rule update --resource-group testGroup --name testServer \\
--rule-name allowiprange --start-ip-address 107.46.14.2 --end-ip-address 107.46.14.218
"""

Expand Down Expand Up @@ -233,8 +252,8 @@
- name: Restore 'testServer2' to 'testServerNew', where 'testServerNew' is in a different resource group from 'testServer2'.
text: |
az mysql flexible-server restore --resource-group testGroup --name testServerNew \\
--source-server "/subscriptions/${SubID}/resourceGroups/${ResourceGroup}/providers/Microsoft.DBforMySQL/servers/testServer2" \\
--restore-time "2017-06-15T13:10:00Z"
--source-server "/subscriptions/${SubID}/resourceGroups/${ResourceGroup}/providers/Microsoft.DBforMySQL/servers/testServer2" \\
--restore-time "2017-06-15T13:10:00Z"
"""

helps['mysql flexible-server show'] = """
Expand Down
70 changes: 64 additions & 6 deletions src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,33 @@
- name: Create a PostgreSQL flexible server with default params ( resource group, location, servername, username, password ) with public access without any firewall rules.
text: |
az postgres flexible-server create --public-access none

- name: Create a PostgreSQL flexible server with public access and add client IP address to have access to the server
text: |
az postgres flexible-server create --public-access <my_client_ip>
- name: Create a PostgreSQL flexible server with public access and add the range of IP address to have access to this server
text: |
az postgres flexible-server create --public-access <start_ip_address-end_ip_address>
- name: Create a PostgreSQL flexible server with public access and allow applications from Azure IP addresses to connect to your flexible server
text: |
az postgres flexible-server create --public-access 0.0.0.0
- name: Create a PostgreSQL flexible server with specified SKU and storage, using defaults from local context.
text: |
az postgres flexible-server create --name testServer --admin-password password
- name: Create a PostgreSQL flexible server using already existing virtual network and subnet. If provided virtual network and subnet does not exists then virtual network and subnet with default address prefix will be created.
text: |
az postgres flexible-server create --vnet myVnet --subnet mySubnet
- name: Create a PostgreSQL flexible server using already existing virtual network, subnet, and using the subnet ID. The provided subnet should not have any other resource deployed in it and this subnet will be delegated to Microsoft.DBforMySQL/flexibleServers, if not already delegated.
text: |
az postgres flexible-server create --subnet /subscriptions/{SubID}/resourceGroups/{ResourceGroup}/providers/Microsoft.Network/virtualNetworks/{VNetName}/subnets/{SubnetName}
- name: Create a PostgreSQL flexible server using new virtual network, subnet with non-default address prefix.
text: |
az postgres flexible-server create --vnet myVnet --address-prefixes 10.0.0.0/24 --subnet mySubnet --subnet-prefixes 10.0.0.0/24
- name: Create a PostgreSQL flexible server with parameters set.
text: |
az postgres flexible-server create --location northeurope --resource-group testGroup --name testServer --admin-user username \\
--admin-password password --sku-name Standard_D4s_v3 --tier GeneralPurpose --public-access 0.0.0.0 \\
--storage-size 512 --tags "key=value" --version 12
az postgres flexible-server create --location northeurope --resource-group testGroup \\
--name testServer --admin-user username --admin-password password \\
--sku-name Standard_D4s_v3 --tier GeneralPurpose --public-access 0.0.0.0 \\
--storage-size 512 --tags "key=value" --version 12
"""

helps['postgres flexible-server delete'] = """
Expand All @@ -50,6 +68,46 @@
text: az postgres flexible-server delete --resource-group testGroup --name testServer --yes
"""

helps['postgres flexible-server db'] = """
type: group
short-summary: Manage PostgreSQL databases on a flexible server.
"""

helps['postgres flexible-server db create'] = """
type: command
short-summary: Create a PostgreSQL database on a flexible server.
examples:
- name: Create database 'testDatabase' in the flexible server 'testServer' with the default parameters.
text: az postgres flexible-server db create --resource-group testGroup --server-name testServer --database-name testDatabase
- name: Create database 'testDatabase' in the flexible server 'testServer' with a given character set and collation rules.
text: az postgres flexible-server db create --resource-group testGroup --server-name testServer --database-name testDatabase \\
--charset validCharset --collation validCollation
"""

helps['postgres flexible-server db delete'] = """
type: command
short-summary: Delete a database on a flexible server.
examples:
- name: Delete database 'testDatabase' in the flexible server 'testServer'.
text: az postgres flexible-server db delete --resource-group testGroup --server-name testServer --database-name testDatabase
"""

helps['postgres flexible-server db list'] = """
type: command
short-summary: List the databases for a flexible server.
examples:
- name: List databases in the flexible server 'testServer'.
text: az postgres flexible-server db list --resource-group testGroup --server-name testServer
"""

helps['postgres flexible-server db show'] = """
type: command
short-summary: Show the details of a database.
examples:
- name: Show database 'testDatabase' in the server 'testServer'.
text: az postgres flexible-server db show --resource-group testGroup --server-name testServer --database-name testDatabase
"""

helps['postgres flexible-server firewall-rule'] = """
type: group
short-summary: Manage firewall rules for a server.
Expand Down Expand Up @@ -167,8 +225,8 @@
- name: Restore 'testServer2' to 'testServerNew', where 'testServerNew' is in a different resource group from 'testServer2'.
text: |
az postgres flexible-server restore --resource-group testGroup --name testServerNew \\
--source-server "/subscriptions/${SubID}/resourceGroups/${ResourceGroup}/providers/Microsoft.DBforPostgreSQL/servers/testServer2" \\
--restore-time "2017-06-15T13:10:00Z"
--source-server "/subscriptions/${SubID}/resourceGroups/${ResourceGroup}/providers/Microsoft.DBforPostgreSQL/servers/testServer2" \\
--restore-time "2017-06-15T13:10:00Z"
"""

helps['postgres flexible-server show'] = """
Expand Down
38 changes: 20 additions & 18 deletions src/azure-cli/azure/cli/command_modules/rdbms/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def _flexible_server_params(command_group):
arg_group='Authentication')
c.argument('tags', tags_type)
c.argument('public_access', options_list=['--public-access'],
help='Determines the public access. Enter single or range of IP addresses to be included in the allowed list of IPs. IP address ranges must be dash-separated and not contain any spaces. Specifying 0.0.0.0 allows public access from any resources deployed within Azure to access your server. Specifying no IP address sets the server in public access mode but does not create a firewall rule. ',
help='Determines the public access. Enter single or range of IP addresses to be included in the allowed list of IPs. IP address ranges must be dash-separated and not contain any spaces. Specifying 0.0.0.0 allows public access from any resources deployed within Azure to access your server. Setting it to "None" sets the server in public access mode but does not create a firewall rule. ',
validator=public_access_validator)
c.argument('high_availability', default="Disabled", options_list=['--high-availability'], help='Enable or disable high availability feature. Default value is Disabled.')
c.argument('assign_identity', options_list=['--assign-identity'],
Expand Down Expand Up @@ -421,23 +421,25 @@ def _flexible_server_params(command_group):
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. ')

# db
if command_group == "mysql":
with self.argument_context('{} flexible-server db'.format(command_group)) as c:
c.argument('server_name', options_list=['--server-name', '-s'], help='Name of the server.')
c.argument('database_name', id_part='child_name_1', arg_type=database_name_arg_type, options_list=['--database-name', '-d'], help='The name of the database.')

with self.argument_context('{} flexible-server db create'.format(command_group)) as c:
c.argument('charset', options_list=['--charset'], help='The charset of the database')
c.argument('collation', options_list=['--collation'], help='The collation of the database')
c.argument('database_name', arg_type=database_name_setter_arg_type, options_list=['--database-name', '-d'], help='The name of the database.')

with self.argument_context('{} flexible-server db list'.format(command_group)) as c:
c.argument('server_name', id_part=None, options_list=['--server-name', '-s'], arg_type=server_name_arg_type)
c.argument('database_name', id_part=None, arg_type=database_name_setter_arg_type, options_list=['--database-name', '-d'], help='The name of the database.')

with self.argument_context('{} flexible-server db delete'.format(command_group)) as c:
c.argument('database_name', arg_type=database_name_getter_arg_type, options_list=['--database-name', '-d'], help='The name of the database.')
c.argument('yes', options_list=['--yes', '-y'], action='store_true', help='Do not prompt for confirmation.')
for scope in ['create', 'delete', 'list', 'show']:
argument_context_string = '{} flexible-server db {}'.format(command_group, scope)
with self.argument_context(argument_context_string) as c:
c.argument('resource_group_name', arg_type=resource_group_name_type)
c.argument('server_name', id_part='name', options_list=['--server-name', '-s'], arg_type=server_name_arg_type)
c.argument('database_name', id_part='child_name_1', arg_type=database_name_arg_type, options_list=['--database-name', '-d'], help='The name of a database.')

with self.argument_context('{} flexible-server db list'.format(command_group)) as c:
c.argument('server_name', id_part=None, options_list=['--server-name', '-s'], arg_type=server_name_arg_type)
c.argument('database_name', id_part=None, arg_type=database_name_arg_type, options_list=['--database-name', '-d'], help='The name of the database.')

with self.argument_context('{} flexible-server db create'.format(command_group)) as c:
c.argument('database_name', id_part='child_name_1', arg_type=database_name_setter_arg_type, options_list=['--database-name', '-d'], help='The name of a database.')
c.argument('charset', help='The charset of the database. The default value is UTF8')
c.argument('collation', help='The collation of the database.')

with self.argument_context('{} flexible-server db delete'.format(command_group)) as c:
c.argument('database_name', id_part='child_name_1', arg_type=database_name_getter_arg_type, options_list=['--database-name', '-d'], help='The name of a database.')
c.argument('yes', options_list=['--yes', '-y'], action='store_true', help='Do not prompt for confirmation.')

with self.argument_context('{} flexible-server show-connection-string'.format(command_group)) as c:
c.argument('server_name', options_list=['--server-name', '-s'], arg_type=server_name_arg_type, help='Name of the server.')
Expand Down
4 changes: 2 additions & 2 deletions src/azure-cli/azure/cli/command_modules/rdbms/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def load_command_table(self, _):
g.custom_wait_command('wait', '_server_mariadb_get')
g.command('restart', 'begin_restart')
g.command('start', 'begin_start')
g.command('stop', 'begin_stop')
g.custom_command('stop', '_server_stop')

with self.command_group('mysql server', mysql_servers_sdk, client_factory=cf_mysql_servers) as g:
g.custom_command('create', '_server_create')
Expand All @@ -267,7 +267,7 @@ def load_command_table(self, _):
g.custom_wait_command('wait', '_server_mysql_get')
g.command('restart', 'begin_restart')
g.command('start', 'begin_start')
g.command('stop', 'begin_stop')
g.custom_command('stop', '_server_stop')
g.custom_command('upgrade', '_server_mysql_upgrade')

with self.command_group('postgres server', postgres_servers_sdk, client_factory=cf_postgres_servers) as g:
Expand Down
6 changes: 6 additions & 0 deletions src/azure-cli/azure/cli/command_modules/rdbms/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,12 @@ def _server_mysql_get(cmd, resource_group_name, server_name):
return client.servers.get(resource_group_name, server_name)


def _server_stop(cmd, client, resource_group_name, server_name):
logger.warning("Server will be automatically started after 7 days "
"if you do not perform a manual start operation")
return client.begin_stop(resource_group_name, server_name)


def _server_postgresql_get(cmd, resource_group_name, server_name):
client = get_postgresql_management_client(cmd.cli_ctx)
return client.servers.get(resource_group_name, server_name)
Expand Down
Loading