Skip to content

Commit

Permalink
Batch link to vcenter (#7218)
Browse files Browse the repository at this point in the history
  • Loading branch information
nascarsayan authored Mar 1, 2024
1 parent 5c25e74 commit 56151c9
Show file tree
Hide file tree
Showing 37 changed files with 6,883 additions and 1,272 deletions.
7 changes: 7 additions & 0 deletions src/connectedvmware/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
Release History
===============
1.0.0
++++++
* Add command `az connectedvmware create-from-machines`.
* Delete HCRP Machine resource by default during `delete vm`. To retain, use `--retain-machine` flag.
* Use GA API Version for VCENTER_KIND_GET_API_VERSION.
* Set extension to non-preview version

0.2.4
++++++
* Link existing HCRP machine to vCenter using the CLI.
Expand Down
17 changes: 17 additions & 0 deletions src/connectedvmware/azext_connectedvmware/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# Client factory for vmware clients.
from .vendored_sdks.connectedvmware import AzureArcVMwareManagementServiceAPI
from .vendored_sdks.hybridcompute import HybridComputeManagementClient
from .vendored_sdks.resourcegraph import ResourceGraphClient


def cf_connectedvmware(cli_ctx: AzCli, *_) -> AzureArcVMwareManagementServiceAPI:
Expand Down Expand Up @@ -100,3 +101,19 @@ def cf_machine_extension(cli_ctx: AzCli, *_):
Client factory for machines.
"""
return cf_hybridcompute(cli_ctx).machine_extensions


def cf_resource_graph(cli_ctx: AzCli, *_) -> ResourceGraphClient:
"""
Client factory for resource graph.
"""
# NOTE 1: Adding base_url_bound=False to avoid the following error
# TypeError: __init__() got multiple values for argument 'base_url'
# NOTE 2: Hardcoding subscription_bound=False to avoid the following error
# Bearer token authentication is not permitted for non-TLS protected (non-https) URLs.
return get_mgmt_service_client(
cli_ctx,
ResourceGraphClient,
subscription_bound=False,
base_url_bound=False,
)
25 changes: 25 additions & 0 deletions src/connectedvmware/azext_connectedvmware/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,31 @@
--vcenter contoso-vcenter
"""

helps[
'connectedvmware vm create-from-machines'
] = """
type: command
short-summary: "Create VMInstance resource(s) from existing Microsoft.HybridCompute machines."
examples:
- name: Create VMware resources from the specified Arc for Servers machine in the vCenter
text: |-
az connectedvmware vm create-from-machines \
--resource-group contoso-rg --name contoso-vm \
--vcenter-id /subscriptions/fedcba98-7654-3210-0123-456789abcdef/resourceGroups/contoso-rg-2/providers/Microsoft.HybridCompute/vcenters/contoso-vcenter
- name: Creates VMware resources from all Arc for Servers machines in the specified resource group belonging to that vCenter
text: |-
az connectedvmware vm create-from-machines \
--resource-group contoso-rg \
--vcenter-id /subscriptions/fedcba98-7654-3210-0123-456789abcdef/resourceGroups/contoso-rg-2/providers/Microsoft.HybridCompute/vcenters/contoso-vcenter
- name: Create VMware resources from all Arc for Servers machines in the specified subscription belonging to that vCenter
text: |-
az connectedvmware vm create-from-machines \
--subscription contoso-sub \
--vcenter-id /subscriptions/fedcba98-7654-3210-0123-456789abcdef/resourceGroups/contoso-rg-2/providers/Microsoft.HybridCompute/vcenters/contoso-vcenter
"""

helps[
'connectedvmware vm delete'
] = """
Expand Down
26 changes: 26 additions & 0 deletions src/connectedvmware/azext_connectedvmware/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,26 @@ def load_arguments(self, _):
with self.argument_context('connectedvmware vm-template delete') as c:
c.argument('force', action='store_true', help="Whether force delete or not.")

with self.argument_context('connectedvmware vm create-from-machines') as c:
c.argument(
'rg_name', options_list=['--resource-group', '-g'],
help=(
"Name of the resource group which will be scanned for HCRP machines. "
"NOTE: The default group configured using 'az configure --defaults group=<name>' "
"is not used, and it must be specified explicitly."
)
)
c.argument(
'resource_name', resource_name, options_list=['--name', '-n'],
help="Name of the Microsoft.HybridCompute Machine resource. "
"Provide this parameter if you want to "
"convert a single machine to VMware VM."
)
c.argument(
'vcenter', vcenter, options_list=['--vcenter-id', '-v'],
help="ARM ID of the vCenter to which the machines will be linked."
)

with self.argument_context('connectedvmware vm create') as c:
c.argument(
'resource_name', resource_name, options_list=['--name', '-n'],
Expand Down Expand Up @@ -216,10 +236,16 @@ def load_arguments(self, _):
action='store_true',
help='Delete the VM from the VMware host.',
)
c.argument(
'retain_machine',
action='store_true',
help='Retain the parent Microsoft.HybridCompute Machine resource',
)
c.argument(
'delete_machine',
action='store_true',
help='Delete the parent Microsoft.HybridCompute Machine resource',
deprecate_info=c.deprecate(hide=True),
)
c.argument(
'retain',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"azext.isPreview": true,
"azext.isPreview": false,
"azext.minCliCoreVersion": "2.0.67",
"azext.maxCliCoreVersion": "4.0.0"
}
1 change: 1 addition & 0 deletions src/connectedvmware/azext_connectedvmware/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def load_command_table(self: AzCommandsLoader, _):
'connectedvmware vm', client_factory=cf_virtual_machine_instance
) as g:
g.custom_command('create', 'create_vm', supports_no_wait=True)
g.custom_command('create-from-machines', 'create_from_machines')
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')
Expand Down
Loading

0 comments on commit 56151c9

Please sign in to comment.