-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add convenience script for ssh-ing into VM instance #4
base: docs
Are you sure you want to change the base?
Conversation
I'm trying to create a setup where I have "one VM for development", and "one VM under test" - it's kinda a pain to try to remember which IP address is associated with which one, so this is a little shortcut to make my workflow better. |
I have a pattern I end up using a bit that might help here. I have a script, #!/bin/bash
# vim: set ts=8 sts=8 sw=8 noet:
fatal() {
local rc=$1
local msg=$2
shift 2
printf "ERROR: $msg\n" "$@" >&2
exit $rc
}
DOMAIN="$1"
LOOKUPHOST="$2"
LOOKUPPORT="$3"
if [[ -z $DOMAIN || -z $LOOKUPHOST || -z $LOOKUPPORT ]]; then
fatal 2 'missing arguments'
fi
sans_domain=$(sed "s/\\.${DOMAIN}\$//" <<< "$LOOKUPHOST")
if ! res=$(virsh domifaddr "$sans_domain"); then
fatal 3 'could not look up libvirt domain "%s"\n' "$sans_domain"
fi
if ! ip=$(awk '$3 == "ipv4" { gsub("/.*", "", $4);
print($4); exit(0); }' <<< "$res") || [[ -z "$ip" ]]; then
fatal 4 'could not locate IP address for "%s"\n' "$sans_domain"
fi
printf 'translating "%s" --> %s\n' "$sans_domain" "$ip" >&2
exec nc "$ip" "$LOOKUPPORT" I then configure an entry in
When
It has the advantage that it will work for other tools that leverage
It will correctly fail to connect if the domain you specify is not running or doesn't exist:
What do you think? |
So, first impressions: That's extremely rad, and I plan on playing with my ssh config way more now that I know it applies to this suite of commands. The only thing that bums me out about that current implementation is that it requires some... manual intervention to make things work (custom script, custom path, custom config). I updated this PR to incorporate basically everything you did, but hopefully make it easier for folks checking out this repo for the first time. TL;DR:
|
Usage: