blob: d8cd7e936cd8d3fac9069afb08eca80d14a3a14d [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
Devananda van der Veen7611c892012-11-23 10:54:54 -080080# whether to create a fake environment, eg. for devstack-gate
81BM_USE_FAKE_ENV=`trueorfalse False $BM_USE_FAKE_ENV`
82
83# Extra options to pass to bm_poseur
84# change the bridge name or IP: --bridge br99 --bridge-ip 192.0.2.1
85# change the virtualization type: --engine qemu
86BM_POSEUR_EXTRA_OPTS=${BM_POSEUR_EXTRA_OPTS:-}
87
Arata Notsubbf06452013-07-26 20:26:07 +090088# To provide PXE, configure nova-network's dnsmasq rather than run the one
89# dedicated to baremetal. When enable this, make sure these conditions are
90# fulfilled:
Adam Spierscb961592013-10-05 12:11:07 +010091#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010092# 1) nova-compute and nova-network runs on the same host
93# 2) nova-network uses FlatDHCPManager
Adam Spierscb961592013-10-05 12:11:07 +010094#
Arata Notsubbf06452013-07-26 20:26:07 +090095# NOTE: the other BM_DNSMASQ_* have no effect on the behavior if this option
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010096# is enabled.
Arata Notsubbf06452013-07-26 20:26:07 +090097BM_DNSMASQ_FROM_NOVA_NETWORK=`trueorfalse False $BM_DNSMASQ_FROM_NOVA_NETWORK`
98
Devananda van der Veen7611c892012-11-23 10:54:54 -080099# BM_DNSMASQ_IFACE should match FLAT_NETWORK_BRIDGE
100if [ "$BM_USE_FAKE_ENV" ]; then
101 BM_DNSMASQ_IFACE=${BM_DNSMASQ_IFACE:-br99}
102 BM_DNSMASQ_RANGE=${BM_DNSMASQ_RANGE:-192.0.2.32,192.0.2.48}
103else
104 BM_DNSMASQ_IFACE=${BM_DNSMASQ_IFACE:-eth0}
105 # if testing on a physical network,
106 # BM_DNSMASQ_RANGE must be changed to suit your network
107 BM_DNSMASQ_RANGE=${BM_DNSMASQ_RANGE:-}
108fi
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800109
Chris Krelle35336282013-02-03 15:48:43 -0800110# BM_DNSMASQ_DNS provide dns server to bootstrap clients
111BM_DNSMASQ_DNS=${BM_DNSMASQ_DNS:-}
112
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100113# BM_FIRST_MAC *must* be set to the MAC address of the node you will
114# boot. This is passed to dnsmasq along with the kernel/ramdisk to
115# deploy via PXE.
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800116BM_FIRST_MAC=${BM_FIRST_MAC:-}
117
118# BM_SECOND_MAC is only important if the host has >1 NIC.
119BM_SECOND_MAC=${BM_SECOND_MAC:-}
120
121# Hostname for the baremetal nova-compute node, if not run on this host
122BM_HOSTNAME=${BM_HOSTNAME:-$(hostname -f)}
123
124# BM_PM_* options are only necessary if BM_POWER_MANAGER=...IPMI
125BM_PM_ADDR=${BM_PM_ADDR:-0.0.0.0}
126BM_PM_USER=${BM_PM_USER:-user}
127BM_PM_PASS=${BM_PM_PASS:-pass}
128
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100129# BM_FLAVOR_* options are arbitrary and not necessarily related to
130# physical hardware capacity. These can be changed if you are testing
131# BaremetalHostManager with multiple nodes and different flavors.
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800132BM_CPU_ARCH=${BM_CPU_ARCH:-x86_64}
133BM_FLAVOR_CPU=${BM_FLAVOR_CPU:-1}
134BM_FLAVOR_RAM=${BM_FLAVOR_RAM:-1024}
135BM_FLAVOR_ROOT_DISK=${BM_FLAVOR_ROOT_DISK:-10}
136BM_FLAVOR_EPHEMERAL_DISK=${BM_FLAVOR_EPHEMERAL_DISK:-0}
137BM_FLAVOR_SWAP=${BM_FLAVOR_SWAP:-1}
138BM_FLAVOR_NAME=${BM_FLAVOR_NAME:-bm.small}
139BM_FLAVOR_ID=${BM_FLAVOR_ID:-11}
140BM_FLAVOR_ARCH=${BM_FLAVOR_ARCH:-$BM_CPU_ARCH}
141
142
143# Below this, we set some path and filenames.
144# Defaults are probably sufficient.
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800145BM_IMAGE_BUILD_DIR=${BM_IMAGE_BUILD_DIR:-$DEST/diskimage-builder}
Devananda van der Veen7611c892012-11-23 10:54:54 -0800146BM_POSEUR_DIR=${BM_POSEUR_DIR:-$DEST/bm_poseur}
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800147
Arata Notsud3a18ae2013-08-02 20:58:56 +0900148# Use DIB to create deploy ramdisk and kernel.
149BM_BUILD_DEPLOY_RAMDISK=`trueorfalse True $BM_BUILD_DEPLOY_RAMDISK`
150# If not use DIB, these files are used as deploy ramdisk/kernel.
151# (The value must be a relative path from $TOP_DIR/files/)
152BM_DEPLOY_RAMDISK=${BM_DEPLOY_RAMDISK:-}
153BM_DEPLOY_KERNEL=${BM_DEPLOY_KERNEL:-}
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800154
155# If you need to add any extra flavors to the deploy ramdisk image
156# eg, specific network drivers, specify them here
157BM_DEPLOY_FLAVOR=${BM_DEPLOY_FLAVOR:-}
158
159# set URL and version for google shell-in-a-box
160BM_SHELL_IN_A_BOX=${BM_SHELL_IN_A_BOX:-http://shellinabox.googlecode.com/files/shellinabox-2.14.tar.gz}
161
162
163# Functions
164# ---------
165
166# Check if baremetal is properly enabled
167# Returns false if VIRT_DRIVER is not baremetal, or if ENABLED_SERVICES
168# does not contain "baremetal"
169function is_baremetal() {
170 if [[ "$ENABLED_SERVICES" =~ 'baremetal' && "$VIRT_DRIVER" = 'baremetal' ]]; then
171 return 0
172 fi
173 return 1
174}
175
176# Install diskimage-builder and shell-in-a-box
177# so that we can build the deployment kernel & ramdisk
178function prepare_baremetal_toolchain() {
179 git_clone $BM_IMAGE_BUILD_REPO $BM_IMAGE_BUILD_DIR $BM_IMAGE_BUILD_BRANCH
Devananda van der Veen7611c892012-11-23 10:54:54 -0800180 git_clone $BM_POSEUR_REPO $BM_POSEUR_DIR $BM_POSEUR_BRANCH
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800181
182 local shellinabox_basename=$(basename $BM_SHELL_IN_A_BOX)
183 if [[ ! -e $DEST/$shellinabox_basename ]]; then
184 cd $DEST
185 wget $BM_SHELL_IN_A_BOX
186 fi
187 if [[ ! -d $DEST/${shellinabox_basename%%.tar.gz} ]]; then
188 cd $DEST
189 tar xzf $shellinabox_basename
190 fi
191 if [[ ! $(which shellinaboxd) ]]; then
192 cd $DEST/${shellinabox_basename%%.tar.gz}
193 ./configure
194 make
195 sudo make install
196 fi
197}
198
Devananda van der Veen7611c892012-11-23 10:54:54 -0800199# set up virtualized environment for devstack-gate testing
200function create_fake_baremetal_env() {
201 local bm_poseur="$BM_POSEUR_DIR/bm_poseur"
202 # TODO(deva): add support for >1 VM
203 sudo $bm_poseur $BM_POSEUR_EXTRA_OPTS create-bridge
204 sudo $bm_poseur $BM_POSEUR_EXTRA_OPTS create-vm
205 BM_FIRST_MAC=$(sudo $bm_poseur get-macs)
206
207 # NOTE: there is currently a limitation in baremetal driver
Adam Spierscb961592013-10-05 12:11:07 +0100208 # that requires second MAC even if it is not used.
209 # Passing a fake value allows this to work.
Devananda van der Veen7611c892012-11-23 10:54:54 -0800210 # TODO(deva): remove this after driver issue is fixed.
211 BM_SECOND_MAC='12:34:56:78:90:12'
212}
213
214function cleanup_fake_baremetal_env() {
215 local bm_poseur="$BM_POSEUR_DIR/bm_poseur"
216 sudo $bm_poseur $BM_POSEUR_EXTRA_OPTS destroy-vm
217 sudo $bm_poseur $BM_POSEUR_EXTRA_OPTS destroy-bridge
218}
219
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800220# prepare various directories needed by baremetal hypervisor
221function configure_baremetal_nova_dirs() {
222 # ensure /tftpboot is prepared
223 sudo mkdir -p /tftpboot
224 sudo mkdir -p /tftpboot/pxelinux.cfg
Lucas Alvares Gomes74aad312013-08-28 11:32:14 +0100225
226 PXEBIN=/usr/share/syslinux/pxelinux.0
227 if [ ! -f $PXEBIN ]; then
228 PXEBIN=/usr/lib/syslinux/pxelinux.0
229 if [ ! -f $PXEBIN ]; then
230 die $LINENO "pxelinux.0 (from SYSLINUX) not found."
231 fi
232 fi
233
234 sudo cp $PXEBIN /tftpboot/
Émilien Macchib2ef8902013-05-04 00:48:20 +0200235 sudo chown -R $STACK_USER:$LIBVIRT_GROUP /tftpboot
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800236
237 # ensure $NOVA_STATE_PATH/baremetal is prepared
238 sudo mkdir -p $NOVA_STATE_PATH/baremetal
239 sudo mkdir -p $NOVA_STATE_PATH/baremetal/console
240 sudo mkdir -p $NOVA_STATE_PATH/baremetal/dnsmasq
241 sudo touch $NOVA_STATE_PATH/baremetal/dnsmasq/dnsmasq-dhcp.host
Attila Fazekas91b8d132013-01-06 22:40:09 +0100242 sudo chown -R $STACK_USER $NOVA_STATE_PATH/baremetal
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800243
244 # ensure dnsmasq is installed but not running
245 # because baremetal driver will reconfigure and restart this as needed
Devananda van der Veen75eaaf42012-12-28 15:40:21 -0800246 is_package_installed dnsmasq || install_package dnsmasq
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800247 stop_service dnsmasq
248}
249
250# build deploy kernel+ramdisk, then upload them to glance
251# this function sets BM_DEPLOY_KERNEL_ID and BM_DEPLOY_RAMDISK_ID
252function upload_baremetal_deploy() {
253 token=$1
254
Arata Notsud3a18ae2013-08-02 20:58:56 +0900255 if [ "$BM_BUILD_DEPLOY_RAMDISK" = "True" ]; then
256 BM_DEPLOY_KERNEL=bm-deploy.kernel
257 BM_DEPLOY_RAMDISK=bm-deploy.initramfs
258 if [ ! -e "$TOP_DIR/files/$BM_DEPLOY_KERNEL" -o ! -e "$TOP_DIR/files/$BM_DEPLOY_RAMDISK" ]; then
259 $BM_IMAGE_BUILD_DIR/bin/ramdisk-image-create $BM_DEPLOY_FLAVOR deploy \
260 -o $TOP_DIR/files/bm-deploy
261 fi
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800262 fi
263
264 # load them into glance
265 BM_DEPLOY_KERNEL_ID=$(glance \
Sean Dague101b4242013-10-22 08:47:11 -0400266 --os-auth-token $token \
267 --os-image-url http://$GLANCE_HOSTPORT \
268 image-create \
269 --name $BM_DEPLOY_KERNEL \
270 --is-public True --disk-format=aki \
271 < $TOP_DIR/files/$BM_DEPLOY_KERNEL | grep ' id ' | get_field 2)
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800272 BM_DEPLOY_RAMDISK_ID=$(glance \
Sean Dague101b4242013-10-22 08:47:11 -0400273 --os-auth-token $token \
274 --os-image-url http://$GLANCE_HOSTPORT \
275 image-create \
276 --name $BM_DEPLOY_RAMDISK \
277 --is-public True --disk-format=ari \
278 < $TOP_DIR/files/$BM_DEPLOY_RAMDISK | grep ' id ' | get_field 2)
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800279}
280
281# create a basic baremetal flavor, associated with deploy kernel & ramdisk
282#
283# Usage: create_baremetal_flavor <aki_uuid> <ari_uuid>
284function create_baremetal_flavor() {
285 aki=$1
286 ari=$2
287 nova flavor-create $BM_FLAVOR_NAME $BM_FLAVOR_ID \
Sean Dague101b4242013-10-22 08:47:11 -0400288 $BM_FLAVOR_RAM $BM_FLAVOR_ROOT_DISK $BM_FLAVOR_CPU
Devananda van der Veen75eaaf42012-12-28 15:40:21 -0800289 nova flavor-key $BM_FLAVOR_NAME set \
Sean Dague101b4242013-10-22 08:47:11 -0400290 "cpu_arch"="$BM_FLAVOR_ARCH" \
291 "baremetal:deploy_kernel_id"="$aki" \
292 "baremetal:deploy_ramdisk_id"="$ari"
Devananda van der Veen2920b7d2013-03-04 11:47:14 -0800293
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800294}
295
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100296# Pull run-time kernel/ramdisk out of disk image and load into glance.
297# Note that $file is currently expected to be in qcow2 format.
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800298# Sets KERNEL_ID and RAMDISK_ID
299#
300# Usage: extract_and_upload_k_and_r_from_image $token $file
301function extract_and_upload_k_and_r_from_image() {
302 token=$1
303 file=$2
304 image_name=$(basename "$file" ".qcow2")
305
306 # this call returns the file names as "$kernel,$ramdisk"
307 out=$($BM_IMAGE_BUILD_DIR/bin/disk-image-get-kernel \
308 -x -d $TOP_DIR/files -o bm-deploy -i $file)
309 if [ $? -ne 0 ]; then
Lucas Alvares Gomesc33d1f92013-09-06 18:14:51 +0100310 die $LINENO "Failed to get kernel and ramdisk from $file"
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800311 fi
312 XTRACE=$(set +o | grep xtrace)
313 set +o xtrace
314 out=$(echo "$out" | tail -1)
315 $XTRACE
316 OUT_KERNEL=${out%%,*}
317 OUT_RAMDISK=${out##*,}
318
319 # load them into glance
320 KERNEL_ID=$(glance \
Sean Dague101b4242013-10-22 08:47:11 -0400321 --os-auth-token $token \
322 --os-image-url http://$GLANCE_HOSTPORT \
323 image-create \
324 --name $image_name-kernel \
325 --is-public True --disk-format=aki \
326 < $TOP_DIR/files/$OUT_KERNEL | grep ' id ' | get_field 2)
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800327 RAMDISK_ID=$(glance \
Sean Dague101b4242013-10-22 08:47:11 -0400328 --os-auth-token $token \
329 --os-image-url http://$GLANCE_HOSTPORT \
330 image-create \
331 --name $image_name-initrd \
332 --is-public True --disk-format=ari \
333 < $TOP_DIR/files/$OUT_RAMDISK | grep ' id ' | get_field 2)
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800334}
335
336
337# Re-implementation of devstack's "upload_image" function
338#
339# Takes the same parameters, but has some peculiarities which made it
340# easier to create a separate method, rather than complicate the logic
341# of the existing function.
342function upload_baremetal_image() {
343 local image_url=$1
344 local token=$2
345
346 # Create a directory for the downloaded image tarballs.
347 mkdir -p $FILES/images
348
349 # Downloads the image (uec ami+aki style), then extracts it.
350 IMAGE_FNAME=`basename "$image_url"`
351 if [[ ! -f $FILES/$IMAGE_FNAME || \
352 "$(stat -c "%s" $FILES/$IMAGE_FNAME)" = "0" ]]; then
353 wget -c $image_url -O $FILES/$IMAGE_FNAME
354 if [[ $? -ne 0 ]]; then
355 echo "Not found: $image_url"
356 return
357 fi
358 fi
359
360 local KERNEL=""
361 local RAMDISK=""
362 local DISK_FORMAT=""
363 local CONTAINER_FORMAT=""
364 case "$IMAGE_FNAME" in
365 *.tar.gz|*.tgz)
366 # Extract ami and aki files
367 [ "${IMAGE_FNAME%.tar.gz}" != "$IMAGE_FNAME" ] &&
368 IMAGE_NAME="${IMAGE_FNAME%.tar.gz}" ||
369 IMAGE_NAME="${IMAGE_FNAME%.tgz}"
370 xdir="$FILES/images/$IMAGE_NAME"
371 rm -Rf "$xdir";
372 mkdir "$xdir"
373 tar -zxf $FILES/$IMAGE_FNAME -C "$xdir"
374 KERNEL=$(for f in "$xdir/"*-vmlinuz* "$xdir/"aki-*/image; do
Sean Dague101b4242013-10-22 08:47:11 -0400375 [ -f "$f" ] && echo "$f" && break; done; true)
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800376 RAMDISK=$(for f in "$xdir/"*-initrd* "$xdir/"ari-*/image; do
Sean Dague101b4242013-10-22 08:47:11 -0400377 [ -f "$f" ] && echo "$f" && break; done; true)
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800378 IMAGE=$(for f in "$xdir/"*.img "$xdir/"ami-*/image; do
Sean Dague101b4242013-10-22 08:47:11 -0400379 [ -f "$f" ] && echo "$f" && break; done; true)
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800380 if [[ -z "$IMAGE_NAME" ]]; then
381 IMAGE_NAME=$(basename "$IMAGE" ".img")
382 fi
383 DISK_FORMAT=ami
384 CONTAINER_FORMAT=ami
385 ;;
386 *.qcow2)
387 IMAGE="$FILES/${IMAGE_FNAME}"
388 IMAGE_NAME=$(basename "$IMAGE" ".qcow2")
389 DISK_FORMAT=qcow2
390 CONTAINER_FORMAT=bare
391 ;;
392 *) echo "Do not know what to do with $IMAGE_FNAME"; false;;
393 esac
394
395 if [ "$CONTAINER_FORMAT" = "bare" ]; then
396 extract_and_upload_k_and_r_from_image $token $IMAGE
397 elif [ "$CONTAINER_FORMAT" = "ami" ]; then
398 KERNEL_ID=$(glance \
399 --os-auth-token $token \
400 --os-image-url http://$GLANCE_HOSTPORT \
401 image-create \
Christian Berendta7a219a2013-07-30 18:22:32 +0200402 --name "$IMAGE_NAME-kernel" --is-public True \
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800403 --container-format aki \
404 --disk-format aki < "$KERNEL" | grep ' id ' | get_field 2)
405 RAMDISK_ID=$(glance \
406 --os-auth-token $token \
407 --os-image-url http://$GLANCE_HOSTPORT \
408 image-create \
Christian Berendta7a219a2013-07-30 18:22:32 +0200409 --name "$IMAGE_NAME-ramdisk" --is-public True \
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800410 --container-format ari \
411 --disk-format ari < "$RAMDISK" | grep ' id ' | get_field 2)
412 else
Sean Dague101b4242013-10-22 08:47:11 -0400413 # TODO(deva): add support for other image types
414 return
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800415 fi
416
417 glance \
Sean Dague101b4242013-10-22 08:47:11 -0400418 --os-auth-token $token \
419 --os-image-url http://$GLANCE_HOSTPORT \
420 image-create \
421 --name "${IMAGE_NAME%.img}" --is-public True \
422 --container-format $CONTAINER_FORMAT \
423 --disk-format $DISK_FORMAT \
424 ${KERNEL_ID:+--property kernel_id=$KERNEL_ID} \
425 ${RAMDISK_ID:+--property ramdisk_id=$RAMDISK_ID} < "${IMAGE}"
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800426
Tim Miller9a3ba4b2013-03-18 18:08:27 -0700427 # override DEFAULT_IMAGE_NAME so that tempest can find the image
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800428 # that we just uploaded in glance
429 DEFAULT_IMAGE_NAME="${IMAGE_NAME%.img}"
430}
431
432function clear_baremetal_of_all_nodes() {
Arata Notsu24f79612013-02-13 21:01:18 +0900433 list=$(nova baremetal-node-list | awk -F '| ' 'NR>3 {print $2}' )
Sean Dague16dd8b32014-02-03 09:10:54 +0900434 for node in $list; do
Arata Notsu24f79612013-02-13 21:01:18 +0900435 nova baremetal-node-delete $node
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800436 done
437}
438
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100439# Inform nova-baremetal about nodes, MACs, etc.
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800440# Defaults to using BM_FIRST_MAC and BM_SECOND_MAC if parameters not specified
441#
442# Usage: add_baremetal_node <first_mac> <second_mac>
443function add_baremetal_node() {
444 mac_1=${1:-$BM_FIRST_MAC}
445 mac_2=${2:-$BM_SECOND_MAC}
446
Arata Notsu24f79612013-02-13 21:01:18 +0900447 id=$(nova baremetal-node-create \
Sean Dague101b4242013-10-22 08:47:11 -0400448 --pm_address="$BM_PM_ADDR" \
449 --pm_user="$BM_PM_USER" \
450 --pm_password="$BM_PM_PASS" \
451 "$BM_HOSTNAME" \
452 "$BM_FLAVOR_CPU" \
453 "$BM_FLAVOR_RAM" \
454 "$BM_FLAVOR_ROOT_DISK" \
455 "$mac_1" \
456 | grep ' id ' | get_field 2 )
Lucas Alvares Gomesc33d1f92013-09-06 18:14:51 +0100457 [ $? -eq 0 ] || [ "$id" ] || die $LINENO "Error adding baremetal node"
Arata Notsuaf15d352013-10-11 21:56:56 +0900458 if [ -n "$mac_2" ]; then
459 id2=$(nova baremetal-interface-add "$id" "$mac_2" )
460 [ $? -eq 0 ] || [ "$id2" ] || die $LINENO "Error adding interface to barmetal node $id"
461 fi
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800462}
463
464
465# Restore xtrace
466$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400467
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100468# Tell emacs to use shell-script-mode
469## Local variables:
470## mode: shell-script
471## End: