Refactor storage validation and error codes for containers
Simplifies and streamlines storage validation logic in create_lxc_container, removing redundant content checks and using direct exit codes for unsupported storage types. Updates error_handler.func with clearer, more specific Proxmox exit code explanations and improves code consistency and readability throughout error handling functions.
This commit is contained in:
parent
9307060c45
commit
d677488b29
@ -3336,43 +3336,25 @@ create_lxc_container() {
|
||||
fi
|
||||
|
||||
msg_info "Validating storage '$CONTAINER_STORAGE'"
|
||||
STORAGE_CONTENT=$(grep -A10 -E "^(dir|nfs|cifs|btrfs|cephfs|lvm|lvmthin|zfspool|rbd|iscsi|iscsidirect|zfs|linstor|pbs): $CONTAINER_STORAGE$" /etc/pve/storage.cfg | grep -m1 content | awk '{$1=""; print $0}' | xargs)
|
||||
|
||||
if [[ -z "$STORAGE_CONTENT" ]]; then
|
||||
if pvesm status -content rootdir 2>/dev/null | awk 'NR>1{print $1}' | grep -qx "$CONTAINER_STORAGE"; then
|
||||
STORAGE_CONTENT="rootdir"
|
||||
fi
|
||||
fi
|
||||
|
||||
STORAGE_TYPE=$(grep -E "^[^:]+: $CONTAINER_STORAGE$" /etc/pve/storage.cfg | cut -d: -f1 | head -1)
|
||||
|
||||
case "$STORAGE_TYPE" in
|
||||
linstor | rbd | cephfs | iscsi | iscsidirect | nfs | cifs)
|
||||
if ! pvesm status -storage "$CONTAINER_STORAGE" &>/dev/null; then
|
||||
msg_error "Storage '$CONTAINER_STORAGE' ($STORAGE_TYPE) not accessible"
|
||||
exit 217
|
||||
fi
|
||||
iscsidirect) exit 212 ;;
|
||||
iscsi | zfs) exit 213 ;;
|
||||
cephfs) exit 219 ;;
|
||||
pbs) exit 224 ;;
|
||||
linstor | rbd | nfs | cifs)
|
||||
pvesm status -storage "$CONTAINER_STORAGE" &>/dev/null || exit 217
|
||||
;;
|
||||
esac
|
||||
|
||||
if ! pvesm status -content rootdir 2>/dev/null | awk 'NR>1{print $1}' | grep -qx "$CONTAINER_STORAGE"; then
|
||||
if ! grep -qw "rootdir" <<<"$STORAGE_CONTENT"; then
|
||||
msg_error "Storage '$CONTAINER_STORAGE' does not support 'rootdir'"
|
||||
exit 217
|
||||
fi
|
||||
fi
|
||||
pvesm status -content rootdir 2>/dev/null | awk 'NR>1{print $1}' | grep -qx "$CONTAINER_STORAGE" || exit 213
|
||||
msg_ok "Storage '$CONTAINER_STORAGE' ($STORAGE_TYPE) validated"
|
||||
|
||||
msg_info "Validating template storage '$TEMPLATE_STORAGE'"
|
||||
TEMPLATE_CONTENT=$(grep -A10 -E "^(dir|nfs|cifs|btrfs|cephfs|lvm|lvmthin|zfspool|rbd|iscsi|iscsidirect|zfs|linstor|pbs): $TEMPLATE_STORAGE$" /etc/pve/storage.cfg | grep -m1 content | awk '{$1=""; print $0}' | xargs)
|
||||
if [[ -z "$TEMPLATE_CONTENT" ]]; then
|
||||
if pvesm status -content vztmpl 2>/dev/null | awk 'NR>1{print $1}' | grep -qx "$TEMPLATE_STORAGE"; then
|
||||
TEMPLATE_CONTENT="vztmpl"
|
||||
fi
|
||||
fi
|
||||
TEMPLATE_TYPE=$(grep -E "^[^:]+: $TEMPLATE_STORAGE$" /etc/pve/storage.cfg | cut -d: -f1)
|
||||
|
||||
if ! grep -qw "vztmpl" <<<"$TEMPLATE_CONTENT"; then
|
||||
if ! pvesm status -content vztmpl 2>/dev/null | awk 'NR>1{print $1}' | grep -qx "$TEMPLATE_STORAGE"; then
|
||||
msg_warn "Template storage '$TEMPLATE_STORAGE' may not support 'vztmpl'"
|
||||
fi
|
||||
msg_ok "Template storage '$TEMPLATE_STORAGE' validated"
|
||||
|
||||
@ -91,51 +91,31 @@ explain_exit_code() {
|
||||
254) echo "MongoDB: Fatal query error" ;;
|
||||
|
||||
# --- Proxmox Custom Codes ---
|
||||
200) echo "Custom: Failed to create lock file" ;;
|
||||
203) echo "Custom: Missing CTID variable" ;;
|
||||
204) echo "Custom: Missing PCT_OSTYPE variable" ;;
|
||||
205) echo "Custom: Invalid CTID (<100)" ;;
|
||||
206) echo "Custom: CTID already in use (check 'pct list' and /etc/pve/lxc/)" ;;
|
||||
# --- Proxmox Custom Codes ---
|
||||
200) echo "Custom: Failed to create lock file" ;;
|
||||
203) echo "Custom: Missing CTID variable" ;;
|
||||
204) echo "Custom: Missing PCT_OSTYPE variable" ;;
|
||||
205) echo "Custom: Invalid CTID (<100)" ;;
|
||||
206) echo "Custom: CTID already in use (check 'pct list' and /etc/pve/lxc/)" ;;
|
||||
207) echo "Custom: Password contains unescaped special characters (-, /, \\, *, etc.)" ;;
|
||||
208) echo "Custom: Invalid configuration (DNS/MAC/Network format error)" ;;
|
||||
209) echo "Custom: Container creation failed (check logs for pct create output)" ;;
|
||||
210) echo "Custom: Cluster not quorate" ;;
|
||||
211) echo "Custom: Timeout waiting for template lock (concurrent download in progress)" ;;
|
||||
214) echo "Custom: Not enough storage space" ;;
|
||||
215) echo "Custom: Container created but not listed (ghost state - check /etc/pve/lxc/)" ;;
|
||||
216) echo "Custom: RootFS entry missing in config (incomplete creation)" ;;
|
||||
217) echo "Custom: Storage does not support rootdir (check storage capabilities)" ;;
|
||||
218) echo "Custom: Template file corrupted or incomplete download (size <1MB or invalid archive)" ;;
|
||||
220) echo "Custom: Unable to resolve template path" ;;
|
||||
221) echo "Custom: Template file exists but not readable (check file permissions)" ;;
|
||||
222) echo "Custom: Template download failed after 3 attempts (network/storage issue)" ;;
|
||||
223) echo "Custom: Template not available after download (storage sync issue)" ;;
|
||||
225) echo "Custom: No template available for OS/Version (check 'pveam available')" ;;
|
||||
231) echo "Custom: LXC stack upgrade/retry failed (outdated pve-container - check https://github.com/community-scripts/ProxmoxVE/discussions/8126)" ;;
|
||||
|
||||
# --- Default ---
|
||||
*) echo "Unknown error" ;;
|
||||
208) echo "Custom: Invalid configuration (DNS/MAC/Network format error)" ;;
|
||||
209) echo "Custom: Container creation failed (check logs for pct create output)" ;;
|
||||
210) echo "Custom: Cluster not quorate" ;;
|
||||
211) echo "Custom: Timeout waiting for template lock (concurrent download in progress)" ;;
|
||||
214) echo "Custom: Not enough storage space" ;;
|
||||
215) echo "Custom: Container created but not listed (ghost state - check /etc/pve/lxc/)" ;;
|
||||
216) echo "Custom: RootFS entry missing in config (incomplete creation)" ;;
|
||||
217) echo "Custom: Storage does not support rootdir (check storage capabilities)" ;;
|
||||
218) echo "Custom: Template file corrupted or incomplete download (size <1MB or invalid archive)" ;;
|
||||
220) echo "Custom: Unable to resolve template path" ;;
|
||||
221) echo "Custom: Template file exists but not readable (check file permissions)" ;;
|
||||
222) echo "Custom: Template download failed after 3 attempts (network/storage issue)" ;;
|
||||
223) echo "Custom: Template not available after download (storage sync issue)" ;;
|
||||
225) echo "Custom: No template available for OS/Version (check 'pveam available')" ;;
|
||||
231) echo "Custom: LXC stack upgrade/retry failed (outdated pve-container - check https://github.com/community-scripts/ProxmoxVE/discussions/8126)" ;;
|
||||
200) echo "Proxmox: Failed to create lock file" ;;
|
||||
203) echo "Proxmox: Missing CTID variable" ;;
|
||||
204) echo "Proxmox: Missing PCT_OSTYPE variable" ;;
|
||||
205) echo "Proxmox: Invalid CTID (<100)" ;;
|
||||
206) echo "Proxmox: CTID already in use" ;;
|
||||
207) echo "Proxmox: Password contains unescaped special characters" ;;
|
||||
208) echo "Proxmox: Invalid configuration (DNS/MAC/Network format)" ;;
|
||||
209) echo "Proxmox: Container creation failed" ;;
|
||||
210) echo "Proxmox: Cluster not quorate" ;;
|
||||
211) echo "Proxmox: Timeout waiting for template lock" ;;
|
||||
212) echo "Proxmox: Storage type 'iscsidirect' does not support containers (VMs only)" ;;
|
||||
213) echo "Proxmox: Storage type does not support 'rootdir' content" ;;
|
||||
214) echo "Proxmox: Not enough storage space" ;;
|
||||
215) echo "Proxmox: Container created but not listed (ghost state)" ;;
|
||||
216) echo "Proxmox: RootFS entry missing in config" ;;
|
||||
217) echo "Proxmox: Storage not accessible" ;;
|
||||
219) echo "Proxmox: CephFS does not support containers - use RBD" ;;
|
||||
224) echo "Proxmox: PBS storage is for backups only" ;;
|
||||
218) echo "Proxmox: Template file corrupted or incomplete" ;;
|
||||
220) echo "Proxmox: Unable to resolve template path" ;;
|
||||
221) echo "Proxmox: Template file not readable" ;;
|
||||
222) echo "Proxmox: Template download failed" ;;
|
||||
223) echo "Proxmox: Template not available after download" ;;
|
||||
225) echo "Proxmox: No template available for OS/Version" ;;
|
||||
231) echo "Proxmox: LXC stack upgrade failed" ;;
|
||||
|
||||
# --- Default ---
|
||||
*) echo "Unknown error" ;;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user