OSDN Git Service

9b5faa0380f13e3490e910878cb2622830f7c1d8
[fulcon/Fulcon.git] / src / subcmd / net-del
1 #!/bin/bash
2
3 # Copyright (C) 2015-2016 NIWA Hideyuki
4
5 FULCONDRIVER=`fulcon driver-name`
6 PATH=/usr/lib/fulcon/driver/$FULCONDRIVER:/usr/lib/fulcon/lib:$PATH
7
8 FULCONDIR=/var/lib/fulcon
9
10 # check root
11 if [ ${EUID:-${UID}} != 0 ]; then
12     echo "error: Because you are not root, you cannot execute this command. "
13     exit 1
14 fi
15
16 usage()
17 {
18         echo "usage: net-del -n NUMBER CONTAINER_NAME"
19 }
20
21 # check options
22 FLG_N=0 ; NUM=""
23
24 while getopts n: OPT ; do
25   case $OPT in
26   n) FLG_N=1 ; NUM=$OPTARG ;;
27   \? ) usage; exit -1;;
28   esac
29 done
30 shift $((OPTIND - 1))
31
32 # check args
33 if [ $# -ne 1 ]; then
34         usage
35         exit -1
36 fi
37
38 # check number
39 if [ $FLG_N -ne 1 ]; then
40         usage
41         echo 'error: It is necessary to specify "-n NUMBER"'
42         exit -1
43 fi
44
45 LXCNAME=$1
46 brctl show  |& egrep ${LXCNAME}${NUM} >& /dev/null
47 if [ $? -ne 0 ]; then
48         echo "error: can't find" ${LXCNAME}${NUM}
49         exit -1
50 fi
51 ip link delete ${LXCNAME}${NUM} type veth 
52 echo "deleted" ${LXCNAME}${NUM}
53
54 # delete a IP address for container
55 rm -f $FULCONDIR/container/${LXCNAME}/net/${LXCNAME}${NUM}
56
57 # check bridges
58 for i in `brctl show | egrep fulcon | awk '(NF==3){print $1}'`
59 do
60         ip link set $i down
61         brctl delbr $i
62 done
63
64 exit 0