summaryrefslogtreecommitdiffstats
path: root/fuel/deploy/setup_vms/apply_setup.sh
blob: b38cf5dbae35dc4c9c91d3a7a07961f237752ceb (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
#!/bin/bash
##############################################################################
# Copyright (c) 2015 Ericsson AB and others.
# stefan.k.berg@ericsson.com
# jonas.bjurel@ericsson.com
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

error_exit () {
  echo "$@"
  exit 1
}

netdir='../libvirt/networks'
vmdir='../libvirt/vms'
tmpfile=/tmp/foo

if [ ! -d $netdir ]; then
  error_exit "No net directory $netdir"
  exit 1
elif [ ! -d $vmdir ]; then
  error_exit "No VM directory $vmdir"
  exit 1
fi

if [ $# -ne 2 ]; then
  echo "Argument error."
  echo "`basename $0` <path to storage dir> <size in GB of disk per VM>"
  exit 1
fi

storagedir=$1
size=$2

if [ ! -d $storagedir ]; then
  error_exit "Could not find storagedir directory $storagedir"
fi

# Create storage space and patch it in
for vm in $vmdir/*
do
  storage=${storagedir}/`basename ${vm}`.raw
  if [ -f ${storage} ]; then
     error_exit "Storage already present: ${storage}"
  fi
  echo "Creating ${size} GB of storage in ${storage}"
  fallocate -l ${size}G ${storage} || \
    error_exit "Could not create storage"
  sed "s:<source file='disk.raw':<source file='${storage}':" $vm >$tmpfile
  virsh define $tmpfile
done

for net in $netdir/*
do
  virsh net-define $net
  virsh net-autostart `basename $net`
  virsh net-start `basename $net`
done