Skip to content

Commit

Permalink
add power-control and iso builder
Browse files Browse the repository at this point in the history
  • Loading branch information
ajanis committed Aug 29, 2024
1 parent 2572fe6 commit f4c3456
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 6 deletions.
12 changes: 6 additions & 6 deletions harmonic/scripts/iso-builders/ubuntu-create-liveiso.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
113 changes: 113 additions & 0 deletions harmonic/scripts/maas-command-helpers/maas-power-control.sh
Original file line number Diff line number Diff line change
@@ -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 <hostname> <ipmi command + args>]
Get MAAS host power parameters and run IPMI command
-n | [REQUIRED] <hostname> | 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}"



0 comments on commit f4c3456

Please sign in to comment.