Skip to content

Commit

Permalink
Added common.sh with curl wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
danielerez committed Sep 26, 2024
1 parent 27044c2 commit d9ca597
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
28 changes: 28 additions & 0 deletions data/scripts/bin/common.sh.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

curl_assisted_service() {
local endpoint=$1
local method=${2:-GET}
local additional_options=("${@:3}") # Capture all arguments starting from the third one
local baseURL="${SERVICE_BASE_URL}api/assisted-install/v2"

case "${method}" in
"PATCH")
curl -s -S -X PATCH "${additional_options[@]}" "${baseURL}${endpoint}" \
-H "Authorization: ${AGENT_AUTH_TOKEN}" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
;;
"POST")
curl -s -S -X POST "${additional_options[@]}" "${baseURL}${endpoint}" \
-H "Authorization: ${AGENT_AUTH_TOKEN}" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
;;
"GET")
curl -s -S -X GET "${additional_options[@]}" "${baseURL}${endpoint}" \
-H "Authorization: ${AGENT_AUTH_TOKEN}" \
-H "Accept: application/json"
;;
esac
}
15 changes: 7 additions & 8 deletions data/scripts/bin/update-hosts.sh.template
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/bin/bash
set -e

BASE_URL="${SERVICE_BASE_URL}api/assisted-install/v2"
# shellcheck disable=SC1091
source "common.sh"

total_required_nodes=$(( REQUIRED_MASTER_NODES + REQUIRED_WORKER_NODES ))

declare host_ids
while [[ "${num_of_hosts}" != "${total_required_nodes}" ]]
do
echo "Waiting for ${total_required_nodes} required hosts..." 1>&2
host_ids=$(curl -s -S "${BASE_URL}/infra-envs/${INFRA_ENV_ID}/hosts" | jq -r .[].id)
host_ids=$(curl_assisted_service "/infra-envs/${INFRA_ENV_ID}/hosts" | jq -r .[].id)
if [[ -n ${host_ids} ]]; then
num_of_hosts=0
for id in ${host_ids}; do
Expand All @@ -25,14 +26,12 @@ if [[ -n ${host_ids} ]]; then
for id in ${host_ids}; do
args='["--save-partlabel", "agent*"]'
# Update host's installer-args (for passing '--save-partlabel' to coreos-installer)
curl -s -S -X PATCH "${BASE_URL}/infra-envs/${INFRA_ENV_ID}/hosts/${id}/installer-args" \
-H "Content-Type: application/json" \
-d '{"args": '"${args}"'}'
curl_assisted_service "${BASE_URL}/infra-envs/${INFRA_ENV_ID}/hosts/${id}/installer-args" \
PATCH -d '{"args": '"${args}"'}'

# Update host's ignition (used when booting from the installation disk after bootstrap)
curl -s -S -X PATCH "${BASE_URL}/infra-envs/${INFRA_ENV_ID}/hosts/${id}/ignition" \
-H "Content-Type: application/json" \
-d '{"config": '"${ignition}"'}'
curl_assisted_service "${BASE_URL}/infra-envs/${INFRA_ENV_ID}/hosts/${id}/ignition" \
PATCH -d '{"config": '"${ignition}"'}'

echo "Updated installer-args and ignition of host with id: ${id}"
done
Expand Down
1 change: 1 addition & 0 deletions pkg/asset/ignition/bootstrap_ignition.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var (
"release-image.sh",
"update-hosts.sh",
"create-virtual-device.sh",
"common.sh",
}
)

Expand Down

0 comments on commit d9ca597

Please sign in to comment.