Automatic Deployment
[genesis.git] / fuel / deploy / setup_vms / apply_setup.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2015 Ericsson AB and others.
4 # stefan.k.berg@ericsson.com
5 # jonas.bjurel@ericsson.com
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 error_exit () {
13   echo "$@"
14   exit 1
15 }
16
17 netdir='../libvirt/networks'
18 vmdir='../libvirt/vms'
19 tmpfile=/tmp/foo
20
21 if [ ! -d $netdir ]; then
22   error_exit "No net directory $netdir"
23   exit 1
24 elif [ ! -d $vmdir ]; then
25   error_exit "No VM directory $vmdir"
26   exit 1
27 fi
28
29 if [ $# -ne 2 ]; then
30   echo "Argument error."
31   echo "`basename $0` <path to storage dir> <size in GB of disk per VM>"
32   exit 1
33 fi
34
35 storagedir=$1
36 size=$2
37
38 if [ ! -d $storagedir ]; then
39   error_exit "Could not find storagedir directory $storagedir"
40 fi
41
42 # Create storage space and patch it in
43 for vm in $vmdir/*
44 do
45   storage=${storagedir}/`basename ${vm}`.raw
46   if [ -f ${storage} ]; then
47      error_exit "Storage already present: ${storage}"
48   fi
49   echo "Creating ${size} GB of storage in ${storage}"
50   fallocate -l ${size}G ${storage} || \
51     error_exit "Could not create storage"
52   sed "s:<source file='disk.raw':<source file='${storage}':" $vm >$tmpfile
53   virsh define $tmpfile
54 done
55
56 for net in $netdir/*
57 do
58   virsh net-define $net
59   virsh net-autostart `basename $net`
60   virsh net-start `basename $net`
61 done