-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Adding CRUD azure cli commands for Managed instance and Managed database resources #6428
Changes from 2 commits
1e8b0d2
00a3e49
ed33cdc
ef4e608
8a0bf79
bdb1c99
e38567a
5e6c067
2e27e38
7ea3a7c
5186243
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,23 @@ | |
Release History | ||
=============== | ||
|
||
2.0.27 | ||
++++++ | ||
* Added new Managed instance and Managed database CRUD commands. | ||
* Managed instance commands: | ||
* az sql managed instance create | ||
* az sql managed instance show | ||
* az sql managed instance list | ||
* az sql managed instance update | ||
* az sql managed instance delete | ||
|
||
* Managed database commands: | ||
* az sql managed db create | ||
* az sql managed db show | ||
* az sql managed db list | ||
* az sql managed instance restore | ||
* az sql managed instance delete | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming these should say "db" instead of "instance" right? |
||
|
||
2.0.26 | ||
++++++ | ||
* BREAKING CHANGES: Updated database, data warehouse, and elastic pool commands to use Azure-standard SKU properties for configuring performance level. This has resulted in some changes to the respose objects returned from db, dw, and elastic-pool commands. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -426,3 +426,83 @@ | |
- name: Create a vnet rule by providing the vnet and subnet name. The subnet id is created by taking the resource group name and subscription id of the SQL server. | ||
text: az sql server vnet-rule create --subnet subnetName --vnet-name vnetName | ||
""" | ||
helps['sql managed instance'] = """ | ||
type: group | ||
short-summary: Manage SQL managed instances. | ||
""" | ||
helps['sql managed instance create'] = """ | ||
type: command | ||
short-summary: Create a managed instance. | ||
examples: | ||
- name: Create a managed instance with specified parameters and with identity | ||
text: az sql managed instance create -g mygroup -mi myinstance -l mylocation -i -u myusername -p mypassword --license-type mylicensetype --subnet-id mysubnetid --vcores vcorenum --storage-size-in-gb storagesizenum --sku-name skuname | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For |
||
""" | ||
helps['sql managed instance list'] = """ | ||
type: command | ||
short-summary: List available managed instances. | ||
examples: | ||
- name: List all managed instances in the current subscription. | ||
text: az sql managed instance list | ||
- name: List all managed instances in a resource group. | ||
text: az sql managed instance list -g mygroup | ||
""" | ||
helps['sql managed instance show'] = """ | ||
type: command | ||
short-summary: Get the details for a managed instance. | ||
examples: | ||
- name: Get the details for a managed instance | ||
text: az sql managed instance show -g mygroup -mi myinstance | ||
""" | ||
helps['sql managed instance update'] = """ | ||
type: command | ||
short-summary: Update a managed instance. | ||
examples: | ||
- name: Updates a managed instance with specified parameters and with identity | ||
text: az sql managed instance update -g mygroup -mi myinstance -i -p mypassword --license-type mylicensetype --vcores vcorenum --storage-size-in-gb storagesizenum | ||
""" | ||
helps['sql managed instance delete'] = """ | ||
type: command | ||
short-summary: Delete a managed instance. | ||
examples: | ||
- name: Delete a managed instance | ||
text: az sql managed instance delete -g mygroup -mi myinstance --yes | ||
""" | ||
helps['sql managed db'] = """ | ||
type: group | ||
short-summary: Manage managed databases. | ||
""" | ||
helps['sql managed db create'] = """ | ||
type: command | ||
short-summary: Create a managed database. | ||
examples: | ||
- name: Create a managed database with specified collation | ||
text: az sql managed db create -g mygroup -mi myinstance -name mymanageddb --collation collationname | ||
""" | ||
helps['sql managed db list'] = """ | ||
type: command | ||
short-summary: List maanged databases on a managed instance. | ||
examples: | ||
- name: List maanged databases on a managed instance | ||
text: az sql managed db list -g mygroup -mi myinstance | ||
""" | ||
helps['sql managed db show'] = """ | ||
type: command | ||
short-summary: Get the details for a managed database. | ||
examples: | ||
- name: Get the details for a managed database | ||
text: az sql managed db show -g mygroup -mi myinstance -name mymanageddb | ||
""" | ||
helps['sql managed db restore'] = """ | ||
type: command | ||
short-summary: Restores a managed database. | ||
examples: | ||
- name: Restores a managed database using Point in time restore | ||
text: az sql managed db restore -g mygroup -mi myinstance -name mymanageddb --target-managed-database-name targetmidb --time pointintime | ||
""" | ||
helps['sql managed db delete'] = """ | ||
type: command | ||
short-summary: Delete a managed database. | ||
examples: | ||
- name: Delete a managed database | ||
text: az sql managed db delete -g mygroup -mi myinstance -name mymanageddb --yes | ||
""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,8 @@ | |
ExportRequest, | ||
Server, | ||
ServerAzureADAdministrator, | ||
Sku | ||
Sku, | ||
ManagedInstance | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make alphabetical please |
||
) | ||
|
||
from azure.mgmt.sql.models.sql_management_client_enums import ( | ||
|
@@ -140,9 +141,13 @@ def __repr__(self): | |
help='Specifies whether to enable zone redundancy', | ||
arg_type=get_three_state_flag()) | ||
|
||
managed_instance_param_type = CLIArgumentType( | ||
options_list=['--managed_instance', '-mi'], | ||
help='Name of the Azure SQL managed instance.') | ||
|
||
db_service_objective_examples = 'Basic, S0, P1, GP_Gen4_1, BC_Gen5_2.' | ||
dw_service_objective_examples = 'DW100, DW1000c' | ||
mi_service_objective_examples = 'GP_Gen4, GP_Gen5' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this unused? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is unused, indeed, removed it |
||
|
||
|
||
############################################### | ||
|
@@ -1005,3 +1010,133 @@ def _configure_security_policy_storage_params(arg_ctx): | |
c.extra('vnet_name', | ||
options_list=['--vnet-name'], | ||
help='The virtual network name') | ||
|
||
############################################### | ||
# sql managed instance # | ||
############################################### | ||
with self.argument_context('sql managed instance') as c: | ||
c.argument('managed_instance_name', | ||
help='The managed instance name', | ||
options_list=['--name', '-n'], | ||
# Allow --ids command line argument. id_part=name is 1st name in uri | ||
id_part='name') | ||
|
||
with self.argument_context('sql managed instance create') as c: | ||
# Create args that will be used to build up the ManagedInstance object | ||
create_args_for_complex_type( | ||
c, 'parameters', ManagedInstance, [ | ||
'administrator_login', | ||
'administrator_login_password', | ||
'location', | ||
'license_type', | ||
'subnet_id', | ||
'vcores', | ||
'storage_size_in_gb', | ||
'sku_name', | ||
]) | ||
|
||
c.argument('administrator_login', | ||
options_list=['--admin-user', '-u'], | ||
required=True) | ||
|
||
c.argument('administrator_login_password', | ||
options_list=['--admin-password', '-p'], | ||
required=True) | ||
|
||
c.argument('subnet_id', | ||
required=True, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are all these parameters really required? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, subnet_id, admin-user and admin-password are required. license-type, vcores, storage and sku_name are not required and they get default values if not specified in request. I will talk to the PMs to see if we want to force explicit setting of this parameters, or not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parameters really should not be required if they are not required. More required parameters = more difficult for new users. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, checked, will remove requirement where it is not needed. |
||
options_list=['--subnet-id', '-subn']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to remove or change
Actually I just realized that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed it, left only --subnet |
||
|
||
c.argument('license_type', | ||
required=True, | ||
arg_type=get_enum_type(DatabaseLicenseType)) | ||
|
||
c.argument('vcores', | ||
required=True, | ||
help='Number of vcores to search for. If unspecified, all vcore sizes are shown.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like MI to be consistent with DB and pool. So this parameter should be |
||
|
||
c.argument('storage_size_in_gb', | ||
required=True, | ||
help='Number of vcores to search for. If unspecified, all vcore sizes are shown.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
|
||
c.argument('sku_name', | ||
required=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use same design as DB & pool: --edition/--tier and --family parameters There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, will do. I have --family, --tier and --service-objective parameters now, same as for SQL db. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO you don't need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To answer your question, no there are no parameter sets like in PowerShell. If you look in custom.py you will see that there is code to look up the sku name in capabilities based on family and tier. It's a little complicated, but I strongly feel that it substantially improves the new user experience because the values are more discoverable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also having separate params allows syntax like this: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I am trying to remove --service-objective parameter which maps to sku.name, but sku.name is required parameter it seems. So I would need to populate sku.name even if not requiring it in command from other two parameters (--family and --tier)? Or I am missing something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it needs to be populated in custom.py. See _find_elastic_pool_sku_from_capabilities for example. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your MI code can be mostly the same, except that:
Something like this:
Note that db & pool capabilities return the "canonical sku" so we can copy the sku object directly from the chosen capability. You don't have this so you have to construct the sku object. This might be something Nemanja could add in managed instance capabilities. |
||
|
||
c.argument('assign_identity', | ||
options_list=['--assign-identity', '-i'], | ||
help='Generate and assign an Azure Active Directory Identity for this managed instance' | ||
'for use with key management services like Azure KeyVault.') | ||
|
||
with self.argument_context('sql managed instance update') as c: | ||
# Create args that will be used to build up the ManagedInstance object | ||
create_args_for_complex_type( | ||
c, 'parameters', ManagedInstance, [ | ||
'administrator_login_password', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can sku not be updated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not currently. We cannot update to different edition. We can only update password, storage, capacity and identity info |
||
'license_type', | ||
'v_cores', | ||
'storage_size_in_gb', | ||
]) | ||
|
||
c.argument('administrator_login_password', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of repeating There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not actually repeating them. They are different in properties. administrator_login_password is required when creating instance, and optional when updating it. And assign_identity provides additional help info when doing update instance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good |
||
options_list=['--admin-password', '-p'], | ||
required=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems wrong that this is required. There is no way to not update the password? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should not be required. This was copied from create parameters where password is required. Fixed |
||
|
||
c.argument('license_type', | ||
required=False, | ||
arg_type=get_enum_type(DatabaseLicenseType)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a ManagedInstanceLicenseType? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately not. Will have to use this one I guess |
||
|
||
c.argument('v_cores', | ||
required=False, | ||
help='Number of vcores to search for. If unspecified, all vcore sizes are shown.') | ||
|
||
c.argument('storage_size_in_gb', | ||
required=False, | ||
help='Number of vcores to search for. If unspecified, all vcore sizes are shown.') | ||
|
||
c.argument('assign_identity', | ||
options_list=['--assign-identity', '-i'], | ||
help='Generate and assign an Azure Active Directory Identity for this managed instance' | ||
'for use with key management services like Azure KeyVault.') | ||
|
||
############################################### | ||
# sql managed db # | ||
############################################### | ||
with self.argument_context('sql managed db') as c: | ||
c.argument('managed_instance_name', | ||
arg_type=managed_instance_param_type, | ||
# Allow --ids command line argument. id_part=name is 1st name in uri | ||
id_part='name') | ||
|
||
c.argument('database_name', | ||
options_list=['--name', '-n'], | ||
help='The name of the Azure SQL Managed Database.', | ||
# Allow --ids command line argument. id_part=child_name_1 is 2nd name in uri | ||
id_part='child_name_1') | ||
|
||
with self.argument_context('sql managed db create') as c: | ||
create_args_for_complex_type( | ||
c, 'parameters', ManagedInstance, [ | ||
'collation', | ||
]) | ||
|
||
c.argument('collation', | ||
required=False, | ||
help='The collation of the Azure SQL Managed Database collation to use.') | ||
|
||
with self.argument_context('sql managed db restore') as c: | ||
create_args_for_complex_type( | ||
c, 'parameters', ManagedInstance, [ | ||
'target_managed_database_name', | ||
'restore_point_in_time' | ||
]) | ||
c.argument('target_managed_database_name', | ||
help='Name of the database that will be created as the restore destination.') | ||
|
||
restore_point_arg_group = 'Restore Point' | ||
|
||
c.argument('restore_point_in_time', | ||
options_list=['--time', '-t'], | ||
arg_group=restore_point_arg_group, | ||
help='The point in time of the source database that will be restored to create the' | ||
' new database. Must be greater than or equal to the source database\'s' | ||
' earliestRestoreDate value.') |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,8 @@ | |
get_sql_server_usages_operations, | ||
get_sql_subscription_usages_operations, | ||
get_sql_virtual_network_rules_operations, | ||
get_sql_managed_instances_operations, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alphabetical please :) |
||
get_sql_managed_databases_operations | ||
) | ||
|
||
from ._validators import ( | ||
|
@@ -406,3 +408,41 @@ def load_command_table(self, _): | |
c.command('create', 'create_or_update') | ||
c.command('delete', 'delete') | ||
c.custom_command('set', 'server_dns_alias_set') | ||
|
||
############################################### | ||
# sql managed instance # | ||
############################################### | ||
|
||
managed_instances_operations = CliCommandType( | ||
operations_tmpl='azure.mgmt.sql.operations.managed_instances_operations#ManagedInstancesOperations.{}', | ||
client_factory=get_sql_managed_instances_operations) | ||
|
||
with self.command_group('sql managed instance', | ||
managed_instances_operations, | ||
client_factory=get_sql_managed_instances_operations) as g: | ||
|
||
g.custom_command('create', 'managed_instance_create') | ||
g.command('delete', 'delete', confirmation=True) | ||
g.command('show', 'get') | ||
g.custom_command('list', 'managed_instance_list') | ||
g.generic_update_command('update', custom_func_name='managed_instance_update') | ||
|
||
############################################### | ||
# sql managed db # | ||
############################################### | ||
|
||
managed_databases_operations = CliCommandType( | ||
operations_tmpl='azure.mgmt.sql.operations.managed_databases_operations#ManagedDatabasesOperations.{}', | ||
client_factory=get_sql_managed_databases_operations) | ||
|
||
with self.command_group('sql managed db', | ||
managed_databases_operations, | ||
client_factory=get_sql_managed_databases_operations) as g: | ||
|
||
g.custom_command('create', 'managed_db_create', | ||
supports_no_wait=True) | ||
g.custom_command('restore', 'managed_db_restore', | ||
supports_no_wait=True) | ||
g.command('show', 'get') | ||
g.custom_command('list', 'managed_db_list') | ||
g.command('delete', 'delete', confirmation=True, supports_no_wait=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to update this too :)