-
Notifications
You must be signed in to change notification settings - Fork 1.5k
initial changes for stack-hci vmconnect command #9021
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
base: main
Are you sure you want to change the base?
Changes from 9 commits
532951a
d939b59
79de363
f7bdf31
71df898
2fa6076
837963d
12b2485
63aeaef
570a285
976cf8f
ad22a99
8b5b2c7
7a62fd5
de846d4
3f79d75
0a4bcd0
3dcd57e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,3 +75,146 @@ def pre_instance_update(self, instance): | |
| args = self.ctx.args | ||
| if args.system_assigned: | ||
| args.type = 'None' | ||
|
|
||
|
|
||
| class VmConnectEnable(_VmConnectEnable): | ||
| @classmethod | ||
| def _build_arguments_schema(cls, *args, **kwargs): | ||
| from azure.cli.core.aaz import AAZResourceGroupNameArg, AAZStrArg | ||
| args_schema = super()._build_arguments_schema(*args, **kwargs) | ||
| args_schema.cluster_name = AAZStrArg( | ||
| options=["--cluster-name", "-n"], | ||
| help="The name of the cluster.", | ||
| required=True | ||
| ) | ||
| args_schema.resource_group = AAZResourceGroupNameArg( | ||
| options=["--resource-group", "-g"], | ||
| help="Name of resource group.", | ||
| required=True | ||
| ) | ||
| args_schema.vm_name = AAZStrArg( | ||
| options=["--vm-name"], | ||
| help="The name of the virtual machine.", | ||
| required=True | ||
| ) | ||
| return args_schema | ||
|
|
||
| def __call__(self, cmd, **kwargs): | ||
| from azure.cli.core.commands.client_factory import get_subscription_id | ||
| from azure.cli.core.util import send_raw_request | ||
| import json | ||
|
|
||
| cluster_name = kwargs.get('cluster_name') | ||
| resource_group = kwargs.get('resource_group') | ||
| vm_name = kwargs.get('vm_name') | ||
| subscription_id = get_subscription_id(cmd.cli_ctx) | ||
|
|
||
| # Construct the REST API path | ||
| path = ( | ||
| f"/subscriptions/{subscription_id}/resourceGroups/{resource_group}/" | ||
| "providers/Microsoft.AzureStackHCI/clusters/" | ||
| f"{cluster_name}/jobs/VmConnectDeprovision" | ||
| ) | ||
| # API version | ||
| api_version = "2023-12-01-preview" | ||
| url = f"https://management.azure.com{path}?api-version={api_version}" | ||
hvedati marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # Default payload with VM name | ||
| payload = { | ||
| "properties": { | ||
| "jobType": "VmConnectProvision", | ||
| "deploymentMode": "Deploy", | ||
| "vmConnectProvisionJobDetails": [ | ||
| { | ||
| "vmName": vm_name | ||
| } | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| # Make the REST API call | ||
| try: | ||
| response = send_raw_request(cmd.cli_ctx, "PUT", url, body=json.dumps(payload)) | ||
| if response.content: | ||
| return response.json() | ||
| else: | ||
| return { | ||
| "message": ( | ||
| f"VM Connect provision job initiated successfully for VM: {vm_name}" | ||
|
||
| ) | ||
| } | ||
| except Exception as e: | ||
| from azure.cli.core.util import CLIError | ||
| raise CLIError(f"Failed to enable VM Connect for VM '{vm_name}': {str(e)}") | ||
|
|
||
|
|
||
| class VmConnectDisable(_VmConnectDisable): | ||
| @classmethod | ||
| def _build_arguments_schema(cls, *args, **kwargs): | ||
| from azure.cli.core.aaz import AAZResourceGroupNameArg, AAZStrArg | ||
| args_schema = super()._build_arguments_schema(*args, **kwargs) | ||
| args_schema.cluster_name = AAZStrArg( | ||
| options=["--cluster-name", "-n"], | ||
| help="The name of the cluster.", | ||
| required=True | ||
| ) | ||
| args_schema.resource_group = AAZResourceGroupNameArg( | ||
| options=["--resource-group", "-g"], | ||
| help="Name of resource group.", | ||
| required=True | ||
| ) | ||
| args_schema.vm_name = AAZStrArg( | ||
| options=["--vm-name"], | ||
| help="The name of the virtual machine.", | ||
| required=True | ||
| ) | ||
| return args_schema | ||
|
|
||
| def __call__(self, cmd, **kwargs): | ||
| from azure.cli.core.commands.client_factory import get_subscription_id | ||
| from azure.cli.core.util import send_raw_request | ||
| import json | ||
|
|
||
| cluster_name = kwargs.get('cluster_name') | ||
| resource_group = kwargs.get('resource_group') | ||
| vm_name = kwargs.get('vm_name') | ||
|
|
||
| subscription_id = get_subscription_id(cmd.cli_ctx) | ||
|
|
||
| # Construct the REST API path for deprovision | ||
| path = ( | ||
| f"/subscriptions/{subscription_id}/resourceGroups/{resource_group}/" | ||
| "providers/Microsoft.AzureStackHCI/clusters/" | ||
| f"{cluster_name}/jobs/VmConnectDeprovision" | ||
hvedati marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| # API version | ||
| api_version = "2023-12-01-preview" | ||
| url = f"https://management.azure.com{path}?api-version={api_version}" | ||
|
|
||
| # Payload for VM Connect deprovision | ||
| payload = { | ||
| "properties": { | ||
| "jobType": "VmConnectRemove", | ||
| "deploymentMode": "Deploy", | ||
| "vmConnectRemoveJobDetails": [ | ||
| { | ||
| "vmName": vm_name | ||
| } | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| # Make the REST API call | ||
| try: | ||
| response = send_raw_request(cmd.cli_ctx, "PUT", url, body=json.dumps(payload)) | ||
| if response.content: | ||
| return response.json() | ||
| else: | ||
| return { | ||
| "message": ( | ||
| f"VM Connect provision job initiated successfully for VM: {vm_name}" | ||
hvedati marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
| } | ||
| except Exception as e: | ||
| from azure.cli.core.util import CLIError | ||
| raise CLIError(f"Failed to disable VM Connect for VM '{vm_name}': {str(e)}") | ||
Uh oh!
There was an error while loading. Please reload this page.