Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # **create-nodes** |
| 4 | |
| 5 | # Creates baremetal poseur nodes for ironic testing purposes |
| 6 | |
| 7 | set -exu |
| 8 | |
| 9 | # Keep track of the devstack directory |
| 10 | TOP_DIR=$(cd $(dirname "$0")/.. && pwd) |
| 11 | |
| 12 | CPU=$1 |
| 13 | MEM=$(( 1024 * $2 )) |
| 14 | # extra G to allow fuzz for partition table : flavor size and registered size |
| 15 | # need to be different to actual size. |
| 16 | DISK=$(( $3 + 1)) |
| 17 | |
| 18 | case $4 in |
| 19 | i386) ARCH='i686' ;; |
| 20 | amd64) ARCH='x86_64' ;; |
| 21 | *) echo "Unsupported arch $4!" ; exit 1 ;; |
| 22 | esac |
| 23 | |
| 24 | TOTAL=$(($5 - 1)) |
| 25 | BRIDGE=$6 |
| 26 | EMULATOR=$7 |
| 27 | |
| 28 | LIBVIRT_NIC_DRIVER=${LIBVIRT_NIC_DRIVER:-"e1000"} |
| 29 | LIBVIRT_STORAGE_POOL=${LIBVIRT_STORAGE_POOL:-"default"} |
Adam Gandelman | bd93f02 | 2014-03-17 16:31:49 -0700 | [diff] [blame] | 30 | LIBVIRT_CONNECT_URI=${LIBVIRT_CONNECT_URI:-"qemu:///system"} |
| 31 | |
| 32 | export VIRSH_DEFAULT_CONNECT_URI=$LIBVIRT_CONNECT_URI |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 33 | |
| 34 | if ! virsh pool-list --all | grep -q $LIBVIRT_STORAGE_POOL; then |
| 35 | virsh pool-define-as --name $LIBVIRT_STORAGE_POOL dir --target /var/lib/libvirt/images >&2 |
| 36 | virsh pool-autostart $LIBVIRT_STORAGE_POOL >&2 |
| 37 | virsh pool-start $LIBVIRT_STORAGE_POOL >&2 |
| 38 | fi |
| 39 | |
| 40 | pool_state=$(virsh pool-info $LIBVIRT_STORAGE_POOL | grep State | awk '{ print $2 }') |
| 41 | if [ "$pool_state" != "running" ] ; then |
| 42 | [ ! -d /var/lib/libvirt/images ] && sudo mkdir /var/lib/libvirt/images |
| 43 | virsh pool-start $LIBVIRT_STORAGE_POOL >&2 |
| 44 | fi |
| 45 | |
| 46 | PREALLOC= |
| 47 | if [ -f /etc/debian_version ]; then |
| 48 | PREALLOC="--prealloc-metadata" |
| 49 | fi |
| 50 | |
| 51 | DOMS="" |
| 52 | for idx in $(seq 0 $TOTAL) ; do |
| 53 | NAME="baremetal${BRIDGE}_${idx}" |
| 54 | DOMS="$DOMS $NAME" |
| 55 | VOL_NAME="baremetal${BRIDGE}-${idx}.qcow2" |
| 56 | (virsh list --all | grep -q $NAME) && continue |
| 57 | |
| 58 | virsh vol-list --pool $LIBVIRT_STORAGE_POOL | grep -q $VOL_NAME && |
| 59 | virsh vol-delete $VOL_NAME --pool $LIBVIRT_STORAGE_POOL >&2 |
| 60 | virsh vol-create-as $LIBVIRT_STORAGE_POOL ${VOL_NAME} ${DISK}G --format qcow2 $PREALLOC >&2 |
| 61 | volume_path=$(virsh vol-path --pool $LIBVIRT_STORAGE_POOL $VOL_NAME) |
| 62 | # Pre-touch the VM to set +C, as it can only be set on empty files. |
| 63 | sudo touch "$volume_path" |
| 64 | sudo chattr +C "$volume_path" || true |
| 65 | $TOP_DIR/scripts/configure-vm --bootdev network --name $NAME --image "$volume_path" --arch $ARCH --cpus $CPU --memory $MEM --libvirt-nic-driver $LIBVIRT_NIC_DRIVER --emulator $EMULATOR --network $BRIDGE >&2 |
| 66 | done |
| 67 | |
| 68 | for dom in $DOMS ; do |
| 69 | # echo mac |
| 70 | virsh dumpxml $dom | grep "mac address" | head -1 | cut -d\' -f2 |
| 71 | done |