Created
July 20, 2017 09:15
-
-
Save ljjjustin/689529dddc32074660e9a0e6fc2431d5 to your computer and use it in GitHub Desktop.
trovelogin.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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