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

[connectedvmware] Added tags support and fix know bugs. #4264

Merged
merged 8 commits into from
Jan 4, 2022
6 changes: 6 additions & 0 deletions src/connectedvmware/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
Release History
===============

0.1.6
++++++
* Fix vm update
* Fix inventory item show
* Add support for tagging

0.1.5
++++++
* Fixed inventory item id issue.
Expand Down
28 changes: 23 additions & 5 deletions src/connectedvmware/azext_connectedvmware/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def connect_vcenter(
port=port,
extended_location=extended_location,
credentials=username_creds,
tags=tags
)

return sdk_no_wait(
Expand Down Expand Up @@ -206,14 +207,14 @@ def show_inventory_item(
inventory_item
):

return client.get(resource_group_name, vcenter, inventory_item)
return client.get(resource_group_name, vcenter.split('/')[-1], inventory_item.split('/')[-1])


def list_inventory_item(
client: InventoryItemsOperations, resource_group_name, vcenter
):

return client.list_by_v_center(resource_group_name, vcenter)
return client.list_by_v_center(resource_group_name, vcenter.split('/')[-1])


# endregion
Expand Down Expand Up @@ -283,13 +284,15 @@ def create_resource_pool(
location=location,
extended_location=extended_location,
inventory_item_id=inventory_item_id,
tags=tags
)
else:
resource_pool = ResourcePool(
location=location,
extended_location=extended_location,
v_center_id=vcenter_id,
mo_ref_id=mo_ref_id,
tags=tags
)

return sdk_no_wait(
Expand Down Expand Up @@ -391,13 +394,15 @@ def create_cluster(
location=location,
extended_location=extended_location,
inventory_item_id=inventory_item_id,
tags=tags
)
else:
cluster = Cluster(
location=location,
extended_location=extended_location,
v_center_id=vcenter_id,
mo_ref_id=mo_ref_id,
tags=tags
)

return sdk_no_wait(
Expand Down Expand Up @@ -499,13 +504,15 @@ def create_datastore(
location=location,
extended_location=extended_location,
inventory_item_id=inventory_item_id,
tags=tags
)
else:
datastore = Datastore(
location=location,
extended_location=extended_location,
v_center_id=vcenter_id,
mo_ref_id=mo_ref_id,
tags=tags
)

return sdk_no_wait(
Expand Down Expand Up @@ -607,13 +614,15 @@ def create_host(
location=location,
extended_location=extended_location,
inventory_item_id=inventory_item_id,
tags=tags
)
else:
host = Host(
location=location,
extended_location=extended_location,
v_center_id=vcenter_id,
mo_ref_id=mo_ref_id,
tags=tags
)

return sdk_no_wait(
Expand Down Expand Up @@ -715,13 +724,15 @@ def create_virtual_network(
location=location,
extended_location=extended_location,
inventory_item_id=inventory_item_id,
tags=tags
)
else:
virtual_network = VirtualNetwork(
location=location,
extended_location=extended_location,
v_center_id=vcenter_id,
mo_ref_id=mo_ref_id,
tags=tags
)

return sdk_no_wait(
Expand Down Expand Up @@ -829,13 +840,15 @@ def create_vm_template(
location=location,
extended_location=extended_location,
inventory_item_id=inventory_item_id,
tags=tags
)
else:
vm_template = VirtualMachineTemplate(
location=location,
extended_location=extended_location,
v_center_id=vcenter_id,
mo_ref_id=mo_ref_id,
tags=tags
)

return sdk_no_wait(
Expand Down Expand Up @@ -1071,6 +1084,7 @@ def create_vm(
os_profile=os_profile,
network_profile=network_profile,
storage_profile=storage_profile,
tags=tags
)
else:
vm = VirtualMachine(
Expand All @@ -1082,6 +1096,7 @@ def create_vm(
os_profile=os_profile,
network_profile=network_profile,
storage_profile=storage_profile,
tags=tags
)

return sdk_no_wait(
Expand Down Expand Up @@ -1121,14 +1136,17 @@ def update_vm(
num_cores_per_socket=num_cores_per_socket,
)

vm_update = VirtualMachineUpdate(hardware_profile=hardware_profile)
vm_update = VirtualMachineUpdate(
hardware_profile=hardware_profile,
tags=tags
)

return sdk_no_wait(
no_wait,
client.begin_update,
resource_group_name,
resource_name,
vm_update,
tags,
vm_update
)


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# --------------------------------------------------------------------------------------------
# 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.scenario_tests import AllowLargeResponse
from azure.cli.testsdk import ScenarioTest, ResourceGroupPreparer
from knack.util import CLIError
from azure.cli.testsdk import ScenarioTest

TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..'))


class ConnectedvmwareScenarioTest(ScenarioTest):
@ResourceGroupPreparer(name_prefix='cli_test_connectedvmware')
def test_connectedvmware_vcenter(self, resource_group):

self.kwargs.update({'name': 'test1'})

# raise CLIError('TODO')
93mishra marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ def test_connectedvmware(self):
# At least 1 disk should be there for the vm resource.
assert len(resource_list) >= 1

# Update VM.
self.cmd('az connectedvmware vm update -g {rg} --name {vm_name} --memory-size 2048 --num-CPUs 2')
93mishra marked this conversation as resolved.
Show resolved Hide resolved

# Stop VM.
self.cmd('az connectedvmware vm stop -g {rg} --name {vm_name}')

Expand Down
2 changes: 1 addition & 1 deletion src/connectedvmware/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# TODO: Confirm this is the right version number you want and it matches your
# HISTORY.rst entry.

VERSION = '0.1.5'
VERSION = '0.1.6'

# The full list of classifiers is available at
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
Expand Down