OSDN Git Service

addition of -c option to list
[fulcon/Fulcon.git] / src / slot-os / list
1 #!/bin/bash
2
3 # Copyright (C) 2016 NIWA Hideyuki
4
5 FULCONDRIVER=`fulcon driver-name`
6 PATH=/usr/lib/slot-os/lib:/usr/lib/fulcon/driver/$FULCONDRIVER:/usr/lib/fulcon/lib:$PATH
7
8 FULCONDIR=/var/lib/fulcon
9 SLOTOSDIR=/var/lib/slot-os
10
11 usage()
12 {
13         echo "usage: list [ -c ] [ SLOT_NUMBER ...]"
14 }
15
16 lsdir() {
17   ls -f --ind=none $1 | sed '/^\.\{1,2\}$/d'
18 }
19
20 # check options
21 FLG_C=0
22
23 while getopts c OPT
24 do
25   case $OPT in
26   "c" ) FLG_C=1 ;;
27   \?  ) usage; exit -1;;
28   esac
29 done
30 shift `expr $OPTIND - 1`
31
32 list1()
33 {
34         i=$1
35         CNAME=`printf "slot%02d" $i`
36         STATUS=`fulcon-status $CNAME`
37         if [ !  -f $FULCONDIR/container/$CNAME/imagename ]; then
38                 return
39         fi
40         IMAGE=`sed -e 's%fulcon/%%' $FULCONDIR/container/$CNAME/imagename`
41
42         # network information
43         IPADDR=""
44         if [ x"$STATUS" == x"RUNNING" ]; then
45                 IPADDR=`fulcon-ip $CNAME`
46         fi
47
48         if [ -d $SLOTOSDIR/slot/$i/net ]; then
49                 for k in `lsdir $SLOTOSDIR/slot/$i/net`
50                 do
51                         IP1=`awk '{printf "%s ",$3}' $SLOTOSDIR/slot/$i/net/$k`
52                         IPADDR="$IPADDR $IP1"
53                 done
54         fi
55
56         # autostart information
57         if [ -f $SLOTOSDIR/slot/$i/autostart ]; then
58                 AUTOSTART="A"
59         else
60                 AUTOSTART="-"
61         fi
62
63         if [ -d $SLOTOSDIR/slot/$i ]; then
64                 printf "%2d : %8s %s %3s%% %3s %s %1s %s " \
65                         $i $STATUS $CNAME \
66                         `cat $SLOTOSDIR/slot/$i/cpu` \
67                         `cat $SLOTOSDIR/slot/$i/cpuset` \
68                         `cat $SLOTOSDIR/slot/$i/memory` \
69                         $AUTOSTART \
70                         $IMAGE
71         fi
72
73         echo $IPADDR
74 }
75
76
77 display_list()
78 {
79         for i in $NUMS
80         do
81                 NUM=$i
82                 NUM=`echo $NUM | sed -e 's/slot//'` 
83                 NUM=`expr $NUM + 1`
84                 if [ $? -ne 0 ]; then
85                         echo "error: slot $i is not exist"
86                         continue
87                 else
88                         NUM=`expr $NUM - 1`
89                 fi
90
91                 if [ -d $SLOTOSDIR/slot/$NUM ]; then
92                         CNAME=`cat $SLOTOSDIR/slot/$NUM/fulcon`
93                         list1 $NUM
94                 else
95                         echo "error: slot $NUM is not exist"
96                 fi
97         done
98 }
99
100 if [ ! -d $SLOTOSDIR/slot -o ! -d $SLOTOSDIR/slot/0 ]; then
101         exit -1
102 fi
103
104 NUMS=$*
105
106 FLG=0
107 if [ $# -eq 0 -o x"$1" == x"list" ]; then
108         NUMS=`lsdir $SLOTOSDIR/slot | sort -n`
109         FLG=1
110 fi
111
112
113 if [ $FLG_C -eq 0 ]; then
114         display_list
115 else
116         tput clear
117
118         while : 
119         do
120                 if [ $FLG -eq 1 ]; then
121                         NUMS=`lsdir $SLOTOSDIR/slot | sort -n`
122                 fi
123
124                 display_list
125                 sleep 1
126                 tput clear
127         done
128 fi
129
130 exit 0