Proxmox Module: temp_internet function
This commit is contained in:
parent
ad28cdb698
commit
1b2904afcd
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,6 +10,7 @@ conf.d/90_misc_local.fish
|
||||
conf.d/local.d/
|
||||
functions/local/
|
||||
completions/local/
|
||||
modules/*/conf.d/90_overrides.fish
|
||||
|
||||
# Must be moved later
|
||||
completions/alacritty.fish
|
||||
|
||||
7
modules/proxmox_host/conf.d/90_overrides.fish.example
Normal file
7
modules/proxmox_host/conf.d/90_overrides.fish.example
Normal file
@ -0,0 +1,7 @@
|
||||
# Default temporary Internet settings.
|
||||
|
||||
set -g PROXMOX_TEMP_INTERNET_BRIDGE vmbr1
|
||||
set -g PROXMOX_TEMP_INTERNET_MODEL virtio
|
||||
|
||||
set -g PROXMOX_TEMP_INTERNET_IP "192.0.2.100/24"
|
||||
set -g PROXMOX_TEMP_INTERNET_GATEWAY "192.0.2.1"
|
||||
94
modules/proxmox_host/functions/temp_internet.fish
Normal file
94
modules/proxmox_host/functions/temp_internet.fish
Normal file
@ -0,0 +1,94 @@
|
||||
function temp_internet --description "Temporarily add or remove Internet access from a VM"
|
||||
set -l action $argv[1]
|
||||
set -l vmid $argv[2]
|
||||
|
||||
if test -z "$action"
|
||||
echo "Usage: temp_internet {add|rm} <vmid> [ip/cidr] [gateway] [bridge] [model]"
|
||||
return 1
|
||||
end
|
||||
|
||||
if test -z "$vmid"
|
||||
echo "Error: VMID is required."
|
||||
return 1
|
||||
end
|
||||
|
||||
switch $action
|
||||
case add
|
||||
set -l ip $argv[3]
|
||||
set -l gateway $argv[4]
|
||||
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
|
||||
|
||||
if test -z "$ip"
|
||||
echo "Error: No IP specified and PROXMOX_TEMP_INTERNET_IP is not configured."
|
||||
return 1
|
||||
end
|
||||
|
||||
if test -z "$gateway"
|
||||
echo "Error: No gateway specified and PROXMOX_TEMP_INTERNET_GATEWAY is not configured."
|
||||
return 1
|
||||
end
|
||||
|
||||
if test -z "$bridge"
|
||||
echo "Error: PROXMOX_TEMP_INTERNET_BRIDGE is not configured."
|
||||
return 1
|
||||
end
|
||||
|
||||
if test -z "$model"
|
||||
echo "Error: PROXMOX_TEMP_INTERNET_MODEL is not configured."
|
||||
return 1
|
||||
end
|
||||
|
||||
set -l vmname (qm config $vmid | awk -F': ' '/^name:/ { print $2 }')
|
||||
|
||||
echo "Adding temporary Internet access to VM $vmid ($vmname)"
|
||||
echo " IP: $ip"
|
||||
echo " Gateway: $gateway"
|
||||
echo " Bridge: $bridge"
|
||||
echo " Model: $model"
|
||||
|
||||
read -l -P "Continue? [y/N]: " confirm
|
||||
|
||||
if test "$confirm" != y
|
||||
echo "Aborted."
|
||||
return 1
|
||||
end
|
||||
|
||||
qm set $vmid \
|
||||
--net1 "$model,bridge=$bridge" \
|
||||
--ipconfig1 "ip=$ip,gw=$gateway"
|
||||
|
||||
or return
|
||||
|
||||
restartvm $vmid
|
||||
|
||||
case rm
|
||||
set -l vmname (qm config $vmid | awk -F': ' '/^name:/ { print $2 }')
|
||||
|
||||
echo "Removing temporary Internet access from VM $vmid ($vmname)"
|
||||
|
||||
read -l -P "Continue? [y/N]: " confirm
|
||||
|
||||
if test "$confirm" != y
|
||||
echo "Aborted."
|
||||
return 1
|
||||
end
|
||||
|
||||
qm set $vmid --delete net1
|
||||
or return
|
||||
|
||||
qm set $vmid --delete ipconfig1
|
||||
or return
|
||||
|
||||
restartvm $vmid
|
||||
|
||||
case '*'
|
||||
echo "Usage: temp_internet {add|rm} <vmid> [ip/cidr] [gateway] [bridge] [model]"
|
||||
return 1
|
||||
end
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user