Skip to content

Instantly share code, notes, and snippets.

@bahamat
Created March 9, 2020 18:33
Show Gist options
  • Save bahamat/1bee584ffd73b9d090d47e3b72568f95 to your computer and use it in GitHub Desktop.
Save bahamat/1bee584ffd73b9d090d47e3b72568f95 to your computer and use it in GitHub Desktop.
sdc-ssh: SSH to CN by hostname or uuid for Triton headnode
#!/bin/bash
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright 2020 Joyent, Inc.
if [[ -n "$TRACE" ]]; then
export PS4='[\D{%FT%TZ}] ${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -o xtrace
fi
target="$1"
if (( ${#target} == 36 )); then
# target is a uuid
ip=$(sdc-server admin-ip "$target")
else
# target is a hostname
ip=$(sdc-cnapi /servers?hostname=${target}\&extras=sysinfo | json -Ha sysinfo.'Admin IP')
fi
if (( ${#ip} == 0 )); then
printf 'Compute node "%s" not found\n' "$target"
exit 1
fi
ssh -l root -i /root/.ssh/sdc.id_rsa "$ip"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment