4 SCRIPTDIR="$(readlink -f $(dirname ${BASH_SOURCE[0]}))"
5 LIBDIR="$(dirname $(dirname $(dirname ${SCRIPTDIR})))/env/lib"
9 source $LIBDIR/common.sh
11 if [[ $EUID -ne 0 ]]; then
12 echo "This script must be run as root"
16 function deprovision_compute_node {
18 if kubectl get baremetalhost $name -n metal3 &>/dev/null; then
19 kubectl patch baremetalhost $name -n metal3 --type merge \
20 -p '{"spec":{"image":{"url":"","checksum":""}}}'
24 function make_bm_hosts {
25 while IFS=',' read -r name ipmi_username ipmi_password ipmi_address boot_mac os_username os_password os_image_name; do
26 node_machine_values >${SCRIPTDIR}/${name}-values.yaml
27 helm -n metal3 install ${name} ${SCRIPTDIR}/../../machine --create-namespace -f ${SCRIPTDIR}/${name}-values.yaml
32 function configure_nodes {
33 if [ ! -d $IRONIC_DATA_DIR ]; then
34 mkdir -p $IRONIC_DATA_DIR
37 #make sure nodes.json file in /opt/ironic/ are configured
38 if [ ! -f $NODES_FILE ]; then
39 cp ${SCRIPTDIR}/nodes.json.sample $NODES_FILE
43 function deprovision_bm_hosts {
44 while IFS=',' read -r name ipmi_username ipmi_password ipmi_address boot_mac os_username os_password os_image_name; do
45 deprovision_compute_node $name
49 function clean_bm_hosts {
50 while IFS=',' read -r name ipmi_username ipmi_password ipmi_address boot_mac os_username os_password os_image_name; do
51 helm -n metal3 uninstall ${name}
52 rm -rf ${SCRIPTDIR}/${name}-values.yaml
57 list_nodes | clean_bm_hosts
58 if [ -f $NODES_FILE ]; then
63 function apply_bm_hosts {
64 list_nodes | make_bm_hosts
67 function deprovision_all_hosts {
68 list_nodes | deprovision_bm_hosts
71 if [ "$1" == "deprovision" ]; then
77 if [ "$1" == "provision" ]; then
83 if [ "$1" == "clean" ]; then
89 echo "Usage: metal3.sh"
90 echo "provision - provision baremetal node as specified in common.sh"
91 echo "deprovision - deprovision baremetal node as specified in common.sh"
92 echo "clean - clean all the bmh resources"