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