This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Note: This further tweaks rhel and centos images | |
# built by the maas-image-builder | |
# | |
# This is supplemental to the kickstart file | |
# that gets auto-generated by the maas-image-builder. | |
# It does not supercede those settings, unless | |
# you purposely reverse a change, like unlocking | |
# the root user's account | |
# | |
# Since it is supplemental, there are no "required" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run dist-upgrade all deployed machines running ubuntu | |
(maas admin machines read|jq -r '.[]|select((.status==6) and .osystem=="ubuntu").hostname')|\ | |
xargs -n1 -P0 bash -c 'ssh $0 "sudo 2>/dev/null bash -c '"'"'apt update;apt dist-upgrade -y;apt autoremove -y'"'"'"' | |
# Run dist-upgrade all deployed machines running ubuntu with a certain tag | |
# To see list of tags, run: maas admin tags read|jq -r '.[].name' | |
(maas admin tag machines ${TAG}|jq -r '.[]|select((.status==6) and .osystem=="ubuntu").hostname')|\ | |
xargs -n1 -P0 bash -c 'ssh $0 "sudo 2>/dev/null bash -c '"'"'apt update;apt dist-upgrade -y;apt autoremove -y'"'"'"' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cleanup-snaps() { | |
for SNAP in $(sudo find 2>/dev/null /snap -maxdepth 2 -type l -name current |awk -F/ '{print $3}');do | |
local -a OLD_REVS=($(sudo find 2>/dev/null /snap/${SNAP} -maxdepth 1 ! -name "$(readlink /snap/${SNAP}/current)" ! -name ${SNAP} -type d -exec basename {} \;)) | |
[[ ${#OLD_REVS[@]} -ge 1 ]] && { printf '%s %s\n' ${SNAP} ${OLD_REVS[@]}|\ | |
xargs -rn2 -P1 bash -c 'sudo snap remove $0 --revision=$1|\ | |
sed -r "s/^.*\(|\)//g;s/removed/of snap $0 &/g;s/^.*$/"$(printf "\e[1m&\e[0m")"/g;s/revision/Revision/g"' | |
[[ $? -eq 0 ]] && { printf "\e[1A\e[60G\e[38;2;0;230;0mOK\e[0m\n"; } || { printf "\e[58G\e[38;2;240;0;0mFAILED\e[0m\n";} ; } | |
[[ ${#OLD_REVS[@]} -lt 1 ]] && printf "\e[38;2;150;150;150msnap \"${SNAP}\" only has a single revision\e[60GOK\e[0m\n" || true | |
done | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
show-uca-repos() { | |
local PROPOSED=false | |
local OS_REL= | |
local ALL=false | |
local DESC="\e[1m${FUNCNAME}\e[0m: Prints correct apt repo string for a given OpenStack release" | |
show-uca-repos_usage() { | |
printf "\n\e[2G${DESC}\n\n" | |
printf "\e[2G\e[1mUsage\e[0m: ${FUNCNAME%%_*} [-p ] [-a ] [-r <release>] \n\n" | |
printf "\e[4G -p, --proposed\e[24GShow strings for proposed repos (Default: false)\n" | |
printf "\e[4G -a, --all \e[24GShow strings for both released and proposed repos (Default: false)\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add-loops() { | |
[[ -n ${1} && ${1} =~ ^[0-9]+$ ]] && local C=${1} || { printf "${FUNCNAME} <count>\n";return 2; } | |
[[ ${EUID} = 0 ]] && export SU= || export SU=sudo | |
local -a LOOP_DEVS=($(find /dev -maxdepth 1 -iregex '.*loop[0-9]+'|sort -V)) | |
local M=$(cat 2>/dev/null /proc/cmdline|grep -oP '(?<=max_loop=)[^ ]+') | |
[[ -n ${M} && ${M} =~ ^[0-9]+$ ]] || local M=256 | |
[[ $((${#LOOP_DEVS[@]}+${C})) -gt ${M} ]] && { printf "Can only add up to $(($M-${#LOOP_DEVS[@]})) new devices\n";return 2; } | |
local L=${LOOP_DEVS[-1]//[^0-9]/} | |
local S=$(($L+1)) | |
local E=$(($S+$C)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This error happens when dnsmasq tries to start on a host that: | |
# 1) Is running the bind9.service (named) | |
# 2) Host's /etc/bind/named.conf.options is missing or has "any" set for listen-on[-v6] declarations. | |
# | |
# named creates a listener for the virtual ethernet that conflicts with the lisenter created by dnsmasq | |
# | |
# Fix is to tell named to only listen to IPs on physical nics | |
# | |
# The function below tries to determine phyical and loopback nics and edits /etc/bind/named.conf.options accordingly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
microcloud-tag-cleanup() { | |
local OTAG=$1 | |
local NTAG=$2 | |
# remove ready machines from a given tag ${OTAG} | |
# delete given tags ${OTAG} that do not contain machines | |
# Exclude a given tag ${NTAG} from deletion | |
[[ -z $OTAG || $OTAG =~ [-]+h ]] && { printf "${FUNCNAME}: <tag_name> [ exclude_name ]\n";return 1; } | |
local MAAS_INFO=$(maas 2>/dev/null ${MAAS_PROFILE} machines read) | |
jq 2>/dev/null -r '.[]|"\(.tag_names|to_entries[]|select(.value|startswith("'${OTAG}'")).value) \(select(.status==4).system_id)"' <<< ${MAAS_INFO}|xargs -n2 -P0 bash -c 'maas 2>/dev/null ${MAAS_PROFILE} tag update-nodes $0 remove=$1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export MAX=256;for ((i=$(sudo find 2>/dev/null /dev -iname "loop[0-9]*"|wc -l); i<$MAX; i++));do sudo mknod -m0660 /dev/loop${i} b 7 ${i} && sudo chown root.disk /dev/loop${i};done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gen-sa-ip() { | |
gen-sa-ip_usage() { printf "\nFunction: ${FUNCNAME%_*}\n\nPurpose: Generates a random IP address using the self-assigned range (169.254.0.0-169.254.255.255)\n\n\tUsage: ${FUNCNAME%_*}\n\n" 1>&2;return; } | |
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_usage; return; } | |
printf '169.254.%01d.%01d\n' $((RANDOM%256)) $((RANDOM%256)) | |
} | |
export -f gen-sa-ip | |
wrap() { | |
local DESC="${FUNCNAME}: Like fold, but with indents\n" | |
[[ $1 = '--desc' ]] && { printf "${DESC}";return; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ipmi-consoles() { | |
declare -ag IPMI_IP_LIST=($(printf 10.38.14."%s\n" {4..39})) | |
byobu new-session -d -s CONSOLES | |
SPLITS=6 | |
WIN=0 | |
export IPMI_USER=root | |
export IPMI_PASSWORD=calvin | |
for ((i=0; i<${#IPMI_IP_LIST[@]}; i+=${SPLITS}));do | |
PANES=("${IPMI_IP_LIST[@]:i:${SPLITS}}") | |
for p in ${!PANES[@]};do |