Last active
April 22, 2025 02:59
-
-
Save 1a1a11a/02735f2e6f46adf5481b3116e6e4d3bf to your computer and use it in GitHub Desktop.
cloudlab API
This file contains hidden or 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 | |
# https://gitlab.flux.utah.edu/stoller/portal-tools | |
# git clone https://gitlab.flux.utah.edu/stoller/portal-tools | |
# cd portal-tools; python3 setup.py install | |
# sudo cp cl.sh /usr/local/bin/cl && sudo chmod +x /usr/local/bin/cl | |
# set -eux | |
PROJ=cache | |
USER=juncheng | |
PROFILE=compute | |
SITE=wisc | |
NODES_WISC=(d7525 d8545 sm220u sm110p c220g5 c240g5 c4130) | |
NODES_CLEMSON=(c6320 c8220 c8220x c6420 dss7500 r6525 r650 r7525) | |
NODES_UTAH=(flex01 flex02 flex03 flex04 d2950 d6515 c6525-25g c6525-100g dl360) | |
NODE1="" | |
N_NODE1=1 | |
if [ $# -le 0 ]; then | |
echo "Usage: $0 <node>" | |
exit 1 | |
fi | |
NODE1=$1 | |
if [ $# -eq 2 ]; then | |
N_NODE1=$2 | |
fi | |
if [[ " ${NODES_WISC[@]} " =~ " ${NODE1} " ]]; then | |
SITE=wisc | |
elif [[ " ${NODES_CLEMSON[@]} " =~ " ${NODE1} " ]]; then | |
SITE=clemson | |
elif [[ " ${NODES_UTAH[@]} " =~ " ${NODE1} " ]]; then | |
SITE=utah | |
else | |
echo "Node not found in a site" | |
exit 1 | |
fi | |
EXP=${N_NODE1}-${NODE1}-${RANDOM} | |
#### create experiment #### | |
reset | |
echo "create experiment with ${N_NODE1} ${NODE1} in ${SITE} exp ${EXP} proj ${PROJ} profile ${PROFILE}" | |
startExperiment --project ${PROJ} --name ${EXP} --binding='{"nNode1": "'${N_NODE1}'", "site": "'${SITE}'", "nodeType1": "'${NODE1}'", "anyHardware": "False"}' --site ${SITE} ${PROJ},${PROFILE} | |
#### wait for the experiment to be ready #### | |
status=$(experimentStatus -j ${PROJ},${EXP} | jq -r '.status') | |
echo -n waiting for the experiment to be ready | |
while [[ "${status}" != "ready" ]]; do | |
sleep 20 | |
echo -n . | |
status=$(experimentStatus -j ${PROJ},${EXP} | jq -r '.status') | |
if [[ "${status}" == "failed" || "${status}" == "" ]]; then | |
echo | |
echo "experiment failed" | |
terminateExperiment ${PROJ},${EXP} | |
exit 1 | |
fi | |
done | |
extendExperiment -m 'I need them longer' ${PROJ},${EXP} 144 | |
# wait for the nodes to be ready | |
sleep 80 | |
echo | |
#### obtain hostname #### | |
hostnames=$(experimentStatus -j ${PROJ},${EXP} | jq -r '.aggregate_status | to_entries[] | .value.nodes | to_entries[] | .value.hostname') | |
hostids=() | |
hostips=() | |
#### initiate the node #### | |
for hostname in ${hostnames[@]}; do | |
hostid=$(ssh -q \ | |
-o StrictHostKeyChecking=no \ | |
-o UserKnownHostsFile=/dev/null \ | |
-o LogLevel=ERROR -o ConnectTimeout=10 \ | |
${USER}@${hostname} "cat /var/emulab/boot/nodeid | tr -dc '[:print:]'") | |
hostids+=($hostid) | |
hostip=$(ssh -q \ | |
-o StrictHostKeyChecking=no \ | |
-o UserKnownHostsFile=/dev/null \ | |
-o LogLevel=ERROR -o ConnectTimeout=10 \ | |
${USER}@${hostname} "cat /var/emulab/boot/myip | tr -dc '[:print:]'") | |
hostips+=($hostip) | |
(ssh -q -t \ | |
-o StrictHostKeyChecking=no \ | |
-o UserKnownHostsFile=/dev/null \ | |
-o ServerAliveInterval=1200 \ | |
${USER}@${hostname} """bash /proj/${PROJ}-PG0/jason/scripts/init.sh""") | |
done | |
wait | |
#### set fastscp DNS name #### | |
echo | |
dns_name_base=cl | |
dns_name_start_idx=0 | |
for i in $(seq 0 100); do | |
dns_name=${dns_name_base}${i} | |
(ssh -q -t \ | |
-o StrictHostKeyChecking=no \ | |
-o UserKnownHostsFile=/dev/null \ | |
-o LogLevel=ERROR -o ConnectTimeout=10 \ | |
${USER}@${dns_name}.fastscp.com "ls >/dev/null") 2>/dev/null | |
if [[ $? != 0 ]]; then | |
dns_name_start_idx=$i | |
break | |
fi | |
done | |
n=${#hostips[@]} | |
n1=$((n - 1)) | |
for idx in $(seq 0 ${n1}); do | |
hostip=${hostips[idx]} | |
hostid=${hostids[idx]} | |
dns_name_idx=$((dns_name_start_idx + idx)) | |
dns_name=${dns_name_base}${dns_name_idx} | |
echo "set DNS name ${dns_name} for ${hostip} ${hostid}" | |
cf_dns ${dns_name} ${hostip} | |
done | |
echo "#############################################################################" | |
echo "############ #############" | |
for hostid in ${hostids[@]}; do | |
echo "########### finish preparing node ${hostid} ############" | |
done | |
echo "############ #############" | |
echo "#############################################################################" | |
# terminateExperiment ${PROJ},${EXP} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment