Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
- ADD_CHAIN138_TO_LEDGER_LIVE: Ledger form done; public code review repo bis-innovations/LedgerLive; init/push commands - CONTRACT_DEPLOYMENT_RUNBOOK: Chain 138 gas price 1 gwei, 36-addr check, TransactionMirror workaround - CONTRACT_*: AddressMapper, MirrorManager deployed 2026-02-12; 36-address on-chain check - NEXT_STEPS_FOR_YOU: Ledger done; steps completable now (no LAN); run-completable-tasks-from-anywhere - MASTER_INDEX, OPERATOR_OPTIONAL, SMART_CONTRACTS_INVENTORY_SIMPLE: updates - LEDGER_BLOCKCHAIN_INTEGRATION_COMPLETE: bis-innovations/LedgerLive reference Co-authored-by: Cursor <cursoragent@cursor.com>
241 lines
8.0 KiB
Bash
Executable File
241 lines
8.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Create local-lvm storage on pve and pve2 to allow container migrations from ml110
|
|
# This script creates LVM thin pool storage compatible with ml110's local-lvm
|
|
|
|
set -euo pipefail
|
|
|
|
# Load IP configuration
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
|
|
|
|
|
|
PROXMOX_HOST_PVE="${PROXMOX_HOST_R630_01}"
|
|
PROXMOX_HOST_PVE2="${PROXMOX_HOST_R630_02}"
|
|
PVE_PASS="password"
|
|
STORAGE_NAME="local-lvm"
|
|
VG_NAME="pve"
|
|
|
|
# Colors
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m'
|
|
|
|
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
|
|
log_success() { echo -e "${GREEN}[✓]${NC} $1"; }
|
|
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
|
|
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
|
|
|
|
# Check if storage already exists
|
|
check_storage() {
|
|
local host=$1
|
|
local storage_name=$2
|
|
|
|
log_info "Checking if $storage_name exists on $host..."
|
|
|
|
if sshpass -p "$PVE_PASS" ssh -o StrictHostKeyChecking=accept-new root@${host} \
|
|
"pvesm status | grep -q '$storage_name'" 2>/dev/null; then
|
|
log_success "Storage $storage_name already exists on $host"
|
|
return 0
|
|
else
|
|
log_info "Storage $storage_name does not exist on $host"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Check if volume group exists
|
|
check_vg() {
|
|
local host=$1
|
|
local vg_name=$2
|
|
|
|
log_info "Checking if volume group $vg_name exists on $host..."
|
|
|
|
if sshpass -p "$PVE_PASS" ssh -o StrictHostKeyChecking=accept-new root@${host} \
|
|
"vgs | grep -q '$vg_name'" 2>/dev/null; then
|
|
log_success "Volume group $vg_name exists on $host"
|
|
return 0
|
|
else
|
|
log_error "Volume group $vg_name does not exist on $host"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Check if thin pool exists
|
|
check_thin_pool() {
|
|
local host=$1
|
|
local vg_name=$2
|
|
local pool_name="data"
|
|
|
|
log_info "Checking if thin pool ${vg_name}/${pool_name} exists on $host..."
|
|
|
|
if sshpass -p "$PVE_PASS" ssh -o StrictHostKeyChecking=accept-new root@${host} \
|
|
"lvs ${vg_name}/${pool_name} 2>/dev/null | grep -q '$pool_name'" 2>/dev/null; then
|
|
log_success "Thin pool ${vg_name}/${pool_name} exists on $host"
|
|
return 0
|
|
else
|
|
log_info "Thin pool ${vg_name}/${pool_name} does not exist on $host"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Create thin pool (if VG exists but pool doesn't)
|
|
create_thin_pool() {
|
|
local host=$1
|
|
local vg_name=$2
|
|
local pool_name="data"
|
|
|
|
log_info "Creating thin pool ${vg_name}/${pool_name} on $host..."
|
|
|
|
# Get available space in VG
|
|
local vg_free=$(sshpass -p "$PVE_PASS" ssh -o StrictHostKeyChecking=accept-new root@${host} \
|
|
"vgs -o vg_free --noheadings --units g $vg_name 2>/dev/null | awk '{print int(\$1)}'" || echo "0")
|
|
|
|
if [ "$vg_free" -lt 10 ]; then
|
|
log_error "Not enough free space in volume group (${vg_free}G available, need at least 10G)"
|
|
return 1
|
|
fi
|
|
|
|
log_info "Available space: ${vg_free}G"
|
|
|
|
# Use 80% of available space for thin pool
|
|
local pool_size=$((vg_free * 80 / 100))
|
|
log_info "Creating thin pool with ${pool_size}G"
|
|
|
|
sshpass -p "$PVE_PASS" ssh -o StrictHostKeyChecking=accept-new root@${host} <<EOF
|
|
lvcreate -L ${pool_size}G -n ${pool_name} ${vg_name}
|
|
lvconvert --type thin-pool ${vg_name}/${pool_name}
|
|
EOF
|
|
|
|
if [ $? -eq 0 ]; then
|
|
log_success "Thin pool ${vg_name}/${pool_name} created successfully"
|
|
return 0
|
|
else
|
|
log_error "Failed to create thin pool"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Add storage to Proxmox
|
|
add_storage() {
|
|
local host=$1
|
|
local storage_name=$2
|
|
local vg_name=$3
|
|
local pool_name="data"
|
|
|
|
log_info "Adding $storage_name storage to Proxmox on $host..."
|
|
|
|
sshpass -p "$PVE_PASS" ssh -o StrictHostKeyChecking=accept-new root@${host} <<EOF
|
|
pvesm add lvmthin ${storage_name} \
|
|
--thinpool ${vg_name}/${pool_name} \
|
|
--content images,rootdir \
|
|
--nodes ${host} 2>&1
|
|
EOF
|
|
|
|
if [ $? -eq 0 ]; then
|
|
log_success "Storage $storage_name added successfully"
|
|
return 0
|
|
else
|
|
log_warn "Storage may already exist or command had non-zero exit"
|
|
# Check if it exists now
|
|
if check_storage "$host" "$storage_name"; then
|
|
return 0
|
|
fi
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Process a single node
|
|
process_node() {
|
|
local host=$1
|
|
local node_name=$2
|
|
|
|
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
log_info "Processing node: $node_name ($host)"
|
|
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo ""
|
|
|
|
# Check if storage already exists
|
|
if check_storage "$host" "$STORAGE_NAME"; then
|
|
log_info "Storage already configured, skipping..."
|
|
return 0
|
|
fi
|
|
|
|
# Check volume group
|
|
if ! check_vg "$host" "$VG_NAME"; then
|
|
log_error "Volume group $VG_NAME does not exist. Cannot create local-lvm storage."
|
|
log_info "You may need to:"
|
|
log_info " 1. Create a volume group first"
|
|
log_info " 2. Or use existing storage (local) and convert containers after migration"
|
|
return 1
|
|
fi
|
|
|
|
# Check/create thin pool
|
|
if ! check_thin_pool "$host" "$VG_NAME"; then
|
|
if ! create_thin_pool "$host" "$VG_NAME"; then
|
|
log_error "Failed to create thin pool"
|
|
return 1
|
|
fi
|
|
fi
|
|
|
|
# Add storage to Proxmox
|
|
if ! add_storage "$host" "$STORAGE_NAME" "$VG_NAME"; then
|
|
log_error "Failed to add storage to Proxmox"
|
|
return 1
|
|
fi
|
|
|
|
log_success "Storage setup complete for $node_name"
|
|
echo ""
|
|
return 0
|
|
}
|
|
|
|
# Main execution
|
|
main() {
|
|
echo ""
|
|
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
log_info "Create local-lvm Storage for Migrations"
|
|
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo ""
|
|
|
|
log_info "This script will create local-lvm storage on:"
|
|
log_info " • pve (${PROXMOX_HOST_R630_01:-192.168.11.11})"
|
|
log_info " • pve2 (${PROXMOX_HOST_R630_02:-192.168.11.12})"
|
|
echo ""
|
|
log_info "This storage will allow containers to be migrated"
|
|
log_info "from ml110 (which uses local-lvm) to pve/pve2."
|
|
echo ""
|
|
|
|
# Process pve
|
|
process_node "$PROXMOX_HOST_PVE" "pve"
|
|
|
|
# Process pve2 (if accessible)
|
|
if sshpass -p "$PVE_PASS" ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=accept-new root@${PROXMOX_HOST_PVE2} "echo 'connected'" 2>/dev/null; then
|
|
process_node "$PROXMOX_HOST_PVE2" "pve2"
|
|
else
|
|
log_warn "Cannot connect to pve2 (${PROXMOX_HOST_R630_02:-192.168.11.12}), skipping..."
|
|
fi
|
|
|
|
echo ""
|
|
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
log_info "Storage Creation Summary"
|
|
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo ""
|
|
|
|
# Verify storage on both nodes
|
|
log_info "Verifying storage creation..."
|
|
check_storage "$PROXMOX_HOST_PVE" "$STORAGE_NAME"
|
|
if sshpass -p "$PVE_PASS" ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=accept-new root@${PROXMOX_HOST_PVE2} "echo 'connected'" 2>/dev/null; then
|
|
check_storage "$PROXMOX_HOST_PVE2" "$STORAGE_NAME"
|
|
fi
|
|
|
|
echo ""
|
|
log_info "Next steps:"
|
|
log_info " 1. Verify storage is available: ssh root@<node> 'pvesm status'"
|
|
log_info " 2. Run migration script: ./scripts/rename-and-migrate-chain138-containers.sh"
|
|
echo ""
|
|
}
|
|
|
|
main "$@"
|
|
|