summaryrefslogtreecommitdiffstats
path: root/compass/deploy/setup-env.sh
blob: ffa9aa55a644d41f139fe514f8461c75ca10fbea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
rm -rf compass-install
git clone http://git.openstack.org/stackforge/compass-install
cd compass-install

function join { local IFS="$1"; shift; echo "$*"; }
source ${SCRIPT_DIR}/../deploy/conf/${CONF_NAME}.conf
source ${SCRIPT_DIR}/../deploy/func.sh
if [[ ! -z $VIRT_NUMBER ]]; then
    mac_array=$(${SCRIPT_DIR}/../deploy/mac_generator.sh $VIRT_NUMBER)
    mac_list=$(join , $mac_array)
    echo "pxe_boot_macs: [${mac_list}]" >> install/group_vars/all
    echo "test: true" >> install/group_vars/all
fi
virsh list |grep compass
if [[ $? == 0 ]]; then
    compass_old=`virsh list |grep compass|awk '{print$2}'`
    virsh destroy ${compass_old}
    virsh undefine ${compass_old}
fi
sudo vagrant up compass_nodocker
if [[ $? != 0 ]]; then
    echo "installation of compass failed"
    sudo vagrant destroy compass_nodocker
    exit 1
fi
echo "compass is up"

tear_down_machines
if [[ -n $mac_array ]]; then
    echo "bringing up pxe boot vms"
    i=0
    for mac in $mac_array; do
        echo "creating vm disk for instance pxe${i}"
        sudo qemu-img create -f raw /home/pxe${i}.raw ${VIRT_DISK}
        sudo virt-install --accelerate --hvm --connect qemu:///system \
             --name pxe$i --ram=$VIRT_MEM --pxe --disk /home/pxe$i.raw,format=raw \
             --vcpus=$VIRT_CPUS --graphics vnc,listen=0.0.0.0 \
             --network=bridge:virbr2,mac=$mac \
             --network=bridge:virbr2 \
             --network=bridge:virbr2 \
             --network=bridge:virbr2 \
             --noautoconsole --autostart --os-type=linux --os-variant=rhel6
        if [[ $? != 0 ]]; then
            echo "launching pxe${i} failed"
            exit 1
        fi
        echo "checking pxe${i} state"
        state=$(virsh domstate pxe${i})
        if [[ "$state" == "running" ]]; then
            echo "pxe${i} is running"
            sudo virsh destroy pxe${i}
        fi
        echo "add network boot option and make pxe${i} reboot if failing"
        sudo sed -i "/<boot dev='hd'\/>/ a\    <boot dev='network'\/>" /etc/libvirt/qemu/pxe${i}.xml
        sudo sed -i "/<boot dev='network'\/>/ a\    <bios useserial='yes' rebootTimeout='0'\/>" /etc/libvirt/qemu/pxe${i}.xml
        sudo virsh define /etc/libvirt/qemu/pxe${i}.xml
        sudo virsh start pxe${i}
        let i=i+1
    done
fi
machines=${mac_list}