pve admin tooling
This commit is contained in:
7
proxmox/admin_scripts/broadcast_reboot.sh
Executable file
7
proxmox/admin_scripts/broadcast_reboot.sh
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
source /root/telegram.env
|
||||
|
||||
tgmsg 'booted; Check nomigrate Start'
|
||||
|
||||
sleep 300 # nonmigrate kube minimum uptime to take an another node offline
|
||||
tgmsg "$(uptime -p)"
|
32
proxmox/admin_scripts/confirm_norunning.sh
Executable file
32
proxmox/admin_scripts/confirm_norunning.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
if ! which jq >> /dev/null; then
|
||||
echo "jq not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
includingNomigrate=0
|
||||
if [[ "$#" -gt 0 ]]; then
|
||||
includingNomigrate="$1"
|
||||
fi
|
||||
host="$(hostname)"
|
||||
if [[ "$#" -gt 1 ]]; then
|
||||
host="$2"
|
||||
fi
|
||||
|
||||
function running_ids {
|
||||
if [[ "$includingNomigrate" == 1 ]]; then
|
||||
pvesh get "/nodes/${host}/qemu" --output-format json |\
|
||||
jq -r 'map(select( .status == "running" ) | .vmid) | sort | @csv'
|
||||
else
|
||||
pvesh get "/nodes/${host}/qemu" --output-format json |\
|
||||
jq -r 'map(select( .status == "running" and (.tags | split(";") | all(.!="nomigrate")) ) | .vmid) | sort | @csv'
|
||||
fi
|
||||
}
|
||||
|
||||
running_ids="$(running_ids)"
|
||||
if [[ "$running_ids" != "" ]]; then
|
||||
echo "ERROR: VMs running on $host: $running_ids"
|
||||
exit 1
|
||||
fi
|
4
proxmox/admin_scripts/list_users.sh
Executable file
4
proxmox/admin_scripts/list_users.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
pvesh get /access/acl -o json | jq -r '.[] | select(.roleid == "K-SPACE_VM_USER") | .ugid' | sort | uniq
|
25
proxmox/admin_scripts/shutdown_nomigrates.sh
Executable file
25
proxmox/admin_scripts/shutdown_nomigrates.sh
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
#set -e
|
||||
|
||||
if ! which jq >> /dev/null; then
|
||||
echo "jq not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#echo "USAGE: $0 [node (=hostname))]"
|
||||
host="$HOSTNAME"
|
||||
if [[ "$#" -ge 1 ]]; then
|
||||
host="$1"
|
||||
fi
|
||||
|
||||
function shutdown_ids {
|
||||
pvesh get "/nodes/${host}/qemu" --output-format json |\
|
||||
jq -r 'map(select( .status == "running" and (.tags | split(";") | any(.=="nomigrate")) ) | .vmid)[]'
|
||||
}
|
||||
|
||||
shutdown_ids | while IFS= read -r vmid; do
|
||||
pvesh create "/nodes/${host}/qemu/${vmid}/status/shutdown" -timeout 1 &
|
||||
sleep 1
|
||||
done
|
||||
|
||||
wait
|
54
proxmox/admin_scripts/template.sh
Executable file
54
proxmox/admin_scripts/template.sh
Executable file
@@ -0,0 +1,54 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# https://wiki.k-space.ee/en/hosting/proxmox
|
||||
# image does not come from debian, but whole thing probably replaced with self-service thing anyway
|
||||
|
||||
if [[ "$#" -ne 2 ]]; then
|
||||
echo "ERROR: expected exactly 2 arguments"
|
||||
echo "USAGE: $0 <storage> <vmid>"
|
||||
exit 1
|
||||
fi
|
||||
storage="$1"
|
||||
vmid="$2"
|
||||
img=debian-12
|
||||
ident=d12.v2
|
||||
size=100G
|
||||
|
||||
# will error if vmid exists
|
||||
qm create "$vmid" \
|
||||
--cpu x86-64-v3 --numa 1 \
|
||||
--cores 16 --vcpus 8 \
|
||||
--memory 4096 \
|
||||
--scsihw virtio-scsi-pci \
|
||||
--ide0 none,media=cdrom --ide2 "$storage":cloudinit,format=raw \
|
||||
--boot order='ide0;scsi0' \
|
||||
--serial0 socket --vga serial0 \
|
||||
--net0 virtio,bridge=vmbr0 \
|
||||
--ipconfig0 ip='193.40.103.99/24',gw='193.40.103.1',ip6='2001:bb8:4008:20::99/64',gw6='2001:bb8:4008:20::1' \
|
||||
--searchdomain zoo.k-space.ee --nameserver '1.1.1.1 8.8.8.8' \
|
||||
--ostype l26 --hotplug disk,network,usb,memory,cpu --onboot 1 \
|
||||
--agent 1,fstrim_cloned_disks=1 \
|
||||
--name "$ident.$HOSTNAME" --description "https://wiki.k-space.ee/en/hosting/proxmox"$'\n\n'"Base template: $ident"$'\n\n'"User: UNDOCUMENTED"
|
||||
|
||||
# Whole script supposed to be replaced by self-service suite anyway.
|
||||
#TODO: virt-builder version is crap, replacing it with drop-in:
|
||||
wget 'https://cdimage.debian.org/images/cloud/bookworm/latest/debian-12-genericcloud-amd64.raw' -O "$img".img
|
||||
|
||||
function cleanup {
|
||||
rm "$img".img
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
virt-customize -a "$img".img \
|
||||
--root-password disabled \
|
||||
--install qemu-guest-agent,sshguard \
|
||||
--run-command 'unattended-upgrades unattended-upgrades/enable_auto_updates boolean true | debconf-set-selections' \
|
||||
--run-command 'dpkg-reconfigure -f noninteractive unattended-upgrades' \
|
||||
--append-line '/lib/udev/rules.d/80-hotplug-cpu-mem.rules:SUBSYSTEM=="cpu", ACTION=="add", TEST=="online", ATTR{online}=="0", ATTR{online}="1"' \
|
||||
--append-line '/lib/udev/rules.d/80-hotplug-cpu-mem.rules:SUBSYSTEM=="memory", ACTION=="add", TEST=="state", ATTR{state}=="offline", ATTR{state}="online"'
|
||||
|
||||
qm set "$vmid" --scsi0 "$storage":0,import-from="$PWD/$img.img",discard=on,ssd=1
|
||||
qm disk resize "$vmid" scsi0 "$size"
|
||||
|
||||
qm template "$vmid"
|
Reference in New Issue
Block a user