MAAS Show and Tell: Custom BMC enlistment scripts

For this week’s Show and Tell, Lee explains how to create a custom BMC enlistment script with MAAS 2.9:

Please be sure to leave questions or comments below. See you next time!

1 Like

Custom BMC enlistment script

#!/bin/bash -e
#
# 25-virsh-config - Configure a commissioning machine for virsh
#
# Author: Lee Trager <lee.trager@canonical.com>
#
# Copyright (C) 2020 Canonical
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# --- Start MAAS 1.0 script metadata ---
# # Named so that this runs before the builtin BMC detection script,
# # 30-maas-01-bmc-config
# name: 25-virsh-config
# title: Configure the machine for virsh use
# description: Configure the machine for virsh use
# tags:
#  - bmc-detect # Allow this script to run when commissioning is disabled
#               # during enlistment
#  - enlisting  # Allows custom script to run during enlistment.
# script_type: commissioning
# parameters:
#   maas_auto_ipmi_user:
#     type: string
#     max: 20
#     argument_format: '{input}'
# timeout: 10
# --- End MAAS 1.0 script metadata ---

if [ -z "$BMC_CONFIG_PATH" ]; then
    echo "ERROR: BMC_CONFIG_PATH environment variable not defined!" 1>&2
    exit 1
elif [ -f "$BMC_CONFIG_PATH" ]; then
    echo "SKIPPING: Another script has already run BMC detection!"
    [ -n "$RESULT_PATH" ] && echo "status: skipped" >> $RESULT_PATH
    exit 0
fi

USERNAME=$1

echo "Virsh BMC detected!"
cat <<EOF > $BMC_CONFIG_PATH
power_type: virsh
power_address: qemu+ssh://$USERNAME@10.0.0.1/system
power_pass: password
power_id: maas-test-5
EOF
1 Like