diff --git a/modules/proxmox_host/conf.d/90_overrides.fish.example b/modules/proxmox_host/conf.d/90_overrides.fish.example index 209a9f2..c0bc3e5 100644 --- a/modules/proxmox_host/conf.d/90_overrides.fish.example +++ b/modules/proxmox_host/conf.d/90_overrides.fish.example @@ -1,7 +1,15 @@ # Default temporary Internet settings. -set -g PROXMOX_TEMP_INTERNET_BRIDGE vmbr1 -set -g PROXMOX_TEMP_INTERNET_MODEL virtio +set -g VM_TEMP_NET_BRIDGE vmbr1 +set -g VM_TEMP_NET_MODEL virtio -set -g PROXMOX_TEMP_INTERNET_IP "192.0.2.100/24" -set -g PROXMOX_TEMP_INTERNET_GATEWAY "192.0.2.1" \ No newline at end of file +set -g VM_TEMP_NET_IP "192.0.2.100/24" +set -g VM_TEMP_NET_GATEWAY "192.0.2.1" + +# Default template settings. + +set -g VM_TEMPLATE_BRIDGE vmbr0 +set -g VM_TEMPLATE_BRIDGES vmbr0 vmbr1 vmbr2 + +set -g VM_TEMPLATE_IMAGE "/root/os_images/debian-13-generic-amd64.qcow2" +set -g VM_TEMPLATE_STORAGE netapp-lvm \ No newline at end of file diff --git a/modules/proxmox_host/functions/create_template.fish b/modules/proxmox_host/functions/create_template.fish new file mode 100644 index 0000000..1ea32f9 --- /dev/null +++ b/modules/proxmox_host/functions/create_template.fish @@ -0,0 +1,112 @@ +function create_template --description "Create a Debian cloud-init template" + + if contains -- $argv[1] -h --help + echo "Usage: create_template [bridge] [image] [storage]" + return 0 + end + + set -l vmid $argv[1] + set -l name $argv[2] + set -l bridge $argv[3] + set -l image $argv[4] + set -l storage $argv[5] + + echo "Proxmox Debian Template Creator" + echo + + # Required values + + if test -z "$vmid" + read -l -P "Template ID: " vmid + end + + if test -z "$vmid" + echo "Error: Template ID is required." + return 1 + end + + if test -z "$name" + echo "Example: debian13tmpl" + read -l -P "Template Name: " name + end + + if test -z "$name" + echo "Error: Template name is required." + return 1 + end + + # Optional values with configured defaults + + test -n "$bridge"; or set bridge $VM_TEMPLATE_BRIDGE + test -n "$image"; or set image $VM_TEMPLATE_IMAGE + test -n "$storage"; or set storage $VM_TEMPLATE_STORAGE + + if test -z "$bridge" + echo "Error: VM_TEMPLATE_BRIDGE is not configured." + return 1 + end + + if test -z "$image" + echo "Error: VM_TEMPLATE_IMAGE is not configured." + return 1 + end + + if test -z "$storage" + echo "Error: VM_TEMPLATE_STORAGE is not configured." + return 1 + end + + # Prompt for bridge if it wasn't supplied + + if test -z "$argv[3]" + set -l options (string join "/" $VM_TEMPLATE_BRIDGES) + read -l -P "Bridge [$options]: " tmp + + if test -n "$tmp" + set bridge $tmp + end + end + + echo + echo "Template ID: $vmid" + echo "Name: $name" + echo "Bridge: $bridge" + echo "Image: $image" + echo "Storage: $storage" + echo + + read -l -P "Continue? [y/N]: " confirm + + if test "$confirm" != y + echo "Aborted." + return 1 + end + + qm create $vmid \ + --name $name \ + --ostype l26 \ + --machine q35 \ + --cpu host \ + --cores 2 \ + --memory 2048 \ + --agent enabled=1 \ + --scsihw virtio-scsi-single \ + --net0 "virtio,bridge=$bridge" + or return + + qm set $vmid \ + --scsi0 "$storage:0,import-from=$image,discard=on,ssd=1,iothread=1" \ + --ide2 "$storage:cloudinit" \ + --boot order=scsi0 \ + --serial0 socket \ + --vga serial0 \ + --ipconfig0 ip=dhcp + or return + + qm template $vmid + or return + + echo + echo "Template '$name' ($vmid) created successfully." + +end \ No newline at end of file diff --git a/modules/proxmox_host/functions/temp_internet.fish b/modules/proxmox_host/functions/temp_internet.fish index 95aa2c5..7c19783 100644 --- a/modules/proxmox_host/functions/temp_internet.fish +++ b/modules/proxmox_host/functions/temp_internet.fish @@ -19,28 +19,28 @@ function temp_internet --description "Temporarily add or remove Internet access set -l bridge $argv[5] set -l model $argv[6] - test -n "$ip"; or set ip $PROXMOX_TEMP_INTERNET_IP - test -n "$gateway"; or set gateway $PROXMOX_TEMP_INTERNET_GATEWAY - test -n "$bridge"; or set bridge $PROXMOX_TEMP_INTERNET_BRIDGE - test -n "$model"; or set model $PROXMOX_TEMP_INTERNET_MODEL + test -n "$ip"; or set ip $VM_TEMP_NET_IP + test -n "$gateway"; or set gateway $VM_TEMP_NET_GATEWAY + test -n "$bridge"; or set bridge $VM_TEMP_NET_BRIDGE + test -n "$model"; or set model $VM_TEMP_NET_MODEL if test -z "$ip" - echo "Error: No IP specified and PROXMOX_TEMP_INTERNET_IP is not configured." + echo "Error: VM_TEMP_NET_IP is not configured." return 1 end if test -z "$gateway" - echo "Error: No gateway specified and PROXMOX_TEMP_INTERNET_GATEWAY is not configured." + echo "Error: VM_TEMP_NET_GATEWAY is not configured." return 1 end if test -z "$bridge" - echo "Error: PROXMOX_TEMP_INTERNET_BRIDGE is not configured." + echo "Error: VM_TEMP_NET_BRIDGE is not configured." return 1 end if test -z "$model" - echo "Error: PROXMOX_TEMP_INTERNET_MODEL is not configured." + echo "Error: VM_TEMP_NET_MODEL is not configured." return 1 end