blob: af90c063607d9ef4605cbb9ff43d284df453e47b [file] [log] [blame]
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01001## vim: tabstop=4 shiftwidth=4 softtabstop=4
Devananda van der Veenf35cf912012-11-12 17:58:38 -08002
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01003## Copyright (c) 2012 Hewlett-Packard Development Company, L.P.
4## All Rights Reserved.
5##
6## Licensed under the Apache License, Version 2.0 (the "License"); you may
7## not use this file except in compliance with the License. You may obtain
8## a copy of the License at
9##
10## http://www.apache.org/licenses/LICENSE-2.0
11##
12## Unless required by applicable law or agreed to in writing, software
13## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15## License for the specific language governing permissions and limitations
16## under the License.
Devananda van der Veenf35cf912012-11-12 17:58:38 -080017
18
19# This file provides devstack with the environment and utilities to
20# control nova-compute's baremetal driver.
21# It sets reasonable defaults to run within a single host,
22# using virtual machines in place of physical hardware.
23# However, by changing just a few options, devstack+baremetal can in fact
24# control physical hardware resources on the same network, if you know
25# the MAC address(es) and IPMI credentials.
26#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010027# At a minimum, to enable the baremetal driver, you must set these in localrc:
28#
Devananda van der Veenf35cf912012-11-12 17:58:38 -080029# VIRT_DRIVER=baremetal
30# ENABLED_SERVICES="$ENABLED_SERVICES,baremetal"
31#
32#
33# We utilize diskimage-builder to create a ramdisk, and then
34# baremetal driver uses that to push a disk image onto the node(s).
35#
36# Below we define various defaults which control the behavior of the
Tim Miller9a3ba4b2013-03-18 18:08:27 -070037# baremetal compute service, and inform it of the hardware it will control.
Devananda van der Veenf35cf912012-11-12 17:58:38 -080038#
39# Below that, various functions are defined, which are called by devstack
40# in the following order:
41#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010042# before nova-cpu starts:
43#
Devananda van der Veenf35cf912012-11-12 17:58:38 -080044# - prepare_baremetal_toolchain
45# - configure_baremetal_nova_dirs
46#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010047# after nova and glance have started:
48#
Devananda van der Veenf35cf912012-11-12 17:58:38 -080049# - build_and_upload_baremetal_deploy_k_and_r $token
50# - create_baremetal_flavor $BM_DEPLOY_KERNEL_ID $BM_DEPLOY_RAMDISK_ID
51# - upload_baremetal_image $url $token
52# - add_baremetal_node <first_mac> <second_mac>
53
54
55# Save trace setting
56XTRACE=$(set +o | grep xtrace)
57set +o xtrace
58
Dean Troyercc6b4432013-04-08 15:38:03 -050059
Devananda van der Veenf35cf912012-11-12 17:58:38 -080060# Sub-driver settings
61# -------------------
62
63# sub-driver to use for kernel deployment
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010064#
65# - nova.virt.baremetal.pxe.PXE
66# - nova.virt.baremetal.tilera.TILERA
Devananda van der Veenf35cf912012-11-12 17:58:38 -080067BM_DRIVER=${BM_DRIVER:-nova.virt.baremetal.pxe.PXE}
68
69# sub-driver to use for remote power management
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010070#
Devananda van der Veenf35cf912012-11-12 17:58:38 -080071# - nova.virt.baremetal.fake.FakePowerManager, for manual power control
Ghe Riverocc404a42013-03-06 11:48:03 +010072# - nova.virt.baremetal.ipmi.IPMI, for remote IPMI
Devananda van der Veenf35cf912012-11-12 17:58:38 -080073# - nova.virt.baremetal.tilera_pdu.Pdu, for TilePro hardware
74BM_POWER_MANAGER=${BM_POWER_MANAGER:-nova.virt.baremetal.fake.FakePowerManager}
75
76
77# These should be customized to your environment and hardware
78# -----------------------------------------------------------
79
Arata Notsubbf06452013-07-26 20:26:07 +090080# To provide PXE, configure nova-network's dnsmasq rather than run the one
81# dedicated to baremetal. When enable this, make sure these conditions are
82# fulfilled:
Adam Spierscb961592013-10-05 12:11:07 +010083#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010084# 1) nova-compute and nova-network runs on the same host
85# 2) nova-network uses FlatDHCPManager
Adam Spierscb961592013-10-05 12:11:07 +010086#
Arata Notsubbf06452013-07-26 20:26:07 +090087# NOTE: the other BM_DNSMASQ_* have no effect on the behavior if this option
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010088# is enabled.
Arata Notsubbf06452013-07-26 20:26:07 +090089BM_DNSMASQ_FROM_NOVA_NETWORK=`trueorfalse False $BM_DNSMASQ_FROM_NOVA_NETWORK`
90
Devananda van der Veen7611c892012-11-23 10:54:54 -080091# BM_DNSMASQ_IFACE should match FLAT_NETWORK_BRIDGE
Eric Windische994f572014-02-28 15:13:37 -050092BM_DNSMASQ_IFACE=${BM_DNSMASQ_IFACE:-eth0}
93# if testing on a physical network,
94# BM_DNSMASQ_RANGE must be changed to suit your network
95BM_DNSMASQ_RANGE=${BM_DNSMASQ_RANGE:-}
Devananda van der Veenf35cf912012-11-12 17:58:38 -080096
Chris Krelle35336282013-02-03 15:48:43 -080097# BM_DNSMASQ_DNS provide dns server to bootstrap clients
98BM_DNSMASQ_DNS=${BM_DNSMASQ_DNS:-}
99
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100100# BM_FIRST_MAC *must* be set to the MAC address of the node you will
101# boot. This is passed to dnsmasq along with the kernel/ramdisk to
102# deploy via PXE.
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800103BM_FIRST_MAC=${BM_FIRST_MAC:-}
104
105# BM_SECOND_MAC is only important if the host has >1 NIC.
106BM_SECOND_MAC=${BM_SECOND_MAC:-}
107
108# Hostname for the baremetal nova-compute node, if not run on this host
109BM_HOSTNAME=${BM_HOSTNAME:-$(hostname -f)}
110
111# BM_PM_* options are only necessary if BM_POWER_MANAGER=...IPMI
112BM_PM_ADDR=${BM_PM_ADDR:-0.0.0.0}
113BM_PM_USER=${BM_PM_USER:-user}
114BM_PM_PASS=${BM_PM_PASS:-pass}
115
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100116# BM_FLAVOR_* options are arbitrary and not necessarily related to
117# physical hardware capacity. These can be changed if you are testing
118# BaremetalHostManager with multiple nodes and different flavors.
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800119BM_CPU_ARCH=${BM_CPU_ARCH:-x86_64}
120BM_FLAVOR_CPU=${BM_FLAVOR_CPU:-1}
121BM_FLAVOR_RAM=${BM_FLAVOR_RAM:-1024}
122BM_FLAVOR_ROOT_DISK=${BM_FLAVOR_ROOT_DISK:-10}
123BM_FLAVOR_EPHEMERAL_DISK=${BM_FLAVOR_EPHEMERAL_DISK:-0}
124BM_FLAVOR_SWAP=${BM_FLAVOR_SWAP:-1}
125BM_FLAVOR_NAME=${BM_FLAVOR_NAME:-bm.small}
126BM_FLAVOR_ID=${BM_FLAVOR_ID:-11}
127BM_FLAVOR_ARCH=${BM_FLAVOR_ARCH:-$BM_CPU_ARCH}
128
129
Arata Notsud3a18ae2013-08-02 20:58:56 +0900130# Use DIB to create deploy ramdisk and kernel.
131BM_BUILD_DEPLOY_RAMDISK=`trueorfalse True $BM_BUILD_DEPLOY_RAMDISK`
132# If not use DIB, these files are used as deploy ramdisk/kernel.
133# (The value must be a relative path from $TOP_DIR/files/)
134BM_DEPLOY_RAMDISK=${BM_DEPLOY_RAMDISK:-}
135BM_DEPLOY_KERNEL=${BM_DEPLOY_KERNEL:-}
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800136
137# If you need to add any extra flavors to the deploy ramdisk image
138# eg, specific network drivers, specify them here
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400139#
140# NOTE(deva): this will be moved to lib/ironic in a future patch
141# for now, set the default to a suitable value for Ironic's needs
142BM_DEPLOY_FLAVOR=${BM_DEPLOY_FLAVOR:--a amd64 ubuntu deploy-ironic}
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800143
144# set URL and version for google shell-in-a-box
145BM_SHELL_IN_A_BOX=${BM_SHELL_IN_A_BOX:-http://shellinabox.googlecode.com/files/shellinabox-2.14.tar.gz}
146
147
148# Functions
149# ---------
150
151# Check if baremetal is properly enabled
152# Returns false if VIRT_DRIVER is not baremetal, or if ENABLED_SERVICES
153# does not contain "baremetal"
Ian Wienandaee18c72014-02-21 15:35:08 +1100154function is_baremetal {
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800155 if [[ "$ENABLED_SERVICES" =~ 'baremetal' && "$VIRT_DRIVER" = 'baremetal' ]]; then
156 return 0
157 fi
158 return 1
159}
160
161# Install diskimage-builder and shell-in-a-box
162# so that we can build the deployment kernel & ramdisk
Ian Wienandaee18c72014-02-21 15:35:08 +1100163function prepare_baremetal_toolchain {
Steve Bakercbfb3ae2014-05-05 16:06:47 +1200164 if [[ $(type -P ramdisk-image-create) == "" ]]; then
165 pip_install diskimage_builder
166 fi
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800167 local shellinabox_basename=$(basename $BM_SHELL_IN_A_BOX)
168 if [[ ! -e $DEST/$shellinabox_basename ]]; then
169 cd $DEST
170 wget $BM_SHELL_IN_A_BOX
171 fi
172 if [[ ! -d $DEST/${shellinabox_basename%%.tar.gz} ]]; then
173 cd $DEST
174 tar xzf $shellinabox_basename
175 fi
176 if [[ ! $(which shellinaboxd) ]]; then
177 cd $DEST/${shellinabox_basename%%.tar.gz}
178 ./configure
179 make
180 sudo make install
181 fi
182}
183
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800184# prepare various directories needed by baremetal hypervisor
Ian Wienandaee18c72014-02-21 15:35:08 +1100185function configure_baremetal_nova_dirs {
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800186 # ensure /tftpboot is prepared
187 sudo mkdir -p /tftpboot
188 sudo mkdir -p /tftpboot/pxelinux.cfg
Lucas Alvares Gomes74aad312013-08-28 11:32:14 +0100189
190 PXEBIN=/usr/share/syslinux/pxelinux.0
191 if [ ! -f $PXEBIN ]; then
192 PXEBIN=/usr/lib/syslinux/pxelinux.0
193 if [ ! -f $PXEBIN ]; then
194 die $LINENO "pxelinux.0 (from SYSLINUX) not found."
195 fi
196 fi
197
198 sudo cp $PXEBIN /tftpboot/
Émilien Macchib2ef8902013-05-04 00:48:20 +0200199 sudo chown -R $STACK_USER:$LIBVIRT_GROUP /tftpboot
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800200
201 # ensure $NOVA_STATE_PATH/baremetal is prepared
202 sudo mkdir -p $NOVA_STATE_PATH/baremetal
203 sudo mkdir -p $NOVA_STATE_PATH/baremetal/console
204 sudo mkdir -p $NOVA_STATE_PATH/baremetal/dnsmasq
205 sudo touch $NOVA_STATE_PATH/baremetal/dnsmasq/dnsmasq-dhcp.host
Attila Fazekas91b8d132013-01-06 22:40:09 +0100206 sudo chown -R $STACK_USER $NOVA_STATE_PATH/baremetal
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800207
208 # ensure dnsmasq is installed but not running
209 # because baremetal driver will reconfigure and restart this as needed
Devananda van der Veen75eaaf42012-12-28 15:40:21 -0800210 is_package_installed dnsmasq || install_package dnsmasq
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800211 stop_service dnsmasq
212}
213
214# build deploy kernel+ramdisk, then upload them to glance
215# this function sets BM_DEPLOY_KERNEL_ID and BM_DEPLOY_RAMDISK_ID
Ian Wienandaee18c72014-02-21 15:35:08 +1100216function upload_baremetal_deploy {
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800217 token=$1
218
Arata Notsud3a18ae2013-08-02 20:58:56 +0900219 if [ "$BM_BUILD_DEPLOY_RAMDISK" = "True" ]; then
220 BM_DEPLOY_KERNEL=bm-deploy.kernel
221 BM_DEPLOY_RAMDISK=bm-deploy.initramfs
222 if [ ! -e "$TOP_DIR/files/$BM_DEPLOY_KERNEL" -o ! -e "$TOP_DIR/files/$BM_DEPLOY_RAMDISK" ]; then
Steve Bakercbfb3ae2014-05-05 16:06:47 +1200223 ramdisk-image-create $BM_DEPLOY_FLAVOR \
Arata Notsud3a18ae2013-08-02 20:58:56 +0900224 -o $TOP_DIR/files/bm-deploy
225 fi
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800226 fi
227
228 # load them into glance
Steve Martinelli8d3ac2d2014-08-02 23:47:15 -0400229 BM_DEPLOY_KERNEL_ID=$(openstack \
230 --os-token $token \
231 --os-url http://$GLANCE_HOSTPORT \
232 image create \
233 $BM_DEPLOY_KERNEL \
234 --public --disk-format=aki \
Dean Troyer01026932014-08-15 15:53:03 -0500235 --container-format=aki \
Sean Dague101b4242013-10-22 08:47:11 -0400236 < $TOP_DIR/files/$BM_DEPLOY_KERNEL | grep ' id ' | get_field 2)
Steve Martinelli8d3ac2d2014-08-02 23:47:15 -0400237 BM_DEPLOY_RAMDISK_ID=$(openstack \
238 --os-token $token \
239 --os-url http://$GLANCE_HOSTPORT \
240 image create \
241 $BM_DEPLOY_RAMDISK \
242 --public --disk-format=ari \
Dean Troyer01026932014-08-15 15:53:03 -0500243 --container-format=ari \
Sean Dague101b4242013-10-22 08:47:11 -0400244 < $TOP_DIR/files/$BM_DEPLOY_RAMDISK | grep ' id ' | get_field 2)
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800245}
246
247# create a basic baremetal flavor, associated with deploy kernel & ramdisk
248#
249# Usage: create_baremetal_flavor <aki_uuid> <ari_uuid>
Ian Wienandaee18c72014-02-21 15:35:08 +1100250function create_baremetal_flavor {
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800251 aki=$1
252 ari=$2
253 nova flavor-create $BM_FLAVOR_NAME $BM_FLAVOR_ID \
Sean Dague101b4242013-10-22 08:47:11 -0400254 $BM_FLAVOR_RAM $BM_FLAVOR_ROOT_DISK $BM_FLAVOR_CPU
Devananda van der Veen75eaaf42012-12-28 15:40:21 -0800255 nova flavor-key $BM_FLAVOR_NAME set \
Sean Dague101b4242013-10-22 08:47:11 -0400256 "cpu_arch"="$BM_FLAVOR_ARCH" \
257 "baremetal:deploy_kernel_id"="$aki" \
258 "baremetal:deploy_ramdisk_id"="$ari"
Devananda van der Veen2920b7d2013-03-04 11:47:14 -0800259
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800260}
261
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100262# Pull run-time kernel/ramdisk out of disk image and load into glance.
263# Note that $file is currently expected to be in qcow2 format.
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800264# Sets KERNEL_ID and RAMDISK_ID
265#
266# Usage: extract_and_upload_k_and_r_from_image $token $file
Ian Wienandaee18c72014-02-21 15:35:08 +1100267function extract_and_upload_k_and_r_from_image {
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800268 token=$1
269 file=$2
270 image_name=$(basename "$file" ".qcow2")
271
272 # this call returns the file names as "$kernel,$ramdisk"
Steve Bakercbfb3ae2014-05-05 16:06:47 +1200273 out=$(disk-image-get-kernel \
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800274 -x -d $TOP_DIR/files -o bm-deploy -i $file)
275 if [ $? -ne 0 ]; then
Lucas Alvares Gomesc33d1f92013-09-06 18:14:51 +0100276 die $LINENO "Failed to get kernel and ramdisk from $file"
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800277 fi
278 XTRACE=$(set +o | grep xtrace)
279 set +o xtrace
280 out=$(echo "$out" | tail -1)
281 $XTRACE
282 OUT_KERNEL=${out%%,*}
283 OUT_RAMDISK=${out##*,}
284
285 # load them into glance
Steve Martinelli8d3ac2d2014-08-02 23:47:15 -0400286 KERNEL_ID=$(openstack \
287 --os-token $token \
288 --os-url http://$GLANCE_HOSTPORT \
289 image create \
290 $image_name-kernel \
291 --public --disk-format=aki \
Dean Troyer01026932014-08-15 15:53:03 -0500292 --container-format=aki \
Sean Dague101b4242013-10-22 08:47:11 -0400293 < $TOP_DIR/files/$OUT_KERNEL | grep ' id ' | get_field 2)
Steve Martinelli8d3ac2d2014-08-02 23:47:15 -0400294 RAMDISK_ID=$(openstack \
295 --os-token $token \
296 --os-url http://$GLANCE_HOSTPORT \
297 image create \
298 $image_name-initrd \
299 --public --disk-format=ari \
Dean Troyer01026932014-08-15 15:53:03 -0500300 --container-format=ari \
Sean Dague101b4242013-10-22 08:47:11 -0400301 < $TOP_DIR/files/$OUT_RAMDISK | grep ' id ' | get_field 2)
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800302}
303
304
305# Re-implementation of devstack's "upload_image" function
306#
307# Takes the same parameters, but has some peculiarities which made it
308# easier to create a separate method, rather than complicate the logic
309# of the existing function.
Ian Wienandaee18c72014-02-21 15:35:08 +1100310function upload_baremetal_image {
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800311 local image_url=$1
312 local token=$2
313
314 # Create a directory for the downloaded image tarballs.
315 mkdir -p $FILES/images
316
317 # Downloads the image (uec ami+aki style), then extracts it.
318 IMAGE_FNAME=`basename "$image_url"`
319 if [[ ! -f $FILES/$IMAGE_FNAME || \
320 "$(stat -c "%s" $FILES/$IMAGE_FNAME)" = "0" ]]; then
321 wget -c $image_url -O $FILES/$IMAGE_FNAME
322 if [[ $? -ne 0 ]]; then
323 echo "Not found: $image_url"
324 return
325 fi
326 fi
327
328 local KERNEL=""
329 local RAMDISK=""
330 local DISK_FORMAT=""
331 local CONTAINER_FORMAT=""
332 case "$IMAGE_FNAME" in
333 *.tar.gz|*.tgz)
334 # Extract ami and aki files
335 [ "${IMAGE_FNAME%.tar.gz}" != "$IMAGE_FNAME" ] &&
336 IMAGE_NAME="${IMAGE_FNAME%.tar.gz}" ||
337 IMAGE_NAME="${IMAGE_FNAME%.tgz}"
338 xdir="$FILES/images/$IMAGE_NAME"
339 rm -Rf "$xdir";
340 mkdir "$xdir"
341 tar -zxf $FILES/$IMAGE_FNAME -C "$xdir"
342 KERNEL=$(for f in "$xdir/"*-vmlinuz* "$xdir/"aki-*/image; do
Sean Dague101b4242013-10-22 08:47:11 -0400343 [ -f "$f" ] && echo "$f" && break; done; true)
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800344 RAMDISK=$(for f in "$xdir/"*-initrd* "$xdir/"ari-*/image; do
Sean Dague101b4242013-10-22 08:47:11 -0400345 [ -f "$f" ] && echo "$f" && break; done; true)
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800346 IMAGE=$(for f in "$xdir/"*.img "$xdir/"ami-*/image; do
Sean Dague101b4242013-10-22 08:47:11 -0400347 [ -f "$f" ] && echo "$f" && break; done; true)
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800348 if [[ -z "$IMAGE_NAME" ]]; then
349 IMAGE_NAME=$(basename "$IMAGE" ".img")
350 fi
351 DISK_FORMAT=ami
352 CONTAINER_FORMAT=ami
353 ;;
354 *.qcow2)
355 IMAGE="$FILES/${IMAGE_FNAME}"
356 IMAGE_NAME=$(basename "$IMAGE" ".qcow2")
357 DISK_FORMAT=qcow2
358 CONTAINER_FORMAT=bare
359 ;;
360 *) echo "Do not know what to do with $IMAGE_FNAME"; false;;
361 esac
362
363 if [ "$CONTAINER_FORMAT" = "bare" ]; then
364 extract_and_upload_k_and_r_from_image $token $IMAGE
365 elif [ "$CONTAINER_FORMAT" = "ami" ]; then
Steve Martinelli8d3ac2d2014-08-02 23:47:15 -0400366 KERNEL_ID=$(openstack \
367 --os-token $token \
368 --os-url http://$GLANCE_HOSTPORT \
369 image create \
370 "$IMAGE_NAME-kernel" --public \
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800371 --container-format aki \
372 --disk-format aki < "$KERNEL" | grep ' id ' | get_field 2)
Steve Martinelli8d3ac2d2014-08-02 23:47:15 -0400373 RAMDISK_ID=$(openstack \
374 --os-token $token \
375 --os-url http://$GLANCE_HOSTPORT \
376 image create \
377 "$IMAGE_NAME-ramdisk" --public \
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800378 --container-format ari \
379 --disk-format ari < "$RAMDISK" | grep ' id ' | get_field 2)
380 else
Sean Dague101b4242013-10-22 08:47:11 -0400381 # TODO(deva): add support for other image types
382 return
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800383 fi
384
Steve Martinelli8d3ac2d2014-08-02 23:47:15 -0400385 openstack \
386 --os-token $token \
387 --os-url http://$GLANCE_HOSTPORT \
388 image create \
389 "${IMAGE_NAME%.img}" --public \
Sean Dague101b4242013-10-22 08:47:11 -0400390 --container-format $CONTAINER_FORMAT \
391 --disk-format $DISK_FORMAT \
392 ${KERNEL_ID:+--property kernel_id=$KERNEL_ID} \
393 ${RAMDISK_ID:+--property ramdisk_id=$RAMDISK_ID} < "${IMAGE}"
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800394
Tim Miller9a3ba4b2013-03-18 18:08:27 -0700395 # override DEFAULT_IMAGE_NAME so that tempest can find the image
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800396 # that we just uploaded in glance
397 DEFAULT_IMAGE_NAME="${IMAGE_NAME%.img}"
398}
399
Ian Wienandaee18c72014-02-21 15:35:08 +1100400function clear_baremetal_of_all_nodes {
Arata Notsu24f79612013-02-13 21:01:18 +0900401 list=$(nova baremetal-node-list | awk -F '| ' 'NR>3 {print $2}' )
Sean Dague16dd8b32014-02-03 09:10:54 +0900402 for node in $list; do
Arata Notsu24f79612013-02-13 21:01:18 +0900403 nova baremetal-node-delete $node
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800404 done
405}
406
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100407# Inform nova-baremetal about nodes, MACs, etc.
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800408# Defaults to using BM_FIRST_MAC and BM_SECOND_MAC if parameters not specified
409#
410# Usage: add_baremetal_node <first_mac> <second_mac>
Ian Wienandaee18c72014-02-21 15:35:08 +1100411function add_baremetal_node {
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800412 mac_1=${1:-$BM_FIRST_MAC}
413 mac_2=${2:-$BM_SECOND_MAC}
414
Arata Notsu24f79612013-02-13 21:01:18 +0900415 id=$(nova baremetal-node-create \
Sean Dague101b4242013-10-22 08:47:11 -0400416 --pm_address="$BM_PM_ADDR" \
417 --pm_user="$BM_PM_USER" \
418 --pm_password="$BM_PM_PASS" \
419 "$BM_HOSTNAME" \
420 "$BM_FLAVOR_CPU" \
421 "$BM_FLAVOR_RAM" \
422 "$BM_FLAVOR_ROOT_DISK" \
423 "$mac_1" \
424 | grep ' id ' | get_field 2 )
Lucas Alvares Gomesc33d1f92013-09-06 18:14:51 +0100425 [ $? -eq 0 ] || [ "$id" ] || die $LINENO "Error adding baremetal node"
Arata Notsuaf15d352013-10-11 21:56:56 +0900426 if [ -n "$mac_2" ]; then
427 id2=$(nova baremetal-interface-add "$id" "$mac_2" )
428 [ $? -eq 0 ] || [ "$id2" ] || die $LINENO "Error adding interface to barmetal node $id"
429 fi
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800430}
431
432
433# Restore xtrace
434$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400435
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100436# Tell emacs to use shell-script-mode
437## Local variables:
438## mode: shell-script
439## End: