Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 1 | ## vim: tabstop=4 shiftwidth=4 softtabstop=4 |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 2 | |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 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. |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 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 | # |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 27 | # At a minimum, to enable the baremetal driver, you must set these in localrc: |
| 28 | # |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 29 | # 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 Miller | 9a3ba4b | 2013-03-18 18:08:27 -0700 | [diff] [blame] | 37 | # 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] | 38 | # |
| 39 | # Below that, various functions are defined, which are called by devstack |
| 40 | # in the following order: |
| 41 | # |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 42 | # before nova-cpu starts: |
| 43 | # |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 44 | # - prepare_baremetal_toolchain |
| 45 | # - configure_baremetal_nova_dirs |
| 46 | # |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 47 | # after nova and glance have started: |
| 48 | # |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 49 | # - 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 |
| 56 | XTRACE=$(set +o | grep xtrace) |
| 57 | set +o xtrace |
| 58 | |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 59 | |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 60 | # Sub-driver settings |
| 61 | # ------------------- |
| 62 | |
| 63 | # sub-driver to use for kernel deployment |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 64 | # |
| 65 | # - nova.virt.baremetal.pxe.PXE |
| 66 | # - nova.virt.baremetal.tilera.TILERA |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 67 | BM_DRIVER=${BM_DRIVER:-nova.virt.baremetal.pxe.PXE} |
| 68 | |
| 69 | # sub-driver to use for remote power management |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 70 | # |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 71 | # - nova.virt.baremetal.fake.FakePowerManager, for manual power control |
Ghe Rivero | cc404a4 | 2013-03-06 11:48:03 +0100 | [diff] [blame] | 72 | # - nova.virt.baremetal.ipmi.IPMI, for remote IPMI |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 73 | # - nova.virt.baremetal.tilera_pdu.Pdu, for TilePro hardware |
| 74 | BM_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 Notsu | bbf0645 | 2013-07-26 20:26:07 +0900 | [diff] [blame] | 80 | # 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 Spiers | cb96159 | 2013-10-05 12:11:07 +0100 | [diff] [blame] | 83 | # |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 84 | # 1) nova-compute and nova-network runs on the same host |
| 85 | # 2) nova-network uses FlatDHCPManager |
Adam Spiers | cb96159 | 2013-10-05 12:11:07 +0100 | [diff] [blame] | 86 | # |
Arata Notsu | bbf0645 | 2013-07-26 20:26:07 +0900 | [diff] [blame] | 87 | # NOTE: the other BM_DNSMASQ_* have no effect on the behavior if this option |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 88 | # is enabled. |
Arata Notsu | bbf0645 | 2013-07-26 20:26:07 +0900 | [diff] [blame] | 89 | BM_DNSMASQ_FROM_NOVA_NETWORK=`trueorfalse False $BM_DNSMASQ_FROM_NOVA_NETWORK` |
| 90 | |
Devananda van der Veen | 7611c89 | 2012-11-23 10:54:54 -0800 | [diff] [blame] | 91 | # BM_DNSMASQ_IFACE should match FLAT_NETWORK_BRIDGE |
Eric Windisch | e994f57 | 2014-02-28 15:13:37 -0500 | [diff] [blame^] | 92 | BM_DNSMASQ_IFACE=${BM_DNSMASQ_IFACE:-eth0} |
| 93 | # if testing on a physical network, |
| 94 | # BM_DNSMASQ_RANGE must be changed to suit your network |
| 95 | BM_DNSMASQ_RANGE=${BM_DNSMASQ_RANGE:-} |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 96 | |
Chris Krelle | 3533628 | 2013-02-03 15:48:43 -0800 | [diff] [blame] | 97 | # BM_DNSMASQ_DNS provide dns server to bootstrap clients |
| 98 | BM_DNSMASQ_DNS=${BM_DNSMASQ_DNS:-} |
| 99 | |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 100 | # 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 Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 103 | BM_FIRST_MAC=${BM_FIRST_MAC:-} |
| 104 | |
| 105 | # BM_SECOND_MAC is only important if the host has >1 NIC. |
| 106 | BM_SECOND_MAC=${BM_SECOND_MAC:-} |
| 107 | |
| 108 | # Hostname for the baremetal nova-compute node, if not run on this host |
| 109 | BM_HOSTNAME=${BM_HOSTNAME:-$(hostname -f)} |
| 110 | |
| 111 | # BM_PM_* options are only necessary if BM_POWER_MANAGER=...IPMI |
| 112 | BM_PM_ADDR=${BM_PM_ADDR:-0.0.0.0} |
| 113 | BM_PM_USER=${BM_PM_USER:-user} |
| 114 | BM_PM_PASS=${BM_PM_PASS:-pass} |
| 115 | |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 116 | # 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 Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 119 | BM_CPU_ARCH=${BM_CPU_ARCH:-x86_64} |
| 120 | BM_FLAVOR_CPU=${BM_FLAVOR_CPU:-1} |
| 121 | BM_FLAVOR_RAM=${BM_FLAVOR_RAM:-1024} |
| 122 | BM_FLAVOR_ROOT_DISK=${BM_FLAVOR_ROOT_DISK:-10} |
| 123 | BM_FLAVOR_EPHEMERAL_DISK=${BM_FLAVOR_EPHEMERAL_DISK:-0} |
| 124 | BM_FLAVOR_SWAP=${BM_FLAVOR_SWAP:-1} |
| 125 | BM_FLAVOR_NAME=${BM_FLAVOR_NAME:-bm.small} |
| 126 | BM_FLAVOR_ID=${BM_FLAVOR_ID:-11} |
| 127 | BM_FLAVOR_ARCH=${BM_FLAVOR_ARCH:-$BM_CPU_ARCH} |
| 128 | |
| 129 | |
| 130 | # Below this, we set some path and filenames. |
| 131 | # Defaults are probably sufficient. |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 132 | BM_IMAGE_BUILD_DIR=${BM_IMAGE_BUILD_DIR:-$DEST/diskimage-builder} |
| 133 | |
Arata Notsu | d3a18ae | 2013-08-02 20:58:56 +0900 | [diff] [blame] | 134 | # Use DIB to create deploy ramdisk and kernel. |
| 135 | BM_BUILD_DEPLOY_RAMDISK=`trueorfalse True $BM_BUILD_DEPLOY_RAMDISK` |
| 136 | # If not use DIB, these files are used as deploy ramdisk/kernel. |
| 137 | # (The value must be a relative path from $TOP_DIR/files/) |
| 138 | BM_DEPLOY_RAMDISK=${BM_DEPLOY_RAMDISK:-} |
| 139 | BM_DEPLOY_KERNEL=${BM_DEPLOY_KERNEL:-} |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 140 | |
| 141 | # If you need to add any extra flavors to the deploy ramdisk image |
| 142 | # eg, specific network drivers, specify them here |
| 143 | BM_DEPLOY_FLAVOR=${BM_DEPLOY_FLAVOR:-} |
| 144 | |
| 145 | # set URL and version for google shell-in-a-box |
| 146 | BM_SHELL_IN_A_BOX=${BM_SHELL_IN_A_BOX:-http://shellinabox.googlecode.com/files/shellinabox-2.14.tar.gz} |
| 147 | |
| 148 | |
| 149 | # Functions |
| 150 | # --------- |
| 151 | |
| 152 | # Check if baremetal is properly enabled |
| 153 | # Returns false if VIRT_DRIVER is not baremetal, or if ENABLED_SERVICES |
| 154 | # does not contain "baremetal" |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 155 | function is_baremetal { |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 156 | if [[ "$ENABLED_SERVICES" =~ 'baremetal' && "$VIRT_DRIVER" = 'baremetal' ]]; then |
| 157 | return 0 |
| 158 | fi |
| 159 | return 1 |
| 160 | } |
| 161 | |
| 162 | # Install diskimage-builder and shell-in-a-box |
| 163 | # so that we can build the deployment kernel & ramdisk |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 164 | function prepare_baremetal_toolchain { |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 165 | git_clone $BM_IMAGE_BUILD_REPO $BM_IMAGE_BUILD_DIR $BM_IMAGE_BUILD_BRANCH |
| 166 | |
| 167 | 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 Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 184 | # prepare various directories needed by baremetal hypervisor |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 185 | function configure_baremetal_nova_dirs { |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 186 | # ensure /tftpboot is prepared |
| 187 | sudo mkdir -p /tftpboot |
| 188 | sudo mkdir -p /tftpboot/pxelinux.cfg |
Lucas Alvares Gomes | 74aad31 | 2013-08-28 11:32:14 +0100 | [diff] [blame] | 189 | |
| 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 Macchi | b2ef890 | 2013-05-04 00:48:20 +0200 | [diff] [blame] | 199 | sudo chown -R $STACK_USER:$LIBVIRT_GROUP /tftpboot |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 200 | |
| 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 Fazekas | 91b8d13 | 2013-01-06 22:40:09 +0100 | [diff] [blame] | 206 | sudo chown -R $STACK_USER $NOVA_STATE_PATH/baremetal |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 207 | |
| 208 | # ensure dnsmasq is installed but not running |
| 209 | # because baremetal driver will reconfigure and restart this as needed |
Devananda van der Veen | 75eaaf4 | 2012-12-28 15:40:21 -0800 | [diff] [blame] | 210 | is_package_installed dnsmasq || install_package dnsmasq |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 211 | 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 Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 216 | function upload_baremetal_deploy { |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 217 | token=$1 |
| 218 | |
Arata Notsu | d3a18ae | 2013-08-02 20:58:56 +0900 | [diff] [blame] | 219 | 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 |
| 223 | $BM_IMAGE_BUILD_DIR/bin/ramdisk-image-create $BM_DEPLOY_FLAVOR deploy \ |
| 224 | -o $TOP_DIR/files/bm-deploy |
| 225 | fi |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 226 | fi |
| 227 | |
| 228 | # load them into glance |
| 229 | BM_DEPLOY_KERNEL_ID=$(glance \ |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 230 | --os-auth-token $token \ |
| 231 | --os-image-url http://$GLANCE_HOSTPORT \ |
| 232 | image-create \ |
| 233 | --name $BM_DEPLOY_KERNEL \ |
| 234 | --is-public True --disk-format=aki \ |
| 235 | < $TOP_DIR/files/$BM_DEPLOY_KERNEL | grep ' id ' | get_field 2) |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 236 | BM_DEPLOY_RAMDISK_ID=$(glance \ |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 237 | --os-auth-token $token \ |
| 238 | --os-image-url http://$GLANCE_HOSTPORT \ |
| 239 | image-create \ |
| 240 | --name $BM_DEPLOY_RAMDISK \ |
| 241 | --is-public True --disk-format=ari \ |
| 242 | < $TOP_DIR/files/$BM_DEPLOY_RAMDISK | grep ' id ' | get_field 2) |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | # create a basic baremetal flavor, associated with deploy kernel & ramdisk |
| 246 | # |
| 247 | # Usage: create_baremetal_flavor <aki_uuid> <ari_uuid> |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 248 | function create_baremetal_flavor { |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 249 | aki=$1 |
| 250 | ari=$2 |
| 251 | nova flavor-create $BM_FLAVOR_NAME $BM_FLAVOR_ID \ |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 252 | $BM_FLAVOR_RAM $BM_FLAVOR_ROOT_DISK $BM_FLAVOR_CPU |
Devananda van der Veen | 75eaaf4 | 2012-12-28 15:40:21 -0800 | [diff] [blame] | 253 | nova flavor-key $BM_FLAVOR_NAME set \ |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 254 | "cpu_arch"="$BM_FLAVOR_ARCH" \ |
| 255 | "baremetal:deploy_kernel_id"="$aki" \ |
| 256 | "baremetal:deploy_ramdisk_id"="$ari" |
Devananda van der Veen | 2920b7d | 2013-03-04 11:47:14 -0800 | [diff] [blame] | 257 | |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 258 | } |
| 259 | |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 260 | # Pull run-time kernel/ramdisk out of disk image and load into glance. |
| 261 | # Note that $file is currently expected to be in qcow2 format. |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 262 | # Sets KERNEL_ID and RAMDISK_ID |
| 263 | # |
| 264 | # Usage: extract_and_upload_k_and_r_from_image $token $file |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 265 | function extract_and_upload_k_and_r_from_image { |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 266 | token=$1 |
| 267 | file=$2 |
| 268 | image_name=$(basename "$file" ".qcow2") |
| 269 | |
| 270 | # this call returns the file names as "$kernel,$ramdisk" |
| 271 | out=$($BM_IMAGE_BUILD_DIR/bin/disk-image-get-kernel \ |
| 272 | -x -d $TOP_DIR/files -o bm-deploy -i $file) |
| 273 | if [ $? -ne 0 ]; then |
Lucas Alvares Gomes | c33d1f9 | 2013-09-06 18:14:51 +0100 | [diff] [blame] | 274 | die $LINENO "Failed to get kernel and ramdisk from $file" |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 275 | fi |
| 276 | XTRACE=$(set +o | grep xtrace) |
| 277 | set +o xtrace |
| 278 | out=$(echo "$out" | tail -1) |
| 279 | $XTRACE |
| 280 | OUT_KERNEL=${out%%,*} |
| 281 | OUT_RAMDISK=${out##*,} |
| 282 | |
| 283 | # load them into glance |
| 284 | KERNEL_ID=$(glance \ |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 285 | --os-auth-token $token \ |
| 286 | --os-image-url http://$GLANCE_HOSTPORT \ |
| 287 | image-create \ |
| 288 | --name $image_name-kernel \ |
| 289 | --is-public True --disk-format=aki \ |
| 290 | < $TOP_DIR/files/$OUT_KERNEL | grep ' id ' | get_field 2) |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 291 | RAMDISK_ID=$(glance \ |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 292 | --os-auth-token $token \ |
| 293 | --os-image-url http://$GLANCE_HOSTPORT \ |
| 294 | image-create \ |
| 295 | --name $image_name-initrd \ |
| 296 | --is-public True --disk-format=ari \ |
| 297 | < $TOP_DIR/files/$OUT_RAMDISK | grep ' id ' | get_field 2) |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | |
| 301 | # Re-implementation of devstack's "upload_image" function |
| 302 | # |
| 303 | # Takes the same parameters, but has some peculiarities which made it |
| 304 | # easier to create a separate method, rather than complicate the logic |
| 305 | # of the existing function. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 306 | function upload_baremetal_image { |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 307 | local image_url=$1 |
| 308 | local token=$2 |
| 309 | |
| 310 | # Create a directory for the downloaded image tarballs. |
| 311 | mkdir -p $FILES/images |
| 312 | |
| 313 | # Downloads the image (uec ami+aki style), then extracts it. |
| 314 | IMAGE_FNAME=`basename "$image_url"` |
| 315 | if [[ ! -f $FILES/$IMAGE_FNAME || \ |
| 316 | "$(stat -c "%s" $FILES/$IMAGE_FNAME)" = "0" ]]; then |
| 317 | wget -c $image_url -O $FILES/$IMAGE_FNAME |
| 318 | if [[ $? -ne 0 ]]; then |
| 319 | echo "Not found: $image_url" |
| 320 | return |
| 321 | fi |
| 322 | fi |
| 323 | |
| 324 | local KERNEL="" |
| 325 | local RAMDISK="" |
| 326 | local DISK_FORMAT="" |
| 327 | local CONTAINER_FORMAT="" |
| 328 | case "$IMAGE_FNAME" in |
| 329 | *.tar.gz|*.tgz) |
| 330 | # Extract ami and aki files |
| 331 | [ "${IMAGE_FNAME%.tar.gz}" != "$IMAGE_FNAME" ] && |
| 332 | IMAGE_NAME="${IMAGE_FNAME%.tar.gz}" || |
| 333 | IMAGE_NAME="${IMAGE_FNAME%.tgz}" |
| 334 | xdir="$FILES/images/$IMAGE_NAME" |
| 335 | rm -Rf "$xdir"; |
| 336 | mkdir "$xdir" |
| 337 | tar -zxf $FILES/$IMAGE_FNAME -C "$xdir" |
| 338 | KERNEL=$(for f in "$xdir/"*-vmlinuz* "$xdir/"aki-*/image; do |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 339 | [ -f "$f" ] && echo "$f" && break; done; true) |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 340 | RAMDISK=$(for f in "$xdir/"*-initrd* "$xdir/"ari-*/image; do |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 341 | [ -f "$f" ] && echo "$f" && break; done; true) |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 342 | IMAGE=$(for f in "$xdir/"*.img "$xdir/"ami-*/image; do |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 343 | [ -f "$f" ] && echo "$f" && break; done; true) |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 344 | if [[ -z "$IMAGE_NAME" ]]; then |
| 345 | IMAGE_NAME=$(basename "$IMAGE" ".img") |
| 346 | fi |
| 347 | DISK_FORMAT=ami |
| 348 | CONTAINER_FORMAT=ami |
| 349 | ;; |
| 350 | *.qcow2) |
| 351 | IMAGE="$FILES/${IMAGE_FNAME}" |
| 352 | IMAGE_NAME=$(basename "$IMAGE" ".qcow2") |
| 353 | DISK_FORMAT=qcow2 |
| 354 | CONTAINER_FORMAT=bare |
| 355 | ;; |
| 356 | *) echo "Do not know what to do with $IMAGE_FNAME"; false;; |
| 357 | esac |
| 358 | |
| 359 | if [ "$CONTAINER_FORMAT" = "bare" ]; then |
| 360 | extract_and_upload_k_and_r_from_image $token $IMAGE |
| 361 | elif [ "$CONTAINER_FORMAT" = "ami" ]; then |
| 362 | KERNEL_ID=$(glance \ |
| 363 | --os-auth-token $token \ |
| 364 | --os-image-url http://$GLANCE_HOSTPORT \ |
| 365 | image-create \ |
Christian Berendt | a7a219a | 2013-07-30 18:22:32 +0200 | [diff] [blame] | 366 | --name "$IMAGE_NAME-kernel" --is-public True \ |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 367 | --container-format aki \ |
| 368 | --disk-format aki < "$KERNEL" | grep ' id ' | get_field 2) |
| 369 | RAMDISK_ID=$(glance \ |
| 370 | --os-auth-token $token \ |
| 371 | --os-image-url http://$GLANCE_HOSTPORT \ |
| 372 | image-create \ |
Christian Berendt | a7a219a | 2013-07-30 18:22:32 +0200 | [diff] [blame] | 373 | --name "$IMAGE_NAME-ramdisk" --is-public True \ |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 374 | --container-format ari \ |
| 375 | --disk-format ari < "$RAMDISK" | grep ' id ' | get_field 2) |
| 376 | else |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 377 | # TODO(deva): add support for other image types |
| 378 | return |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 379 | fi |
| 380 | |
| 381 | glance \ |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 382 | --os-auth-token $token \ |
| 383 | --os-image-url http://$GLANCE_HOSTPORT \ |
| 384 | image-create \ |
| 385 | --name "${IMAGE_NAME%.img}" --is-public True \ |
| 386 | --container-format $CONTAINER_FORMAT \ |
| 387 | --disk-format $DISK_FORMAT \ |
| 388 | ${KERNEL_ID:+--property kernel_id=$KERNEL_ID} \ |
| 389 | ${RAMDISK_ID:+--property ramdisk_id=$RAMDISK_ID} < "${IMAGE}" |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 390 | |
Tim Miller | 9a3ba4b | 2013-03-18 18:08:27 -0700 | [diff] [blame] | 391 | # 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] | 392 | # that we just uploaded in glance |
| 393 | DEFAULT_IMAGE_NAME="${IMAGE_NAME%.img}" |
| 394 | } |
| 395 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 396 | function clear_baremetal_of_all_nodes { |
Arata Notsu | 24f7961 | 2013-02-13 21:01:18 +0900 | [diff] [blame] | 397 | list=$(nova baremetal-node-list | awk -F '| ' 'NR>3 {print $2}' ) |
Sean Dague | 16dd8b3 | 2014-02-03 09:10:54 +0900 | [diff] [blame] | 398 | for node in $list; do |
Arata Notsu | 24f7961 | 2013-02-13 21:01:18 +0900 | [diff] [blame] | 399 | nova baremetal-node-delete $node |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 400 | done |
| 401 | } |
| 402 | |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 403 | # Inform nova-baremetal about nodes, MACs, etc. |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 404 | # Defaults to using BM_FIRST_MAC and BM_SECOND_MAC if parameters not specified |
| 405 | # |
| 406 | # Usage: add_baremetal_node <first_mac> <second_mac> |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 407 | function add_baremetal_node { |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 408 | mac_1=${1:-$BM_FIRST_MAC} |
| 409 | mac_2=${2:-$BM_SECOND_MAC} |
| 410 | |
Arata Notsu | 24f7961 | 2013-02-13 21:01:18 +0900 | [diff] [blame] | 411 | id=$(nova baremetal-node-create \ |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 412 | --pm_address="$BM_PM_ADDR" \ |
| 413 | --pm_user="$BM_PM_USER" \ |
| 414 | --pm_password="$BM_PM_PASS" \ |
| 415 | "$BM_HOSTNAME" \ |
| 416 | "$BM_FLAVOR_CPU" \ |
| 417 | "$BM_FLAVOR_RAM" \ |
| 418 | "$BM_FLAVOR_ROOT_DISK" \ |
| 419 | "$mac_1" \ |
| 420 | | grep ' id ' | get_field 2 ) |
Lucas Alvares Gomes | c33d1f9 | 2013-09-06 18:14:51 +0100 | [diff] [blame] | 421 | [ $? -eq 0 ] || [ "$id" ] || die $LINENO "Error adding baremetal node" |
Arata Notsu | af15d35 | 2013-10-11 21:56:56 +0900 | [diff] [blame] | 422 | if [ -n "$mac_2" ]; then |
| 423 | id2=$(nova baremetal-interface-add "$id" "$mac_2" ) |
| 424 | [ $? -eq 0 ] || [ "$id2" ] || die $LINENO "Error adding interface to barmetal node $id" |
| 425 | fi |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | |
| 429 | # Restore xtrace |
| 430 | $XTRACE |
Sean Dague | 584d90e | 2013-03-29 14:34:53 -0400 | [diff] [blame] | 431 | |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 432 | # Tell emacs to use shell-script-mode |
| 433 | ## Local variables: |
| 434 | ## mode: shell-script |
| 435 | ## End: |