Skip to content

Instantly share code, notes, and snippets.

@ljjjustin
Created July 20, 2017 09:15
Show Gist options
  • Save ljjjustin/689529dddc32074660e9a0e6fc2431d5 to your computer and use it in GitHub Desktop.
Save ljjjustin/689529dddc32074660e9a0e6fc2431d5 to your computer and use it in GitHub Desktop.
trovelogin.sh
#!/bin/bash
if [ $# -ne 1 ]; then
echo "usage: $0 <uuid or name>"
exit
fi
get_ephymeral_port() {
LPORT=32768;
UPORT=60999;
while true; do
MPORT=$[$LPORT + ($RANDOM % $UPORT)];
(echo "" >/dev/tcp/127.0.0.1/${MPORT}) >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo $MPORT;
return 0;
fi
done
}
listen_port=$(get_ephymeral_port)
trap "pkill -f ${listen_port}" EXIT
INFO=$(trove show $1)
UUID=$(echo "${INFO}" | grep " id " | awk '{print $4}')
VMID=$(echo "${INFO}" | grep " server_id " | awk '{print $4}')
SECURITY_GROUP="HHY-TROVE-SecGroup_${UUID}"
if ! neutron security-group-show ${SECURITY_GROUP} | grep -w 22 >/dev/null; then
neutron security-group-rule-create --protocol tcp --port-range-min 22 --port-range-max 22 ${SECURITY_GROUP}
fi
address=$(nova show ${VMID} | grep ' trove-mgmt[0-9] ' | awk '{print $5}')
ssh -NTf -L ${listen_port}:${address}:22 root@192.168.101.26
ssh -p ${listen_port} polex@localhost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment