blob: d81113a4d5f4362bda1b0c1927a2b58a342880ba [file] [log] [blame]
Alexander Gordeev06fb29c2014-01-31 18:02:07 +04001#!/usr/bin/env bash
2
3# **create-nodes**
4
5# Creates baremetal poseur nodes for ironic testing purposes
6
7set -exu
8
9# Keep track of the devstack directory
10TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
11
12CPU=$1
13MEM=$(( 1024 * $2 ))
14# extra G to allow fuzz for partition table : flavor size and registered size
15# need to be different to actual size.
16DISK=$(( $3 + 1))
17
18case $4 in
19 i386) ARCH='i686' ;;
20 amd64) ARCH='x86_64' ;;
21 *) echo "Unsupported arch $4!" ; exit 1 ;;
22esac
23
24TOTAL=$(($5 - 1))
25BRIDGE=$6
26EMULATOR=$7
27
28LIBVIRT_NIC_DRIVER=${LIBVIRT_NIC_DRIVER:-"e1000"}
29LIBVIRT_STORAGE_POOL=${LIBVIRT_STORAGE_POOL:-"default"}
Adam Gandelmanbd93f022014-03-17 16:31:49 -070030LIBVIRT_CONNECT_URI=${LIBVIRT_CONNECT_URI:-"qemu:///system"}
31
32export VIRSH_DEFAULT_CONNECT_URI=$LIBVIRT_CONNECT_URI
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040033
34if ! 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
38fi
39
40pool_state=$(virsh pool-info $LIBVIRT_STORAGE_POOL | grep State | awk '{ print $2 }')
41if [ "$pool_state" != "running" ] ; then
42 [ ! -d /var/lib/libvirt/images ] && sudo mkdir /var/lib/libvirt/images
43 virsh pool-start $LIBVIRT_STORAGE_POOL >&2
44fi
45
46PREALLOC=
47if [ -f /etc/debian_version ]; then
48 PREALLOC="--prealloc-metadata"
49fi
50
51DOMS=""
52for 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
66done
67
68for dom in $DOMS ; do
69 # echo mac
70 virsh dumpxml $dom | grep "mac address" | head -1 | cut -d\' -f2
71done