Azure / azure-cli-extensions

Public Repository for Extensions of Azure CLI.
https://docs.microsoft.com/en-us/cli/azure
MIT License
384 stars 1.25k forks source link

az ssh vm does not work on private VM #2762

Open ottnorml opened 3 years ago

ottnorml commented 3 years ago

This is autogenerated. Please review and update as needed.

Describe the bug

I was trying to access a Bastion Host, wich has no public IP address.

Command Name az ssh vm Extension Name: ssh. Version: 0.1.0.

Errors:

'NoneType' object has no attribute 'id'
Traceback (most recent call last):
python3.8/site-packages/knack/cli.py, ln 215, in invoke
    cmd_result = self.invocation.execute(args)
cli/core/commands/__init__.py, ln 654, in execute
    raise ex
cli/core/commands/__init__.py, ln 717, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
cli/core/commands/__init__.py, ln 710, in _run_job
    six.reraise(*sys.exc_info())
...
cliextensions/ssh/azext_ssh/custom.py, ln 19, in ssh_vm
    _do_ssh_op(cmd, resource_group_name, vm_name, ssh_ip,
cliextensions/ssh/azext_ssh/custom.py, ln 32, in _do_ssh_op
    ssh_ip = ssh_ip or ip_utils.get_ssh_ip(cmd, resource_group, vm_name)
cliextensions/ssh/azext_ssh/ip_utils.py, ln 27, in get_ssh_ip
    parsed_ip_id = tools.parse_resource_id(public_ip_ref.id)
AttributeError: 'NoneType' object has no attribute 'id'

To Reproduce:

Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.

Expected Behavior

Successful SSH connection and login.

Environment Summary

macOS-10.15.7-x86_64-i386-64bit
Python 3.8.6
Installer: HOMEBREW

azure-cli 2.15.1

Extensions:
ssh 0.1.0

Additional Context

yungezz commented 3 years ago

hi @fengzhou-msft could you pls have a look? thanks

fengzhou-msft commented 3 years ago

Please use option --prefer-private-ip, by default only public IPs are used.

janegilring commented 3 years ago

I also ran into this when connecting to a VM which only have a private IP. A more user friendly error hinting to try with the --prefer-private-ip would be useful.

jiasli commented 3 years ago

@janegilring, this is a nice suggestion. Let me mark this issue as a feature request.