Inserting VZGOT development tree within GIT
[safe/jmp/vzgot] / shell / vzgot.net
1 #! /bin/sh
2 #----------------------------------------------------
3 #shell used to assign/remove route needed by
4 #a container when container is started or stopped
5 #
6 #----------------------------------------------------
7 #Syntaxe
8 #vzgot.net VE_name assign|remove [base_dir]
9 #       VE_name is the container dir name
10 #       "assign" to set container needed route 
11 #       "remove" to reset container needed route 
12 #       base_dir is this application root directory
13 #       used for devel only.
14 #----------------------------------------------------
15 CONTNAME=$1
16 ACTION=$2
17 BASE=$3
18 #----------------------------------------------------
19 if ! [ -f $BASE/etc/vzgot/vzgot_config ] ; then
20   echo "Missing vzgot config file"
21   exit 1        #trouble trouble
22   fi
23 . $BASE/etc/vzgot/vzgot_config
24
25 #specific container configuration override (if needed)
26 if [ -f $BASE/$VZLIB/vzdir/$CONTNAME/vzgot_config ] ; then
27   $BASE/$VZLIB/vzdir/$CONTNAME/vzgot_config
28   fi
29 #----------------------------------------------------
30 FLINUX="RedHat"
31 if [ -f $VZLIB/vzdir/$CONTNAME/linux ] ; then
32   FLINUX=`cat $VZLIB/vzdir/$CONTNAME/linux`
33   fi
34
35 #lets prepare all routing according type of linux
36 #RedHat beeing the default
37 case "$FLINUX" in 
38   "*"           |                                               \
39   "RedHat"      )
40      NETINFO="$BASE/$VZLIB/vzdir/$CONTNAME/rootfs/etc/sysconfig/network-scripts"
41      for f in $NETINFO/ifcfg-*
42        do
43        EXT=`basename $f | cut -d'-' -f2`
44        case "$EXT" in 
45          "lo"   )       #local interface, nothing to do 
46            ;;
47          *      )
48            ADDR=`grep IPADDR $f | cut -d'=' -f2`
49            case "$ACTION" in
50              "assign"   )
51                 #pre-emptive route assignation
52                 /sbin/route add $ADDR dev $BRIDGENAME
53                ;;
54              "remove"   )
55                 /sbin/route del $ADDR dev $BRIDGENAME
56                ;;
57              *          )
58                echo "ACTION request '$ACTION' is unexpected!"
59                ;;
60              esac
61            ;;
62          esac
63        done
64      ;;
65
66   "Debian"      )
67      NETINFO="$BASE/$VZLIB/vzdir/$CONTNAME/rootfs/etc/network"
68      for ADDR in `grep address $NETINFO/interfaces | cut -d' ' -f2`
69        do
70        case "$ACTION" in
71          "assign"       )
72             #pre-emptive route assignation
73             /sbin/route add $ADDR dev $BRIDGENAME
74             ;;
75          "remove"       )
76             /sbin/route del $ADDR dev $BRIDGENAME
77             ;;
78          *              )
79             echo "ACTION request '$ACTION' is unexpected!"
80             ;;
81          esac
82        done
83      ;;
84   esac
85 #----------------------------------------------------
86 exit 0