-
Notifications
You must be signed in to change notification settings - Fork 3
/
prep-networks
executable file
·61 lines (48 loc) · 1.55 KB
/
prep-networks
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
srcdir=$(readlink -m $(dirname $0))
source $srcdir/common
print_help() {
echo "$0 [os type] [provisioning mode: on|off]"
echo
echo "This script generates the virtual mgmt and private networks"
echo
echo "Valid os types are: $IMG_TYPES"
exit 0
}
[ "-h" == "$1" ] && print_help
TYPE=$1
PROVISIONING_MODE=$2
checktype $TYPE
test -z $VMS_DIR && error "VMS_DIR is not set"
vm=zzz-$TYPE
sub=$(getsub $TYPE)
privsub=$(( $sub - 50 ))
ipaddr=192.168.$sub.100
mac=$(grep "zzz-@NAME@" $srcdir/net-mgmt \
| sed 's/.*mac="\(.*\)" name=.*/\1/' | sed "s/@MAC@/$privsub/")
[ -n "$mac" ] && macopt=",mac=$mac"
$VIRSH shutdown $vm > /dev/null 2>&1
virsh_shutdown_wait $vm
foreach_host $TYPE 10 "$VIRSH shutdown" > /dev/null 2>&1
foreach_host $TYPE 10 virsh_shutdown_wait
$VIRSH net-destroy $TYPE-mgmt && $VIRSH net-undefine $TYPE-mgmt
$VIRSH net-destroy $TYPE-priv && $VIRSH net-undefine $TYPE-priv
tmp=$(mktemp)
if [[ "$PROVISIONING_MODE" == "on" ]]; then
info "Setting up $TYPE mgmt network without libvirt dhcp"
sed -e "s/@NAME@/$TYPE/g" -e "s/@SUB@/$sub/g" \
$srcdir/net-mgmt-nodhcp > $tmp
else
info "Setting up $TYPE mgmt network with libvirt dhcp"
sed -e "s/@NAME@/$TYPE/g" -e "s/@SUB@/$sub/g" -e "s/@MAC@/$privsub/g" \
$srcdir/net-mgmt > $tmp
fi
$VIRSH net-define $tmp
tmp=$(mktemp)
sed -e "s/@NAME@/$TYPE/g" -e "s/@SUB@/$privsub/g" \
$srcdir/net-priv > $tmp
$VIRSH net-define $tmp
$VIRSH net-start $TYPE-mgmt
$VIRSH net-autostart $TYPE-mgmt
$VIRSH net-start $TYPE-priv
$VIRSH net-autostart $TYPE-priv