blob: b018acddc9edc76efd2d980d32bf2a6ee7b0c22b [file] [log] [blame]
Adam Gandelman22ec45e2014-10-16 17:41:22 -07001#!/usr/bin/env bash
2
3# **create-nodes**
4
5# Creates baremetal poseur nodes for ironic testing purposes
6
7set -ex
8
Dean Troyerdc97cb72015-03-28 08:20:50 -05009# Keep track of the DevStack directory
Adam Gandelman22ec45e2014-10-16 17:41:22 -070010TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
11
12NAME=$1
13CPU=$2
14MEM=$(( 1024 * $3 ))
Dean Troyerdc97cb72015-03-28 08:20:50 -050015# Extra G to allow fuzz for partition table : flavor size and registered size
Adam Gandelman22ec45e2014-10-16 17:41:22 -070016# need to be different to actual size.
17DISK=$(( $4 + 1))
18
19case $5 in
20 i386) ARCH='i686' ;;
21 amd64) ARCH='x86_64' ;;
22 *) echo "Unsupported arch $4!" ; exit 1 ;;
23esac
24
25BRIDGE=$6
26EMULATOR=$7
27LOGDIR=$8
28
29LIBVIRT_NIC_DRIVER=${LIBVIRT_NIC_DRIVER:-"e1000"}
30LIBVIRT_STORAGE_POOL=${LIBVIRT_STORAGE_POOL:-"default"}
31LIBVIRT_CONNECT_URI=${LIBVIRT_CONNECT_URI:-"qemu:///system"}
32
33export VIRSH_DEFAULT_CONNECT_URI=$LIBVIRT_CONNECT_URI
34
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
47if [ -n "$LOGDIR" ] ; then
48 mkdir -p "$LOGDIR"
49fi
50
51PREALLOC=
52if [ -f /etc/debian_version ]; then
53 PREALLOC="--prealloc-metadata"
54fi
55
56if [ -n "$LOGDIR" ] ; then
57 VM_LOGGING="--console-log $LOGDIR/${NAME}_console.log"
58else
59 VM_LOGGING=""
60fi
61VOL_NAME="${NAME}.qcow2"
62
63if ! virsh list --all | grep -q $NAME; then
64 virsh vol-list --pool $LIBVIRT_STORAGE_POOL | grep -q $VOL_NAME &&
65 virsh vol-delete $VOL_NAME --pool $LIBVIRT_STORAGE_POOL >&2
66 virsh vol-create-as $LIBVIRT_STORAGE_POOL ${VOL_NAME} ${DISK}G --format qcow2 $PREALLOC >&2
67 volume_path=$(virsh vol-path --pool $LIBVIRT_STORAGE_POOL $VOL_NAME)
68 # Pre-touch the VM to set +C, as it can only be set on empty files.
69 sudo touch "$volume_path"
70 sudo chattr +C "$volume_path" || true
71 $TOP_DIR/scripts/configure-vm \
72 --bootdev network --name $NAME --image "$volume_path" \
73 --arch $ARCH --cpus $CPU --memory $MEM --libvirt-nic-driver $LIBVIRT_NIC_DRIVER \
74 --emulator $EMULATOR --network $BRIDGE $VM_LOGGING >&2
75
76fi
77
78# echo mac
79virsh dumpxml $NAME | grep "mac address" | head -1 | cut -d\' -f2