Skip to content

Commit 8872fc9

Browse files
committed
Fixed status check on adhoc deploy
1 parent 5e1d958 commit 8872fc9

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

.github/scripts/adhoc.sh

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,23 +97,25 @@ if [[ ${ACTION} == "deploy-metal" ]]; then
9797
RESPONSE=$(curl -s -X POST "https://api.phoenixnap.com/bmc/v1/servers" -H "Authorization: Bearer ${TOKEN}" \
9898
-H "Content-Type: application/json" -d @adhoc-server-deploy-final.json)
9999

100-
IP_ADDRESS=$(jq -r '.publicIpAddresses[0]' <<< "$RESPONSE")
101-
DEVICE_ID=$(jq -r '.id' <<< "$RESPONSE")
100+
IP_ADDRESS=$(jq -r '.publicIpAddresses[0]' <<< "${RESPONSE}")
101+
DEVICE_ID=$(jq -r '.id' <<< "${RESPONSE}")
102102
echo "Got Address ${IP_ADDRESS} and Device Id ${DEVICE_ID}"
103103
popd
104104

105+
echo "Waiting for Server Ready"
105106
STATUS=0
106107
for i in {1..60}; do
107-
if [[ $STATUS -eq 0 ]]; then
108-
[[ "$(curl -s -H "Authorization: Bearer $TOKEN" \
109-
https://api.phoenixnap.com/bmc/v1/servers/$ID | jq -r '.status')" == "powered-on" ]] && STATUS=1
108+
STATUS_RESPONSE=$(curl -s -H "Authorization: Bearer ${TOKEN}" "https://api.phoenixnap.com/bmc/v1/servers/${DEVICE_ID}")
109+
if [[ ${STATUS} -eq 0 ]]; then
110+
[[ "$(echo "${STATUS_RESPONSE}" | jq -r '.status')" == "powered-on" ]] && STATUS=1
110111
fi
111-
if [[ $STATUS -eq 1 ]]; then
112-
nc -z -w 2 "$IP" 22 && break
112+
113+
if [[ ${STATUS} -eq 1 ]]; then
114+
nc -z -w 2 "${IP_ADDRESS}" 22 && break
113115
fi
114-
sleep 5
116+
sleep 10
115117
done
116-
118+
117119
DURATION=$(($(date +%s) - ${BEGIN_SECS}))
118120
if [[ ${STATUS} -eq 0 ]]; then
119121
echo "Failed to provision device ${ACTOR} after ${DURATION} seconds"
@@ -135,9 +137,9 @@ if [[ ${ACTION} == "delete-metal" ]]; then
135137
DEVICE_NAME=$5
136138

137139
TOKEN=$(getApiToken "${PROJECT_ID}" "${API_KEY}")
138-
echo " DELETING: $name (ID: $id)"
139-
curl -s -X DELETE -H "Authorization: Bearer ${TOKEN}" https://api.phoenixnap.com/bmc/v1/servers/$id >/dev/null
140-
140+
echo "Deleting Server ${DEVICE_NAME}"
141+
curl -s -X DELETE -H "Authorization: Bearer ${TOKEN}" https://api.phoenixnap.com/bmc/v1/servers/${DEVICE_ID} >/dev/null
142+
echo "STATUS_RESPONSE: ${STATUS_RESPONSE}"
141143
echo "ACTION=${ACTION}" | tee -a ${OUTPUT_NAME}
142144
echo "DEVICE_NAME=${DEVICE_NAME}" | tee -a ${OUTPUT_NAME}
143145
echo "DEVICE_ID=${DEVICE_ID}" | tee -a ${OUTPUT_NAME}

0 commit comments

Comments
 (0)