From 40e954735c53eb79d4f8262c2066cad9950548dc Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Mon, 12 Nov 2012 11:47:26 +1300 Subject: [PATCH] Make it possible to set a size from within a flavour, and use that for devstack. --- README.md | 10 ++++++++++ bin/disk-image-create | 6 ++---- docs/ci.md | 8 ++++---- flavours/devstack/README.md | 3 +++ flavours/devstack/block-device-size.d/10-size | 9 +++++++++ lib/common-functions | 9 +++++++++ lib/img-defaults | 2 +- 7 files changed, 38 insertions(+), 9 deletions(-) create mode 100755 flavours/devstack/block-device-size.d/10-size diff --git a/README.md b/README.md index 3f6243b3..7740f96a 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,16 @@ Writing a flavour Make as many of the following subdirectories as you need, depending on what part of the process you need to customise: +* block-device-size.d: Alter the size (in GB) of the disk image. This is useful + when a particular flavour will require a certain minimum (or maximum) size. + You can either error and stop the build, or adjust the size to match. + NB: Due to the current simple implementation, the last output value wins + so this should be used rarely - only one flavour in a mix can reliably set + a size. + + * outputs: $IMAGE\_SIZE={size_in_GB} + * inputs: $IMAGE_SIZE={size_in_GB} + * block-device.d: customise the block device that the image will be made on (e.g. to make partitions). diff --git a/bin/disk-image-create b/bin/disk-image-create index 9f0c394d..34686b2f 100755 --- a/bin/disk-image-create +++ b/bin/disk-image-create @@ -46,6 +46,7 @@ ensure_nbd mk_build_dir ensure_base_available +eval_run_d block-device-size "IMAGE_SIZE=" qemu-img create -f qcow2 $TMP_IMAGE_PATH ${IMAGE_SIZE}G @@ -60,10 +61,7 @@ fi sudo qemu-nbd -c $NBD_DEV $CACHE $TMP_IMAGE_PATH export EXTRA_UNMOUNT="sudo qemu-nbd -d $NBD_DEV" export IMAGE_BLOCK_DEVICE=$NBD_DEV -TEMP=`run_d block-device` -echo "$TEMP" -TEMP=`echo "$TEMP" | grep "IMAGE_BLOCK_DEVICE="` -eval "$TEMP" +eval_run_d block-device "IMAGE_BLOCK_DEVICE=" sudo mkfs -F -t $FS_TYPE -L cloudimg-rootfs ${IMAGE_BLOCK_DEVICE} diff --git a/docs/ci.md b/docs/ci.md index b85e9fb3..68d3ecee 100644 --- a/docs/ci.md +++ b/docs/ci.md @@ -16,7 +16,7 @@ Jenkins * Jobs to build: * bootstrap VM from-scratch (archive bootstrap.qcow2). - disk-image-create vm devstack -o bootstrap.qcow2 -a i386 + disk-image-create vm devstack -o bootstrap -a i386 * devstack nova-bm execution (archive the resulting image). Chained off of the bootstrap vm build @@ -26,17 +26,17 @@ Jenkins * bootstrap VM via image-build chain (archive bm-cloud.qcow2). disk-image-create vm glance nova-bm swift mysql haproxy-api \ - haproxy-mysql cinder quantum rabbitmq -o bootstrap-prod.qcow2 + haproxy-mysql cinder quantum rabbitmq -o bootstrap-prod * baremetal SPOF node build (archive the resulting image). disk-image-create mysql haproxy-mysql haproxy-api local-boot \ - rabbitmq -o baremetal-spof.qcow2 + rabbitmq -o baremetal-spof * baremetal demo node build (archive the resulting image). disk-image-create vm glance nova-bm swift cinder quantum \ - -o bootstrap-prod.qcow2 + -o bootstrap-prod * ramdisk deploy image buil diff --git a/flavours/devstack/README.md b/flavours/devstack/README.md index 6f0e3ae6..5bfadc49 100644 --- a/flavours/devstack/README.md +++ b/flavours/devstack/README.md @@ -1,2 +1,5 @@ Creates an image prepped to make a devstack baremetal cloud. See demo/scripts/demo within the built image. + +This flavour forces a 16GB image to allow room for Swift, Cinder and instance +disk images. diff --git a/flavours/devstack/block-device-size.d/10-size b/flavours/devstack/block-device-size.d/10-size new file mode 100755 index 00000000..df0f0c47 --- /dev/null +++ b/flavours/devstack/block-device-size.d/10-size @@ -0,0 +1,9 @@ +#!/bin/bash +# Add the stack user we recommend folk use. + +set -e +set -x + +if (( '16' '>' $IMAGE_SIZE )); then + echo IMAGE_SIZE=16 +fi diff --git a/lib/common-functions b/lib/common-functions index 736657e8..21eac23b 100644 --- a/lib/common-functions +++ b/lib/common-functions @@ -34,3 +34,12 @@ function check_flavour () { [ -d $TMP_HOOKS_PATH ] || generate_hooks } +# Run a hook, looking for a regex in its stdout, and eval the matched lines. +# $1 is the hook to run +# $2 is the regex to look for +function eval_run_d () { + local TEMP=`run_d $1` + echo "$TEMP" + TEMP=`echo "$TEMP" | grep "$2"` + eval "$TEMP" +} diff --git a/lib/img-defaults b/lib/img-defaults index a693fe14..dbd0c1fa 100644 --- a/lib/img-defaults +++ b/lib/img-defaults @@ -7,7 +7,7 @@ FS_TYPE=${FS_TYPE:-ext4} # Used to set the file extension only at this stage. IMAGE_TYPE=${IMAGE_TYPE:-qcow2} IMAGE_NAME=${IMAGE_NAME:-image} -IMAGE_SIZE=${IMAGE_SIZE:-1} # N.B. This size is in GB +export IMAGE_SIZE=${IMAGE_SIZE:-1} # N.B. This size is in GB # Set via the CLI normally. # IMAGE_FLAVOUR= IMG_PATH=~/.cache/image-create