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

Fix SSH into VMs without public IP #6126

Merged
merged 6 commits into from
Apr 14, 2023
Merged

Conversation

dionhaefner
Copy link
Contributor


This checklist is used to make sure that common guidelines for a pull request are followed.

Related command

Without the fix:

$ az ssh vm -n <myvm> -g <mygroup>
The command failed with an unexpected error. Here is the traceback:
'publicIPAddress'
Traceback (most recent call last):
  File "/Users/dion/.virtualenvs/tempenv-5ea7193651842/lib/python3.10/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
  File "/Users/dion/.virtualenvs/tempenv-5ea7193651842/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 663, in execute
    raise ex
  File "/Users/dion/.virtualenvs/tempenv-5ea7193651842/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "/Users/dion/.virtualenvs/tempenv-5ea7193651842/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 697, in _run_job
    result = cmd_copy(params)
  File "/Users/dion/.virtualenvs/tempenv-5ea7193651842/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 333, in __call__
    return self.handler(*args, **kwargs)
  File "/Users/dion/.virtualenvs/tempenv-5ea7193651842/lib/python3.10/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
  File "/Users/dion/.azure/cliextensions/ssh/azext_ssh/custom.py", line 66, in ssh_vm
    _do_ssh_op(cmd, ssh_session, op_call)
  File "/Users/dion/.azure/cliextensions/ssh/azext_ssh/custom.py", line 159, in _do_ssh_op
    op_info.ip = op_info.ip or ip_utils.get_ssh_ip(cmd, op_info.resource_group_name,
  File "/Users/dion/.azure/cliextensions/ssh/azext_ssh/ip_utils.py", line 36, in get_ssh_ip
    public_ip_ref = ip_config["publicIPAddress"]
KeyError: 'publicIPAddress'

With the fix:

$ az ssh vm -n <myvm> -g <mygroup>
No public IP detected, attempting private IP (you must bring your own connectivity).
Use --prefer-private-ip to avoid this message.
OpenSSH_9.0p1, LibreSSL 3.3.6
Welcome to Ubuntu 20.04.5 LTS (GNU/Linux 5.15.0-1034-azure x86_64)

General Guidelines

  • Have you run azdev style <YOUR_EXT> locally? (pip install azdev required)
  • Have you run python scripts/ci/test_index.py -q locally?

For new extensions:

About Extension Publish

There is a pipeline to automatically build, upload and publish extension wheels.
Once your pull request is merged into main branch, a new pull request will be created to update src/index.json automatically.
You only need to update the version information in file setup.py and historical information in file HISTORY.rst in your PR but do not modify src/index.json.

@azure-client-tools-bot-prd
Copy link

Hi @dionhaefner,
Since the current milestone time is less than 7 days, this pr will be reviewed in the next milestone.

@ghost ghost added the customer-reported Issues that are reported by GitHub users external to the Azure organization. label Mar 29, 2023
@ghost
Copy link

ghost commented Mar 29, 2023

Thank you for your contribution dionhaefner! We will review the pull request and get back to you soon.

@ghost ghost added Auto-Assign Auto assign by bot VM SSH labels Mar 29, 2023
@ghost ghost requested review from jiasli and yonzhan March 29, 2023 08:04
@ghost ghost assigned jiasli Mar 29, 2023
@ghost ghost requested review from zhoxing-ms and wangzelin007 March 29, 2023 08:04
@ghost ghost assigned zhoxing-ms Mar 29, 2023
@ghost ghost added the Compute label Mar 29, 2023
@yonzhan
Copy link
Collaborator

yonzhan commented Mar 29, 2023

SSH

@jiasli jiasli requested a review from vthiebaut10 April 12, 2023 05:20
@zhoxing-ms
Copy link
Contributor

Could you please add test for this case?

@zhoxing-ms
Copy link
Contributor

zhoxing-ms commented Apr 12, 2023

Please write the description of PR change into the HISTORY.rst. If you want to release a new extension version for this PR, please also upgrade the version defined in the setup.py.

@vthiebaut10
Copy link
Contributor

@zhoxing - There are no scenario tests for this extension at the moment, and I don't think there is an easy way to test this logic simply with unit tests. This part of the code is currently untested by automated tests, which is something that I've been planning on addressing soon.

@navba-MSFT
Copy link
Contributor

Please write the description of PR change into the HISTORY.rst. If you want to release a new extension version for this PR, please also upgrade the version defined in the setup.py.

@dionhaefner I have submitted a PR for this suggestion in your branch https://github.com/dionhaefner/azure-cli-extensions/tree/patch-1 to save your time. Could you please approve it so that it can be reviewed again here ?

@dionhaefner
Copy link
Contributor Author

Merged, thanks! 👍

Pull in changes to history
@dionhaefner
Copy link
Contributor Author

@microsoft-github-policy-service agree

@zhoxing-ms zhoxing-ms merged commit ff4b800 into Azure:main Apr 14, 2023
@azclibot
Copy link
Collaborator

[Release] Update index.json for extension [ ssh ] : https://dev.azure.com/azclitools/internal/_build/results?buildId=47919&view=results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Assign Auto assign by bot Compute customer-reported Issues that are reported by GitHub users external to the Azure organization. VM SSH
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants