OSDN Git Service

The function to add or to delete the ip address is added to the container.
authorNIWA Hideyuki <niwa.hideyuki@jp.fujitsu.com>
Mon, 29 Dec 2014 12:52:24 +0000 (21:52 +0900)
committerNIWA Hideyuki <niwa.hideyuki@jp.fujitsu.com>
Mon, 29 Dec 2014 12:52:24 +0000 (21:52 +0900)
lxcf/Makefile
lxcf/cmd/add-ipaddr [new file with mode: 0755]
lxcf/cmd/del-ipaddr [new file with mode: 0755]
lxcf/lib/lxcf-add-ipaddr [new file with mode: 0755]
lxcf/lib/lxcf-del-ipaddr [new file with mode: 0755]
lxcf/lib/lxcf-find-init
lxcf/lxcf.spec

index c54887b..eb823bb 100644 (file)
@@ -146,6 +146,8 @@ install_lib_lxcf: .prepare
        install -m 755 lib/lxcf-rename $(DESTDIR)$(libdir)/lxcf/lxcf-rename
        install -m 755 lib/lxcf-snapshot-pull $(DESTDIR)$(libdir)/lxcf/lxcf-snapshot-pull
        install -m 755 lib/lxcf-find-init $(DESTDIR)$(libdir)/lxcf/lxcf-find-init
+       install -m 755 lib/lxcf-add-ipaddr $(DESTDIR)$(libdir)/lxcf/lxcf-add-ipaddr
+       install -m 755 lib/lxcf-del-ipaddr $(DESTDIR)$(libdir)/lxcf/lxcf-del-ipaddr
 
 install_sbin_lxcf: .prepare
        install -d -m 755 $(DESTDIR)$(sbindir)
@@ -202,6 +204,8 @@ install_sbin_lxcf: .prepare
        install -m 755 cmd/api $(DESTDIR)$(libdir)/lxcf/sbin/api
        install -m 755 cmd/api-passwd $(DESTDIR)$(libdir)/lxcf/sbin/api-passwd
        install -m 755 cmd/snapshot-pull $(DESTDIR)$(libdir)/lxcf/sbin/snapshot-pull
+       install -m 755 cmd/add-ipaddr $(DESTDIR)$(libdir)/lxcf/sbin/add-ipaddr
+       install -m 755 cmd/del-ipaddr $(DESTDIR)$(libdir)/lxcf/sbin/del-ipaddr
 
 install_conf: .prepare
        install -m 644 conf/helpfile.txt $(DESTDIR)$(libdir)/lxcf/helpfile.txt
diff --git a/lxcf/cmd/add-ipaddr b/lxcf/cmd/add-ipaddr
new file mode 100755 (executable)
index 0000000..0cb5997
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/bash
+# copyright (C) 2014 FUJITSU LIMITED All Rights Reserved
+
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; version 2
+# of the License.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
+# 02110-1301, USA.
+
+# check root
+if [ ${EUID:-${UID}} != 0 ]; then
+    echo "error: Because you are not root, you cannot execute this command. "
+    exit 1
+fi
+
+/usr/lib64/lxcf/lxcf-add-ipaddr $*
+
+exit $?
+
diff --git a/lxcf/cmd/del-ipaddr b/lxcf/cmd/del-ipaddr
new file mode 100755 (executable)
index 0000000..dec3d96
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/bash
+# copyright (C) 2014 FUJITSU LIMITED All Rights Reserved
+
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; version 2
+# of the License.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
+# 02110-1301, USA.
+
+# check root
+if [ ${EUID:-${UID}} != 0 ]; then
+    echo "error: Because you are not root, you cannot execute this command. "
+    exit 1
+fi
+
+/usr/lib64/lxcf/lxcf-del-ipaddr $*
+
+exit $?
+
diff --git a/lxcf/lib/lxcf-add-ipaddr b/lxcf/lib/lxcf-add-ipaddr
new file mode 100755 (executable)
index 0000000..848d8ce
--- /dev/null
@@ -0,0 +1,77 @@
+#!/bin/bash
+# copyright (C) 2013-2014 FUJITSU LIMITED All Rights Reserved
+
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; version 2
+# of the License.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
+# 02110-1301, USA.
+
+# check distro
+DISTRO=`/usr/lib64/lxcf/lxcf-distro`
+
+# check root
+if [ ${EUID:-${UID}} != 0 ]; then
+    echo "error: Because you are not root, you cannot execute this command. "
+    exit 1
+fi
+
+# check args
+if [ $# -ne 4 ]; then
+       echo "usage: lxcf-add-ipaddr CONTAINER_NAME Number IPADDR BRIDGHE "
+       exit -1
+fi
+
+LXCNAME=$1
+LXCNUM=$2
+LXCIP=$3
+LXCBR=$4
+LXCBRIP=`echo $3 | awk -F . '{printf "%s.%s.%s.1\n",$1,$2,$3}'`
+
+LXCPROC=`/usr/lib64/lxcf/lxcf-find-init $LXCNAME`
+if [ $? -ne 0 ]; then
+       echo "error: can't find" $LXCNAME
+       exit -1
+fi
+
+mkdir -p /var/run/netns/
+ln -s /proc/${LXCPROC}/ns/net /var/run/netns/$LXCNAME
+
+brctl show $LXCBR |& egrep 'No such device' >& /dev/null
+if [ $? -eq 0 ]; then
+       brctl addbr $LXCBR
+       ip link set $LXCBR up
+       ip addr add ${LXCBRIP}/24 dev $LXCBR
+fi
+
+brctl show $LXCBR |& egrep vh${LXCNAME}${LXCNUM} >& /dev/null
+if [ $? -eq 0 ]; then
+       ip link delete vh${LXCNAME}${LXCNUM} type veth 
+fi
+
+ip link add name vh${LXCNAME}${LXCNUM} type veth peer name vg${LXCNAME}${LXCNUM}
+ip link set vh${LXCNAME}${LXCNUM} up
+brctl addif $LXCBR vh${LXCNAME}${LXCNUM}
+
+ip link set vg${LXCNAME}${LXCNUM} netns $LXCNAME
+
+# Setting of network in container
+ip netns exec $LXCNAME ip link set vg${LXCNAME}${LXCNUM} name eth${LXCNUM}
+
+ip netns exec $LXCNAME ip addr add ${LXCIP}/24 dev eth${LXCNUM}
+ip netns exec $LXCNAME ip link set eth${LXCNUM} up
+ip netns exec $LXCNAME ip route delete default >& /dev/null
+ip netns exec $LXCNAME ip route add default via ${LXCBRIP}
+
+rm -f /var/run/netns/$LXCNAME
+
+exit 0
diff --git a/lxcf/lib/lxcf-del-ipaddr b/lxcf/lib/lxcf-del-ipaddr
new file mode 100755 (executable)
index 0000000..788762e
--- /dev/null
@@ -0,0 +1,44 @@
+#!/bin/bash
+# copyright (C) 2013-2014 FUJITSU LIMITED All Rights Reserved
+
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; version 2
+# of the License.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
+# 02110-1301, USA.
+
+# check distro
+DISTRO=`/usr/lib64/lxcf/lxcf-distro`
+
+# check root
+if [ ${EUID:-${UID}} != 0 ]; then
+    echo "error: Because you are not root, you cannot execute this command. "
+    exit 1
+fi
+
+# check args
+if [ $# -ne 2 ]; then
+       echo "usage: lxcf-del-ipaddr CONTAINER_NAME Number"
+       exit -1
+fi
+
+LXCNAME=$1
+LXCNUM=$2
+brctl show $LXCBR |& egrep vh${LXCNAME}${LXCNUM} >& /dev/null
+if [ $? -ne 0 ]; then
+       echo "error: can't find" vh${LXCNAME}${LXCNUM}
+       exit -1
+fi
+
+ip link delete vh${LXCNAME}${LXCNUM} type veth 
+
+exit 0
index 0167ce8..219b285 100755 (executable)
@@ -1,5 +1,5 @@
 #!/bin/bash
-# copyright (C) 2013-2014 FUJITSU LIMITED All Rights Reserved
+# copyright (C) 2014 FUJITSU LIMITED All Rights Reserved
 
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
index 2c8cb05..8850120 100644 (file)
@@ -66,7 +66,7 @@ systemctl restart libvirtd
 %doc README COPYING ChangeLog AUTHORS example
 
 %changelog
-* Thu Nov 14 2014 NIWA Hideyuki <niwa.hideyuki@jp.fujitsu.com> - 0.11-1
+* Fri Nov 14 2014 NIWA Hideyuki <niwa.hideyuki@jp.fujitsu.com> - 0.11-1
 - New Build. update to release 0.11-1
 
 * Thu Sep 25 2014 NIWA Hideyuki <niwa.hideyuki@jp.fujitsu.com> - 0.10-1