b65cf31640da51fc8e1aebb765eb794dabf980ad
[genesis.git] / fuel / prototypes / libvirt / setup_vms / 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 netdir='../examples/networks'
13 vmdir='../examples/vms'
14
15 if [ -d $netdir ]; then
16   echo "Net directory already present"
17   exit 1
18 elif [ -d $vmdir ]; then
19   echo "VM directory already present"
20   exit 1
21 fi
22
23 mkdir -p $netdir
24 mkdir -p $vmdir
25
26 # Check that no VM is up
27 if virsh list | egrep -q "fuel-master|controller|compute" ; then
28   echo "Can't dump while VMs are up:"
29   virsh list | egrep "fuel-master|controller|compute"
30   exit 1
31 fi
32
33 # Dump all networks in the fuell* namespace
34 for net in `virsh net-list --all | tail -n+3 | awk '{ print $1 }' | grep fuel`
35 do
36   virsh net-dumpxml $net > $netdir/$net
37 done
38
39 # Dump all fuel-master, compute* and controller* VMs
40 for vm in `virsh list --all | tail -n+3 | awk '{ print $2 }' | egrep 'fuel-master|compute|controller'`
41 do
42   virsh dumpxml $vm > $vmdir/$vm
43 done
44
45 # Remove all attached ISOs, generalize the rest of the setup
46 for vm in $vmdir/*
47 do
48   sed -i '/.iso/d' $vm
49   sed -i "s/<source file='.*raw'/<source file='disk.raw'/" $vm
50   sed -i '/<uuid/d' $vm
51   sed -i '/<mac/d' $vm
52 done
53
54 # Generalize all nets
55 for net in $netdir/*
56 do
57   sed -i '/<uuid/d' $net
58   sed -i '/<mac/d' $net
59 done