Initial commit: loc_az_hci (smom-dbis-138 excluded via .gitignore)
Some checks failed
Test / test (push) Has been cancelled

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
defiQUG
2026-02-08 09:04:46 -08:00
commit c39465c2bd
386 changed files with 50649 additions and 0 deletions

77
scripts/lib/git_helpers.sh Executable file
View File

@@ -0,0 +1,77 @@
#!/bin/bash
# Git/Gitea Helper Functions
# Loads credentials from .env file for automated Git operations
set -euo pipefail
# Load Git credentials from .env file
load_git_credentials() {
local env_file="${1:-${PROJECT_ROOT:-.}/.env}"
if [ -f "$env_file" ]; then
# Source Gitea credentials
export GITEA_URL="${GITEA_URL:-http://192.168.1.121:3000}"
export GITEA_USERNAME="${GITEA_USERNAME:-pandoramannli}"
export GITEA_PASSWORD="${GITEA_PASSWORD:-admin123}"
export GITEA_TOKEN="${GITEA_TOKEN:-}"
export GITEA_REPO_OWNER="${GITEA_REPO_OWNER:-pandoramannli}"
export GITEA_REPO_NAME="${GITEA_REPO_NAME:-gitops}"
export GITEA_REPO_URL="${GITEA_REPO_URL:-http://192.168.1.121:3000/pandoramannli/gitops.git}"
export GITEA_SSH_URL="${GITEA_SSH_URL:-ssh://git@192.168.1.121:2222/pandoramannli/gitops.git}"
export GIT_USER_NAME="${GIT_USER_NAME:-Admin}"
export GIT_USER_EMAIL="${GIT_USER_EMAIL:-admin@hc-stack.local}"
# Override with .env values if present
set -a
source <(grep -E "^GITEA_|^GIT_USER_" "$env_file" 2>/dev/null | grep -v "^#" || true)
set +a
fi
}
# Get Git remote URL with credentials
get_git_remote_with_auth() {
load_git_credentials
if [ -n "${GITEA_TOKEN:-}" ]; then
# Use token authentication (preferred)
echo "http://oauth2:${GITEA_TOKEN}@${GITEA_URL#http://}/$(echo ${GITEA_REPO_URL} | sed 's|.*://[^/]*/||')"
else
# Use username/password authentication
echo "http://${GITEA_USERNAME}:${GITEA_PASSWORD}@${GITEA_URL#http://}/$(echo ${GITEA_REPO_URL} | sed 's|.*://[^/]*/||')"
fi
}
# Configure Git with credentials
configure_git_credentials() {
load_git_credentials
git config user.name "${GIT_USER_NAME}"
git config user.email "${GIT_USER_EMAIL}"
# Set up credential helper for this repo
local repo_url="${GITEA_REPO_URL}"
if [[ "$repo_url" == http* ]]; then
if [ -n "${GITEA_TOKEN:-}" ]; then
# Use token authentication (preferred)
git remote set-url origin "http://oauth2:${GITEA_TOKEN}@${repo_url#http://}"
else
# Use username/password authentication
git remote set-url origin "http://${GITEA_USERNAME}:${GITEA_PASSWORD}@${repo_url#http://}"
fi
fi
}
# Push to Gitea repository
push_to_gitea() {
local repo_path="${1:-.}"
local branch="${2:-main}"
load_git_credentials
configure_git_credentials
cd "$repo_path"
git add -A
git commit -m "${3:-Update GitOps manifests}" || true
git push origin "$branch" 2>&1
}

126
scripts/lib/proxmox_vm_helpers.sh Executable file
View File

@@ -0,0 +1,126 @@
#!/bin/bash
source ~/.bashrc
# Proxmox VM Helper Functions
# Shared library for Proxmox VM operations with guest-agent IP discovery
set -euo pipefail
# Ensure we're on a Proxmox node
if ! command -v qm >/dev/null 2>&1; then
echo "[ERROR] qm command not found. Run this on a Proxmox host." >&2
exit 1
fi
# Ensure jq is installed
if ! command -v jq >/dev/null 2>&1; then
echo "[ERROR] jq command not found. Install with: apt update && apt install -y jq" >&2
exit 1
fi
# get_vm_ip_from_guest_agent <vmid>
#
# Uses qemu-guest-agent to read network interfaces and returns the first
# non-loopback IPv4 address. Requires:
# - qemu-guest-agent installed in the guest
# - Agent enabled in VM config: qm set <vmid> --agent enabled=1
#
# Returns: IP address or empty string if not available
get_vm_ip_from_guest_agent() {
local vmid="$1"
# This will exit non-zero if guest agent is not running or not enabled
qm guest cmd "$vmid" network-get-interfaces 2>/dev/null \
| jq -r '
.[]?."ip-addresses"[]?
| select(.["ip-address-type"] == "ipv4"
and ."ip-address" != "127.0.0.1")
| ."ip-address"
' \
| head -n1 || echo ""
}
# Convenience wrapper that logs and optionally fails
# get_vm_ip_or_warn <vmid> <name>
#
# Returns: IP address or empty string
# Prints: Warning message if IP not available
get_vm_ip_or_warn() {
local vmid="$1"
local name="$2"
local ip
ip="$(get_vm_ip_from_guest_agent "$vmid" || true)"
if [[ -z "$ip" ]]; then
echo "[WARN] No IP from guest agent for VM $vmid ($name)." >&2
echo " - Ensure qemu-guest-agent is installed in the guest" >&2
echo " - Ensure 'Agent' is enabled in VM options" >&2
echo " - VM must be powered on" >&2
return 1
fi
echo "$ip"
}
# get_vm_ip_or_fallback <vmid> <name> <fallback_ip>
#
# Tries guest agent first, falls back to provided IP if agent not available
# Useful for bootstrap scenarios
get_vm_ip_or_fallback() {
local vmid="$1"
local name="$2"
local fallback_ip="${3:-}"
local ip
ip="$(get_vm_ip_from_guest_agent "$vmid" || true)"
if [[ -n "$ip" ]]; then
echo "$ip"
return 0
fi
if [[ -n "$fallback_ip" ]]; then
echo "[INFO] Guest agent not available for VM $vmid ($name), using fallback IP: $fallback_ip" >&2
echo "$fallback_ip"
return 0
fi
echo "[ERROR] No IP available for VM $vmid ($name) (no guest agent, no fallback)" >&2
return 1
}
# ensure_guest_agent_enabled <vmid>
#
# Ensures guest agent is enabled in VM config (doesn't install in guest)
ensure_guest_agent_enabled() {
local vmid="$1"
qm set "$vmid" --agent enabled=1 >/dev/null 2>&1 || true
}
# check_vm_status <vmid>
#
# Returns VM status (running, stopped, etc.)
check_vm_status() {
local vmid="$1"
qm status "$vmid" 2>/dev/null | awk '{print $2}' || echo "unknown"
}
# wait_for_guest_agent <vmid> <timeout_seconds>
#
# Waits for guest agent to become available
wait_for_guest_agent() {
local vmid="$1"
local timeout="${2:-60}"
local elapsed=0
while [ $elapsed -lt $timeout ]; do
if get_vm_ip_from_guest_agent "$vmid" >/dev/null 2>&1; then
return 0
fi
sleep 2
elapsed=$((elapsed + 2))
done
return 1
}