update
This commit is contained in:
+22
-13
@@ -49,6 +49,15 @@ TAPM_ISO_NFS_FAIL() {
|
||||
return 1
|
||||
}
|
||||
|
||||
TAPM_ISO_NFS_LOCAL_TEMPLATE() {
|
||||
local storage="$1"
|
||||
|
||||
pveam list "$storage" 2>/dev/null |
|
||||
awk 'NR > 1 && $1 ~ /:vztmpl\/debian-(13|12)-standard_/ { print $1 }' |
|
||||
sort -V |
|
||||
tail -1
|
||||
}
|
||||
|
||||
TAPM_ISO_NFS_SELECT_STORAGE() {
|
||||
local variable="$1"
|
||||
local label="$2"
|
||||
@@ -198,19 +207,19 @@ TAPM_DEPLOY_ISO_NFS_LXC() {
|
||||
}
|
||||
|
||||
echo -e "\n${idsCL[LightCyan]}Locating a Debian container template...${idsCL[Default]}"
|
||||
pveam update || { TAPM_ISO_NFS_FAIL "Could not refresh the template catalog."; return 1; }
|
||||
template_name="$(
|
||||
pveam available --section system |
|
||||
awk '$2 ~ /^debian-(13|12)-standard_/ { print $2 }' |
|
||||
sort -V |
|
||||
tail -1
|
||||
)"
|
||||
[[ -n "$template_name" ]] ||
|
||||
{ TAPM_ISO_NFS_FAIL "No supported Debian 12/13 standard template was found."; return 1; }
|
||||
template_path="${template_storage}:vztmpl/${template_name}"
|
||||
if ! pveam list "$template_storage" 2>/dev/null |
|
||||
awk 'NR > 1 { print $1 }' |
|
||||
grep -Fxq -- "$template_path"; then
|
||||
template_path="$(TAPM_ISO_NFS_LOCAL_TEMPLATE "$template_storage")"
|
||||
if [[ -z "$template_path" ]]; then
|
||||
pveam update ||
|
||||
{ TAPM_ISO_NFS_FAIL "Could not refresh the template catalog."; return 1; }
|
||||
template_name="$(
|
||||
pveam available --section system |
|
||||
awk '$2 ~ /^debian-(13|12)-standard_/ { print $2 }' |
|
||||
sort -V |
|
||||
tail -1
|
||||
)"
|
||||
[[ -n "$template_name" ]] ||
|
||||
{ TAPM_ISO_NFS_FAIL "No supported Debian 12/13 standard template was found."; return 1; }
|
||||
template_path="${template_storage}:vztmpl/${template_name}"
|
||||
pveam download "$template_storage" "$template_name" ||
|
||||
{ TAPM_ISO_NFS_FAIL "The Debian template download failed."; return 1; }
|
||||
fi
|
||||
|
||||
+37
-7
@@ -60,6 +60,28 @@ TAPM_PULSE_VALID_NONNEGATIVE_INTEGER() {
|
||||
[[ "${1:-}" =~ ^[0-9]+$ ]]
|
||||
}
|
||||
|
||||
TAPM_PULSE_BACKOFF_NEXT() {
|
||||
local current="${1:-1}"
|
||||
local maximum="${2:-8}"
|
||||
local next
|
||||
|
||||
[[ "$current" =~ ^[1-9][0-9]*$ &&
|
||||
"$maximum" =~ ^[1-9][0-9]*$ ]] || return 1
|
||||
next=$((current * 2))
|
||||
(( next > maximum )) && next="$maximum"
|
||||
printf '%s\n' "$next"
|
||||
}
|
||||
|
||||
TAPM_PULSE_BACKOFF_SLEEP() {
|
||||
local deadline="$1"
|
||||
local delay="$2"
|
||||
local remaining=$((deadline - SECONDS))
|
||||
|
||||
(( remaining > 0 )) || return 0
|
||||
(( delay > remaining )) && delay="$remaining"
|
||||
sleep "$delay"
|
||||
}
|
||||
|
||||
TAPM_PULSE_VALID_PORT() {
|
||||
[[ "${1:-}" =~ ^[0-9]+$ ]] && (( 10#$1 >= 1 && 10#$1 <= 65535 ))
|
||||
}
|
||||
@@ -498,7 +520,8 @@ TAPM_PULSE_CONFIGURE_SECURITY() {
|
||||
local token_variable="$6"
|
||||
local requested_password="${7:-}"
|
||||
local bootstrap_output bootstrap_token generated_username generated_password generated_api_token
|
||||
local request_file curl_config response security_ready='no' attempt
|
||||
local request_file curl_config response security_ready='no'
|
||||
local deadline delay
|
||||
|
||||
generated_username='admin'
|
||||
if [[ -n "$requested_password" ]]; then
|
||||
@@ -577,7 +600,9 @@ raise SystemExit(0 if success is True else 1)
|
||||
{
|
||||
printf 'header = "X-API-Token: %s"\n' "$generated_api_token"
|
||||
} >"$curl_config" || return 1
|
||||
for (( attempt = 1; attempt <= 15; attempt++ )); do
|
||||
deadline=$((SECONDS + 30))
|
||||
delay=1
|
||||
while (( SECONDS < deadline )); do
|
||||
if curl --fail --silent --show-error \
|
||||
--connect-timeout 3 --max-time 5 \
|
||||
--config "$curl_config" \
|
||||
@@ -585,7 +610,8 @@ raise SystemExit(0 if success is True else 1)
|
||||
security_ready='yes'
|
||||
break
|
||||
fi
|
||||
sleep 2
|
||||
TAPM_PULSE_BACKOFF_SLEEP "$deadline" "$delay"
|
||||
delay="$(TAPM_PULSE_BACKOFF_NEXT "$delay" 4)"
|
||||
done
|
||||
if [[ "$security_ready" != 'yes' ]]; then
|
||||
unset generated_password generated_api_token
|
||||
@@ -796,7 +822,8 @@ TAPM_PULSE_WAIT_AGENT_REGISTERED() {
|
||||
local node="$3"
|
||||
local temp_dir="$4"
|
||||
local curl_config="${temp_dir}/agent-${node}-verify.curl"
|
||||
local encoded_node response attempt
|
||||
local encoded_node response
|
||||
local deadline delay
|
||||
|
||||
printf 'header = "X-API-Token: %s"\n' "$token" >"$curl_config" || return 1
|
||||
chmod 0600 "$curl_config" || return 1
|
||||
@@ -809,8 +836,10 @@ print(urllib.parse.quote(os.environ["TAPM_PULSE_NODE_NAME"], safe=""))
|
||||
|
||||
# Pulse v6.1.1 completes its Proxmox setup before sending the first host
|
||||
# report. Its built-in registration retries can span at least 135 seconds,
|
||||
# so allow up to four minutes before treating the active agent as unconfirmed.
|
||||
for (( attempt = 1; attempt <= 80; attempt++ )); do
|
||||
# so allow up to four minutes while backing off repeated local lookups.
|
||||
deadline=$((SECONDS + 240))
|
||||
delay=1
|
||||
while (( SECONDS < deadline )); do
|
||||
response="$(
|
||||
curl --fail --silent --show-error \
|
||||
--connect-timeout 3 --max-time 5 \
|
||||
@@ -821,7 +850,8 @@ print(urllib.parse.quote(os.environ["TAPM_PULSE_NODE_NAME"], safe=""))
|
||||
if TAPM_PULSE_AGENT_REGISTERED_FROM_RESPONSE "$response"; then
|
||||
return 0
|
||||
fi
|
||||
sleep 3
|
||||
TAPM_PULSE_BACKOFF_SLEEP "$deadline" "$delay"
|
||||
delay="$(TAPM_PULSE_BACKOFF_NEXT "$delay" 8)"
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
+31
-18
@@ -5,6 +5,7 @@ TAPM_FLEET_IDENTITY_FILE="${TAPM_FLEET_IDENTITY_FILE:-${TAPM_FLEET_STATE_DIR}/id
|
||||
TAPM_FLEET_INSTALLATION_ID=''
|
||||
TAPM_FLEET_CREDENTIAL=''
|
||||
TAPM_FLEET_LAST_VERSION=''
|
||||
TAPM_FLEET_ENROLLED=0
|
||||
TAPM_FLEET_REGISTERED=0
|
||||
TAPM_FLEET_STARTED_AT=0
|
||||
TAPM_FLEET_VERSION=''
|
||||
@@ -26,6 +27,8 @@ TAPM_FLEET_LOAD_IDENTITY() {
|
||||
TAPM_FLEET_INSTALLATION_ID="$(TAPM_FLEET_READ_VALUE INSTALLATION_ID)"
|
||||
TAPM_FLEET_CREDENTIAL="$(TAPM_FLEET_READ_VALUE CREDENTIAL)"
|
||||
TAPM_FLEET_LAST_VERSION="$(TAPM_FLEET_READ_VALUE LAST_VERSION)"
|
||||
TAPM_FLEET_ENROLLED="$(TAPM_FLEET_READ_VALUE ENROLLED)"
|
||||
[[ "$TAPM_FLEET_ENROLLED" == 1 ]] || TAPM_FLEET_ENROLLED=0
|
||||
}
|
||||
|
||||
TAPM_FLEET_VALID_IDENTITY() {
|
||||
@@ -43,6 +46,7 @@ TAPM_FLEET_WRITE_IDENTITY() {
|
||||
printf 'INSTALLATION_ID=%s\n' "$TAPM_FLEET_INSTALLATION_ID"
|
||||
printf 'CREDENTIAL=%s\n' "$TAPM_FLEET_CREDENTIAL"
|
||||
printf 'LAST_VERSION=%s\n' "$TAPM_FLEET_LAST_VERSION"
|
||||
printf 'ENROLLED=%s\n' "$TAPM_FLEET_ENROLLED"
|
||||
} >"$temporary_file" ||
|
||||
! chmod 0600 "$temporary_file" ||
|
||||
! mv -f "$temporary_file" "$TAPM_FLEET_IDENTITY_FILE"; then
|
||||
@@ -64,6 +68,7 @@ TAPM_FLEET_ENSURE_IDENTITY() {
|
||||
fi
|
||||
TAPM_FLEET_CREDENTIAL="$(openssl rand -hex 32)" || return 1
|
||||
TAPM_FLEET_LAST_VERSION=''
|
||||
TAPM_FLEET_ENROLLED=0
|
||||
TAPM_FLEET_WRITE_IDENTITY
|
||||
}
|
||||
|
||||
@@ -155,23 +160,27 @@ TAPM_FLEET_EVENT_SEND() {
|
||||
local duration="${4:-0}"
|
||||
local event_payload=''
|
||||
|
||||
(( TAPM_FLEET_REGISTERED == 1 )) || return 0
|
||||
event_payload="$(mktemp "${TMPDIR:-/tmp}/tapm-fleet-event.XXXXXX")" || return 0
|
||||
(( TAPM_FLEET_REGISTERED == 1 )) || return 1
|
||||
event_payload="$(mktemp "${TMPDIR:-/tmp}/tapm-fleet-event.XXXXXX")" || return 1
|
||||
chmod 0600 "$event_payload" 2>/dev/null || {
|
||||
rm -f "$event_payload"
|
||||
return 0
|
||||
return 1
|
||||
}
|
||||
if ! TAPM_FLEET_JSON "$event" "$result" "$error_code" "$duration" >"$event_payload"; then
|
||||
rm -f "$event_payload"
|
||||
return 0
|
||||
return 1
|
||||
fi
|
||||
printf 'header = "Content-Type: application/json"\nheader = "Authorization: Bearer %s"\nurl = "%s/api/v1/hosts/events"\n' \
|
||||
if printf 'header = "Content-Type: application/json"\nheader = "Authorization: Bearer %s"\nurl = "%s/api/v1/hosts/events"\n' \
|
||||
"$TAPM_FLEET_CREDENTIAL" "$TAPM_BROKER_URL" |
|
||||
curl --fail --silent --show-error \
|
||||
--connect-timeout 3 --max-time 10 \
|
||||
--config - --data-binary "@${event_payload}" \
|
||||
>/dev/null 2>&1 || true
|
||||
>/dev/null 2>&1; then
|
||||
rm -f "$event_payload"
|
||||
return 0
|
||||
fi
|
||||
rm -f "$event_payload"
|
||||
return 1
|
||||
}
|
||||
|
||||
TAPM_FLEET_START() {
|
||||
@@ -181,34 +190,38 @@ TAPM_FLEET_START() {
|
||||
command -v python3 >/dev/null 2>&1 || return 0
|
||||
command -v curl >/dev/null 2>&1 || return 0
|
||||
TAPM_FLEET_COLLECT_METADATA
|
||||
if TAPM_FLEET_REGISTER; then
|
||||
if (( TAPM_FLEET_ENROLLED == 1 )); then
|
||||
TAPM_FLEET_REGISTERED=1
|
||||
else
|
||||
return 0
|
||||
elif TAPM_FLEET_REGISTER; then
|
||||
TAPM_FLEET_REGISTERED=1
|
||||
TAPM_FLEET_ENROLLED=1
|
||||
TAPM_FLEET_WRITE_IDENTITY || true
|
||||
fi
|
||||
if [[ -n "$TAPM_FLEET_LAST_VERSION" &&
|
||||
"$TAPM_FLEET_LAST_VERSION" != "$TAPM_FLEET_VERSION" ]]; then
|
||||
TAPM_FLEET_EVENT_SEND upgraded success
|
||||
fi
|
||||
TAPM_FLEET_EVENT_SEND run_started started
|
||||
}
|
||||
|
||||
TAPM_FLEET_FINISH() {
|
||||
local exit_status="${1:-0}"
|
||||
local duration=0
|
||||
local event_sent=0
|
||||
|
||||
if [[ "$TAPM_FLEET_STARTED_AT" =~ ^[0-9]+$ ]] &&
|
||||
(( TAPM_FLEET_STARTED_AT > 0 )); then
|
||||
duration="$(( $(date +%s) - TAPM_FLEET_STARTED_AT ))"
|
||||
fi
|
||||
if (( exit_status == 0 )); then
|
||||
TAPM_FLEET_EVENT_SEND run_completed success '' "$duration"
|
||||
TAPM_FLEET_EVENT_SEND run_completed success '' "$duration" &&
|
||||
event_sent=1
|
||||
else
|
||||
TAPM_FLEET_EVENT_SEND run_failed failure exit_nonzero "$duration"
|
||||
TAPM_FLEET_EVENT_SEND run_failed failure exit_nonzero "$duration" &&
|
||||
event_sent=1
|
||||
fi
|
||||
if (( TAPM_FLEET_REGISTERED == 1 )) && TAPM_FLEET_VALID_IDENTITY; then
|
||||
if (( event_sent == 1 )) && TAPM_FLEET_VALID_IDENTITY; then
|
||||
TAPM_FLEET_LAST_VERSION="$TAPM_FLEET_VERSION"
|
||||
TAPM_FLEET_WRITE_IDENTITY || true
|
||||
else
|
||||
# A failed event may mean the broker no longer recognizes this local
|
||||
# credential. Re-enroll on the next invocation, not during this one.
|
||||
TAPM_FLEET_ENROLLED=0
|
||||
fi
|
||||
TAPM_FLEET_VALID_IDENTITY && TAPM_FLEET_WRITE_IDENTITY || true
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -23,3 +23,17 @@ TAPM_VIRTIO_LABELED_FILENAME() {
|
||||
|
||||
printf 'virtio-win-%s%s.iso\n' "$label" "${version:+-${version}}"
|
||||
}
|
||||
|
||||
TAPM_VIRTIO_CACHE_VALID() {
|
||||
local checked_at="${1:-}"
|
||||
local now="${2:-}"
|
||||
local max_age="${3:-}"
|
||||
local filename="${4:-}"
|
||||
|
||||
[[ "$checked_at" =~ ^[0-9]+$ &&
|
||||
"$now" =~ ^[0-9]+$ &&
|
||||
"$max_age" =~ ^[1-9][0-9]*$ &&
|
||||
"$filename" =~ ^virtio-win(-[0-9]+\.[0-9]+\.[0-9]+)?\.iso$ ]] ||
|
||||
return 1
|
||||
(( now >= checked_at && now - checked_at < max_age ))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user