-
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
[Compute] disk update: Add --disk-encryption-set and --encryption-type; snapshot create/update: Add --disk-encryption-set and --encryption-type #11805
Changes from all commits
97e2f06
8a8db11
4c0dd7d
1d35e94
8ff7d0d
fe49682
8cec412
ca2330d
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 |
---|---|---|
|
@@ -327,7 +327,11 @@ def list_managed_disks(cmd, resource_group_name=None): | |
return client.disks.list() | ||
|
||
|
||
def update_managed_disk(cmd, instance, size_gb=None, sku=None, disk_iops_read_write=None, disk_mbps_read_write=None): | ||
def update_managed_disk(cmd, resource_group_name, instance, size_gb=None, sku=None, disk_iops_read_write=None, | ||
disk_mbps_read_write=None, encryption_type=None, disk_encryption_set=None): | ||
from msrestazure.tools import resource_id, is_valid_resource_id | ||
from azure.cli.core.commands.client_factory import get_subscription_id | ||
|
||
if size_gb is not None: | ||
instance.disk_size_gb = size_gb | ||
if sku is not None: | ||
|
@@ -336,6 +340,17 @@ def update_managed_disk(cmd, instance, size_gb=None, sku=None, disk_iops_read_wr | |
instance.disk_iops_read_write = disk_iops_read_write | ||
if disk_mbps_read_write is not None: | ||
instance.disk_mbps_read_write = disk_mbps_read_write | ||
if disk_encryption_set is not None: | ||
if instance.encryption.type != 'EncryptionAtRestWithCustomerKey' and \ | ||
encryption_type != 'EncryptionAtRestWithCustomerKey': | ||
raise CLIError('usage error: Please set --encryption-type to EncryptionAtRestWithCustomerKey') | ||
if not is_valid_resource_id(disk_encryption_set): | ||
disk_encryption_set = resource_id( | ||
subscription=get_subscription_id(cmd.cli_ctx), resource_group=resource_group_name, | ||
namespace='Microsoft.Compute', type='diskEncryptionSets', name=disk_encryption_set) | ||
instance.encryption.disk_encryption_set_id = disk_encryption_set | ||
if encryption_type is not None: | ||
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 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 add a check now. |
||
instance.encryption.type = encryption_type | ||
return instance | ||
# endregion | ||
|
||
|
@@ -408,12 +423,18 @@ def list_images(cmd, resource_group_name=None): | |
|
||
|
||
# region Snapshots | ||
# pylint: disable=unused-argument,too-many-locals | ||
def create_snapshot(cmd, resource_group_name, snapshot_name, location=None, size_gb=None, sku='Standard_LRS', | ||
source=None, for_upload=None, incremental=None, # pylint: disable=unused-argument | ||
source=None, for_upload=None, incremental=None, | ||
# below are generated internally from 'source' | ||
source_blob_uri=None, source_disk=None, source_snapshot=None, source_storage_account_id=None, | ||
hyper_v_generation=None, tags=None, no_wait=False): | ||
Snapshot, CreationData, DiskCreateOption = cmd.get_models('Snapshot', 'CreationData', 'DiskCreateOption') | ||
hyper_v_generation=None, tags=None, no_wait=False, disk_encryption_set=None, | ||
encryption_type=None): | ||
from msrestazure.tools import resource_id, is_valid_resource_id | ||
from azure.cli.core.commands.client_factory import get_subscription_id | ||
|
||
Snapshot, CreationData, DiskCreateOption, Encryption = cmd.get_models( | ||
'Snapshot', 'CreationData', 'DiskCreateOption', 'Encryption') | ||
|
||
location = location or _get_resource_group_location(cmd.cli_ctx, resource_group_name) | ||
if source_blob_uri: | ||
|
@@ -432,8 +453,22 @@ def create_snapshot(cmd, resource_group_name, snapshot_name, location=None, size | |
|
||
if size_gb is None and option == DiskCreateOption.empty: | ||
raise CLIError('Please supply size for the snapshots') | ||
|
||
if disk_encryption_set is not None and not is_valid_resource_id(disk_encryption_set): | ||
disk_encryption_set = resource_id( | ||
subscription=get_subscription_id(cmd.cli_ctx), resource_group=resource_group_name, | ||
namespace='Microsoft.Compute', type='diskEncryptionSets', name=disk_encryption_set) | ||
|
||
if disk_encryption_set is not None and encryption_type is None: | ||
raise CLIError('usage error: Please specify --encryption-type.') | ||
if encryption_type is not None: | ||
encryption = Encryption(type=encryption_type, disk_encryption_set_id=disk_encryption_set) | ||
else: | ||
encryption = None | ||
|
||
snapshot = Snapshot(location=location, creation_data=creation_data, tags=(tags or {}), | ||
sku=_get_sku_object(cmd, sku), disk_size_gb=size_gb, incremental=incremental) | ||
sku=_get_sku_object(cmd, sku), disk_size_gb=size_gb, incremental=incremental, | ||
encryption=encryption) | ||
if hyper_v_generation: | ||
snapshot.hyper_vgeneration = hyper_v_generation | ||
|
||
|
@@ -453,9 +488,23 @@ def list_snapshots(cmd, resource_group_name=None): | |
return client.snapshots.list() | ||
|
||
|
||
def update_snapshot(cmd, instance, sku=None): | ||
def update_snapshot(cmd, resource_group_name, instance, sku=None, disk_encryption_set=None, encryption_type=None): | ||
from msrestazure.tools import resource_id, is_valid_resource_id | ||
from azure.cli.core.commands.client_factory import get_subscription_id | ||
|
||
if sku is not None: | ||
_set_sku(cmd, instance, sku) | ||
if disk_encryption_set is not None: | ||
if instance.encryption.type != 'EncryptionAtRestWithCustomerKey' and \ | ||
encryption_type != 'EncryptionAtRestWithCustomerKey': | ||
raise CLIError('usage error: Please set --encryption-type to EncryptionAtRestWithCustomerKey') | ||
if not is_valid_resource_id(disk_encryption_set): | ||
disk_encryption_set = resource_id( | ||
subscription=get_subscription_id(cmd.cli_ctx), resource_group=resource_group_name, | ||
namespace='Microsoft.Compute', type='diskEncryptionSets', name=disk_encryption_set) | ||
instance.encryption.disk_encryption_set_id = disk_encryption_set | ||
if encryption_type is not None: | ||
instance.encryption.type = encryption_type | ||
return instance | ||
# endregion | ||
|
||
|
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.
I add this check because service will ignore disk_encryption_set if encryption_type is not set correctly. No error threw by service.