Skip to content

Commit

Permalink
[vmware] Use the New Resource Model for VM operations (#6578)
Browse files Browse the repository at this point in the history
  • Loading branch information
nascarsayan authored Aug 8, 2023
1 parent 26ae0e5 commit 6f266c3
Show file tree
Hide file tree
Showing 102 changed files with 26,313 additions and 2,590 deletions.
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

0 comments on commit 6f266c3

Please sign in to comment.