-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKVMNetworkExport.bash
executable file
·54 lines (46 loc) · 1.8 KB
/
KVMNetworkExport.bash
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
#!/bin/bash
RemoteKVM=cap
StoragePool=/sandbox/KVMMigration
ExcludedNetworks="default kop"
# Get the ID of the remote KVM and remove the double-quote if any
# centos7: ID="centos"
# ovirt 4: ID="centos"
# ubuntu: ID=ubuntu
# powerKVM: ID=ibm_powerkvm
temp=`ssh root@$RemoteKVM "grep \"^ID=\" /etc/os-release" | awk -F= '{print \$2}'`
temp="${temp%\"}"
RemoteID="${temp#\"}"
echo
echo "####################################################################"
echo
echo "the Remote system \"$RemoteKVM\" type is: $RemoteID"
echo
echo "####################################################################"
echo "IMPORTING THE NETWORKS TO THE DESTINATION..."
echo
echo
echo "--> getting the list of networks to import"
ListOfNetworks=""
for i in `virsh net-list --all | awk '{print $1}' | egrep -v 'Name|-------'`
do
if [[ $ExcludedNetworks != *"$i"* ]]; then
ListOfNetworks="$i $ListOfNetworks"
fi
done
echo "Network List to Import : $ListOfNetworks"
echo "--> Generating the files needed to import the networks into $StoragePool/Networks"
mkdir -p $StoragePool/Networks
for i in $ListOfNetworks
do
mkdir $StoragePool/Networks/$i
virsh net-dumpxml $i > $StoragePool/Networks/$i/$i.xml
Bridge=`virsh net-info $i | grep "^Bridge:" | awk -F: '{print $2}' | xargs`
echo $Bridge > $StoragePool/Networks/$i/BridgeName
VLANFile=`grep -l "BRIDGE=\"$Bridge\"" /etc/sysconfig/network-scripts/ifcfg-*`
echo $VLANFile | awk -F"ifcfg-" '{print $2}' > $StoragePool/Networks/$i/VlanName
awk -F. '{print $2}' $StoragePool/Networks/$i/VlanName > $StoragePool/Networks/$i/VlanID
done
echo "---> Copying the $StoragePool/Networks dir to the host $RemoteKVM"
rsync -av $StoragePool/Networks root@$RemoteKVM:$StoragePool
echo "---> Deleting $StoragePool/Networks from local source as not needed anymore"
rm -rf $StoragePool/Networks