From 9610f287fd1e7fda99cc8ecbc4b2f4710feaadf6 Mon Sep 17 00:00:00 2001 From: Candifloss Date: Fri, 24 Jul 2026 18:19:03 +0530 Subject: [PATCH] Proxmox function: `setvmip` --- modules/proxmox_host/functions/setvmip.fish | 44 +++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 modules/proxmox_host/functions/setvmip.fish diff --git a/modules/proxmox_host/functions/setvmip.fish b/modules/proxmox_host/functions/setvmip.fish new file mode 100644 index 0000000..1eb7899 --- /dev/null +++ b/modules/proxmox_host/functions/setvmip.fish @@ -0,0 +1,44 @@ +function setvmip --description "Set a VM's Cloud-Init IP" + if test (count $argv) -lt 2 + echo "Usage: setvmip [gateway] [ipconfig]" + return 1 + end + + set -l vmid $argv[1] + set -l new_ip $argv[2] + set -l new_gw $argv[3] + set -l config $argv[4] + + test -n "$config"; or set config ipconfig0 + + set -l qmconfig (qm config "$vmid") + + set -l name (string match -rg '^name: (.*)' $qmconfig) + set -l current (string match -r "^$config: .*" $qmconfig) + + if test -z "$current" + echo "Error: $config not found on VM $vmid." + return 1 + end + + set -l old_ip (string match -rg 'ip=([^, ]+)' $current) + set -l old_gw (string match -rg 'gw=([^, ]+)' $current) + + test -n "$new_gw"; or set new_gw "$old_gw" + + echo + printf "VM: %s (%s)\n" "$vmid" "$name" + printf "Config: %s\n" "$config" + printf "IP: %s → %s\n" "$old_ip" "$new_ip" + printf "Gateway: %s → %s\n" "$old_gw" "$new_gw" + echo + + read -P "Apply? [y/N]: " confirm + + if not string match -iqr '^y(es)?$' "$confirm" + echo "Aborted." + return 0 + end + + qm set "$vmid" --$config "ip=$new_ip,gw=$new_gw" +end \ No newline at end of file