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

[vmware] Use the New Resource Model for VM operations #6578

Merged
merged 23 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6c3b6ad
change folder
nascarsayan Jul 31, 2023
695a302
added hybridcompute, fixed lint issues
nascarsayan Jul 31, 2023
109d81b
temp
nascarsayan Jul 31, 2023
cb8afda
generate sdk for suppressed apis
nascarsayan Jul 31, 2023
29825c4
made necessary changes, todo: verify full flow and modify tests
nascarsayan Jul 31, 2023
46f8661
Merge branch 'main' of https://github.com/Azure/azure-cli-extensions …
nascarsayan Jul 31, 2023
64294a9
lint fixes
nascarsayan Jul 31, 2023
0bede36
modified tests, fixed lints, but put after delete failing
nascarsayan Aug 1, 2023
63f0be4
not deleting machine resource till service bug gets fixed
nascarsayan Aug 2, 2023
fa1fe1b
re-enable cluster and hosts as pr is merged
nascarsayan Aug 2, 2023
7428fce
remove extra #
nascarsayan Aug 2, 2023
42da06e
tests ran successfully
nascarsayan Aug 2, 2023
53688cc
add init.py in vendored_sdks folder
nascarsayan Aug 2, 2023
ceaad41
infer kind from vcenter resource
nascarsayan Aug 5, 2023
0fdeaaf
minor version upgrade
nascarsayan Aug 5, 2023
f981d8a
lint and style
nascarsayan Aug 5, 2023
3704c17
Deprecating retain and list
nascarsayan Aug 7, 2023
d6f4aaf
Adding back the help for vm list
nascarsayan Aug 7, 2023
72bef6e
Update src/connectedvmware/HISTORY.rst
nascarsayan Aug 8, 2023
ead6ad1
remove test-output xml files
nascarsayan Aug 8, 2023
50ad349
Merge branch 'dev/snaskar/nrm-pp-refresh' of github.com:nascarsayan/a…
nascarsayan Aug 8, 2023
6975ab6
fix type for list
nascarsayan Aug 8, 2023
241c114
dont update version in setup.py so as not to release till we have swa…
nascarsayan Aug 8, 2023
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
11 changes: 11 additions & 0 deletions src/connectedvmware/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
Release History
===============

0.2.0
++++++
* Using New Resource Model for all VM operations:
* `vm` command : Create, Update, Delete, Show, Start, Stop, Restart VirtualMachineInstance
* `vm guest-agent` command : Enable, Show VMInstanceGuestAgent
* `vm extension` command : Create, Update, Delete, Show, List MachineExtensions
* If underlying machine is not present, it gets created during vm create
* Added delete-from-host flag for `vm delete`
* Deprecated VM List option as VM Instance is a child resource of Machines.
* Updated tests and helps accordingly.

0.1.12
++++++
* Fixed VM extension issue.
Expand Down
2 changes: 1 addition & 1 deletion src/connectedvmware/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ az connectedvmware virtual-network create \
--name resourceName
```

##### Create Virtual Machine Resource
##### Create Virtual Machine Instance Resource

```
az connectedvmware vm create \
Expand Down
53 changes: 38 additions & 15 deletions src/connectedvmware/azext_connectedvmware/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,83 +4,106 @@
# --------------------------------------------------------------------------------------------

from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.cli.core import AzCli
# Client factory for vmware clients.
from .vendored_sdks import AzureArcVMwareManagementServiceAPI
from .vendored_sdks.connectedvmware import AzureArcVMwareManagementServiceAPI
from .vendored_sdks.hybridcompute import HybridComputeManagementClient


def cf_connectedvmware(cli_ctx, *_):
def cf_connectedvmware(cli_ctx: AzCli, *_) -> AzureArcVMwareManagementServiceAPI:
return get_mgmt_service_client(cli_ctx, AzureArcVMwareManagementServiceAPI)


def cf_vcenter(cli_ctx, *_):
def cf_hybridcompute(cli_ctx: AzCli, *_) -> HybridComputeManagementClient:
return get_mgmt_service_client(cli_ctx, HybridComputeManagementClient)


def cf_vcenter(cli_ctx: AzCli, *_):
"""
Client factory for vcenters.
"""
return cf_connectedvmware(cli_ctx).vcenters


def cf_resource_pool(cli_ctx, *_):
def cf_resource_pool(cli_ctx: AzCli, *_):
"""
Client factory for resourcepools.
"""
return cf_connectedvmware(cli_ctx).resource_pools


def cf_cluster(cli_ctx, *_):
def cf_cluster(cli_ctx: AzCli, *_):
"""
Client factory for clusters.
"""
return cf_connectedvmware(cli_ctx).clusters


def cf_datastore(cli_ctx, *_):
def cf_datastore(cli_ctx: AzCli, *_):
"""
Client factory for datastores.
"""
return cf_connectedvmware(cli_ctx).datastores


def cf_host(cli_ctx, *_):
def cf_host(cli_ctx: AzCli, *_):
"""
Client factory for hosts.
"""
return cf_connectedvmware(cli_ctx).hosts


def cf_virtual_network(cli_ctx, *_):
def cf_virtual_network(cli_ctx: AzCli, *_):
"""
Client factory for virtual networks.
"""
return cf_connectedvmware(cli_ctx).virtual_networks


def cf_virtual_machine_template(cli_ctx, *_):
def cf_virtual_machine_template(cli_ctx: AzCli, *_):
"""
Client factory for vm templates.
"""
return cf_connectedvmware(cli_ctx).virtual_machine_templates


def cf_virtual_machine(cli_ctx, *_):
def cf_virtual_machine(cli_ctx: AzCli, *_):
"""
Client factory for virtual machines.
"""
return cf_connectedvmware(cli_ctx).virtual_machines


def cf_inventory_item(cli_ctx, *_):
def cf_virtual_machine_instance(cli_ctx: AzCli, *_):
"""
Client factory for virtual machine instances.
"""
return cf_connectedvmware(cli_ctx).virtual_machine_instances


def cf_inventory_item(cli_ctx: AzCli, *_):
"""
Client factory for inventory items.
"""
return cf_connectedvmware(cli_ctx).inventory_items


def cf_guest_agent(cli_ctx, *_):
def cf_vminstance_guest_agent(cli_ctx: AzCli, *_):
"""
Client factory for guest agent.
"""
return cf_connectedvmware(cli_ctx).guest_agents
return cf_connectedvmware(cli_ctx).vm_instance_guest_agents


def cf_machine_extension(cli_ctx, *_):
return cf_connectedvmware(cli_ctx).machine_extensions
def cf_machine(cli_ctx: AzCli, *_):
"""
Client factory for machines.
"""
return cf_hybridcompute(cli_ctx).machines


def cf_machine_extension(cli_ctx: AzCli, *_):
"""
Client factory for machines.
"""
return cf_hybridcompute(cli_ctx).machine_extensions
13 changes: 12 additions & 1 deletion src/connectedvmware/azext_connectedvmware/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,21 @@ def load_arguments(self, _):

with self.argument_context('connectedvmware vm delete') as c:
c.argument('force', action='store_true', help="Whether force delete or not.")
c.argument(
'delete_from_host',
action='store_true',
help='Delete the VM from the VMware host.',
)
c.argument(
'delete_machine',
action='store_true',
help='Delete the parent Microsoft.HybridCompute Machine resource',
)
c.argument(
'retain',
action='store_true',
help='Disable the VM from azure; delete the ARM resource but retain the VM in VMware.',
help='Retain the VM in the VMWare host',
deprecate_info=c.deprecate(hide=True),
)

with self.argument_context('connectedvmware vm stop') as c:
Expand Down
19 changes: 11 additions & 8 deletions src/connectedvmware/azext_connectedvmware/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@
# --------------------------------------------------------------------------------------------
# pylint: disable=line-too-long, disable=too-many-statements

from azure.cli.core import AzCommandsLoader
from ._client_factory import (
cf_vcenter,
cf_resource_pool,
cf_virtual_network,
cf_virtual_machine_template,
cf_virtual_machine,
cf_virtual_machine_instance,
cf_inventory_item,
cf_guest_agent,
cf_vminstance_guest_agent,
cf_cluster,
cf_datastore,
cf_host,
cf_machine_extension,
)


def load_command_table(self, _):
def load_command_table(self: AzCommandsLoader, _):

with self.command_group('connectedvmware vcenter', client_factory=cf_vcenter) as g:
g.custom_command('connect', 'connect_vcenter', supports_no_wait=True)
Expand Down Expand Up @@ -82,19 +83,21 @@ def load_command_table(self, _):
g.custom_command('list', 'list_vm_template')

with self.command_group(
'connectedvmware vm', client_factory=cf_virtual_machine
'connectedvmware vm', client_factory=cf_virtual_machine_instance
) as g:
g.custom_command('create', 'create_vm', supports_no_wait=True)
g.custom_command('delete', 'delete_vm', supports_no_wait=True, confirmation=True)
g.custom_command('update', 'update_vm', supports_no_wait=True)
g.custom_show_command('show', 'show_vm')
g.custom_command('list', 'list_vm')
# g.custom_command('list', 'list_vm')
g.custom_command('list', 'list_vm',
deprecate_info=g.deprecate(redirect='az connectedvmware vm show', hide=True))
g.custom_command('start', 'start_vm', supports_no_wait=True)
g.custom_command('stop', 'stop_vm', supports_no_wait=True)
g.custom_command('restart', 'restart_vm', supports_no_wait=True)

with self.command_group(
'connectedvmware vm nic', client_factory=cf_virtual_machine
'connectedvmware vm nic', client_factory=cf_virtual_machine_instance
) as g:
g.custom_command('add', 'add_nic', supports_no_wait=True)
g.custom_command('update', 'update_nic', supports_no_wait=True)
Expand All @@ -103,7 +106,7 @@ def load_command_table(self, _):
g.custom_command('list', 'list_nics')

with self.command_group(
'connectedvmware vm disk', client_factory=cf_virtual_machine
'connectedvmware vm disk', client_factory=cf_virtual_machine_instance
) as g:
g.custom_command('add', 'add_disk', supports_no_wait=True)
g.custom_command('update', 'update_disk', supports_no_wait=True)
Expand All @@ -112,7 +115,7 @@ def load_command_table(self, _):
g.custom_command('list', 'list_disks')

with self.command_group(
'connectedvmware vm guest-agent', client_factory=cf_guest_agent
'connectedvmware vm guest-agent', client_factory=cf_vminstance_guest_agent
) as g:
g.custom_command('enable', 'enable_guest_agent', supports_no_wait=True)
g.custom_show_command('show', 'show_guest_agent')
Expand Down
Loading