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

private-cloud cmk-encryption commands, identity commands, and test cases #5151

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
9 changes: 9 additions & 0 deletions src/vmware/HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Release History

## 4.0.3 (2022-07)
jonathanhe-msft marked this conversation as resolved.
Show resolved Hide resolved

- Add `az vmware private-cloud enable-cmk-encryption`
- Add `az vmware private-cloud disable-cmk-encryption`
- Deprecate `az vmware private-cloud add-cmk-encryption`
- Deprecate `az vmware private-cloud delete-cmk-encryption`
- Removed `--mi-system-assigned` parameter from `az vmware private-cloud identity assign`
jonathanhe-msft marked this conversation as resolved.
Show resolved Hide resolved
- Renamed `--mi-system-assigned` parameter from `az vmware private-cloud create` to `--identity`
jonathanhe-msft marked this conversation as resolved.
Show resolved Hide resolved

## 4.0.2 (2022-02)

- Update `az vmware datastore disk-pool-volume create` to only accept one argument for --mount-option
Expand Down
10 changes: 10 additions & 0 deletions src/vmware/azext_vmware/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@
short-summary: Delete a Customer Managed Keys Encryption from a private cloud.
"""

helps['vmware private-cloud enable-cmk-encryption'] = """
type: command
short-summary: Enable a Customer Managed Keys Encryption to a private cloud.
"""

helps['vmware private-cloud disable-cmk-encryption'] = """
type: command
short-summary: Disable a Customer Managed Keys Encryption from a private cloud.
"""

helps['vmware private-cloud identity'] = """
type: group
short-summary: Commands for Managed Identity in a private cloud.
Expand Down
11 changes: 6 additions & 5 deletions src/vmware/azext_vmware/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def load_arguments(self, _):
c.argument('nsxt_password', help='NSX-T Manager password.')
c.argument('accept_eula', help='Accept the end-user license agreement without prompting.')
c.argument('network_block', help='A subnet at least of size /22. Make sure the CIDR format is conformed to (A.B.C.D/X) where A,B,C,D are between 0 and 255, and X is between 0 and 22.')
c.argument('mi_system_assigned', help='Enable a system assigned identity.')
c.argument('identity', help='Enable a system assigned identity.')
jonathanhe-msft marked this conversation as resolved.
Show resolved Hide resolved

with self.argument_context('vmware private-cloud show') as c:
c.argument('name', options_list=['--name', '-n'], help='Name of the private cloud.')
Expand All @@ -60,7 +60,11 @@ def load_arguments(self, _):
c.argument('secondary_zone', help='The secondary availability zone for the private cloud.')

with self.argument_context('vmware private-cloud add-cmk-encryption') as c:
c.argument('enc_status', help='Status of customer managed encryption key. Possible values include "Enabled" and "Disabled".')
c.argument('enc_kv_key_name', help='The name of the encryption key vault key.')
c.argument('enc_kv_url', help='The URL of the encryption key vault.')
c.argument('enc_kv_key_version', help='The version of the encryption key vault key.')

with self.argument_context('vmware private-cloud enable-cmk-encryption') as c:
c.argument('enc_kv_key_name', help='The name of the encryption key vault key.')
c.argument('enc_kv_url', help='The URL of the encryption key vault.')
c.argument('enc_kv_key_version', help='The version of the encryption key vault key.')
Expand Down Expand Up @@ -99,9 +103,6 @@ def load_arguments(self, _):
c.argument('domain', help='The domain\'s dns name.')
c.argument('name', options_list=['--name', '-n'], help='The name of the identity source.')

with self.argument_context('vmware private-cloud identity') as c:
c.argument('system_assigned', help='Enable a system assigned identity.')

with self.argument_context('vmware private-cloud update') as c:
c.argument('name', options_list=['--name', '-n'], help='Name of the private cloud.')

Expand Down
6 changes: 4 additions & 2 deletions src/vmware/azext_vmware/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ def load_command_table(self, _):
g.custom_command('delete-identity-source', 'privatecloud_deleteidentitysource')
g.custom_command('add-availability-zone', 'privatecloud_addavailabilityzone')
g.custom_command('delete-availability-zone', 'privatecloud_deleteavailabilityzone')
g.custom_command('add-cmk-encryption', 'privatecloud_addcmkencryption')
g.custom_command('delete-cmk-encryption', 'privatecloud_deletecmkenryption')
g.custom_command('add-cmk-encryption', 'privatecloud_addcmkencryption', deprecate_info=g.deprecate(redirect='az vmware private-cloud enable-cmk-encryption', hide=True))
g.custom_command('delete-cmk-encryption', 'privatecloud_deletecmkenryption', deprecate_info=g.deprecate(redirect='az vmware private-cloud disable-cmk-encryption', hide=True))
g.custom_command('enable-cmk-encryption', 'privatecloud_addcmkencryption')
g.custom_command('disable-cmk-encryption', 'privatecloud_deletecmkenryption')
g.custom_command('rotate-vcenter-password', 'privatecloud_rotate_vcenter_password')
g.custom_command('rotate-nsxt-password', 'privatecloud_rotate_nsxt_password')

Expand Down
48 changes: 23 additions & 25 deletions src/vmware/azext_vmware/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ def privatecloud_show(client: AVSClient, resource_group_name, name):
return client.private_clouds.get(resource_group_name, name)


def privatecloud_create(client: AVSClient, resource_group_name, name, sku, cluster_size, network_block, location=None, internet=None, vcenter_password=None, nsxt_password=None, tags=None, accept_eula=False, mi_system_assigned=False, yes=False):
def privatecloud_create(client: AVSClient, resource_group_name, name, sku, cluster_size, network_block, location=None, internet=None, vcenter_password=None, nsxt_password=None, tags=None, identity=False, accept_eula=False, yes=False):
from knack.prompting import prompt_y_n
if not accept_eula:
print(LEGAL_TERMS)
msg = 'Do you agree to the above additional terms for AVS?'
if not yes and not prompt_y_n(msg, default="n"):
return None

from azext_vmware.vendored_sdks.avs_client.models import PrivateCloud, Circuit, ManagementCluster, Sku, PrivateCloudIdentity
from azext_vmware.vendored_sdks.avs_client.models import PrivateCloud, Circuit, ManagementCluster, Sku, PrivateCloudIdentity, ResourceIdentityType
cloud = PrivateCloud(sku=Sku(name=sku), ciruit=Circuit(), management_cluster=ManagementCluster(cluster_size=cluster_size), network_block=network_block)
if location is not None:
cloud.location = location
if tags is not None:
cloud.tags = tags
if mi_system_assigned:
cloud.identity = PrivateCloudIdentity(type='SystemAssigned')
if identity:
cloud.identity = PrivateCloudIdentity(type=ResourceIdentityType.SYSTEM_ASSIGNED)
if internet is not None:
cloud.internet = internet
if vcenter_password is not None:
Expand All @@ -74,8 +74,8 @@ def privatecloud_create(client: AVSClient, resource_group_name, name, sku, clust


def privatecloud_update(client: AVSClient, resource_group_name, name, cluster_size=None, internet=None, tags=None):
from azext_vmware.vendored_sdks.avs_client.models import PrivateCloudUpdate, ManagementCluster
private_cloud_update = PrivateCloudUpdate()
from azext_vmware.vendored_sdks.avs_client.models import ManagementCluster
private_cloud_update = client.private_clouds.get(resource_group_name, name)
if tags is not None:
private_cloud_update.tags = tags
if cluster_size is not None:
Expand Down Expand Up @@ -122,8 +122,8 @@ def privatecloud_deleteidentitysource(client: AVSClient, resource_group_name, na


def privatecloud_addavailabilityzone(client: AVSClient, resource_group_name, private_cloud, strategy=None, zone=None, secondary_zone=None):
from azext_vmware.vendored_sdks.avs_client.models import AvailabilityProperties, PrivateCloudUpdate
pc = PrivateCloudUpdate()
from azext_vmware.vendored_sdks.avs_client.models import AvailabilityProperties
pc = client.private_clouds.get(resource_group_name, private_cloud)
pc.availability = AvailabilityProperties(strategy=strategy, zone=zone, secondary_zone=secondary_zone)
return client.private_clouds.begin_update(resource_group_name=resource_group_name, private_cloud_name=private_cloud, private_cloud_update=pc)

Expand All @@ -133,16 +133,15 @@ def privatecloud_deleteavailabilityzone(client: AVSClient, resource_group_name,
msg = 'This will delete the availability zone. Are you sure?'
if not yes and not prompt_y_n(msg, default="n"):
return None
from azext_vmware.vendored_sdks.avs_client.models import PrivateCloudUpdate
pc = PrivateCloudUpdate()
pc = client.private_clouds.get(resource_group_name, private_cloud)
pc.availability = None
return client.private_clouds.begin_update(resource_group_name=resource_group_name, private_cloud_name=private_cloud, private_cloud_update=pc)


def privatecloud_addcmkencryption(client: AVSClient, resource_group_name, private_cloud, enc_status=None, enc_kv_key_name=None, enc_kv_key_version=None, enc_kv_url=None):
from azext_vmware.vendored_sdks.avs_client.models import Encryption, EncryptionKeyVaultProperties, PrivateCloudUpdate
pc = PrivateCloudUpdate()
pc.encryption = Encryption(status=enc_status, key_vault_properties=EncryptionKeyVaultProperties(key_name=enc_kv_key_name, key_version=enc_kv_key_version, key_vault_url=enc_kv_url))
def privatecloud_addcmkencryption(client: AVSClient, resource_group_name, private_cloud, enc_kv_key_name=None, enc_kv_key_version=None, enc_kv_url=None):
from azext_vmware.vendored_sdks.avs_client.models import Encryption, EncryptionKeyVaultProperties, EncryptionState
pc = client.private_clouds.get(resource_group_name, private_cloud)
pc.encryption = Encryption(status=EncryptionState.ENABLED, key_vault_properties=EncryptionKeyVaultProperties(key_name=enc_kv_key_name, key_version=enc_kv_key_version, key_vault_url=enc_kv_url))
return client.private_clouds.begin_update(resource_group_name=resource_group_name, private_cloud_name=private_cloud, private_cloud_update=pc)


Expand All @@ -151,24 +150,23 @@ def privatecloud_deletecmkenryption(client: AVSClient, resource_group_name, priv
msg = 'This will delete the managed keys encryption. Are you sure?'
if not yes and not prompt_y_n(msg, default="n"):
return None
from azext_vmware.vendored_sdks.avs_client.models import PrivateCloudUpdate
pc = PrivateCloudUpdate()
pc.encryption = None
from azext_vmware.vendored_sdks.avs_client.models import Encryption, EncryptionState
pc = client.private_clouds.get(resource_group_name, private_cloud)
pc.encryption = Encryption(status=EncryptionState.DISABLED)
return client.private_clouds.begin_update(resource_group_name=resource_group_name, private_cloud_name=private_cloud, private_cloud_update=pc)


def privatecloud_identity_assign(client: AVSClient, resource_group_name, private_cloud, system_assigned=False):
from azext_vmware.vendored_sdks.avs_client.models import PrivateCloudIdentity, PrivateCloudUpdate
pc = PrivateCloudUpdate()
if system_assigned:
pc.identity = PrivateCloudIdentity(type="SystemAssigned")
def privatecloud_identity_assign(client: AVSClient, resource_group_name, private_cloud):
from azext_vmware.vendored_sdks.avs_client.models import PrivateCloudIdentity, ResourceIdentityType
pc = client.private_clouds.get(resource_group_name, private_cloud)
pc.identity = PrivateCloudIdentity(type=ResourceIdentityType.SYSTEM_ASSIGNED)
return client.private_clouds.begin_update(resource_group_name=resource_group_name, private_cloud_name=private_cloud, private_cloud_update=pc)


def privatecloud_identity_remove(client: AVSClient, resource_group_name, private_cloud):
from azext_vmware.vendored_sdks.avs_client.models import PrivateCloudIdentity, PrivateCloudUpdate
pc = PrivateCloudUpdate()
pc.identity = PrivateCloudIdentity(type="None")
from azext_vmware.vendored_sdks.avs_client.models import PrivateCloudIdentity, ResourceIdentityType
pc = client.private_clouds.get(resource_group_name, private_cloud)
pc.identity = PrivateCloudIdentity(type=ResourceIdentityType.NONE)
return client.private_clouds.begin_update(resource_group_name=resource_group_name, private_cloud_name=private_cloud, private_cloud_update=pc)


Expand Down
Loading