blob: 140bffe46f882df99579ff01dba166d0fe2cbf28 [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
Adam Gandelman8af6fae2014-04-11 17:06:14 -07007set -ex
Alexander Gordeev06fb29c2014-01-31 18:02:07 +04008
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
Adam Gandelman8af6fae2014-04-11 17:06:14 -070027LOGDIR=$8
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040028
29LIBVIRT_NIC_DRIVER=${LIBVIRT_NIC_DRIVER:-"e1000"}
30LIBVIRT_STORAGE_POOL=${LIBVIRT_STORAGE_POOL:-"default"}
Adam Gandelmanbd93f022014-03-17 16:31:49 -070031LIBVIRT_CONNECT_URI=${LIBVIRT_CONNECT_URI:-"qemu:///system"}
32
33export VIRSH_DEFAULT_CONNECT_URI=$LIBVIRT_CONNECT_URI
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040034
35if ! virsh pool-list --all | grep -q $LIBVIRT_STORAGE_POOL; then
36 virsh pool-define-as --name $LIBVIRT_STORAGE_POOL dir --target /var/lib/libvirt/images >&2
37 virsh pool-autostart $LIBVIRT_STORAGE_POOL >&2
38 virsh pool-start $LIBVIRT_STORAGE_POOL >&2
39fi
40
41pool_state=$(virsh pool-info $LIBVIRT_STORAGE_POOL | grep State | awk '{ print $2 }')
42if [ "$pool_state" != "running" ] ; then
43 [ ! -d /var/lib/libvirt/images ] && sudo mkdir /var/lib/libvirt/images
44 virsh pool-start $LIBVIRT_STORAGE_POOL >&2
45fi
46
Adam Gandelman8af6fae2014-04-11 17:06:14 -070047if [ -n "$LOGDIR" ] ; then
48 mkdir -p "$LOGDIR"
49fi
50
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040051PREALLOC=
52if [ -f /etc/debian_version ]; then
53 PREALLOC="--prealloc-metadata"
54fi
55
56DOMS=""
57for idx in $(seq 0 $TOTAL) ; do
58 NAME="baremetal${BRIDGE}_${idx}"
Adam Gandelman8af6fae2014-04-11 17:06:14 -070059 if [ -n "$LOGDIR" ] ; then
60 VM_LOGGING="--console-log $LOGDIR/${NAME}_console.log"
61 else
62 VM_LOGGING=""
63 fi
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040064 DOMS="$DOMS $NAME"
65 VOL_NAME="baremetal${BRIDGE}-${idx}.qcow2"
66 (virsh list --all | grep -q $NAME) && continue
67
68 virsh vol-list --pool $LIBVIRT_STORAGE_POOL | grep -q $VOL_NAME &&
69 virsh vol-delete $VOL_NAME --pool $LIBVIRT_STORAGE_POOL >&2
70 virsh vol-create-as $LIBVIRT_STORAGE_POOL ${VOL_NAME} ${DISK}G --format qcow2 $PREALLOC >&2
71 volume_path=$(virsh vol-path --pool $LIBVIRT_STORAGE_POOL $VOL_NAME)
72 # Pre-touch the VM to set +C, as it can only be set on empty files.
73 sudo touch "$volume_path"
74 sudo chattr +C "$volume_path" || true
Adam Gandelman8af6fae2014-04-11 17:06:14 -070075 $TOP_DIR/scripts/configure-vm \
76 --bootdev network --name $NAME --image "$volume_path" \
77 --arch $ARCH --cpus $CPU --memory $MEM --libvirt-nic-driver $LIBVIRT_NIC_DRIVER \
78 --emulator $EMULATOR --network $BRIDGE $VM_LOGGING >&2
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040079done
80
81for dom in $DOMS ; do
82 # echo mac
83 virsh dumpxml $dom | grep "mac address" | head -1 | cut -d\' -f2
84done