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

[ssh] Add support to "Microsoft.ConnectedVMwarevSphere/virtualMachines" resource type #5367

Merged
merged 17 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions src/ssh/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ Release History
===============
1.1.3
-----
* Add support to Microsoft.ConnectedVMwarevSphere/virtualMachines Resource Type.
* Correct the format of expected input for --resource-type parameter. From Resource Provider name (e.g. "Microsoft.HybridCompute") to Resource Type name (e.g. "Microsoft.HybridCompute/machines").
* [bug fix] SSH Banners are printed before authentication.

1.1.2
Expand Down
10 changes: 10 additions & 0 deletions src/ssh/azext_ssh/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,13 @@ def cf_connectedmachine_cl(cli_ctx, *_):

def cf_machine(cli_ctx, *_):
return cf_connectedmachine_cl(cli_ctx).machines


def cf_connectedvmware_cl(cli_ctx, *_):
from azext_ssh.vendored_sdks.connectedvmware import AzureArcVMwareManagementServiceAPI
return get_mgmt_service_client(cli_ctx,
AzureArcVMwareManagementServiceAPI)
Comment on lines +35 to +37
Copy link
Contributor

@zhoxing-ms zhoxing-ms Oct 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please define a CustomResourceType for AzureArcVMwareManagementServiceAPI, such as:

CUSTOM_MGMT_STORAGE = CustomResourceType('azext_storage_preview.vendored_sdks.azure_mgmt_storage',
'StorageManagementClient')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhoxing-ms Why do we need to use this custom resource type? do I need to use it for the other clients in the same file as well? (hybrid connectivity and connected machine clients)

Copy link
Contributor Author

@vthiebaut10 vthiebaut10 Oct 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhoxing-ms when I try to use that I get this error: azure.cli.core.profiles._shared.APIVersionException: Unable to get API version for type '<azure.cli.core.profiles._shared.CustomResourceType object at 0x00000267F5ADE250>' in profile 'latest

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhoxing-ms I pushed the changes you requested, but this error still happens. Do you know what might cause that?

Copy link
Contributor

@zhoxing-ms zhoxing-ms Oct 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vthiebaut10 I recommended you define CustomResourceType because the parameter of method get_mgmt_service_client should be passed in client_or_resource_type, I personally think it will be more in line with the code specification.
But it seems that AzureArcVMwareManagementServiceAPI is non-versioned client, so it is not suitable to define as CustomResourceType. So please use AzureArcVMwareManagementServiceAPI directly as before , thanks~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhoxing-ms I reverted the changes.



def cf_vmware(cli_ctx, *_):
return cf_connectedvmware_cl(cli_ctx).virtual_machines
18 changes: 15 additions & 3 deletions src/ssh/azext_ssh/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ def load_arguments(self, _):
help='Path to a certificate file used for authentication when using local user credentials.')
c.argument('port', options_list=['--port'], help='SSH port')
c.argument('resource_type', options_list=['--resource-type'],
help='Resource type should be either Microsoft.Compute or Microsoft.HybridCompute',
completer=["Microsoft.HybridCompute", "Microsoft.Compute"])
help=('Resource type should be either Microsoft.Compute/virtualMachines, '
'Microsoft.HybridCompute/machines, '
'or Microsoft.ConnectedVMwareSphere/virtualMachines.'),
completer=['Microsoft.Compute/virtualMachines', 'Microsoft.HybridCompute/machines',
'Microsoft.ConnectedVMwareSphere/virtualMachines'])
c.argument('ssh_client_folder', options_list=['--ssh-client-folder'],
help='Folder path that contains ssh executables (ssh.exe, ssh-keygen.exe, etc). '
'Default to ssh pre-installed if not provided.')
Expand Down Expand Up @@ -52,7 +55,11 @@ def load_arguments(self, _):
help='Folder where new generated keys will be stored.')
c.argument('port', options_list=['--port'], help='SSH Port')
c.argument('resource_type', options_list=['--resource-type'],
help='Resource type should be either Microsoft.Compute or Microsoft.HybridCompute')
help=('Resource type should be either Microsoft.Compute/virtualMachines, '
'Microsoft.HybridCompute/machines, '
'or Microsoft.ConnectedVMwareSphere/virtualMachines.'),
completer=['Microsoft.Compute/virtualMachines', 'Microsoft.HybridCompute/machines',
'Microsoft.ConnectedVMwareSphere/virtualMachines'])
c.argument('cert_file', options_list=['--certificate-file', '-c'], help='Path to certificate file')
c.argument('ssh_proxy_folder', options_list=['--ssh-proxy-folder'],
help=('Path to the folder where the ssh proxy should be saved. '
Expand All @@ -79,6 +86,11 @@ def load_arguments(self, _):
help='The username for a local user')
c.argument('cert_file', options_list=['--certificate-file', '-c'], help='Path to certificate file')
c.argument('port', options_list=['--port'], help='Port to connect to on the remote host.')
c.argument('resource_type', options_list=['--resource-type'],
help=('Resource type should be either Microsoft.HybridCompute/machines '
'or Microsoft.ConnectedVMwareSphere/virtualMachines.'),
completer=['Microsoft.HybridCompute/machines',
'Microsoft.ConnectedVMwareSphere/virtualMachines'])
c.argument('ssh_client_folder', options_list=['--ssh-client-folder'],
help='Folder path that contains ssh executables (ssh.exe, ssh-keygen.exe, etc). '
'Default to ssh pre-installed if not provided.')
Expand Down
18 changes: 11 additions & 7 deletions src/ssh/azext_ssh/connectivity_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


# Get the Access Details to connect to Arc Connectivity platform from the HybridConnectivity RP
def get_relay_information(cmd, resource_group, vm_name, certificate_validity_in_seconds):
def get_relay_information(cmd, resource_group, vm_name, resource_type, certificate_validity_in_seconds):
from azext_ssh._client_factory import cf_endpoint
client = cf_endpoint(cmd.cli_ctx)

Expand All @@ -39,16 +39,18 @@ def get_relay_information(cmd, resource_group, vm_name, certificate_validity_in_
try:
t0 = time.time()
result = client.list_credentials(resource_group_name=resource_group, machine_name=vm_name,
endpoint_name="default", expiresin=certificate_validity_in_seconds)
resource_type=resource_type, endpoint_name="default",
expiresin=certificate_validity_in_seconds)
time_elapsed = time.time() - t0
telemetry.add_extension_event('ssh', {'Context.Default.AzureCLI.SSHListCredentialsTime': time_elapsed})
except ResourceNotFoundError:
logger.debug("Default Endpoint couldn't be found. Trying to create Default Endpoint.")
_create_default_endpoint(cmd, resource_group, vm_name, client)
_create_default_endpoint(cmd, resource_group, vm_name, resource_type, client)
try:
t0 = time.time()
result = client.list_credentials(resource_group_name=resource_group, machine_name=vm_name,
endpoint_name="default", expiresin=certificate_validity_in_seconds)
resource_type=resource_type, endpoint_name="default",
expiresin=certificate_validity_in_seconds)
time_elapsed = time.time() - t0
telemetry.add_extension_event('ssh', {'Context.Default.AzureCLI.SSHListCredentialsTime': time_elapsed})
except Exception as e:
Expand All @@ -58,12 +60,14 @@ def get_relay_information(cmd, resource_group, vm_name, certificate_validity_in_
return result


def _create_default_endpoint(cmd, resource_group, vm_name, client):
def _create_default_endpoint(cmd, resource_group, vm_name, resource_type, client):
namespace = resource_type.split('/', 1)[0]
arc_type = resource_type.split('/', 1)[1]
az_resource_id = resource_id(subscription=get_subscription_id(cmd.cli_ctx), resource_group=resource_group,
namespace="Microsoft.HybridCompute", type="machines", name=vm_name)
namespace=namespace, type=arc_type, name=vm_name)
endpoint_resource = {"id": az_resource_id, "type_properties_type": "default"}
try:
client.create_or_update(resource_group, vm_name, "default", endpoint_resource)
client.create_or_update(resource_group, vm_name, resource_type, "default", endpoint_resource)
except Exception as e:
colorama.init()
raise azclierror.UnauthorizedError(f"Unable to create Default Endpoint for {vm_name} in {resource_group}."
Expand Down
32 changes: 32 additions & 0 deletions src/ssh/azext_ssh/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,35 @@
RECOMMENDATION_RESOURCE_NOT_FOUND = (Fore.YELLOW + "Please ensure the active subscription is set properly "
"and resource exists." + Style.RESET_ALL)
RDP_TERMINATE_SSH_WAIT_TIME_IN_SECONDS = 30

ARC_RESOURCE_TYPE_PLACEHOLDER = "arc_resource_type_placeholder"

SUPPORTED_RESOURCE_TYPES = ["microsoft.hybridcompute/machines",
"microsoft.compute/virtualmachines",
"microsoft.connectedvmwarevsphere/virtualmachines",
"microsoft.scvmm/virtualmachines",
"microsoft.azurestackhci/virtualmachines"]

# Old version incorrectly used resource providers instead of resource type.
# Will continue to support to avoid breaking backwards compatibility.
LEGACY_SUPPORTED_RESOURCE_TYPES = ["microsoft.hybridcompute",
"microsoft.compute",
"microsoft.connectedvmwarevsphere",
"microsoft.scvmm",
"microsoft.azurestackhci"]

RESOURCE_PROVIDER_TO_RESOURCE_TYPE = {
"microsoft.hybridcompute": "Microsoft.HybridCompute/machines",
"microsoft.compute": "Microsoft.Compute/virtualMachines",
"microsoft.connectedvmwarevsphere": "Microsoft.ConnectedVMwarevSphere/virtualMachines",
"microsoft.azurestackhci": "Microsoft.AzureStackHCI/virtualMachines",
"microsoft.scvmm": "Microsoft.ScVmm/virtualMachines"
}

RESOURCE_TYPE_LOWER_CASE_TO_CORRECT_CASE = {
"microsoft.hybridcompute/machines": "Microsoft.HybridCompute/machines",
"microsoft.compute/virtualmachines": "Microsoft.Compute/virtualMachines",
"microsoft.connectedvmwarevsphere/virtualmachines": "Microsoft.ConnectedVMwarevSphere/virtualMachines",
"microsoft.scvmm/virtualmachines": "Microsoft.ScVmm/virtualMachines",
"microsoft.azurestackhci/virtualmachines": "Microsoft.AzureStackHCI/virtualMachines"
}
Loading