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

[Compute] Add disk-encryption-set command group #11411

Merged
merged 27 commits into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b3dd271
[Compute] Add disk-encryption-set command group
qwordy Nov 26, 2019
c31aa1e
Merge branch 'dev' of https://github.com/Azure/azure-cli into 10948
qwordy Nov 27, 2019
a896a9c
history; yaml
qwordy Nov 27, 2019
e57acd7
disk-encryption-set create/show
qwordy Nov 29, 2019
3d60130
Merge branch 'dev' of https://github.com/Azure/azure-cli into 10948
qwordy Nov 29, 2019
aa5609a
disk create: add disk encryption set support
qwordy Nov 29, 2019
1ca3217
Update test
qwordy Dec 2, 2019
05ffe73
Merge branch 'dev' of https://github.com/Azure/azure-cli into 10948
qwordy Dec 3, 2019
904867a
Merge branch 'dev' of https://github.com/Azure/azure-cli into 10948
qwordy Dec 3, 2019
052760a
Add list
qwordy Dec 3, 2019
33bb4ab
Add disk encryption set support for vm create
qwordy Dec 4, 2019
cd37d4f
Fix minor issue
qwordy Dec 4, 2019
94e9803
Merge branch 'dev' of https://github.com/Azure/azure-cli into 10948
qwordy Dec 4, 2019
bef85d0
Update history
qwordy Dec 4, 2019
a4812cc
Update help
qwordy Dec 4, 2019
9a2e1de
Update test
qwordy Dec 4, 2019
e6ade7b
Resolve review comments
qwordy Dec 5, 2019
09d1ed2
Fix a small bug
qwordy Dec 5, 2019
e18fa58
Fix style
qwordy Dec 6, 2019
511125e
Merge branch 'dev' of https://github.com/Azure/azure-cli into 10948
qwordy Dec 9, 2019
c8b3cfd
Add min_api for disk-encryption-set
qwordy Dec 9, 2019
bd24968
Add --os-disk-encryption-set and --data-disk-encryption-sets to vmss …
qwordy Dec 9, 2019
328f8ae
Add disk-encryption-set update
qwordy Dec 9, 2019
11d7a25
disk-encryption-set update; add test
qwordy Dec 10, 2019
a15aae3
Merge from dev
qwordy Dec 10, 2019
850d7fb
Add example
qwordy Dec 10, 2019
906fa13
Merge branch 'dev' of https://github.com/Azure/azure-cli into 10948
qwordy Dec 10, 2019
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
1 change: 1 addition & 0 deletions src/azure-cli/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Release History
**Compute**

* vmss create/update: Add --scale-in-policy, which decides which virtual machines are chosen for removal when a VMSS is scaled-in
* Add disk-encryption-set command group

**Install**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,7 @@ def cf_log_analytics_data_plane(cli_ctx, _):
cred, _, _ = profile.get_login_credentials(
resource="https://api.loganalytics.io")
return LogAnalyticsDataClient(cred)


def cf_disk_encryption_set(cli_ctx, _):
return _compute_client_factory(cli_ctx).disk_encryption_sets
10 changes: 10 additions & 0 deletions src/azure-cli/azure/cli/command_modules/vm/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@
crafted: true
"""

helps['disk-encryption-set'] = """
type: group
short-summary: Disk Encryption Set resource.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ramankumarlive, could you help give a summary of disk encryption set?

"""

helps['disk-encryption-set create'] = """
type: command
short-summary: Create a Disk Encryption Set.
"""

helps['image'] = """
type: group
short-summary: Manage custom virtual machine images.
Expand Down
10 changes: 10 additions & 0 deletions src/azure-cli/azure/cli/command_modules/vm/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def load_arguments(self, _):

extension_instance_name_type = CLIArgumentType(help="Name of extension instance, which can be customized. Default: name of the extension.")
image_template_name_type = CLIArgumentType(overrides=name_arg_type, id_part='name')
disk_encryption_set_name = CLIArgumentType(overrides=name_arg_type, help='Name of disk encryption set.', id_part='name')

# StorageAccountTypes renamed to DiskStorageAccountTypes in 2018_06_01 of azure-mgmt-compute
DiskStorageAccountTypes = DiskStorageAccountTypes or StorageAccountTypes
Expand Down Expand Up @@ -838,3 +839,12 @@ def load_arguments(self, _):
c.argument('analytics_query', options_list=['--analytics-query', '-q'], help="Query to execute over Log Analytics data.")
c.argument('timespan', help="Timespan over which to query. Defaults to querying all available data.")
# endregion

# region disk encryption set
with self.argument_context('disk-encryption-set') as c:
c.argument('disk_encryption_set_name', disk_encryption_set_name)
c.argument('key_url', help='URL pointing to a key or secret in KeyVault.')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the key_url same with Swagger property name? it's confusing with help message.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the name --key or --active-key is better than --key-url.

c.argument('source_vault', help='Resource ID of the KeyVault containing the key or secret.')
qwordy marked this conversation as resolved.
Show resolved Hide resolved
c.argument('location', validator=get_default_location_from_resource_group)
c.argument('tags', tags_type)
# endregion
15 changes: 14 additions & 1 deletion src/azure-cli/azure/cli/command_modules/vm/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
cf_gallery_images, cf_gallery_image_versions,
cf_proximity_placement_groups,
cf_dedicated_hosts, cf_dedicated_host_groups,
cf_log_analytics_data_plane)
cf_log_analytics_data_plane,
cf_disk_encryption_set)
from azure.cli.command_modules.vm._format import (
transform_ip_addresses, transform_vm, transform_vm_create_output, transform_vm_usage_list, transform_vm_list,
transform_sku_for_table_output, transform_disk_show_table_output, transform_extension_show_table_output,
Expand Down Expand Up @@ -172,6 +173,11 @@ def load_command_table(self, _):
client_factory=cf_log_analytics_data_plane,
)

compute_disk_encryption_set_sdk = CliCommandType(
operations_tmpl='azure.mgmt.compute.operations#DiskEncryptionSetsOperations.{}',
client_factory=cf_disk_encryption_set
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, I'm curious about the api-version of this command type. Sometimes you need to set operation_group for the commandType in VM, sometimes you don't. Is there any guideline for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

operation_group - Only used by the azure-cli-vm module to specify which resource API to target. No

)

with self.command_group('disk', compute_disk_sdk, operation_group='disks', min_api='2017-03-30') as g:
g.custom_command('create', 'create_managed_disk', supports_no_wait=True, table_transformer=transform_disk_show_table_output, validator=process_disk_or_snapshot_create_namespace)
g.command('delete', 'delete', supports_no_wait=True, confirmation=True)
Expand All @@ -182,6 +188,13 @@ def load_command_table(self, _):
g.generic_update_command('update', custom_func_name='update_managed_disk', setter_arg_name='disk', supports_no_wait=True)
g.wait_command('wait')

with self.command_group('disk-encryption-set', compute_disk_encryption_set_sdk, client_factory=cf_disk_encryption_set) as g:
g.custom_command('create', 'create_disk_encryption_set')
g.command('delete', 'delete')
# g.command('update', 'update')
g.show_command('show', 'get')
g.command('list', 'list')

with self.command_group('image', compute_image_sdk, min_api='2016-04-30-preview') as g:
g.custom_command('create', 'create_image', validator=process_image_create_namespace)
g.custom_command('list', 'list_images')
Expand Down
19 changes: 19 additions & 0 deletions src/azure-cli/azure/cli/command_modules/vm/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2933,3 +2933,22 @@ def execute_query_for_vm(cmd, client, resource_group_name, vm_name, analytics_qu
'Please check the status of log analytics workpsace.')
return client.query(workspace, QueryBody(query=analytics_query, timespan=timespan))
# endregion


# disk encryption set
def create_disk_encryption_set(cmd, client, resource_group_name, disk_encryption_set_name,
key_url, source_vault, location=None, tags=None):
from msrestazure.tools import resource_id, is_valid_resource_id
qwordy marked this conversation as resolved.
Show resolved Hide resolved
DiskEncryptionSet, EncryptionSetIdentity, KeyVaultAndKeyReference, SourceVault = cmd.get_models(
'DiskEncryptionSet', 'EncryptionSetIdentity', 'KeyVaultAndKeyReference', 'SourceVault')
encryption_set_identity = EncryptionSetIdentity(type='SystemAssigned')
if not is_valid_resource_id(source_vault):
source_vault = resource_id(subscription=client.config.subscription_id, resource_group=resource_group_name,
namespace='Microsoft.KeyVault', type='vaults', name=source_vault)
source_vault = SourceVault(id=source_vault)
keyVault_and_key_reference = KeyVaultAndKeyReference(source_vault=source_vault, key_url=key_url)
disk_encryption_set = DiskEncryptionSet(location=location, tags=tags, identity=encryption_set_identity,
active_key=keyVault_and_key_reference)
return client.create_or_update(resource_group_name, disk_encryption_set_name, disk_encryption_set)

# endregion
Loading