mirror of
https://github.com/GoodOlClint/PSProxmoxVE.git
synced 2026-08-24 11:36:30 +00:00
ci: cleanup honours PVE_TARGET_NODE and the ISO storage var
A pool-scoped token cannot list /nodes, so node discovery fell back to 'pve' and force-cleanup silently found no VMs to destroy.
This commit is contained in:
@@ -13,9 +13,13 @@ ISO_FILENAME="$4"
|
||||
TF_DIR="$5"
|
||||
API_BASE="${PVE_ENDPOINT}/api2/json"
|
||||
|
||||
# Discover node name
|
||||
NODES_JSON=$(curl -sk -H "Authorization: PVEAPIToken=${API_TOKEN}" "${API_BASE}/nodes" 2>/dev/null)
|
||||
NODE=$(echo "$NODES_JSON" | python3 -c "import json,sys; print(json.load(sys.stdin)['data'][0]['node'])" 2>/dev/null || echo "pve")
|
||||
# Node: PVE_TARGET_NODE when set (a pool-scoped token cannot list /nodes), else the first node.
|
||||
NODE="${PVE_TARGET_NODE:-}"
|
||||
if [ -z "$NODE" ]; then
|
||||
NODES_JSON=$(curl -sk -H "Authorization: PVEAPIToken=${API_TOKEN}" "${API_BASE}/nodes" 2>/dev/null)
|
||||
NODE=$(echo "$NODES_JSON" | python3 -c "import json,sys; print(json.load(sys.stdin)['data'][0]['node'])" 2>/dev/null || echo "pve")
|
||||
fi
|
||||
ISO_STORAGE="${TF_VAR_iso_storage:-local}"
|
||||
|
||||
echo "=== Pre-flight cleanup (node: ${NODE}, vmid: ${VM_ID}) ==="
|
||||
|
||||
@@ -53,7 +57,7 @@ if [ -z "$ISO_FILENAME" ]; then
|
||||
echo "No ISO filename specified, skipping ISO cleanup"
|
||||
else
|
||||
ISO_EXISTS=$(curl -sk -H "Authorization: PVEAPIToken=${API_TOKEN}" \
|
||||
"${API_BASE}/nodes/${NODE}/storage/local/content" 2>/dev/null \
|
||||
"${API_BASE}/nodes/${NODE}/storage/${ISO_STORAGE}/content" 2>/dev/null \
|
||||
| python3 -c "
|
||||
import json, sys
|
||||
data = json.load(sys.stdin).get('data', [])
|
||||
@@ -68,7 +72,7 @@ if [ -n "$ISO_EXISTS" ]; then
|
||||
echo " Deleting..."
|
||||
ENCODED=$(python3 -c "import urllib.parse; print(urllib.parse.quote('${ISO_EXISTS}', safe=''))")
|
||||
curl -sk -X DELETE -H "Authorization: PVEAPIToken=${API_TOKEN}" \
|
||||
"${API_BASE}/nodes/${NODE}/storage/local/content/${ENCODED}" >/dev/null 2>&1
|
||||
"${API_BASE}/nodes/${NODE}/storage/${ISO_STORAGE}/content/${ENCODED}" >/dev/null 2>&1
|
||||
sleep 2
|
||||
echo " ISO cleanup done"
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user