OSDN Git Service

Improvement of network function
authorNIWA Hideyuki <niwa.niwa@nifty.ne.jp>
Fri, 11 Mar 2016 06:53:59 +0000 (15:53 +0900)
committerNIWA Hideyuki <niwa.niwa@nifty.ne.jp>
Fri, 11 Mar 2016 06:53:59 +0000 (15:53 +0900)
README.md
src/README
src/doc/help.txt
src/slot-os/erase
src/slot-os/net-add
src/slot-os/net-del
src/subcmd/net-add
src/subcmd/net-del

index 193d860..2e97e0e 100644 (file)
--- a/README.md
+++ b/README.md
@@ -110,7 +110,7 @@ $  sudo fulcon del-user webap-server tom
  
 #### 3.Virtual NIC addition  
   
-$  sudo fulcon net-add webap-server 192.168.17.2/24  
+$  sudo fulcon net-add webap-server 192.168.17.2/24  
   
 Information of network is able to be taken  by "fulcon net-info".  
  
@@ -123,7 +123,7 @@ IP-address specifies it within the range of same netmask as the shared device.
 In the following example, when it is NIC "eth1" and the address is 
 "192.168.0.2/24", "192.168.0.12/24" is allocated in the container.
  
-$ sudo fulcon net-add -d eth1 webap-server 192.168.0.12/24
+$ sudo fulcon net-add -d eth1 webap-server 192.168.0.12/24
   
 #### 4.Attache console to the container.
   
@@ -234,11 +234,8 @@ ls-image
 ls-ocf  
      The list of the OCF image is displayed.  
   
-net-add -n VETH_NUMBER [-d NIC_DEVICE] [-g GATEWAY] [-b BRIDGE_NUMBER ] CONTAINER_NAME IP_ADDR/MASK  
+net-add [-d NIC_DEVICE] [-g GATEWAY] [-b BRIDGE_NUMBER ] VETH_NUMBER CONTAINER_NAME IP_ADDR/MASK  
      NIC is added to the container.   
-     -n VETH_NUMBER  
-          NIC that combines "Container name and specified number" is added.  
-          ex) VETH_NUMBER is 1 and container is "abc" -> nic "abc1"  
      -d NIC_DEVICE  
           The device to connect it to an external network is specified.   
      -g GATEWAY
@@ -246,10 +243,13 @@ net-add -n VETH_NUMBER [-d NIC_DEVICE] [-g GATEWAY] [-b BRIDGE_NUMBER ] CONTAINE
      -b BRIDGE_NUMBER
           BRIDGE that combines "'fulcon' and specified number" is added.  
           ex) BRIDGE_NUMBER is 2 -> nic "fulcon2"  
+     VETH_NUMBER  
+          NIC that combines "Container name and specified number" is added.  
+          ex) VETH_NUMBER is 1 and container is "abc" -> nic "abc1"  
   
-net-del -n VETH_NUMBER CONTAINER_NAME  
+net-del VETH_NUMBER CONTAINER_NAME  
      NIC is deleted from the container.   
-     -n VETH_NUMBER  
+     VETH_NUMBER  
           NIC that combines "Container name and specified number" is added.  
           ex) VETH_NUMBER is 1 and container is "abc" -> nic "abc1"  
   
index 193d860..2e97e0e 100644 (file)
@@ -110,7 +110,7 @@ $  sudo fulcon del-user webap-server tom
  
 #### 3.Virtual NIC addition  
   
-$  sudo fulcon net-add webap-server 192.168.17.2/24  
+$  sudo fulcon net-add webap-server 192.168.17.2/24  
   
 Information of network is able to be taken  by "fulcon net-info".  
  
@@ -123,7 +123,7 @@ IP-address specifies it within the range of same netmask as the shared device.
 In the following example, when it is NIC "eth1" and the address is 
 "192.168.0.2/24", "192.168.0.12/24" is allocated in the container.
  
-$ sudo fulcon net-add -d eth1 webap-server 192.168.0.12/24
+$ sudo fulcon net-add -d eth1 webap-server 192.168.0.12/24
   
 #### 4.Attache console to the container.
   
@@ -234,11 +234,8 @@ ls-image
 ls-ocf  
      The list of the OCF image is displayed.  
   
-net-add -n VETH_NUMBER [-d NIC_DEVICE] [-g GATEWAY] [-b BRIDGE_NUMBER ] CONTAINER_NAME IP_ADDR/MASK  
+net-add [-d NIC_DEVICE] [-g GATEWAY] [-b BRIDGE_NUMBER ] VETH_NUMBER CONTAINER_NAME IP_ADDR/MASK  
      NIC is added to the container.   
-     -n VETH_NUMBER  
-          NIC that combines "Container name and specified number" is added.  
-          ex) VETH_NUMBER is 1 and container is "abc" -> nic "abc1"  
      -d NIC_DEVICE  
           The device to connect it to an external network is specified.   
      -g GATEWAY
@@ -246,10 +243,13 @@ net-add -n VETH_NUMBER [-d NIC_DEVICE] [-g GATEWAY] [-b BRIDGE_NUMBER ] CONTAINE
      -b BRIDGE_NUMBER
           BRIDGE that combines "'fulcon' and specified number" is added.  
           ex) BRIDGE_NUMBER is 2 -> nic "fulcon2"  
+     VETH_NUMBER  
+          NIC that combines "Container name and specified number" is added.  
+          ex) VETH_NUMBER is 1 and container is "abc" -> nic "abc1"  
   
-net-del -n VETH_NUMBER CONTAINER_NAME  
+net-del VETH_NUMBER CONTAINER_NAME  
      NIC is deleted from the container.   
-     -n VETH_NUMBER  
+     VETH_NUMBER  
           NIC that combines "Container name and specified number" is added.  
           ex) VETH_NUMBER is 1 and container is "abc" -> nic "abc1"  
   
index 6347f90..03c5037 100644 (file)
@@ -81,11 +81,8 @@ ls-image
 ls-ocf  
      The list of the OCF image is displayed.  
   
-net-add -n VETH_NUMBER [-d NIC_DEVICE] [-g GATEWAY] [-b BRIDGE_NUMBER ] CONTAINER_NAME IP_ADDR/MASK  
+net-add [-d NIC_DEVICE] [-g GATEWAY] [-b BRIDGE_NUMBER ] VETH_NUMBER CONTAINER_NAME IP_ADDR/MASK  
      NIC is added to the container.   
-     -n VETH_NUMBER  
-          NIC that combines "Container name and specified number" is added.  
-          ex) VETH_NUMBER is 1 and container is "abc" -> nic "abc1"  
      -d NIC_DEVICE  
           The device to connect it to an external network is specified.   
      -g GATEWAY
@@ -93,10 +90,13 @@ net-add -n VETH_NUMBER [-d NIC_DEVICE] [-g GATEWAY] [-b BRIDGE_NUMBER ] CONTAINE
      -b BRIDGE_NUMBER
           BRIDGE that combines "'fulcon' and specified number" is added.  
           ex) BRIDGE_NUMBER is 2 -> nic "fulcon2"  
+     VETH_NUMBER  
+          NIC that combines "Container name and specified number" is added.  
+          ex) VETH_NUMBER is 1 and container is "abc" -> nic "abc1"  
   
-net-del -n VETH_NUMBER CONTAINER_NAME  
+net-del VETH_NUMBER CONTAINER_NAME  
      NIC is deleted from the container.   
-     -n VETH_NUMBER  
+     VETH_NUMBER  
           NIC that combines "Container name and specified number" is added.  
           ex) VETH_NUMBER is 1 and container is "abc" -> nic "abc1"  
   
index 1141ada..913b947 100755 (executable)
@@ -41,6 +41,7 @@ do
        fi
 
        fulcon erase $NAME
+       rm -rf $SLOTOSDIR/slot/$SNUM/net
 
        echo '-' > $SLOTOSDIR/slot/$SNUM/fulcon
 done
index acdd776..6920277 100755 (executable)
@@ -4,10 +4,69 @@
 
 FULCONDRIVER=`fulcon driver-name`
 PATH=/usr/lib/fulcon/driver/$FULCONDRIVER:/usr/lib/fulcon/lib:$PATH
-
 SLOTOSDIR=/var/lib/slot-os
 
+umask 022
+
+# function usage
+usage()
+{
+       echo "usage: net-add [ -d NETDEV ] [ -g GATEWAY ] [ -b BRIDGE_NUMBER ] NIC_NUMBER SLOT_NUMBER IPADDR/MASK "
+}
+
+lsdir() {
+  ls -f --ind=none $1 | sed '/^\.\{1,2\}$/d'
+}
+
+# check options
+FLG_D=0 ; NETDEV=""
+FLG_G=0 ; LXCGATEWAY=""
+FLG_B=0 ; LXCBR="0"
+
+while getopts d:g:b: OPT ; do
+  case $OPT in
+  d) FLG_D=1 ; NETDEV=$OPTARG ;;
+  g) FLG_G=1 ; LXCGATEWAY=$OPTARG ;;
+  b) FLG_B=1 ; LXCBR=$OPTARG ;;
+  \? ) usage; exit -1;;
+  esac
+done
+shift $((OPTIND - 1))
+
+# check args
+if [ $# -ne 3 ]; then
+       usage
+       exit -1
+fi
+
+NICNO=$1
+SLOTNO=$2
+IPADDR=$3
+if [ ! -d $SLOTOSDIR/slot/$SLOTNO ]; then
+       echo "error: $SLOTNO is not exist"
+       exit -1
+fi
+
+NAME=`cat $SLOTOSDIR/slot/$SLOTNO/fulcon`
+
+NEWOPT=""
+if [ $FLG_D -ne 0 ]; then
+       NEWOPT="$NEWOPT -d $NETDEV"
+fi
+if [ $FLG_G -ne 0 ]; then
+       NEWOPT="$NEWOPT -g $LXCGATEWAY"
+fi
+if [ $FLG_B -ne 0 ]; then
+       NEWOPT="$NEWOPT -b $LXCBR"
+fi
+
+NEWOPT="$NEWOPT $NICNO $NAME $IPADDR"
 
-fulcon net-add $*
+fulcon net-add $NEWOPT
 
+if [ $? -eq 0 ]; then
+       rm -rf  $SLOTOSDIR/slot/$SLOTNO/net
+       cp -pr /var/lib/fulcon/container/$NAME/net $SLOTOSDIR/slot/$SLOTNO/
+fi
 
+exit 0
index 6ff6f87..4728ba6 100755 (executable)
@@ -8,6 +8,27 @@ PATH=/usr/lib/fulcon/driver/$FULCONDRIVER:/usr/lib/fulcon/lib:$PATH
 SLOTOSDIR=/var/lib/slot-os
 
 
-fulcon net-del $*
+usage()
+{
+       echo "usage: net-del NIC_NUMBER SLOT_NUMBER"
+}
 
+# check args
+if [ $# -ne 2 ]; then
+       usage
+       exit -1
+fi
+
+NICNUM=$1
+SLOTNO=$2
+NAME=`cat $SLOTOSDIR/slot/$SLOTNO/fulcon`
+
+fulcon net-del $NICNUM $NAME
+
+if [ $? -eq 0 ]; then
+       rm -rf  $SLOTOSDIR/slot/$SLOTNO/net
+       cp -pr /var/lib/fulcon/container/$NAME/net $SLOTOSDIR/slot/$SLOTNO/
+fi
+
+exit 0
 
index 2d88f68..92402c2 100755 (executable)
@@ -12,21 +12,19 @@ umask 022
 # function usage
 usage()
 {
-       echo "usage: net-add -n NUMBER  [ -d NETDEV ] [ -g GATEWAY ] [ -b BRIDGE_NUMBER ] CONTAINER_NAME IPADDR/MASK [ MAC1 MAC2 ]"
+       echo "usage: net-add [ -d NETDEV ] [ -g GATEWAY ] [ -b BRIDGE_NUMBER ] NIC_NUMBER CONTAINER_NAME IPADDR/MASK [ MAC1 MAC2 ]"
 }
 
 NETARGS=$@
 
 # check options
 FLG_D=0 ; NETDEV=""
-FLG_N=0 ; NUM=""
 FLG_G=0 ; LXCGATEWAY=""
 FLG_B=0 ; LXCBR="0"
 
-while getopts d:n:g:b: OPT ; do
+while getopts d:g:b: OPT ; do
   case $OPT in
   d) FLG_D=1 ; NETDEV=$OPTARG ;;
-  n) FLG_N=1 ; NUM=$OPTARG ;;
   g) FLG_G=1 ; LXCGATEWAY=$OPTARG ;;
   b) FLG_B=1 ; LXCBR=$OPTARG ;;
   \? ) usage; exit -1;;
@@ -35,23 +33,16 @@ done
 shift $((OPTIND - 1))
 
 # check args
-if [ $# -ne 2 -a $# -ne 4 ]; then
+if [ $# -ne 3 -a $# -ne 5 ]; then
        usage
        exit -1
 fi
 
-# check number
-if [ $FLG_N -ne 1 ]; then
-       usage
-       echo 'error: It is necessary to specify "-n NUMBER"'
-       exit -1
-fi
-
 # get mac address
-if [ $# -eq 4 ]; then
+if [ $# -eq 5 ]; then
        MACFLG=1
-       MAC1=$3
-       MAC2=$4
+       MAC1=$4
+       MAC2=$5
 else
        MACFLG=0
        MAC1=""
@@ -73,15 +64,16 @@ if [ $? -gt 1 ]; then
 fi
 LXCBR="fulcon"$LXCBR
 
-LXCNAME=$1
-LXCBRIP=`net-ipv4 -g $2`
+NUM=$1
+LXCNAME=$2
+LXCBRIP=`net-ipv4 -g $3`
 if [ $? -ne 0 ]; then
-       echo $2 "must be IP_address/Mask format"
+       echo $3 "must be IP_address/Mask format"
        exit -1
 fi
 
-LXCIP=`echo $2 | awk -F / '{printf "%s",$1}'`
-LXCMASK=`echo $2 | awk -F / '{printf "%s",$2}'`
+LXCIP=`echo $3 | awk -F / '{printf "%s",$1}'`
+LXCMASK=`echo $3 | awk -F / '{printf "%s",$2}'`
 
 if [ x$LXCGATEWAY == x"" ]; then
        LXCGATEWAY=$LXCBRIP
@@ -114,7 +106,7 @@ ip link add name ${LXCNAME}${NUM} type veth peer name vg${LXCNAME}${NUM} >& /dev
 
 # set/get MAC1
 if [ x"$MAC1" != x"" ]; then
-       ip link set ${LXCNAME}${NUM} address $MAC1
+       ip link set ${LXCNAME}${NUM} address $MAC1 
 else
        MAC1=`ip addr show ${LXCNAME}${NUM} | egrep link/ether | awk '{print $2}'`
 fi
index 9b5faa0..9fc9a17 100755 (executable)
@@ -15,34 +15,17 @@ fi
 
 usage()
 {
-       echo "usage: net-del -n NUMBER CONTAINER_NAME"
+       echo "usage: net-del NIC_NUMBER CONTAINER_NAME"
 }
 
-# check options
-FLG_N=0 ; NUM=""
-
-while getopts n: OPT ; do
-  case $OPT in
-  n) FLG_N=1 ; NUM=$OPTARG ;;
-  \? ) usage; exit -1;;
-  esac
-done
-shift $((OPTIND - 1))
-
 # check args
-if [ $# -ne 1 ]; then
-       usage
-       exit -1
-fi
-
-# check number
-if [ $FLG_N -ne 1 ]; then
+if [ $# -ne 2 ]; then
        usage
-       echo 'error: It is necessary to specify "-n NUMBER"'
        exit -1
 fi
 
-LXCNAME=$1
+NUM=$1
+LXCNAME=$2
 brctl show  |& egrep ${LXCNAME}${NUM} >& /dev/null
 if [ $? -ne 0 ]; then
        echo "error: can't find" ${LXCNAME}${NUM}