From 80c24b9ccf9e71e46915472acb30b9a9a334e475 Mon Sep 17 00:00:00 2001 From: Michael McMahon Date: Sun, 8 Feb 2026 17:18:51 -0500 Subject: [PATCH] Just spellcheck --- .../files/simple/usr/local/bin/create-vm | 204 +++++++++--------- 1 file changed, 103 insertions(+), 101 deletions(-) diff --git a/roles/kvmhost/files/simple/usr/local/bin/create-vm b/roles/kvmhost/files/simple/usr/local/bin/create-vm index 07d37ad..d0c6491 100755 --- a/roles/kvmhost/files/simple/usr/local/bin/create-vm +++ b/roles/kvmhost/files/simple/usr/local/bin/create-vm @@ -36,14 +36,14 @@ cat >$cleanup_log <<'EOF' set -xe # To use this cleanup log: # -# 1. find if there is an end or section that has pop: and remove the no +# 1. Find if there is an end or section that has pop: and remove the no # longer relevant lines. # # 2. tac LOG |tee tmpx; bash -xe tmpx EOF err-cleanup() { - echo "in err-cleanup" + echo "In err-cleanup" set -x if (( ${#cleanup_cmds[@]} == 0 )); then return 0 @@ -51,7 +51,7 @@ err-cleanup() { cat <<'EOF' $0: BEGIN WARNING ================= WARNING" A command above has failed, and so the script is exiting. -To cleanup a partially created vm, first consider if the failed command +To cleanup a partially created VM, first consider if the failed command had some effect that needs to be undone (this is unlikely). Then, run the following (also stored as a script in /root/cleanup-create-vm):" $0: END WARNING ================= WARNING" @@ -62,7 +62,7 @@ set -xe # generated by create-vm on $(date -R) EOF chmod +x /root/cleanup-create-vm - # Ensure we have no holes so we can loop backwards + # Ensure we have no holes so we can loop backwards. tmparray=( "${cleanup_cmds[@]}" ) dosleep=false for (( i=${#tmparray[@]} - 1; i >= 0; i-- )); do @@ -72,7 +72,7 @@ EOF dosleep=true echo "${cleanup_cmds[i]}" | tee -a /root/cleanup-create-vm done - echo "$0: end of cleanup" + echo "$0: End of cleanup." } @@ -82,50 +82,50 @@ err() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $pre: $*" >&2; } usage() { cat < lvm single volume setup outside of any + # An option for making a VM like cephmon4, which is backed by mdraid + # -> LVM single volume setup outside of any # script. vg-disk() in this file was # maintained for that kind of case, but I commented # it out because it may be a very long time if ever @@ -186,18 +186,18 @@ cli-arg-check() { if $add_disk; then if ! vm-on && mountpoint -q /mnt/$host; then - err "error: unmount the the vm from /mnt/$host first" + err "ERROR: Unmount the the VM from /mnt/$host first." exit 1 fi return 0 fi - ## from here, checks for when we are actually creating a vm + ## From here, checks for when we are actually creating a VM. - # note: alter this when we upgrade a kvmhost + # Note: Alter this when we upgrade a kvmhost. if [[ ( $release == aramo || $release == ecne ) && $HOSTNAME == kvmhost[234] && \ ! -d /srv/debootstrap-cache/$release/etc ]] ; then - err "error: this os is too old to debootstrap $release. rsync it first to + err "ERROR: This OS is too old to debootstrap $release. rsync it first to /srv/debootstrap-cache/$release ecne exists on kvmhost3 & 5" @@ -210,12 +210,12 @@ ecne exists on kvmhost3 & 5" cpus_regex='^[1-9][0-9]*$' if [[ ! $cpus =~ $cpus_regex ]]; then - err "unexpected cpus arg: $cpus" + err "ERROR: Unexpected CPUs arg: $cpus" exit 1 fi if ! getent hosts $host > /dev/null; then - echo "Could not resolve the hostname to an IP. Add it to the DNS first!" + echo "ERROR: Could not resolve the hostname to an IP. Add IPs to DNS first!" exit 1 fi @@ -247,13 +247,13 @@ set-initial-vars() { ip6=$(getent ahostsv6 "$host" | awk '{ print $1 }' | head -n1) case $ip6 in ::*) - # If we dont have a global ip6 address, the lookup could - # give us a local one. for example, on HAL: + # If we do not have a global IPv6 address, the lookup could + # give us a local one. For example, on HAL: # ::ffff:192.168.0.145 ip6= ;; esac - # once we have other networks, we can add a condition on HOSTNAME + # Once we have other networks, we can add a condition on HOSTNAME. gateway=209.51.188.1 gateway6=2001:470:142::1 @@ -268,7 +268,7 @@ set-initial-vars() { linux_pkg=linux-image-amd64 ;; *) - err "error: unknown release" + err "ERROR: Unknown release" exit 1 ;; esac @@ -303,7 +303,7 @@ free-memory() { low_estimate=$(( total_mem - (x + 600 * vm_count) )) high_estimate=$(( total_mem - (x + 200 * vm_count) )) - # switch to gb for final output. + # Switch to GB for final output. low_estimate=$(echo "scale=1; $low_estimate /1024"|bc -l) high_estimate=$(echo "scale=1; $high_estimate /1024"|bc -l) @@ -313,9 +313,9 @@ free-memory() { Estimate: ${low_estimate}GB to ${high_estimate}GB memory is safe to allocate to VMs. -The range is due to unknown and variable per vm memory overhead, my guess is 200mb to 600mb per VM. +The range is due to unknown and variable per VM memory overhead, my guess is 200mb to 600mb per VM. -Note: running free is misleadingly low vm hosts. free -m:" +Note: Running free is misleadingly low VM hosts. free -m:" free -m } @@ -323,7 +323,7 @@ Note: running free is misleadingly low vm hosts. free -m:" ceph-df() { tmps=$(ceph df -f json | jq -r '"\(.stats.total_bytes) \(.stats.total_used_bytes)"') if [[ $( printf "%s\n" "$tmps" | wc -w) != 2 ]]; then - echo "error: unexpected ceph df output" + echo "ERROR: Unexpected ceph df output." exit 1 fi read -r used_bytes total_bytes <<<"$tmps" @@ -351,7 +351,7 @@ EOF # more space, bug Ian to go install new disks that are on his desk. if (( new_disk_mb / 1024 > gb_available )); then - err "error: requested size $((new_disk_mb / 1024))GB is greater than the available space." + err "ERROR: Requested size $((new_disk_mb / 1024))GB is greater than the available space." exit 1 fi @@ -404,14 +404,14 @@ EOF } mkfs-and-mount-ceph-disk() { - sleep 2 # just paranoid about getting the nbd dev to work + sleep 2 # Just paranoid about getting the nbd dev to work. if [[ $nbd_dev_arg ]]; then rbd-nbd map --device $nbd_dev_arg --exclusive $dname nbd_dev="$nbd_dev_arg" else nbd_dev=$(rbd-nbd map --exclusive $dname) fi - sleep 2 # paranoid + sleep 2 # More paranoia. push-cleanup "rbd-nbd unmap $nbd_dev" cryptsetup luksFormat --cipher aes-xts-plain64 --hash sha256 --use-urandom --key-size 256 $nbd_dev --key-file=- <$keyfile @@ -463,7 +463,7 @@ chroot-add-ceph-disk() { m mount -o bind /$d $d; push-cleanup "umount $PWD/$d" done - # note, this is normal output here: + # Note: This is normal output here: # cryptsetup: WARNING: Couldn't determine cipher modules to load for # tmp.fsf.org-data-crypt0 m chroot . update-initramfs -k all -u @@ -480,9 +480,8 @@ chroot-add-ceph-disk() { } chroot-add-ceph-root-disk() { - # Note: debootstrap would create these, I just want to setup the basic - # disk unlocking all in one place earlier on the script for - # convenience. + # Note: debootstrap would create these, I just want to setup the basic disk + # unlocking all in one place earlier on the script for convenience. m mkdir -p $target/{boot,etc,dev} m mknod $target/dev/sda b 8 0 @@ -498,7 +497,7 @@ EOF } -## calls a bunch of functions +## Calls several functions. ceph-disk() { pool=rbd keyfile=/dev/shm/keyfile @@ -523,7 +522,7 @@ install-dependencies() { # https://dsa.debian.org/howto/install-kvm/ pkgs=(libvirt-dev virtinst pwgen libosinfo-bin) for p in ${pkgs[@]}; do - if ! dpkg -s -- $p |& grep -Fx "Status: install ok installed" &> /dev/null; then + if ! dpkg -s -- $p |& grep -Fx "Status: Install ok installed" &> /dev/null; then m apt-get install -y --no-install-recommends ${pkgs[@]} break fi @@ -692,7 +691,8 @@ EOF min_free= found_vg=false this_vg_set=() - # loop over a single array, checking if this array is the one asked for by the user + # Loop over a single array, checking if this array is the one asked for by + # the user. while (( i < disk_arrays_item_count )) && [[ ${disk_arrays[i]} != , ]]; do vg=${disk_arrays[i]} if ! vgdisplay $vg &>/dev/null; then @@ -706,8 +706,10 @@ EOF #### vg size parsing #### vg_size=$(vgs --units g -o vg_size --noheadings "$vg") if [[ $vg_size != *g ]]; then - echo "error: found unexpected vg_size:$vg_size from vgs -o vg_size --noheadings $vg" - echo "continuing in hopes we find a different array that has expected outputs" + echo "ERROR: Found unexpected vg_size:$vg_size from" + echo " vgs -o vg_size --noheadings $vg" + echo "continuing in hopes we find a different array that has expected" + echo "outputs." continue fi @@ -720,11 +722,11 @@ EOF #### vg free parsing, copies pattern in above block #### vg_free=$(vgs --units g -o vg_free --noheadings "$vg") if [[ $vg_free != *g ]]; then - err "found unexpected vg_free:$vg_free from vgs -o vg_free --noheadings $vg" + err "ERROR: Found unexpected vg_free:$vg_free from vgs -o vg_free --noheadings $vg" err-cleanup exit 1 fi - vg_free=${vg_free##*[< ]} # dunno where this came from but i havent seen it. + vg_free=${vg_free##*[< ]} # Do not know where this came from but I have not seen it. vg_free=${vg_free%g} vg_free=${vg_free%%.*} if [[ ! $min_free ]] || (( vg_free < min_free )); then @@ -772,20 +774,20 @@ EOF return 0 fi - ## if there is just one set on this machine, use it. + ## If there is just one set on this machine, use it. if [[ ! $vg_opt ]] && (( vg_set_count == 1 )); then volgroups=( ${first_vg_set[@]} ) fi if (( ${#volgroups[@]} != 3 )); then - err "error: failed to find array of 3 volume groups, \${volgroups[*]}: ${volgroups[*]}, vg_set_count: $vg_set_count" + err "ERROR: Failed to find array of 3 volume groups, \${volgroups[*]}: ${volgroups[*]}, vg_set_count: $vg_set_count" err-cleanup exit 1 fi if ! mountpoint -q /root/crypt-keys; then - err "error: expected /root/crypt-keys to be a mountpoint, run open-crypt-luks-keys" + err "ERROR: Expected /root/crypt-keys to be a mountpoint, run open-crypt-luks-keys" err-cleanup exit 1 fi @@ -794,7 +796,7 @@ EOF for vg in ${volgroups[@]}; do lvdev=/dev/$vg/$dname if [[ -e $lvdev ]]; then - e "skipping creation of existing lv: $lvdev" + e "Skipping creation of existing lv: $lvdev" else m lvcreate -L $new_disk_mb -n $dname $vg fi @@ -804,7 +806,7 @@ EOF keyfile=/root/crypt-keys/$host keyfile_copies=($keyfile) if [[ -s $keyfile ]]; then - e "keyfile=$keyfile exists. skipping creation" + e "keyfile=$keyfile exists. Skipping creation." else for dir in /root/crypt-keys-backup/*; do if mountpoint -q $dir; then @@ -832,7 +834,7 @@ EOF # This exists because creating integrity devs can take hours, so # if something screws up later, we may want to preserve them and # rerun the script. - e "skipping creation of existing integrity dev: $integrity_dev" + e "Skipping creation of existing integrity dev: $integrity_dev" else m time integritysetup --batch-mode format $lvdev m integritysetup open --allow-discards $lvdev $integrity_name @@ -841,9 +843,9 @@ EOF done mddev=/dev/md/md$dname if [[ -e $mddev ]]; then - e "skipping creation of existing mddev: $mddev" + e "Skipping creation of existing mddev: $mddev" else - # Get stable auto-assembled names + # Get stable auto-assembled names. # https://serverfault.com/questions/763870/raid-device-on-rename-appended-with-0 if ! grep -Fxq "HOMEHOST " /etc/mdadm/mdadm.conf; then sed -i '/^ *HOMEHOST/d' /etc/mdadm/mdadm.conf @@ -859,7 +861,7 @@ EOF # background: --metadata=1.2 is the default metadata level at # least in t9-t11. Passing it avoids a dumb "are you sure" prompt. # We could avoid this by piping yes yes |, however that makes - # reading any errors more confusing. So, at the tradeoff that this + # reading any errors more confusing. So, at the trade-off that this # may need changing in the future, do what helps us more now. m mdadm --create -v $mddev --metadata=1.2 --level 1 --raid-devices=3 --bitmap=internal ${integrity_devs[@]} push-cleanup "mdadm -v --zero-superblock ${integrity_devs[*]}" @@ -876,7 +878,7 @@ EOF fi push-cleanup "sed -i /^$luks_name/d /etc/crypttab" if [[ -e $luks_dev ]]; then - e "skipping creation of existing luks dev: $luks_dev" + e "Skipping creation of existing luks dev: $luks_dev" else # 141 is broken pipe, it is normal when doing yes yes YES | m cryptsetup luksFormat $mddev $keyfile || [[ $? == 141 ]] @@ -898,7 +900,7 @@ EOF if grep -Fx "$line" /etc/crypttab; then e "crypttab line already found above^. not adding" else - err "error: found existing lvdev: $lvdev in /etc/crypttab that is different than expected:" + err "ERROR: Found existing lvdev: $lvdev in /etc/crypttab that is different than expected:" echo "$line" err-cleanup exit 1 @@ -986,10 +988,10 @@ os-bootstrap() { excludes+=,systemd-resolved ;; aramo) - # These dont exist in jammy, they only cause problems. - # this happens when ubuntu removes packages at release time, they stay in our repos by default + # These do not exist in jammy, they only cause problems. + # this happens when Ubuntu removes packages at release time, they stay in our repos by default # - # Having 2 system pythons requires a workaround for ansible + # Having 2 system pythons requires a workaround for Ansible # to do package installs: # # It was fixed by following this @@ -997,7 +999,7 @@ os-bootstrap() { # ln -s apt_inst.cpython* apt_inst.so # ln -s apt_pkg.cpython* apt_pkg.so # - # to find these on the next trisquel rlease, add ubuntu release apt sources, then + # To find these on the next Trisquel release, add ubuntu release apt sources, then # apt list --installed | grep -o '^[^/]*' > pkgs # while read -r l; do apt-cache policy $l | grep jammy >/dev/null || e $l; done $target/etc/kernel-img.conf - # Make machines migrateable util we move everything to the + # Make machines migrate-able util we move everything to the # default config without link_in_boot=false ln -sfT ../vmlinuz $target/boot/vmlinuz ln -sfT ../initrd.img $target/boot/initrd.img @@ -1114,7 +1116,7 @@ EOF export DEBIAN_FRONTEND=noninteractive chroot_apt="eatmydata chroot $target apt-get" - # eatmydata can fail due to libc differences. eg: t11 into a t10 chroot fails. + # eatmydata can fail due to libc differences, e.g., t11 into a t10 chroot fails. if ! m $chroot_apt update; then chroot_apt="chroot $target apt-get" m $chroot_apt update @@ -1137,9 +1139,9 @@ EOF extra_pkgs+=(cryptsetup-initramfs) if [[ $release == etiona || $release == flidas || $release == belenos ]]; then - # iank: 2022: python gives us python2. it doesnt exist in aramo and I do + # iank: 2022: python gives us python2. It does not exist in aramo and I do # not think we need it in nabia. I assume the older distros needed it for - # ansible, but ansible has moved to python3 now. + # Ansible, but Ansible has moved to python3 now. extra_pkgs+=(python) fi @@ -1153,7 +1155,7 @@ EOF rootpw=$(pwgen 12 -s -1) echo root:$rootpw | chroot $target chpasswd - # This doesnt seem to be needed on etiona+ + # This does not seem to be needed since etiona. if [[ $release == flidas || $release == belenos ]]; then m tee $target/etc/init/ttykvm.conf </dev/null; then ipv6_option=",trustGuestRxFilters=yes" @@ -1321,7 +1323,7 @@ create-vm() { # # for 110 gigs, this many pages: '110*1024*1024/2048' # -# todo: automate this. +# TODO: Automate this. # # Example error in t11 if we have no hugepages setup on boot: # @@ -1332,7 +1334,7 @@ create-vm() { vopts+=( --memory=$ram ) fi - # TODO When we upgrade kvmhosts, for ceph we can use --print-xml, then no + # TODO: When we upgrade kvmhosts, for ceph we can use --print-xml, then no # need to destroy and dumpxml. m virt-install ${vopts[@]} @@ -1344,7 +1346,7 @@ create-vm() { virsh dumpxml $host > /tmp/tmp.xml #sed "1s#># xmlns:qemu=\'http://libvirt.org/schemas/domain/qemu/1.0'>#; s###" /tmp/tmp.xml -i - # TODO When we get a newer libvirt, we could probably do this on + # TODO: When we get a newer libvirt, we could probably do this on # virt-install with something like: # --xml "./devices/controller[@type='scsi']/driver/@queues" # --xml xpath.value=$cpus @@ -1356,7 +1358,7 @@ create-vm() { rm -f /tmp/tmp.xml fi - #### End virt-install/libvirt vm creation #### + #### End virt-install/libvirt VM creation #### cat </dev/null; then - echo "installing missing dependency: jq" + echo "Installing missing dependency: jq" apt-get -y install jq fi @@ -1452,16 +1454,16 @@ fi if $dolist; then if (( $# != 0 )); then - err "error: expected 0 args with -l, got $#. exiting" + err "ERROR: Expected 0 args with -l, got $#. Exiting" usage 1 fi elif $add_disk; then if (( $# != 3 )); then - err "error: expected 2 args with -d, got $#. exiting" + err "ERROR: Expected 2 args with -d, got $#. Exiting" usage 1 fi elif (( $# != 5 )); then - err "error: expected 5 args, got $# exiting" + err "ERROR: Expected 5 args, got $#. Exiting." usage 1 fi @@ -1471,7 +1473,7 @@ cli-arg-check set-initial-vars -##### Start actually doing things, this goes on till the end of the script #### +##### Start actually doing things, this goes on till the end of the script. #### if $dolist; then free-memory @@ -1498,7 +1500,7 @@ else nonceph-disk fi -#### From here there are 3 separate paths to successful exit. +#### From here, there are 3 separate paths to successful exit. ## 1. Add disk to VM ## 2. VM with filesystem to be imported later. ## 3. Regular fresh VM. -- 2.25.1