Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # 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. |
| 17 | |
| 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 | # |
| 27 | # At a minimum, to enable the baremetal driver, you must set these in loclarc: |
| 28 | # VIRT_DRIVER=baremetal |
| 29 | # ENABLED_SERVICES="$ENABLED_SERVICES,baremetal" |
| 30 | # |
| 31 | # |
| 32 | # We utilize diskimage-builder to create a ramdisk, and then |
| 33 | # baremetal driver uses that to push a disk image onto the node(s). |
| 34 | # |
| 35 | # Below we define various defaults which control the behavior of the |
| 36 | # baremetal compute service, and inform it of the hardware it will contorl. |
| 37 | # |
| 38 | # Below that, various functions are defined, which are called by devstack |
| 39 | # in the following order: |
| 40 | # |
| 41 | # before nova-cpu starts: |
| 42 | # - prepare_baremetal_toolchain |
| 43 | # - configure_baremetal_nova_dirs |
| 44 | # |
| 45 | # after nova and glance have started: |
| 46 | # - build_and_upload_baremetal_deploy_k_and_r $token |
| 47 | # - create_baremetal_flavor $BM_DEPLOY_KERNEL_ID $BM_DEPLOY_RAMDISK_ID |
| 48 | # - upload_baremetal_image $url $token |
| 49 | # - add_baremetal_node <first_mac> <second_mac> |
| 50 | |
| 51 | |
| 52 | # Save trace setting |
| 53 | XTRACE=$(set +o | grep xtrace) |
| 54 | set +o xtrace |
| 55 | |
| 56 | # Sub-driver settings |
| 57 | # ------------------- |
| 58 | |
| 59 | # sub-driver to use for kernel deployment |
| 60 | # - nova.virt.baremetal.pxe.PXE |
| 61 | # - nova.virt.baremetal.tilera.TILERA |
| 62 | BM_DRIVER=${BM_DRIVER:-nova.virt.baremetal.pxe.PXE} |
| 63 | |
| 64 | # sub-driver to use for remote power management |
| 65 | # - nova.virt.baremetal.fake.FakePowerManager, for manual power control |
| 66 | # - nova.virt.baremetal.ipmi.Ipmi, for remote IPMI |
| 67 | # - nova.virt.baremetal.tilera_pdu.Pdu, for TilePro hardware |
| 68 | BM_POWER_MANAGER=${BM_POWER_MANAGER:-nova.virt.baremetal.fake.FakePowerManager} |
| 69 | |
| 70 | |
| 71 | # These should be customized to your environment and hardware |
| 72 | # ----------------------------------------------------------- |
| 73 | |
Devananda van der Veen | 7611c89 | 2012-11-23 10:54:54 -0800 | [diff] [blame] | 74 | # whether to create a fake environment, eg. for devstack-gate |
| 75 | BM_USE_FAKE_ENV=`trueorfalse False $BM_USE_FAKE_ENV` |
| 76 | |
| 77 | # Extra options to pass to bm_poseur |
| 78 | # change the bridge name or IP: --bridge br99 --bridge-ip 192.0.2.1 |
| 79 | # change the virtualization type: --engine qemu |
| 80 | BM_POSEUR_EXTRA_OPTS=${BM_POSEUR_EXTRA_OPTS:-} |
| 81 | |
| 82 | # BM_DNSMASQ_IFACE should match FLAT_NETWORK_BRIDGE |
| 83 | if [ "$BM_USE_FAKE_ENV" ]; then |
| 84 | BM_DNSMASQ_IFACE=${BM_DNSMASQ_IFACE:-br99} |
| 85 | BM_DNSMASQ_RANGE=${BM_DNSMASQ_RANGE:-192.0.2.32,192.0.2.48} |
| 86 | else |
| 87 | BM_DNSMASQ_IFACE=${BM_DNSMASQ_IFACE:-eth0} |
| 88 | # if testing on a physical network, |
| 89 | # BM_DNSMASQ_RANGE must be changed to suit your network |
| 90 | BM_DNSMASQ_RANGE=${BM_DNSMASQ_RANGE:-} |
| 91 | fi |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 92 | |
Chris Krelle | 3533628 | 2013-02-03 15:48:43 -0800 | [diff] [blame] | 93 | # BM_DNSMASQ_DNS provide dns server to bootstrap clients |
| 94 | BM_DNSMASQ_DNS=${BM_DNSMASQ_DNS:-} |
| 95 | |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 96 | # BM_FIRST_MAC *must* be set to the MAC address of the node you will boot. |
| 97 | # This is passed to dnsmasq along with the kernel/ramdisk to |
| 98 | # deploy via PXE. |
| 99 | BM_FIRST_MAC=${BM_FIRST_MAC:-} |
| 100 | |
| 101 | # BM_SECOND_MAC is only important if the host has >1 NIC. |
| 102 | BM_SECOND_MAC=${BM_SECOND_MAC:-} |
| 103 | |
| 104 | # Hostname for the baremetal nova-compute node, if not run on this host |
| 105 | BM_HOSTNAME=${BM_HOSTNAME:-$(hostname -f)} |
| 106 | |
| 107 | # BM_PM_* options are only necessary if BM_POWER_MANAGER=...IPMI |
| 108 | BM_PM_ADDR=${BM_PM_ADDR:-0.0.0.0} |
| 109 | BM_PM_USER=${BM_PM_USER:-user} |
| 110 | BM_PM_PASS=${BM_PM_PASS:-pass} |
| 111 | |
| 112 | # BM_FLAVOR_* options are arbitrary and not necessarily related to physical |
| 113 | # hardware capacity. These can be changed if you are testing |
| 114 | # BaremetalHostManager with multiple nodes and different flavors. |
| 115 | BM_CPU_ARCH=${BM_CPU_ARCH:-x86_64} |
| 116 | BM_FLAVOR_CPU=${BM_FLAVOR_CPU:-1} |
| 117 | BM_FLAVOR_RAM=${BM_FLAVOR_RAM:-1024} |
| 118 | BM_FLAVOR_ROOT_DISK=${BM_FLAVOR_ROOT_DISK:-10} |
| 119 | BM_FLAVOR_EPHEMERAL_DISK=${BM_FLAVOR_EPHEMERAL_DISK:-0} |
| 120 | BM_FLAVOR_SWAP=${BM_FLAVOR_SWAP:-1} |
| 121 | BM_FLAVOR_NAME=${BM_FLAVOR_NAME:-bm.small} |
| 122 | BM_FLAVOR_ID=${BM_FLAVOR_ID:-11} |
| 123 | BM_FLAVOR_ARCH=${BM_FLAVOR_ARCH:-$BM_CPU_ARCH} |
| 124 | |
| 125 | |
| 126 | # Below this, we set some path and filenames. |
| 127 | # Defaults are probably sufficient. |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 128 | BM_IMAGE_BUILD_DIR=${BM_IMAGE_BUILD_DIR:-$DEST/diskimage-builder} |
Devananda van der Veen | 7611c89 | 2012-11-23 10:54:54 -0800 | [diff] [blame] | 129 | BM_POSEUR_DIR=${BM_POSEUR_DIR:-$DEST/bm_poseur} |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 130 | |
| 131 | BM_HOST_CURRENT_KERNEL=$(uname -r) |
| 132 | BM_DEPLOY_RAMDISK=${BM_DEPLOY_RAMDISK:-bm-deploy-$BM_HOST_CURRENT_KERNEL-initrd} |
| 133 | BM_DEPLOY_KERNEL=${BM_DEPLOY_KERNEL:-bm-deploy-$BM_HOST_CURRENT_KERNEL-vmlinuz} |
| 134 | |
| 135 | # If you need to add any extra flavors to the deploy ramdisk image |
| 136 | # eg, specific network drivers, specify them here |
| 137 | BM_DEPLOY_FLAVOR=${BM_DEPLOY_FLAVOR:-} |
| 138 | |
| 139 | # set URL and version for google shell-in-a-box |
| 140 | BM_SHELL_IN_A_BOX=${BM_SHELL_IN_A_BOX:-http://shellinabox.googlecode.com/files/shellinabox-2.14.tar.gz} |
| 141 | |
| 142 | |
| 143 | # Functions |
| 144 | # --------- |
| 145 | |
| 146 | # Check if baremetal is properly enabled |
| 147 | # Returns false if VIRT_DRIVER is not baremetal, or if ENABLED_SERVICES |
| 148 | # does not contain "baremetal" |
| 149 | function is_baremetal() { |
| 150 | if [[ "$ENABLED_SERVICES" =~ 'baremetal' && "$VIRT_DRIVER" = 'baremetal' ]]; then |
| 151 | return 0 |
| 152 | fi |
| 153 | return 1 |
| 154 | } |
| 155 | |
| 156 | # Install diskimage-builder and shell-in-a-box |
| 157 | # so that we can build the deployment kernel & ramdisk |
| 158 | function prepare_baremetal_toolchain() { |
| 159 | git_clone $BM_IMAGE_BUILD_REPO $BM_IMAGE_BUILD_DIR $BM_IMAGE_BUILD_BRANCH |
Devananda van der Veen | 7611c89 | 2012-11-23 10:54:54 -0800 | [diff] [blame] | 160 | git_clone $BM_POSEUR_REPO $BM_POSEUR_DIR $BM_POSEUR_BRANCH |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 161 | |
| 162 | local shellinabox_basename=$(basename $BM_SHELL_IN_A_BOX) |
| 163 | if [[ ! -e $DEST/$shellinabox_basename ]]; then |
| 164 | cd $DEST |
| 165 | wget $BM_SHELL_IN_A_BOX |
| 166 | fi |
| 167 | if [[ ! -d $DEST/${shellinabox_basename%%.tar.gz} ]]; then |
| 168 | cd $DEST |
| 169 | tar xzf $shellinabox_basename |
| 170 | fi |
| 171 | if [[ ! $(which shellinaboxd) ]]; then |
| 172 | cd $DEST/${shellinabox_basename%%.tar.gz} |
| 173 | ./configure |
| 174 | make |
| 175 | sudo make install |
| 176 | fi |
| 177 | } |
| 178 | |
Devananda van der Veen | 7611c89 | 2012-11-23 10:54:54 -0800 | [diff] [blame] | 179 | # set up virtualized environment for devstack-gate testing |
| 180 | function create_fake_baremetal_env() { |
| 181 | local bm_poseur="$BM_POSEUR_DIR/bm_poseur" |
| 182 | # TODO(deva): add support for >1 VM |
| 183 | sudo $bm_poseur $BM_POSEUR_EXTRA_OPTS create-bridge |
| 184 | sudo $bm_poseur $BM_POSEUR_EXTRA_OPTS create-vm |
| 185 | BM_FIRST_MAC=$(sudo $bm_poseur get-macs) |
| 186 | |
| 187 | # NOTE: there is currently a limitation in baremetal driver |
| 188 | # that requires second MAC even if it is not used. |
| 189 | # Passing a fake value allows this to work. |
| 190 | # TODO(deva): remove this after driver issue is fixed. |
| 191 | BM_SECOND_MAC='12:34:56:78:90:12' |
| 192 | } |
| 193 | |
| 194 | function cleanup_fake_baremetal_env() { |
| 195 | local bm_poseur="$BM_POSEUR_DIR/bm_poseur" |
| 196 | sudo $bm_poseur $BM_POSEUR_EXTRA_OPTS destroy-vm |
| 197 | sudo $bm_poseur $BM_POSEUR_EXTRA_OPTS destroy-bridge |
| 198 | } |
| 199 | |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 200 | # prepare various directories needed by baremetal hypervisor |
| 201 | function configure_baremetal_nova_dirs() { |
| 202 | # ensure /tftpboot is prepared |
| 203 | sudo mkdir -p /tftpboot |
| 204 | sudo mkdir -p /tftpboot/pxelinux.cfg |
| 205 | sudo cp /usr/lib/syslinux/pxelinux.0 /tftpboot/ |
Attila Fazekas | 91b8d13 | 2013-01-06 22:40:09 +0100 | [diff] [blame] | 206 | sudo chown -R $STACK_USER:libvirtd /tftpboot |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 207 | |
| 208 | # ensure $NOVA_STATE_PATH/baremetal is prepared |
| 209 | sudo mkdir -p $NOVA_STATE_PATH/baremetal |
| 210 | sudo mkdir -p $NOVA_STATE_PATH/baremetal/console |
| 211 | sudo mkdir -p $NOVA_STATE_PATH/baremetal/dnsmasq |
| 212 | sudo touch $NOVA_STATE_PATH/baremetal/dnsmasq/dnsmasq-dhcp.host |
Attila Fazekas | 91b8d13 | 2013-01-06 22:40:09 +0100 | [diff] [blame] | 213 | sudo chown -R $STACK_USER $NOVA_STATE_PATH/baremetal |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 214 | |
| 215 | # ensure dnsmasq is installed but not running |
| 216 | # because baremetal driver will reconfigure and restart this as needed |
Devananda van der Veen | 75eaaf4 | 2012-12-28 15:40:21 -0800 | [diff] [blame] | 217 | is_package_installed dnsmasq || install_package dnsmasq |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 218 | stop_service dnsmasq |
| 219 | } |
| 220 | |
| 221 | # build deploy kernel+ramdisk, then upload them to glance |
| 222 | # this function sets BM_DEPLOY_KERNEL_ID and BM_DEPLOY_RAMDISK_ID |
| 223 | function upload_baremetal_deploy() { |
| 224 | token=$1 |
| 225 | |
| 226 | if [ ! -e $TOP_DIR/files/$BM_DEPLOY_KERNEL -a -e /boot/vmlinuz-$BM_HOST_CURRENT_KERNEL ]; then |
| 227 | sudo cp /boot/vmlinuz-$BM_HOST_CURRENT_KERNEL $TOP_DIR/files/$BM_DEPLOY_KERNEL |
| 228 | sudo chmod a+r $TOP_DIR/files/$BM_DEPLOY_KERNEL |
| 229 | fi |
| 230 | if [ ! -e $TOP_DIR/files/$BM_DEPLOY_RAMDISK ]; then |
| 231 | $BM_IMAGE_BUILD_DIR/bin/ramdisk-image-create $BM_DEPLOY_FLAVOR deploy \ |
| 232 | -o $TOP_DIR/files/$BM_DEPLOY_RAMDISK -k $BM_HOST_CURRENT_KERNEL |
| 233 | fi |
| 234 | |
| 235 | # load them into glance |
| 236 | BM_DEPLOY_KERNEL_ID=$(glance \ |
| 237 | --os-auth-token $token \ |
| 238 | --os-image-url http://$GLANCE_HOSTPORT \ |
| 239 | image-create \ |
| 240 | --name $BM_DEPLOY_KERNEL \ |
| 241 | --public --disk-format=aki \ |
| 242 | < $TOP_DIR/files/$BM_DEPLOY_KERNEL | grep ' id ' | get_field 2) |
| 243 | BM_DEPLOY_RAMDISK_ID=$(glance \ |
| 244 | --os-auth-token $token \ |
| 245 | --os-image-url http://$GLANCE_HOSTPORT \ |
| 246 | image-create \ |
| 247 | --name $BM_DEPLOY_RAMDISK \ |
| 248 | --public --disk-format=ari \ |
| 249 | < $TOP_DIR/files/$BM_DEPLOY_RAMDISK | grep ' id ' | get_field 2) |
| 250 | } |
| 251 | |
| 252 | # create a basic baremetal flavor, associated with deploy kernel & ramdisk |
| 253 | # |
| 254 | # Usage: create_baremetal_flavor <aki_uuid> <ari_uuid> |
| 255 | function create_baremetal_flavor() { |
| 256 | aki=$1 |
| 257 | ari=$2 |
| 258 | nova flavor-create $BM_FLAVOR_NAME $BM_FLAVOR_ID \ |
| 259 | $BM_FLAVOR_RAM $BM_FLAVOR_ROOT_DISK $BM_FLAVOR_CPU |
Devananda van der Veen | 75eaaf4 | 2012-12-28 15:40:21 -0800 | [diff] [blame] | 260 | nova flavor-key $BM_FLAVOR_NAME set \ |
| 261 | cpu_arch=$BM_FLAVOR_ARCH \ |
| 262 | deploy_kernel_id=$aki \ |
| 263 | deploy_ramdisk_id=$ari |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | # pull run-time kernel/ramdisk out of disk image and load into glance |
| 267 | # note that $file is currently expected to be in qcow2 format |
| 268 | # Sets KERNEL_ID and RAMDISK_ID |
| 269 | # |
| 270 | # Usage: extract_and_upload_k_and_r_from_image $token $file |
| 271 | function extract_and_upload_k_and_r_from_image() { |
| 272 | token=$1 |
| 273 | file=$2 |
| 274 | image_name=$(basename "$file" ".qcow2") |
| 275 | |
| 276 | # this call returns the file names as "$kernel,$ramdisk" |
| 277 | out=$($BM_IMAGE_BUILD_DIR/bin/disk-image-get-kernel \ |
| 278 | -x -d $TOP_DIR/files -o bm-deploy -i $file) |
| 279 | if [ $? -ne 0 ]; then |
| 280 | die "Failed to get kernel and ramdisk from $file" |
| 281 | fi |
| 282 | XTRACE=$(set +o | grep xtrace) |
| 283 | set +o xtrace |
| 284 | out=$(echo "$out" | tail -1) |
| 285 | $XTRACE |
| 286 | OUT_KERNEL=${out%%,*} |
| 287 | OUT_RAMDISK=${out##*,} |
| 288 | |
| 289 | # load them into glance |
| 290 | KERNEL_ID=$(glance \ |
| 291 | --os-auth-token $token \ |
| 292 | --os-image-url http://$GLANCE_HOSTPORT \ |
| 293 | image-create \ |
| 294 | --name $image_name-kernel \ |
| 295 | --public --disk-format=aki \ |
| 296 | < $TOP_DIR/files/$OUT_KERNEL | grep ' id ' | get_field 2) |
| 297 | RAMDISK_ID=$(glance \ |
| 298 | --os-auth-token $token \ |
| 299 | --os-image-url http://$GLANCE_HOSTPORT \ |
| 300 | image-create \ |
| 301 | --name $image_name-initrd \ |
| 302 | --public --disk-format=ari \ |
| 303 | < $TOP_DIR/files/$OUT_RAMDISK | grep ' id ' | get_field 2) |
| 304 | } |
| 305 | |
| 306 | |
| 307 | # Re-implementation of devstack's "upload_image" function |
| 308 | # |
| 309 | # Takes the same parameters, but has some peculiarities which made it |
| 310 | # easier to create a separate method, rather than complicate the logic |
| 311 | # of the existing function. |
| 312 | function upload_baremetal_image() { |
| 313 | local image_url=$1 |
| 314 | local token=$2 |
| 315 | |
| 316 | # Create a directory for the downloaded image tarballs. |
| 317 | mkdir -p $FILES/images |
| 318 | |
| 319 | # Downloads the image (uec ami+aki style), then extracts it. |
| 320 | IMAGE_FNAME=`basename "$image_url"` |
| 321 | if [[ ! -f $FILES/$IMAGE_FNAME || \ |
| 322 | "$(stat -c "%s" $FILES/$IMAGE_FNAME)" = "0" ]]; then |
| 323 | wget -c $image_url -O $FILES/$IMAGE_FNAME |
| 324 | if [[ $? -ne 0 ]]; then |
| 325 | echo "Not found: $image_url" |
| 326 | return |
| 327 | fi |
| 328 | fi |
| 329 | |
| 330 | local KERNEL="" |
| 331 | local RAMDISK="" |
| 332 | local DISK_FORMAT="" |
| 333 | local CONTAINER_FORMAT="" |
| 334 | case "$IMAGE_FNAME" in |
| 335 | *.tar.gz|*.tgz) |
| 336 | # Extract ami and aki files |
| 337 | [ "${IMAGE_FNAME%.tar.gz}" != "$IMAGE_FNAME" ] && |
| 338 | IMAGE_NAME="${IMAGE_FNAME%.tar.gz}" || |
| 339 | IMAGE_NAME="${IMAGE_FNAME%.tgz}" |
| 340 | xdir="$FILES/images/$IMAGE_NAME" |
| 341 | rm -Rf "$xdir"; |
| 342 | mkdir "$xdir" |
| 343 | tar -zxf $FILES/$IMAGE_FNAME -C "$xdir" |
| 344 | KERNEL=$(for f in "$xdir/"*-vmlinuz* "$xdir/"aki-*/image; do |
| 345 | [ -f "$f" ] && echo "$f" && break; done; true) |
| 346 | RAMDISK=$(for f in "$xdir/"*-initrd* "$xdir/"ari-*/image; do |
| 347 | [ -f "$f" ] && echo "$f" && break; done; true) |
| 348 | IMAGE=$(for f in "$xdir/"*.img "$xdir/"ami-*/image; do |
| 349 | [ -f "$f" ] && echo "$f" && break; done; true) |
| 350 | if [[ -z "$IMAGE_NAME" ]]; then |
| 351 | IMAGE_NAME=$(basename "$IMAGE" ".img") |
| 352 | fi |
| 353 | DISK_FORMAT=ami |
| 354 | CONTAINER_FORMAT=ami |
| 355 | ;; |
| 356 | *.qcow2) |
| 357 | IMAGE="$FILES/${IMAGE_FNAME}" |
| 358 | IMAGE_NAME=$(basename "$IMAGE" ".qcow2") |
| 359 | DISK_FORMAT=qcow2 |
| 360 | CONTAINER_FORMAT=bare |
| 361 | ;; |
| 362 | *) echo "Do not know what to do with $IMAGE_FNAME"; false;; |
| 363 | esac |
| 364 | |
| 365 | if [ "$CONTAINER_FORMAT" = "bare" ]; then |
| 366 | extract_and_upload_k_and_r_from_image $token $IMAGE |
| 367 | elif [ "$CONTAINER_FORMAT" = "ami" ]; then |
| 368 | KERNEL_ID=$(glance \ |
| 369 | --os-auth-token $token \ |
| 370 | --os-image-url http://$GLANCE_HOSTPORT \ |
| 371 | image-create \ |
| 372 | --name "$IMAGE_NAME-kernel" --public \ |
| 373 | --container-format aki \ |
| 374 | --disk-format aki < "$KERNEL" | grep ' id ' | get_field 2) |
| 375 | RAMDISK_ID=$(glance \ |
| 376 | --os-auth-token $token \ |
| 377 | --os-image-url http://$GLANCE_HOSTPORT \ |
| 378 | image-create \ |
| 379 | --name "$IMAGE_NAME-ramdisk" --public \ |
| 380 | --container-format ari \ |
| 381 | --disk-format ari < "$RAMDISK" | grep ' id ' | get_field 2) |
| 382 | else |
| 383 | # TODO(deva): add support for other image types |
| 384 | return |
| 385 | fi |
| 386 | |
| 387 | glance \ |
| 388 | --os-auth-token $token \ |
| 389 | --os-image-url http://$GLANCE_HOSTPORT \ |
| 390 | image-create \ |
| 391 | --name "${IMAGE_NAME%.img}" --public \ |
| 392 | --container-format $CONTAINER_FORMAT \ |
| 393 | --disk-format $DISK_FORMAT \ |
| 394 | ${KERNEL_ID:+--property kernel_id=$KERNEL_ID} \ |
| 395 | ${RAMDISK_ID:+--property ramdisk_id=$RAMDISK_ID} < "${IMAGE}" |
| 396 | |
| 397 | # override DEFAULT_IMAGE_NAME so that tempest can find the image |
| 398 | # that we just uploaded in glance |
| 399 | DEFAULT_IMAGE_NAME="${IMAGE_NAME%.img}" |
| 400 | } |
| 401 | |
| 402 | function clear_baremetal_of_all_nodes() { |
Arata Notsu | 24f7961 | 2013-02-13 21:01:18 +0900 | [diff] [blame^] | 403 | list=$(nova baremetal-node-list | awk -F '| ' 'NR>3 {print $2}' ) |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 404 | for node in $list |
| 405 | do |
Arata Notsu | 24f7961 | 2013-02-13 21:01:18 +0900 | [diff] [blame^] | 406 | nova baremetal-node-delete $node |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 407 | done |
| 408 | } |
| 409 | |
| 410 | # inform nova-baremetal about nodes, MACs, etc |
| 411 | # Defaults to using BM_FIRST_MAC and BM_SECOND_MAC if parameters not specified |
| 412 | # |
| 413 | # Usage: add_baremetal_node <first_mac> <second_mac> |
| 414 | function add_baremetal_node() { |
| 415 | mac_1=${1:-$BM_FIRST_MAC} |
| 416 | mac_2=${2:-$BM_SECOND_MAC} |
| 417 | |
Arata Notsu | 24f7961 | 2013-02-13 21:01:18 +0900 | [diff] [blame^] | 418 | id=$(nova baremetal-node-create \ |
| 419 | --pm_address="$BM_PM_ADDR" \ |
| 420 | --pm_user="$BM_PM_USER" \ |
| 421 | --pm_password="$BM_PM_PASS" \ |
| 422 | "$BM_HOSTNAME" \ |
| 423 | "$BM_FLAVOR_CPU" \ |
| 424 | "$BM_FLAVOR_RAM" \ |
| 425 | "$BM_FLAVOR_ROOT_DISK" \ |
| 426 | "$mac_1" \ |
| 427 | | grep ' id ' | get_field 2 ) |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 428 | [ $? -eq 0 ] || [ "$id" ] || die "Error adding baremetal node" |
Arata Notsu | 24f7961 | 2013-02-13 21:01:18 +0900 | [diff] [blame^] | 429 | id2=$(nova baremetal-add-interface "$id" "$mac_2" ) |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 430 | [ $? -eq 0 ] || [ "$id2" ] || die "Error adding interface to barmetal node $id" |
| 431 | } |
| 432 | |
| 433 | |
| 434 | # Restore xtrace |
| 435 | $XTRACE |