add admin_scripts/affinity_maintenance.sh
This commit is contained in:
51
proxmox/admin_scripts/affinity_maintenance.sh
Executable file
51
proxmox/admin_scripts/affinity_maintenance.sh
Executable file
@@ -0,0 +1,51 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
function usage() {
|
||||||
|
echo "USAGE: $0 1 -- disable all resource affinity rules"
|
||||||
|
echo "USAGE: $0 0 -- (default) attempt to re-enable all rules (including previously not enabled"
|
||||||
|
exit 64
|
||||||
|
}
|
||||||
|
|
||||||
|
if ! which jq >> /dev/null; then
|
||||||
|
echo "jq not found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$#" -ne 1 ]]; then
|
||||||
|
echo "ERROR: expected exactly one argument"
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
|
||||||
|
maintenance=0
|
||||||
|
case "$1" in
|
||||||
|
0)
|
||||||
|
true
|
||||||
|
;;
|
||||||
|
1)
|
||||||
|
maintenance=1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
export rules="$(mktemp)"
|
||||||
|
function cleanup {
|
||||||
|
rm "$rules"
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
pvesh get /cluster/ha/rules --output-format json | jq '[ .[] | select(.affinity == "negative") | select(.type == "resource-affinity") ]' > "$rules"
|
||||||
|
|
||||||
|
if [[ "$maintenance" == 1 ]]; then
|
||||||
|
cat "$rules" | jq -r '.[] | select(.disable == 1) | .comment' | sed 's/^/already disabled rule/g'
|
||||||
|
|
||||||
|
cat "$rules" | jq -r '.[].rule' | while read -r rule; do
|
||||||
|
pvesh set "/cluster/ha/rules/${rule}" --type resource-affinity --disable 1
|
||||||
|
done
|
||||||
|
else
|
||||||
|
cat "$rules" | jq -r '.[].rule' | while read -r rule; do
|
||||||
|
pvesh set "/cluster/ha/rules/${rule}" --type resource-affinity --delete disable || true
|
||||||
|
done
|
||||||
|
fi
|
||||||
@@ -71,9 +71,21 @@ function off {
|
|||||||
_off "$HOSTNAME"
|
_off "$HOSTNAME"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
roff
|
||||||
|
|
||||||
updl
|
updl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function roff {
|
||||||
|
/root/admin_scripts/affinity_maintenance.sh 1
|
||||||
|
echo 'resource affinities: disabled'
|
||||||
|
}
|
||||||
|
|
||||||
|
function ron {
|
||||||
|
/root/admin_scripts/affinity_maintenance.sh 0
|
||||||
|
echo 'resource affinities: enabled'
|
||||||
|
}
|
||||||
|
|
||||||
function _on {
|
function _on {
|
||||||
ha-manager crm-command node-maintenance disable "$1" && \
|
ha-manager crm-command node-maintenance disable "$1" && \
|
||||||
echo "$1": normal mode
|
echo "$1": normal mode
|
||||||
@@ -87,9 +99,11 @@ function on {
|
|||||||
else
|
else
|
||||||
_on "$HOSTNAME"
|
_on "$HOSTNAME"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo 're-enable resource affinities: ron'
|
||||||
}
|
}
|
||||||
|
|
||||||
alias h="echo 'avail cmds: off on | upg upgr | updl localprogress'"
|
alias h="echo 'avail cmds: off on roff ron | upg upgr | updl localprogress'"
|
||||||
|
|
||||||
function localprogress () {
|
function localprogress () {
|
||||||
watch ls -lh "/var/lib/vz/images/$1"
|
watch ls -lh "/var/lib/vz/images/$1"
|
||||||
|
|||||||
Reference in New Issue
Block a user