Skip to content

Commit

Permalink
Add script for local DNS mapping for MCIS (#801)
Browse files Browse the repository at this point in the history
  • Loading branch information
seokho-son authored Sep 28, 2021
1 parent 1ff5702 commit dc8e9e4
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ done

echo ""

LAUNCHCMD="fping -e $VMLIST"
#LAUNCHCMD="fping -e $PRIVIPLIST"
LAUNCHCMD="fping -e $IPLIST"
#LAUNCHCMD="fping -e $IPLIST"
#LAUNCHCMD="fping -e $IPCOMBLIST"
# LAUNCHCMD="fping $PRIVIPLIST -q -n -c 10"

Expand Down
85 changes: 85 additions & 0 deletions src/testclient/scripts/sequentialFullTest/set-mcis-hosts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash

echo "####################################################################"
echo "## Set Local MCIS DNS (/etc/hosts of each VM in MC-Infra)"
echo "####################################################################"

source ../init.sh

echo ""

MCISINFO=$(curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/ns/$NSID/mcis/${MCISID})
VMARRAY=$(jq '.vm' <<<"$MCISINFO")

echo ""
echo "[GENERATED PRIVATE KEY (PEM, PPK) first]"

echo ""

echo "[MCIS INFO: $MCISID]"
# for row in $(echo "${VMARRAY}" | jq -r '.[] | @base64'); do
# _jq() {
# echo ${row} | base64 --decode | jq -r ${1}
# }

# VMKEYID=$(jq '.sshKeyId')
# KEYFILENAME="${VMKEYID}"

# curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/ns/$NSID/resources/sshKey/$VMKEYID -H 'Content-Type: application/json' | jq '.privateKey' | sed -e 's/\\n/\n/g' -e 's/\"//g' >./sshkey-tmp/$KEYFILENAME.pem
# chmod 600 ./sshkey-tmp/$KEYFILENAME.pem
# puttygen ./sshkey-tmp/$KEYFILENAME.pem -o ./sshkey-tmp/$KEYFILENAME.ppk -O private
# done

for rowi in $(echo "${VMARRAY}" | jq -r '.[] | @base64'); do
_jq() {
echo ${rowi} | base64 --decode | jq -r ${1}
}

VMID=$(_jq '.id')
publicIP=$(_jq '.publicIP')
vNetId=$(_jq '.vNetId')

echo "VMID: $VMID"

VMKEYID=$(_jq '.sshKeyId')
KEYINFO=$(curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/ns/${NSID}/resources/sshKey/${VMKEYID})
USERNAME=$(jq -r '.verifiedUsername' <<<"$KEYINFO")
KEYFILENAME="${VMKEYID}"

for rowj in $(echo "${VMARRAY}" | jq -r '.[] | @base64'); do
_jq() {
echo ${rowj} | base64 --decode | jq -r ${1}
}

Bid=$(_jq '.id')
BpublicIP=$(_jq '.publicIP')
BprivateIP=$(_jq '.privateIP')
BvNetId=$(_jq '.vNetId')

CommandToAddHosts=""

if [ "${VMID}" != "${Bid}" ]; then
CommandToAddHosts="sudo sed -i '2i127.0.0.1 ${Bid}' /etc/hosts"
elif [ "${vNetId}" == "${BvNetId}" ]; then
CommandToAddHosts="sudo sed -i '2i${BprivateIP} ${Bid}' /etc/hosts"
else
CommandToAddHosts="sudo sed -i '2i${BpublicIP} ${Bid}' /etc/hosts"
fi

echo "${CommandToAddHosts}"

VAR1=$(ssh -i ./sshkey-tmp/$KEYFILENAME.pem $USERNAME@$publicIP -o StrictHostKeyChecking=no "$CommandToAddHosts")
echo "${VAR1}" | jq ''

done
done

CMD="cat /etc/hosts"
VAR1=$(
curl -H "${AUTH}" -sX POST http://$TumblebugServer/tumblebug/ns/$NSID/cmd/mcis/$MCISID -H 'Content-Type: application/json' -d @- <<EOF
{
"command" : "${CMD}"
}
EOF
)
echo "${VAR1}" | jq . | sed 's/\\n/\n/g'

0 comments on commit dc8e9e4

Please sign in to comment.