Updates docs for SR1 with final revision
[genesis.git] / fuel / prototypes / auto-deploy / examples / libvirt / tools / dump_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 topdir=$(cd $(dirname $(readlink -f $BASH_SOURCE)); cd ..; pwd)
13 netdir=$topdir/conf/networks
14 vmdir=$topdir/conf/vms
15 vms="fuel-master controller1 compute4 compute5"
16 networks="fuel1 fuel2 fuel3 fuel4"
17
18
19 if [ "`whoami`" != "root" ]; then
20   error_exit "You need be root to run this script"
21 fi
22
23 mkdir -p $netdir
24 mkdir -p $vmdir
25
26 if [ `ls -1 $netdir/ | wc -l` -ne 0 ]; then
27   echo "There are files in $netdir already!"
28   exit 1
29 elif [ `ls -1 $vmdir/ | wc -l` -ne 0 ]; then
30   echo "There are files in $vmdir already!"
31   exit 1
32 fi
33
34
35 # Check that no VM is up
36 for vm in $vms
37 do
38     if [ "`virsh domstate $vm`" == "running" ]; then
39         echo "Can't dump while VM are up: $vm"
40         exit 1
41     fi
42 done
43
44 # Dump all networks in the fuell* namespace
45 for net in $networks
46 do
47   virsh net-dumpxml $net > $netdir/$net
48 done
49
50 # Dump all fuel-master, compute* and controller* VMs
51 for vm in $vms
52 do
53   virsh dumpxml $vm > $vmdir/$vm
54 done
55
56 # Remove all attached ISOs, generalize disk file
57 for vm in $vmdir/*
58 do
59   sed -i '/.iso/d' $vm
60   sed -i "s/<source file='.*raw'/<source file='disk.raw'/" $vm
61 done
62
63 # Generalize all nets
64 for net in $netdir/*
65 do
66   sed -i '/<uuid/d' $net
67   sed -i '/<mac/d' $net
68 done