From f4c345682e726827308ffb9b1bd8b13b2e8bd7d7 Mon Sep 17 00:00:00 2001 From: Alan Janis Date: Thu, 29 Aug 2024 09:18:44 +0000 Subject: [PATCH] add power-control and iso builder --- .../iso-builders/ubuntu-create-liveiso.sh | 12 +- .../maas-power-control.sh | 113 ++++++++++++++++++ 2 files changed, 119 insertions(+), 6 deletions(-) create mode 100755 harmonic/scripts/maas-command-helpers/maas-power-control.sh diff --git a/harmonic/scripts/iso-builders/ubuntu-create-liveiso.sh b/harmonic/scripts/iso-builders/ubuntu-create-liveiso.sh index 79642d9..8f2c3b9 100644 --- a/harmonic/scripts/iso-builders/ubuntu-create-liveiso.sh +++ b/harmonic/scripts/iso-builders/ubuntu-create-liveiso.sh @@ -14,16 +14,16 @@ sudo apt update sudo apt install -y xorriso squashfs-tools genisoimage # Mount the ISO -mkdir -p $MOUNT_DIR -sudo mount -o loop $ISO_NAME $MOUNT_DIR +mkdir -p "${MOUNT_DIR}" +sudo mount -o loop "${ISO_NAME}" "${MOUNT_DIR}" # Copy ISO contents -mkdir -p $WORK_DIR -rsync -a $MOUNT_DIR/ $WORK_DIR/ -sudo umount $MOUNT_DIR +mkdir -p "${WORK_DIR}" +rsync -a "${MOUNT_DIR}"/ "${WORK_DIR}"/ +sudo umount "${MOUNT_DIR}" # Make filesystem writable -chmod -R u+w $WORK_DIR +chmod -R u+w "${WORK_DIR}" cat << 'EOG' >> "${WORK_DIR}/boot/grub/grub.cfg" menuentry "Ubuntu 22.04 Live-Only" { diff --git a/harmonic/scripts/maas-command-helpers/maas-power-control.sh b/harmonic/scripts/maas-command-helpers/maas-power-control.sh new file mode 100755 index 0000000..b370596 --- /dev/null +++ b/harmonic/scripts/maas-command-helpers/maas-power-control.sh @@ -0,0 +1,113 @@ +#!/bin/bash +############################################################################## +# +# maas-power-control.yml +# +# Get command line args for BMC control over IPMI +# +############################################################################## +# shellcheck disable=SC2034 +# shellcheck disable=SC2312 + +export sshHost=44.10.4.101 +export maasPath="/snap/bin/maas" +maasHostname="maas-poc-aio01" +# Script Help Function +showHelp() { +cat << EOH +Usage: $0 [-h] [-n ] + +Get MAAS host power parameters and run IPMI command + +-n | [REQUIRED] | The system short hostname as displayed in MAAS + +-h | Display help + +EOH + +} + + +function getHostName() { + read -rp 'Enter the MAAS Host-Name of the system to manage. : ' readHost + export hostName=${readHost} + [[ "${hostName}" =~ ^[[:alnum:]|-]+$ ]] || (echo "Bad Hostname" && showHelp) +} + +function setMaasCmd() { + if [[ "$(hostname -s)" != "${maasHostname}" ]]; then + export maasCmd="ssh ${sshHost} -C ${maasPath}" + else + export maasCmd="${maasPath}" + fi +} +function getHostId() { + "${maasCmd}" admin machines read > /tmp/maasHostList + maasSystemID=$(jq -r --arg maasHost "${hostName}" '.[]|select(.hostname==$maasHost)|.system_id' /tmp/maasHostList) +} + +function getCommandArgs() { +ipmitool -I lanplus -U maas -P OoXXStHRb5e -H 2605:1c00:50f2:3303::100c -6 -y a6ff8d5d19792f3e26afc8fe145c4d8e37dc4290 -L ADMINISTRATOR -C3 chassis power status +"${maasCmd}" admin machine power-parameters "${maasSystemId}" > /tmp/powerParams + +declare -A powerarray + +for powerkey in power_address power_user power_pass k_g privilege_level cipher_suite_id power_driver +do +powerarray[${powerkey}]=$(jq -r --arg key "${powerkey}" 'to_entries[]|select(.key == $key)|.value' /tmp/powerParams) +done +} + +function printCommand() { +cat << 'EOC' + +======================================================================================================= + +Power Command: + +ipmitool -H "${powerarray[${power_address}]}" -U "${powerarray[${power_user}]}" -P "${powerarray[${power_pass}]}" -y "${powerarray[${k_g}]}" -L "${powerarray[${privilege_level}]}" -C "${powerarray[${cipher_suite_id}]}" "${ipmiArgs}" + +======================================================================================================= + +EOC +} + +# MENU + +while getopts ":hn:" o; do + case "${o}" in + h) + showHelp + exit 0 + ;; + n) + hostName=${OPTARG} + ;; + :) + runPrint "Invalid option: -${OPTARG} requires an argument" 1>&2 + showHelp + exit 1 + ;; + \?|*) + runPrint "Invalid option: -${OPTARG}" 1>&2 + showHelp + exit 1 + ;; + esac +done +shift $((OPTIND-1)) +ipmiArgs="$*" + + +# RUN1 +getHostName +setMaasCmd +getHostId +getCommandArgs +printCommand + +read -rp "Press [Enter/Return] to run this command this configuration : ";echo +ipmitool -H "${powerarray[${power_address}]}" -U "${powerarray[${power_user}]}" -P "${powerarray[${power_pass}]}" -y "${powerarray[${k_g}]}" -L "${powerarray[${privilege_level}]}" -C "${powerarray[${cipher_suite_id}]}" "${ipmiArgs}" + + +