191 lines
6.2 KiB
Bash
Executable File
191 lines
6.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -eu
|
|
set -o pipefail
|
|
|
|
SCRIPT_NAME=$(basename $0)
|
|
|
|
OS_AUTH_URL=${OS_AUTH_URL:-""}
|
|
if [ -z "$OS_AUTH_URL" ]; then
|
|
echo "You must source a stackrc file for the Undercloud."
|
|
exit 1
|
|
fi
|
|
|
|
function show_options () {
|
|
echo "Usage: $SCRIPT_NAME [options]"
|
|
echo
|
|
echo "Deploys instances via Ironic in preparation for an Overcloud deployment."
|
|
echo
|
|
echo "Options:"
|
|
echo " --register-nodes -- register nodes from a nodes json file"
|
|
echo " --nodes-json -- nodes json file containing node data"
|
|
echo " for registration."
|
|
echo " Default: nodes.json in the current directory"
|
|
echo " --discover-nodes -- Perform discovery of registered nodes."
|
|
echo " Powers on registered nodes to complete"
|
|
echo " the discovery process."
|
|
echo " --setup-flavors -- Setup Nova flavors to match discovered"
|
|
echo " profiles"
|
|
echo " --deploy-nodes -- Deploy nodes"
|
|
echo " -x -- enable tracing"
|
|
echo " --help, -h -- Print this help message."
|
|
echo
|
|
exit $1
|
|
}
|
|
|
|
TEMP=$(getopt -o ,h -l,register-nodes,nodes-json:,discover-nodes,deploy-nodes,help,setup-flavors -o,x,h -n $SCRIPT_NAME -- "$@")
|
|
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
|
|
|
|
# Note the quotes around `$TEMP': they are essential!
|
|
eval set -- "$TEMP"
|
|
|
|
REGISTER_NODES=
|
|
NODES_JSON=
|
|
DISCOVER_NODES=
|
|
DEPLOY_NODES=
|
|
SETUP_FLAVORS=
|
|
STDERR=/dev/null
|
|
|
|
while true ; do
|
|
case "$1" in
|
|
--register-nodes) REGISTER_NODES="1"; shift 1;;
|
|
--nodes-json) NODES_JSON="$2"; shift 2;;
|
|
--discover-nodes) DISCOVER_NODES="1"; shift 1;;
|
|
--deploy-nodes) DEPLOY_NODES="1"; shift 1;;
|
|
--setup-flavors) SETUP_FLAVORS="1"; shift 1;;
|
|
-x) set -x; STDERR=/dev/stderr; shift 1;;
|
|
-h | --help) show_options 0;;
|
|
--) shift ; break ;;
|
|
*) echo "Error: unsupported option $1." ; exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
function register_nodes {
|
|
NODES_JSON=${NODES_JSON:-"nodes.json"}
|
|
NULL_STATS=${NULL_STATS:-0}
|
|
tmp_json=$NODES_JSON
|
|
if [ "$NULL_STATS" = "1" ]; then
|
|
tmp_json=$(mktemp)
|
|
jq '.nodes[].memory=null | .nodes[].disk=null | .nodes[].arch=null | .nodes[].cpu=null' $NODES_JSON > $tmp_json
|
|
fi
|
|
echo " Registering nodes from $NODES_JSON"
|
|
register-nodes --service-host undercloud --nodes <(jq '.nodes' $tmp_json) 1>/dev/null
|
|
if [ "$NULL_STATS" = "1" ]; then
|
|
rm -f $tmp_json
|
|
fi
|
|
echo " Nodes registered."
|
|
echo
|
|
ironic node-list
|
|
echo
|
|
}
|
|
|
|
function discover_nodes {
|
|
echo " Discovering nodes."
|
|
node_ids=$(ironic node-list | tail -n +4 | head -n -1 | awk -F "| " '{print $2}')
|
|
token=$(keystone token-get | grep ' id ' | awk '{print $4}')
|
|
for node_id in $node_ids; do
|
|
echo -n " Sending node ID $node_id to discoverd for discovery ... "
|
|
# NOTE(dtantsur): this is not a stable CLI
|
|
python -m ironic_discoverd.client introspect $node_id --auth-token $token
|
|
# tftpd chokes when serving 4 or more clients. Seeing less than 3Mb/s
|
|
# throughput. As a workaround, sleep for some time in between sending
|
|
# each node to discovery to give each node enough time to download the
|
|
# kernel/ramdisk before the next node is powered on.
|
|
sleep 10
|
|
echo "DONE."
|
|
done
|
|
|
|
echo " Polling discoverd for discovery results ... "
|
|
for node_id in $node_ids; do
|
|
echo -n " Result for node $node_id is ... "
|
|
while true; do
|
|
res=$(python -m ironic_discoverd.client get_status $node_id --auth-token $token)
|
|
if [[ "$(echo $res | jq '.finished')" != "false" ]]; then
|
|
error=$(echo $res | jq '.error')
|
|
if [ "$error" = "null" ]; then
|
|
echo "DISCOVERED."
|
|
else
|
|
echo "ERROR: $error"
|
|
fi
|
|
break
|
|
fi
|
|
sleep 15
|
|
done
|
|
done
|
|
}
|
|
|
|
function deploy_nodes {
|
|
DEPLOY_HEAT_TEMPLATE=${DEPLOY_HEAT_TEMPLATE:-"$HOME/instack-undercloud/heat-templates/ironic-deployment.yaml"}
|
|
DEPLOY_COUNT=${DEPLOY_COUNT:-"1"}
|
|
DEPLOY_NAME=${DEPLOY_NAMET:-"ironic-discover"}
|
|
echo " Creating heat stack ... "
|
|
heat stack-create $DEPLOY_NAME -f $DEPLOY_HEAT_TEMPLATE -P "node_count=$DEPLOY_COUNT"
|
|
echo " Created."
|
|
echo
|
|
heat stack-show $DEPLOY_NAME
|
|
echo
|
|
}
|
|
|
|
function setup_flavors {
|
|
if ! nova flavor-show baremetal_control 2>$STDERR 1>/dev/null; then
|
|
echo " Creating baremetal_control flavor ... "
|
|
nova flavor-create baremetal_control auto 2048 40 1
|
|
else
|
|
echo " baremetal_control flavor already exists."
|
|
fi
|
|
|
|
if ! nova flavor-show baremetal_compute 2>$STDERR 1>/dev/null; then
|
|
echo " Creating baremetal_compute flavor ... "
|
|
nova flavor-create baremetal_compute auto 4096 40 1
|
|
else
|
|
echo " baremetal_compute flavor already exists."
|
|
fi
|
|
|
|
deploy_kernel_id=$(glance image-show bm-deploy-kernel | awk ' / id / {print $4}')
|
|
deploy_ramdisk_id=$(glance image-show bm-deploy-ramdisk | awk ' / id / {print $4}')
|
|
|
|
echo
|
|
nova flavor-list
|
|
echo
|
|
|
|
echo " Setting baremetal_control flavor keys ... "
|
|
nova flavor-key baremetal_control set \
|
|
"cpu_arch"="x86_64" \
|
|
"baremetal:deploy_kernel_id"="$deploy_kernel_id" \
|
|
"baremetal:deploy_ramdisk_id"="$deploy_ramdisk_id" \
|
|
"baremetal:localboot"="true" \
|
|
"profile=control"
|
|
nova flavor-show baremetal_control
|
|
|
|
echo " Setting baremetal_compute flavor keys ... "
|
|
nova flavor-key baremetal_compute set \
|
|
"cpu_arch"="x86_64" \
|
|
"baremetal:deploy_kernel_id"="$deploy_kernel_id" \
|
|
"baremetal:deploy_ramdisk_id"="$deploy_ramdisk_id" \
|
|
"baremetal:localboot"="true" \
|
|
"profile=compute"
|
|
nova flavor-show baremetal_compute
|
|
}
|
|
|
|
echo "Preparing for deployment..."
|
|
|
|
if [ "$REGISTER_NODES" = 1 ]; then
|
|
register_nodes
|
|
fi
|
|
|
|
if [ "$DISCOVER_NODES" = 1 ]; then
|
|
discover_nodes
|
|
fi
|
|
|
|
if [ "$SETUP_FLAVORS" = 1 ]; then
|
|
setup_flavors
|
|
fi
|
|
|
|
echo "Prepared."
|
|
|
|
if [ "$DEPLOY_NODES" = 1 ]; then
|
|
echo "Deploying..."
|
|
deploy_nodes
|
|
echo "Deployed."
|
|
fi
|