forked from Azure/azure-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_params.py
More file actions
3144 lines (2523 loc) · 130 KB
/
_params.py
File metadata and controls
3144 lines (2523 loc) · 130 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint:disable=too-many-lines
import itertools
from enum import Enum
from azure.mgmt.sql.models import (
Database,
ElasticPool,
ElasticPoolPerDatabaseSettings,
ImportExistingDatabaseDefinition,
ExportDatabaseDefinition,
InstancePool,
ManagedDatabase,
ManagedInstance,
ManagedInstanceAdministrator,
Server,
ServerAzureADAdministrator,
Sku,
BlobAuditingPolicyState,
CatalogCollationType,
CreateMode,
DatabaseLicenseType,
ElasticPoolLicenseType,
SampleName,
SecurityAlertPolicyState,
ServerConnectionType,
ServerKeyType,
StorageKeyType,
TransparentDataEncryptionState,
ManagedInstanceDatabaseFormat
)
from azure.cli.core.commands.parameters import (
get_three_state_flag,
get_enum_type,
get_resource_name_completion_list,
get_location_type,
tags_type,
resource_group_name_type
)
from azure.cli.core.commands.validators import (
get_default_location_from_resource_group
)
from knack.arguments import CLIArgumentType, ignore_type
from .custom import (
AlwaysEncryptedEnclaveType,
ClientAuthenticationType,
ClientType,
ComputeModelType,
DatabaseCapabilitiesAdditionalDetails,
ElasticPoolCapabilitiesAdditionalDetails,
FailoverPolicyType,
ResourceIdType,
ServicePrincipalType,
SqlServerMinimalTlsVersionType,
SqlManagedInstanceMinimalTlsVersionType,
AuthenticationType,
FreemiumType,
FreeLimitExhaustionBehavior,
FailoverGroupDatabasesSecondaryType
)
from ._validators import (
create_args_for_complex_type,
validate_managed_instance_storage_size,
validate_backup_storage_redundancy,
validate_subnet
)
#####
# SizeWithUnitConverter - consider moving to common code (azure.cli.core.commands.parameters)
#####
class SizeWithUnitConverter: # pylint: disable=too-few-public-methods
def __init__(
self,
unit='kB',
result_type=int,
unit_map=None):
self.unit = unit
self.result_type = result_type
self.unit_map = unit_map or {"B": 1, "kB": 1024, "MB": 1024 * 1024, "GB": 1024 * 1024 * 1024,
"TB": 1024 * 1024 * 1024 * 1024}
def __call__(self, value):
numeric_part = ''.join(itertools.takewhile(str.isdigit, value))
unit_part = value[len(numeric_part):]
try:
uvals = (self.unit_map[unit_part] if unit_part else 1) / \
(self.unit_map[self.unit] if self.unit else 1)
return self.result_type(uvals * self.result_type(numeric_part))
except KeyError:
raise ValueError()
def __repr__(self):
return 'Size (in {}) - valid units are {}.'.format(
self.unit,
', '.join(sorted(self.unit_map, key=self.unit_map.__getitem__)))
def get_internal_backup_storage_redundancy(self):
return {
'local': 'Local',
'zone': 'Zone',
'geo': 'Geo',
'geozone': 'GeoZone',
}.get(self.lower(), 'Invalid')
#####
# Reusable param type definitions
#####
sku_arg_group = 'Performance Level'
sku_component_arg_group = 'Performance Level (components)'
serverless_arg_group = 'Serverless offering'
server_configure_help = 'You can configure the default using `az configure --defaults sql-server=<name>`'
time_format_help = 'Time should be in following format: "YYYY-MM-DDTHH:MM:SS".'
storage_arg_group = "Storage"
log_analytics_arg_group = "Log Analytics"
event_hub_arg_group = "Event Hub"
def get_location_type_with_default_from_resource_group(cli_ctx):
return CLIArgumentType(
arg_type=get_location_type(cli_ctx),
required=False,
validator=get_default_location_from_resource_group)
server_param_type = CLIArgumentType(
options_list=['--server', '-s'],
configured_default='sql-server',
help='Name of the Azure SQL Server. ' + server_configure_help,
completer=get_resource_name_completion_list('Microsoft.SQL/servers'),
# Allow --ids command line argument. id_part=name is 1st name in uri
id_part='name')
available_param_type = CLIArgumentType(
options_list=['--available', '-a'],
help='If specified, show only results that are available in the specified region.')
tier_param_type = CLIArgumentType(
arg_group=sku_component_arg_group,
options_list=['--tier', '--edition', '-e'])
capacity_param_type = CLIArgumentType(
arg_group=sku_component_arg_group,
options_list=['--capacity', '-c'])
capacity_or_dtu_param_type = CLIArgumentType(
arg_group=sku_component_arg_group,
options_list=['--capacity', '-c', '--dtu'])
family_param_type = CLIArgumentType(
arg_group=sku_component_arg_group,
options_list=['--family', '-f'])
elastic_pool_id_param_type = CLIArgumentType(
arg_group=sku_arg_group,
options_list=['--elastic-pool'])
compute_model_param_type = CLIArgumentType(
arg_group=serverless_arg_group,
options_list=['--compute-model'],
help='The compute model of the database.',
arg_type=get_enum_type(ComputeModelType))
auto_pause_delay_param_type = CLIArgumentType(
arg_group=serverless_arg_group,
options_list=['--auto-pause-delay'],
help='Time in minutes after which database is automatically paused. '
'A value of -1 means that automatic pause is disabled.')
min_capacity_param_type = CLIArgumentType(
arg_group=serverless_arg_group,
options_list=['--min-capacity'],
help='Minimal capacity that database will always have allocated, if not paused')
max_size_bytes_param_type = CLIArgumentType(
options_list=['--max-size'],
type=SizeWithUnitConverter('B', result_type=int),
help='The max storage size. If no unit is specified, defaults to bytes (B).')
zone_redundant_param_type = CLIArgumentType(
options_list=['--zone-redundant', '-z'],
help='Specifies whether to enable zone redundancy. Default is true if no value is specified',
arg_type=get_three_state_flag())
maintenance_configuration_id_param_type = CLIArgumentType(
options_list=['--maint-config-id', '-m'],
help='Specified maintenance configuration id or name for this resource.')
ledger_on_param_type = CLIArgumentType(
options_list=['--ledger-on'],
help='Create a ledger database, in which the integrity of all data is protected by the ledger feature. '
'All tables in the ledger database must be ledger tables. '
'Note: the value of this property cannot be changed after the database has been created. ',
arg_type=get_three_state_flag("Enabled", "Disabled", False, False))
preferred_enclave_param_type = CLIArgumentType(
options_list=['--preferred-enclave-type'],
help='Specifies type of enclave for this resource.',
arg_type=get_enum_type(AlwaysEncryptedEnclaveType))
database_assign_identity_param_type = CLIArgumentType(
options_list=['--assign-identity', '-i'],
help='Assign identity for database.',
arg_type=get_three_state_flag())
database_expand_keys_param_type = CLIArgumentType(
options_list=['--expand-keys', '-e'],
help='Flag to use to expand all keys in the db show.',
arg_type=get_three_state_flag())
database_encryption_protector_param_type = CLIArgumentType(
options_list=['--encryption-protector'],
help='Specifies the Azure key vault key to be used as database encryption protector key.')
database_keys_param_type = CLIArgumentType(
options_list=['--keys'],
nargs='+',
help='The list of AKV keys for the SQL Database.')
database_keys_to_remove_param_type = CLIArgumentType(
options_list=['--keys-to-remove'],
nargs='+',
help='The list of AKV keys to remove from the SQL Database.')
database_user_assigned_identity_param_type = CLIArgumentType(
options_list=['--user-assigned-identity-id', '--umi'],
nargs='+',
help='The list of user assigned identity for the SQL Database.')
database_federated_client_id_param_type = CLIArgumentType(
options_list=['--federated-client-id'],
help='The federated client id for the SQL Database. It is used for cross tenant CMK scenario.')
database_encryption_protector_auto_rotation_param_type = CLIArgumentType(
options_list=['--encryption-protector-auto-rotation', '--epauto'],
help='Specifies the database encryption protector key auto rotation flag. Can be either true, false or null.',
required=False,
arg_type=get_three_state_flag())
database_availability_zone_param_type = CLIArgumentType(
options_list=['--availability-zone'],
help='Availability zone')
database_use_free_limit = CLIArgumentType(
options_list=['--use-free-limit', '--free-limit'],
help='Whether or not the database uses free monthly limits. Allowed on one database in a subscription.',
arg_type=get_three_state_flag())
database_free_limit_exhaustion_behavior = CLIArgumentType(
options_list=['--free-limit-exhaustion-behavior', '--exhaustion-behavior', '--fleb'],
help='Specifies the behavior when monthly free limits are exhausted for the free database.'
'AutoPause: The database will be auto paused upon exhaustion of free limits for remainder of the month.'
'BillForUsage: The database will continue to be online upon exhaustion of free limits'
'and any overage will be billed.',
arg_type=get_enum_type(FreeLimitExhaustionBehavior))
managed_instance_param_type = CLIArgumentType(
options_list=['--managed-instance', '--mi'],
help='Name of the Azure SQL Managed Instance.')
kid_param_type = CLIArgumentType(
options_list=['--kid', '-k'],
help='The Azure Key Vault key identifier of the server key. An example key identifier is '
'"https://YourVaultName.vault.azure.net/keys/YourKeyName/01234567890123456789012345678901"')
server_key_type_param_type = CLIArgumentType(
options_list=['--server-key-type', '-t'],
help='The type of the server key',
arg_type=get_enum_type(ServerKeyType))
storage_param_type = CLIArgumentType(
options_list=['--storage'],
type=SizeWithUnitConverter('GB', result_type=int, unit_map={"B": 1.0 / (1024 * 1024 * 1024),
"kB": 1.0 / (1024 * 1024),
"MB": 1.0 / 1024,
"GB": 1,
"TB": 1024}),
help='The storage size. If no unit is specified, defaults to gigabytes (GB).',
validator=validate_managed_instance_storage_size)
iops_param_type = CLIArgumentType(
options_list=['--iops'],
type=int,
help='The storage iops.')
backup_storage_redundancy_param_type = CLIArgumentType(
options_list=['--backup-storage-redundancy', '--bsr'],
type=get_internal_backup_storage_redundancy,
help='Backup storage redundancy used to store backups. Allowed values include: Local, Zone, Geo, GeoZone.',
validator=validate_backup_storage_redundancy)
backup_storage_redundancy_param_type_mi = CLIArgumentType(
options_list=['--backup-storage-redundancy', '--bsr'],
type=get_internal_backup_storage_redundancy,
help='Backup storage redundancy used to store backups. Allowed values include: Local, Zone, Geo, GeoZone.',
validator=validate_backup_storage_redundancy)
grace_period_param_type = CLIArgumentType(
help='Interval in hours before automatic failover is initiated '
'if an outage occurs on the primary server. '
'This indicates that Azure SQL Database will not initiate '
'automatic failover before the grace period expires. '
'Please note that failover operation with --allow-data-loss option '
'might cause data loss due to the nature of asynchronous synchronization.')
allow_data_loss_param_type = CLIArgumentType(
help='Complete the failover even if doing so may result in data loss. '
'This will allow the failover to proceed even if a primary database is unavailable.')
try_planned_before_forced_failover_param_type = CLIArgumentType(
options_list=['--try-planned-before-forced-failover', '--tpbff'],
help='Performs a planned failover as the first step, and if it fails for any reason, '
'then initiates a forced failover with potential data loss. '
'This will allow the failover to proceed even if a primary database is unavailable.')
secondary_type_param_type = CLIArgumentType(
help='Intended usage of the secondary instance in the Failover Group. '
'Standby indicates that the secondary instance will be used as a passive replica for disaster recovery only.')
aad_admin_login_param_type = CLIArgumentType(
options_list=['--display-name', '-u'],
required=True,
help='Display name of the Azure AD administrator user or group.')
aad_admin_sid_param_type = CLIArgumentType(
options_list=['--object-id', '-i'],
required=True,
help='The unique ID of the Azure AD administrator.')
read_scale_param_type = CLIArgumentType(
options_list=['--read-scale'],
help='If enabled, connections that have application intent set to readonly '
'in their connection string may be routed to a readonly secondary replica. '
'This property is only settable for Premium and Business Critical databases.',
arg_type=get_enum_type(['Enabled', 'Disabled']))
read_replicas_param_type = CLIArgumentType(
options_list=['--read-replicas', '--ha-replicas'],
type=int,
help='The number of high availability replicas to provision for the database. '
'Only settable for Hyperscale edition.')
blob_storage_target_state_param_type = CLIArgumentType(
arg_group=storage_arg_group,
options_list=['--blob-storage-target-state', '--bsts'],
configured_default='sql-server',
help='Indicate whether blob storage is a destination for audit records.',
arg_type=get_enum_type(BlobAuditingPolicyState))
log_analytics_target_state_param_type = CLIArgumentType(
arg_group=log_analytics_arg_group,
options_list=['--log-analytics-target-state', '--lats'],
configured_default='sql-server',
help='Indicate whether log analytics is a destination for audit records.',
arg_type=get_enum_type(BlobAuditingPolicyState))
log_analytics_workspace_resource_id_param_type = CLIArgumentType(
arg_group=log_analytics_arg_group,
options_list=['--log-analytics-workspace-resource-id', '--lawri'],
configured_default='sql-server',
help='The workspace ID (resource ID of a Log Analytics workspace) for a Log Analytics workspace '
'to which you would like to send Audit Logs.')
event_hub_target_state_param_type = CLIArgumentType(
arg_group=event_hub_arg_group,
options_list=['--event-hub-target-state', '--ehts'],
configured_default='sql-server',
help='Indicate whether event hub is a destination for audit records.',
arg_type=get_enum_type(BlobAuditingPolicyState))
event_hub_authorization_rule_id_param_type = CLIArgumentType(
arg_group=event_hub_arg_group,
options_list=['--event-hub-authorization-rule-id', '--ehari'],
configured_default='sql-server',
help='The resource Id for the event hub authorization rule.')
event_hub_param_type = CLIArgumentType(
arg_group=event_hub_arg_group,
options_list=['--event-hub', '--eh'],
configured_default='sql-server',
help='The name of the event hub. If none is specified '
'when providing event_hub_authorization_rule_id, the default event hub will be selected.')
manual_cutover_param_type = CLIArgumentType(
options_list=['--manual-cutover'],
help='Whether to do manual cutover during Update SLO. Allowed when updating database to Hyperscale tier.',
arg_type=get_three_state_flag())
perform_cutover_param_type = CLIArgumentType(
options_list=['--perform-cutover'],
help='Whether to perform cutover when updating database to Hyperscale tier is in progress.',
arg_type=get_three_state_flag())
authentication_metadata_param_type = CLIArgumentType(
options_list=['--authentication-metadata', '--am'],
help='Preferred metadata to use for authentication of synced on-prem users. Default is AzureAD.',
arg_type=get_enum_type(['AzureAD', 'Windows', 'Paired']))
db_service_objective_examples = 'Basic, S0, P1, GP_Gen4_1, GP_S_Gen5_8, BC_Gen5_2, HS_Gen5_32.'
dw_service_objective_examples = 'DW100, DW1000c'
###############################################
# sql db #
###############################################
class Engine(Enum): # pylint: disable=too-few-public-methods
"""SQL RDBMS engine type."""
db = 'db'
dw = 'dw'
def _configure_db_dw_params(arg_ctx):
"""
Configures params that are based on `Database` resource and therefore apply to one or more DB/DW create/update
commands. The idea is that this does some basic configuration of each property. Each command can then potentially
build on top of this (e.g. to give a parameter more specific help text) and .ignore() parameters that aren't
applicable.
Normally these param configurations would be implemented at the command group level, but these params are used
across 2 different param groups - `sql db` and `sql dw`. So extracting it out into this common function prevents
duplication.
"""
arg_ctx.argument('max_size_bytes',
arg_type=max_size_bytes_param_type)
arg_ctx.argument('elastic_pool_id',
arg_type=elastic_pool_id_param_type)
arg_ctx.argument('compute_model',
arg_type=compute_model_param_type)
arg_ctx.argument('auto_pause_delay',
arg_type=auto_pause_delay_param_type)
arg_ctx.argument('min_capacity',
arg_type=min_capacity_param_type)
arg_ctx.argument('read_scale',
arg_type=read_scale_param_type)
arg_ctx.argument('high_availability_replica_count',
arg_type=read_replicas_param_type)
creation_arg_group = 'Creation'
arg_ctx.argument('collation',
arg_group=creation_arg_group,
help='The collation of the database.')
arg_ctx.argument('catalog_collation',
arg_group=creation_arg_group,
arg_type=get_enum_type(CatalogCollationType),
help='Collation of the metadata catalog.')
# WideWorldImportersStd and WideWorldImportersFull cannot be successfully created.
# AdventureWorksLT is the only sample name that is actually supported.
arg_ctx.argument('sample_name',
arg_group=creation_arg_group,
arg_type=get_enum_type([SampleName.adventure_works_lt]),
help='The name of the sample schema to apply when creating this'
'database.')
arg_ctx.argument('license_type',
arg_type=get_enum_type(DatabaseLicenseType),
help='The license type to apply for this database.'
'``LicenseIncluded`` if you need a license, or ``BasePrice``'
'if you have a license and are eligible for the Azure Hybrid'
'Benefit.')
arg_ctx.argument('zone_redundant',
arg_type=zone_redundant_param_type)
arg_ctx.argument('preferred_enclave_type',
arg_type=preferred_enclave_param_type)
arg_ctx.argument('assign_identity',
arg_type=database_assign_identity_param_type)
arg_ctx.argument('encryption_protector',
arg_type=database_encryption_protector_param_type)
arg_ctx.argument('keys',
arg_type=database_keys_param_type)
arg_ctx.argument('keys_to_remove',
arg_type=database_keys_to_remove_param_type)
arg_ctx.argument('user_assigned_identity_id',
arg_type=database_user_assigned_identity_param_type)
arg_ctx.argument('federated_client_id',
arg_type=database_federated_client_id_param_type)
arg_ctx.argument('expand_keys',
arg_type=database_expand_keys_param_type)
arg_ctx.argument('availability_zone',
arg_type=database_availability_zone_param_type)
arg_ctx.argument('use_free_limit',
arg_type=database_use_free_limit)
arg_ctx.argument('free_limit_exhaustion_behavior',
arg_type=database_free_limit_exhaustion_behavior)
arg_ctx.argument('encryption_protector_auto_rotation',
arg_type=database_encryption_protector_auto_rotation_param_type)
arg_ctx.argument('manual-cutover',
arg_type=manual_cutover_param_type)
arg_ctx.argument('perform-cutover',
arg_type=perform_cutover_param_type)
def _configure_db_dw_create_params(
arg_ctx,
engine,
create_mode):
"""
Configures params for db/dw create commands.
The PUT database REST API has many parameters and many modes (`create_mode`) that control
which parameters are valid. To make it easier for CLI users to get the param combinations
correct, these create modes are separated into different commands (e.g.: create, copy,
restore, etc).
On top of that, some create modes and some params are not allowed if the database edition is
DataWarehouse. For this reason, regular database commands are separated from datawarehouse
commands (`db` vs `dw`.)
As a result, the param combination matrix is a little complicated. When adding a new param,
we want to make sure that the param is visible for the appropriate commands. We also want to
avoid duplication. Instead of spreading out & duplicating the param definitions across all
the different commands, it has been more effective to define this reusable function.
The main task here is to create extra params based on the `Database` model, then .ignore() the params that
aren't applicable to the specified engine and create mode. There is also some minor tweaking of help text
to make the help text more specific to creation.
engine: Engine enum value (e.g. `db`, `dw`)
create_mode: Valid CreateMode enum value (e.g. `default`, `copy`, etc)
"""
# *** Step 0: Validation ***
# DW does not support all create modes. Check that engine and create_mode are consistent.
if engine == Engine.dw and create_mode not in [
CreateMode.default,
CreateMode.point_in_time_restore,
CreateMode.restore]:
raise ValueError('Engine {} does not support create mode {}'.format(engine, create_mode))
# *** Step 1: Create extra params ***
# Create args that will be used to build up the Database object
#
# IMPORTANT: It is very easy to add a new parameter and accidentally forget to .ignore() it in
# some commands that it is not applicable to. Therefore, when adding a new param, you should compare
# command help before & after your change.
# e.g.:
#
# # Get initial help text
# git checkout dev
# $file = 'help_original.txt'
# az sql db create -h >> $file
# az sql db copy -h >> $file
# az sql db restore -h >> $file
# az sql db replica create -h >> $file
# az sql db update -h >> $file
# az sql dw create -h >> $file
# az sql dw update -h >> $file
#
# # Get updated help text
# git checkout mybranch
# $file = 'help_updated.txt'
# az sql db create -h >> $file
# az sql db copy -h >> $file
# az sql db restore -h >> $file
# az sql db replica create -h >> $file
# az sql db update -h >> $file
# az sql dw create -h >> $file
# az sql dw update -h >> $file
#
# Then compare 'help_original.txt' <-> 'help_updated.txt' in your favourite text diff tool.
create_args_for_complex_type(
arg_ctx, 'parameters', Database, [
'catalog_collation',
'collation',
'elastic_pool_id',
'license_type',
'max_size_bytes',
'name',
'restore_point_in_time',
'sample_name',
'sku',
'source_database_deletion_date',
'tags',
'zone_redundant',
'auto_pause_delay',
'min_capacity',
'compute_model',
'read_scale',
'high_availability_replica_count',
'requested_backup_storage_redundancy',
'maintenance_configuration_id',
'is_ledger_on',
'preferred_enclave_type',
'assign_identity',
'encryption_protector',
'keys',
'user_assigned_identity_id',
'federated_client_id',
'availability_zone',
'encryption_protector_auto_rotation',
'use_free_limit',
'free_limit_exhaustion_behavior',
'manual_cutover',
'perform_cutover'
])
# Create args that will be used to build up the Database's Sku object
create_args_for_complex_type(
arg_ctx, 'sku', Sku, [
'capacity',
'family',
'name',
'tier',
])
# *** Step 2: Apply customizations specific to create (as opposed to update) ***
arg_ctx.argument('name', # Note: this is sku name, not database name
options_list=['--service-objective', '--service-level-objective'],
arg_group=sku_arg_group,
required=False,
help='The service objective for the new database. For example: ' +
(db_service_objective_examples if engine == Engine.db else dw_service_objective_examples))
arg_ctx.argument('elastic_pool_id',
help='The name or resource id of the elastic pool to create the database in.')
arg_ctx.argument('requested_backup_storage_redundancy',
arg_type=backup_storage_redundancy_param_type)
arg_ctx.argument('maintenance_configuration_id',
arg_type=maintenance_configuration_id_param_type)
arg_ctx.argument('is_ledger_on',
arg_type=ledger_on_param_type)
arg_ctx.argument('preferred_enclave_type',
arg_type=preferred_enclave_param_type)
arg_ctx.argument('assign_identity',
arg_type=database_assign_identity_param_type)
arg_ctx.argument('encryption_protector',
arg_type=database_encryption_protector_param_type)
arg_ctx.argument('keys',
arg_type=database_keys_param_type)
arg_ctx.argument('user_assigned_identity_id',
arg_type=database_user_assigned_identity_param_type)
arg_ctx.argument('federated_client_id',
arg_type=database_federated_client_id_param_type)
arg_ctx.argument('encryption_protector_auto_rotation',
arg_type=database_encryption_protector_auto_rotation_param_type)
# *** Step 3: Ignore params that are not applicable (based on engine & create mode) ***
# Only applicable to default create mode. Also only applicable to db.
if create_mode != CreateMode.default or engine != Engine.db:
arg_ctx.ignore('sample_name')
arg_ctx.ignore('catalog_collation')
arg_ctx.ignore('maintenance_configuration_id')
arg_ctx.ignore('is_ledger_on')
arg_ctx.ignore('use_free_limit')
arg_ctx.ignore('free_limit_exhaustion_behavior')
# Only applicable to point in time restore or deleted restore create mode.
if create_mode not in [CreateMode.restore, CreateMode.point_in_time_restore]:
arg_ctx.ignore('restore_point_in_time', 'source_database_deletion_date')
# 'collation', 'tier', and 'max_size_bytes' are ignored (or rejected) when creating a copy
# or secondary because their values are determined by the source db.
if create_mode in [CreateMode.copy, CreateMode.secondary]:
arg_ctx.ignore('collation', 'tier', 'max_size_bytes')
# collation and max_size_bytes are ignored when restoring because their values are determined by
# the source db.
if create_mode in [
CreateMode.restore,
CreateMode.point_in_time_restore,
CreateMode.RECOVERY,
CreateMode.RESTORE_LONG_TERM_RETENTION_BACKUP]:
arg_ctx.ignore('collation', 'max_size_bytes')
# 'manual_cutover' and 'perform_cutover' are ignored when creating a database,
# as they are only applicable during update
if create_mode in CreateMode:
arg_ctx.ignore('manual_cutover', 'perform_cutover')
if engine == Engine.dw:
# Elastic pool is only for SQL DB.
arg_ctx.ignore('elastic_pool_id')
# Edition is always 'DataWarehouse'
arg_ctx.ignore('tier')
# License types do not yet exist for DataWarehouse
arg_ctx.ignore('license_type')
# Preferred enclave types do not yet exist for DataWarehouse
arg_ctx.ignore('preferred_enclave_type')
# Family is not applicable to DataWarehouse
arg_ctx.ignore('family')
# Identity is not applicable to DataWarehouse
arg_ctx.ignore('assign_identity')
# Encryption Protector is not applicable to DataWarehouse
arg_ctx.ignore('encryption_protector')
# Keys is not applicable to DataWarehouse
arg_ctx.ignore('keys')
# User Assigned Identities is not applicable to DataWarehouse
arg_ctx.ignore('user_assigned_identity_id')
# Federated client id is not applicable to DataWarehouse
arg_ctx.ignore('federated_client_id')
# Encryption Protector auto rotation is not applicable to DataWarehouse
arg_ctx.ignore('encryption_protector_auto_rotation')
# Provisioning with capacity is not applicable to DataWarehouse
arg_ctx.ignore('capacity')
# Serverless offerings are not applicable to DataWarehouse
arg_ctx.ignore('auto_pause_delay')
arg_ctx.ignore('min_capacity')
arg_ctx.ignore('compute_model')
# Free limit parameters are not applicable to DataWarehouse
arg_ctx.ignore('use_free_limit')
arg_ctx.ignore('free_limit_exhaustion_behavior')
# ReadScale properties are not valid for DataWarehouse
# --read-replica-count was accidentally included in previous releases and
# therefore is hidden using `deprecate_info` instead of `ignore`
arg_ctx.ignore('read_scale')
arg_ctx.ignore('high_availability_replica_count')
arg_ctx.argument('read_replica_count',
options_list=['--read-replica-count'],
deprecate_info=arg_ctx.deprecate(hide=True))
# Zone redundant was accidentally included in previous releases and
# therefore is hidden using `deprecate_info` instead of `ignore`
arg_ctx.argument('zone_redundant',
options_list=['--zone-redundant'],
deprecate_info=arg_ctx.deprecate(hide=True))
# Manual-cutover and Perform-cutover are not valid for DataWarehouse
arg_ctx.ignore('manual_cutover')
arg_ctx.ignore('perform_cutover')
# pylint: disable=too-many-statements
def load_arguments(self, _):
with self.argument_context('sql') as c:
c.argument('location_name', arg_type=get_location_type(self.cli_ctx))
c.argument('usage_name', options_list=['--usage', '-u'])
c.argument('tags', arg_type=tags_type)
c.argument('allow_data_loss',
help='If specified, the failover operation will allow data loss.')
with self.argument_context('sql db') as c:
_configure_db_dw_params(c)
c.argument('server_name',
arg_type=server_param_type)
c.argument('database_name',
options_list=['--name', '-n'],
help='Name of the Azure SQL Database.',
# Allow --ids command line argument. id_part=child_name_1 is 2nd name in uri
id_part='child_name_1')
# SKU-related params are different from DB versus DW, so we want this configuration to apply here
# in 'sql db' group but not in 'sql dw' group. If we wanted to apply to both, we would put the
# configuration into _configure_db_dw_params().
c.argument('tier',
arg_type=tier_param_type,
help='The edition component of the sku. Allowed values include: Basic, Standard, '
'Premium, GeneralPurpose, BusinessCritical, Hyperscale.')
c.argument('capacity',
arg_type=capacity_param_type,
arg_group=sku_component_arg_group,
help='The capacity component of the sku in integer number of DTUs or vcores.')
c.argument('family',
arg_type=family_param_type,
help='The compute generation component of the sku (for vcore skus only). '
'Allowed values include: Gen4, Gen5.')
with self.argument_context('sql db create') as c:
_configure_db_dw_create_params(c, Engine.db, CreateMode.default)
c.argument('yes',
options_list=['--yes', '-y'],
help='Do not prompt for confirmation.', action='store_true')
with self.argument_context('sql db copy') as c:
_configure_db_dw_create_params(c, Engine.db, CreateMode.copy)
c.argument('dest_name',
help='Name of the database that will be created as the copy destination.')
c.argument('dest_resource_group_name',
options_list=['--dest-resource-group'],
help='Name of the resource group to create the copy in.'
' If unspecified, defaults to the origin resource group.')
c.argument('dest_server_name',
options_list=['--dest-server'],
help='Name of the server to create the copy in.'
' If unspecified, defaults to the origin server.')
with self.argument_context('sql db rename') as c:
c.argument('new_name',
help='The new name that the database will be renamed to.')
with self.argument_context('sql db restore') as c:
_configure_db_dw_create_params(c, Engine.db, CreateMode.point_in_time_restore)
c.argument('dest_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. Either --time or --deleted-time (or both) must be specified. ' +
time_format_help)
c.argument('source_database_deletion_date',
options_list=['--deleted-time'],
arg_group=restore_point_arg_group,
help='If specified, restore from a deleted database instead of from an existing database.'
' Must match the deleted time of a deleted database in the same server.'
' Either --time or --deleted-time (or both) must be specified. ' +
time_format_help)
with self.argument_context('sql db show') as c:
# Service tier advisors and transparent data encryption are not included in the first batch
# of GA commands.
c.argument('expand_keys',
options_list=['--expand-keys'],
help='Expand the AKV keys for the database.')
c.argument('keys_filter',
options_list=['--keys-filter'],
help='Expand the AKV keys for the database.')
with self.argument_context('sql db show-deleted') as c:
c.argument('restorable_dropped_database_id',
options_list=['--restorable-dropped-database-id', '-r'],
help='Restorable dropped database id.')
c.argument('expand_keys',
options_list=['--expand-keys'],
arg_type=database_expand_keys_param_type,
help='Expand the AKV keys for the database.')
c.argument('keys_filter',
options_list=['--keys-filter'],
help='Expand the AKV keys for the database.')
with self.argument_context('sql server show') as c:
c.argument('expand_ad_admin',
options_list=['--expand-ad-admin'],
help='Expand the Active Directory Administrator for the server.')
with self.argument_context('sql db list') as c:
c.argument('elastic_pool_name',
options_list=['--elastic-pool'],
help='If specified, lists only the databases in this elastic pool')
with self.argument_context('sql db list-editions') as c:
c.argument('show_details',
options_list=['--show-details', '-d'],
help='List of additional details to include in output.',
nargs='+',
arg_type=get_enum_type(DatabaseCapabilitiesAdditionalDetails))
c.argument('available', arg_type=available_param_type)
search_arg_group = 'Search'
# We could used get_enum_type here, but that will validate the inputs which means there
# will be no way to query for new editions/service objectives that are made available after
# this version of CLI is released.
c.argument('edition',
arg_type=tier_param_type,
arg_group=search_arg_group,
help='Edition to search for. If unspecified, all editions are shown.')
c.argument('service_objective',
arg_group=search_arg_group,
help='Service objective to search for. If unspecified, all service objectives are shown.')
c.argument('dtu',
arg_group=search_arg_group,
help='Number of DTUs to search for. If unspecified, all DTU sizes are shown.')
c.argument('vcores',
arg_group=search_arg_group,
help='Number of vcores to search for. If unspecified, all vcore sizes are shown.')
with self.argument_context('sql db update') as c:
c.argument('service_objective',
arg_group=sku_arg_group,
help='The name of the new service objective. If this is a standalone db service'
' objective and the db is currently in an elastic pool, then the db is removed from'
' the pool.')
c.argument('elastic_pool_id',
help='The name or resource id of the elastic pool to move the database into.')
c.argument('max_size_bytes', help='The new maximum size of the database expressed in bytes.')
c.argument('requested_backup_storage_redundancy',
arg_type=backup_storage_redundancy_param_type)
c.argument('maintenance_configuration_id', arg_type=maintenance_configuration_id_param_type)
c.argument('availability_zone',
arg_type=database_availability_zone_param_type)
c.argument('use_free_limit',
arg_type=database_use_free_limit)
c.argument('free_limit_exhaustion_behavior',
arg_type=database_free_limit_exhaustion_behavior)
c.argument('manual_cutover',
arg_type=manual_cutover_param_type)
c.argument('perform_cutover',
arg_type=perform_cutover_param_type)
with self.argument_context('sql db export') as c:
# Create args that will be used to build up the ExportDatabaseDefinition object
create_args_for_complex_type(
c, 'parameters', ExportDatabaseDefinition, [
'administrator_login',
'administrator_login_password',
'authentication_type',
'storage_key',
'storage_key_type',
'storage_uri',
])
c.argument('administrator_login',