diff --git a/src/vmware/CHANGELOG.md b/src/vmware/CHANGELOG.md index 2dde8b3e47f..610aa1dd767 100644 --- a/src/vmware/CHANGELOG.md +++ b/src/vmware/CHANGELOG.md @@ -1,5 +1,8 @@ # Release History +## 3.1.0 (2021-07) +- Add `az vmware cloud-link` command group + ## 3.0.0 (2021-07) - [BREAKING CHANGE] `az vmware datastore create` has been removed. Please use `az vmware datastore netapp-volume create` or `az vmware datastore disk-pool-volume create` instead. diff --git a/src/vmware/azext_vmware/_help.py b/src/vmware/azext_vmware/_help.py index 0d30d76d60c..117e6fbbfb0 100644 --- a/src/vmware/azext_vmware/_help.py +++ b/src/vmware/azext_vmware/_help.py @@ -376,3 +376,48 @@ type: command short-summary: Delete a global reach connection in a private cloud. """ + +helps['vmware cloud-link'] = """ + type: group + short-summary: Commands to manage cloud links in a private cloud. +""" + +helps['vmware cloud-link create'] = """ + type: command + short-summary: Create a cloud link in a private cloud. + examples: + - name: Create a cloud link. + text: az vmware cloud-link create --resource-group group1 --private-cloud cloud1 --name cloudLink1 --linked-cloud "/subscriptions/12341234-1234-1234-1234-123412341234/resourceGroups/mygroup/providers/Microsoft.AVS/privateClouds/cloud2" +""" + +helps['vmware cloud-link update'] = """ + type: command + short-summary: Create a cloud link in a private cloud. + examples: + - name: Update a cloud link. + text: az vmware cloud-link update --resource-group group1 --private-cloud cloud1 --name cloudLink1 --linked-cloud "/subscriptions/12341234-1234-1234-1234-123412341234/resourceGroups/mygroup/providers/Microsoft.AVS/privateClouds/cloud2" +""" + +helps['vmware cloud-link list'] = """ + type: command + short-summary: List cloud links in a private cloud. + examples: + - name: List cloud links. + text: az vmware cloud-link list --resource-group group1 --private-cloud cloud1 +""" + +helps['vmware cloud-link show'] = """ + type: command + short-summary: Show details of a cloud link in a private cloud. + examples: + - name: Show a cloud link. + text: az vmware cloud-link show --resource-group group1 --private-cloud cloud1 --name cloudLink1 +""" + +helps['vmware cloud-link delete'] = """ + type: command + short-summary: Delete a cloud link in a private cloud. + examples: + - name: Delete a cloud link. + text: az vmware cloud-link delete --resource-group group1 --private-cloud cloud1 --name cloudLink1 +""" diff --git a/src/vmware/azext_vmware/_params.py b/src/vmware/azext_vmware/_params.py index a86b0c6d532..db87f476b88 100644 --- a/src/vmware/azext_vmware/_params.py +++ b/src/vmware/azext_vmware/_params.py @@ -107,3 +107,7 @@ def load_arguments(self, _): with self.argument_context('vmware global-reach-connection create') as c: c.argument('peer_express_route_circuit', help='Identifier of the ExpressRoute Circuit to peer with.') c.argument('authorization_key', help='Authorization key from the peer express route.') + + with self.argument_context('vmware cloud-link') as c: + c.argument('name', options_list=['--name', '-n'], help='The name of the cloud link.') + c.argument('linked_cloud', help='Identifier of the other private cloud participating in the link.') diff --git a/src/vmware/azext_vmware/commands.py b/src/vmware/azext_vmware/commands.py index af09172e119..cf6e55e4f69 100644 --- a/src/vmware/azext_vmware/commands.py +++ b/src/vmware/azext_vmware/commands.py @@ -87,3 +87,10 @@ def load_command_table(self, _): g.custom_command('list', 'globalreachconnection_list') g.custom_command('delete', 'globalreachconnection_delete') g.custom_show_command('show', 'globalreachconnection_show') + + with self.command_group('vmware cloud-link', vmware_sdk, client_factory=cf_vmware) as g: + g.custom_command('create', 'cloud_link_create_or_update') + g.custom_command('update', 'cloud_link_create_or_update') + g.custom_command('list', 'cloud_link_list') + g.custom_command('delete', 'cloud_link_delete') + g.custom_show_command('show', 'cloud_link_show') diff --git a/src/vmware/azext_vmware/custom.py b/src/vmware/azext_vmware/custom.py index 81b9e287830..baef37e4f46 100644 --- a/src/vmware/azext_vmware/custom.py +++ b/src/vmware/azext_vmware/custom.py @@ -272,3 +272,19 @@ def globalreachconnection_show(client: AVSClient, resource_group_name, private_c def globalreachconnection_delete(client: AVSClient, resource_group_name, private_cloud, name): return client.global_reach_connections.begin_delete(resource_group_name=resource_group_name, private_cloud_name=private_cloud, global_reach_connection_name=name) + + +def cloud_link_create_or_update(client: AVSClient, resource_group_name, name, private_cloud, linked_cloud): + return client.cloud_links.begin_create_or_update(resource_group_name=resource_group_name, private_cloud_name=private_cloud, cloud_link_name=name, linked_cloud=linked_cloud) + + +def cloud_link_list(client: AVSClient, resource_group_name, private_cloud): + return client.cloud_links.list(resource_group_name=resource_group_name, private_cloud_name=private_cloud) + + +def cloud_link_show(client: AVSClient, resource_group_name, private_cloud, name): + return client.cloud_links.get(resource_group_name=resource_group_name, private_cloud_name=private_cloud, cloud_link_name=name) + + +def cloud_link_delete(client: AVSClient, resource_group_name, private_cloud, name): + return client.cloud_links.begin_delete(resource_group_name=resource_group_name, private_cloud_name=private_cloud, cloud_link_name=name) diff --git a/src/vmware/azext_vmware/tests/latest/recordings/test_vmware_cloud_link.yaml b/src/vmware/azext_vmware/tests/latest/recordings/test_vmware_cloud_link.yaml new file mode 100644 index 00000000000..ca4e0a71f87 --- /dev/null +++ b/src/vmware/azext_vmware/tests/latest/recordings/test_vmware_cloud_link.yaml @@ -0,0 +1,126 @@ +interactions: +- request: + body: '{"properties": {"linkedCloud": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup/providers/Microsoft.AVS/privateClouds/cloud2"}}' + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - vmware cloud-link create + Connection: + - keep-alive + Content-Length: + - '154' + Content-Type: + - application/json + ParameterSetName: + - -g -c -n --linked-cloud + User-Agent: + - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) + method: PUT + uri: https://localhost:8866/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_hcx000001/providers/Microsoft.AVS/privateClouds/cloud1/cloudLinks/cloudLink1?api-version=2021-06-01 + response: + body: + string: '{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/cloudLinks/cloudLink1","name":"cloudLink1","type":"Microsoft.AVS/privateClouds/cloudLinks","properties":{"status":"Active","linkedCloud":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup/providers/Microsoft.AVS/privateClouds/cloud2"}}' + headers: + content-length: + - '367' + content-type: + - application/json + date: + - Mon, 12 Jul 2021 22:04:02 GMT + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - vmware cloud-link list + Connection: + - keep-alive + ParameterSetName: + - -g -c + User-Agent: + - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) + method: GET + uri: https://localhost:8866/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_hcx000001/providers/Microsoft.AVS/privateClouds/cloud1/cloudLinks?api-version=2021-06-01 + response: + body: + string: '{"value":[{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/cloudLinks/cloudLink1","name":"cloudLink1","type":"Microsoft.AVS/privateClouds/cloudLinks","properties":{"status":"Active","linkedCloud":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup/providers/Microsoft.AVS/privateClouds/cloud2"}}]}' + headers: + content-length: + - '379' + content-type: + - application/json + date: + - Mon, 12 Jul 2021 22:04:04 GMT + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - vmware cloud-link show + Connection: + - keep-alive + ParameterSetName: + - -g -c -n + User-Agent: + - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) + method: GET + uri: https://localhost:8866/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_hcx000001/providers/Microsoft.AVS/privateClouds/cloud1/cloudLinks/cloudLink1?api-version=2021-06-01 + response: + body: + string: '{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/cloudLinks/cloudLink1","name":"cloudLink1","type":"Microsoft.AVS/privateClouds/cloudLinks","properties":{"status":"Active","linkedCloud":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup/providers/Microsoft.AVS/privateClouds/cloud2"}}' + headers: + content-length: + - '367' + content-type: + - application/json + date: + - Mon, 12 Jul 2021 22:04:06 GMT + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - vmware cloud-link delete + Connection: + - keep-alive + Content-Length: + - '0' + ParameterSetName: + - -g -c -n + User-Agent: + - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) + method: DELETE + uri: https://localhost:8866/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_hcx000001/providers/Microsoft.AVS/privateClouds/cloud1/cloudLinks/cloudLink1?api-version=2021-06-01 + response: + body: + string: '' + headers: + content-length: + - '0' + date: + - Mon, 12 Jul 2021 22:04:08 GMT + status: + code: 200 + message: OK +version: 1 diff --git a/src/vmware/azext_vmware/tests/latest/test_cloud_link_scenario.py b/src/vmware/azext_vmware/tests/latest/test_cloud_link_scenario.py new file mode 100644 index 00000000000..1bb6f574211 --- /dev/null +++ b/src/vmware/azext_vmware/tests/latest/test_cloud_link_scenario.py @@ -0,0 +1,38 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +# import os +# import unittest + +from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer) + + +class VmwareCloudLinkScenarioTest(ScenarioTest): + def setUp(self): + # https://vcrpy.readthedocs.io/en/latest/configuration.html#request-matching + self.vcr.match_on = ['scheme', 'method', 'path', 'query'] # not 'host', 'port' + super(VmwareCloudLinkScenarioTest, self).setUp() + + @ResourceGroupPreparer(name_prefix='cli_test_vmware_hcx') + def test_vmware_cloud_link(self): + self.kwargs.update({ + 'privatecloud': 'cloud1', + 'cloud_link': 'cloudLink1', + 'linked_cloud': '/subscriptions/12341234-1234-1234-1234-123412341234/resourceGroups/mygroup/providers/Microsoft.AVS/privateClouds/cloud2', + }) + + rsp = self.cmd('az vmware cloud-link create -g {rg} -c {privatecloud} -n {cloud_link} --linked-cloud {linked_cloud}').get_output_in_json() + self.assertEqual(rsp['type'], 'Microsoft.AVS/privateClouds/cloudLinks') + self.assertEqual(rsp['name'], self.kwargs.get('cloud_link')) + + count = len(self.cmd('az vmware cloud-link list -g {rg} -c {privatecloud}').get_output_in_json()) + self.assertEqual(count, 1, 'count expected to be 1') + + self.cmd('vmware cloud-link show -g {rg} -c {privatecloud} -n {cloud_link}').get_output_in_json() + self.assertEqual(rsp['type'], 'Microsoft.AVS/privateClouds/cloudLinks') + self.assertEqual(rsp['name'], self.kwargs.get('cloud_link')) + + rsp = self.cmd('vmware cloud-link delete -g {rg} -c {privatecloud} -n {cloud_link}').output + self.assertEqual(len(rsp), 0)