OSDN Git Service

The title is applied to the list output.
[lxcf/lxcf.git] / lxcf / lib / lxcf-list
1 #!/bin/sh
2 # copyright (C) 2013-2014 FUJITSU LIMITED All Rights Reserved
3
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; version 2
7 # of the License.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
17 # 02110-1301, USA.
18
19 print_list() {
20         LNAME=`cut -d ' ' -f 1 /opt/lxcf/${LXCNAME}/etc/lxcf/container_name`
21         LMODEL=`cut -d ' ' -f 2 /opt/lxcf/${LXCNAME}/etc/lxcf/container_name`
22         LSTATE=`LANG=C virsh -c lxc:/// list | /usr/bin/awk '($2 == "'${LXCNAME}'"){print $3}'`
23         if [ -z "${LSTATE}"  ]; then
24                 LSTATE="stopped";
25         fi
26         printf "%s\t%s\t%s\n" ${LNAME} ${LMODEL} ${LSTATE}
27 }
28
29 printf "Name\tMode\tState\n"
30 echo   "---------------------------"
31
32 if [ $# -eq 0 ] ; then
33   for LXCNAME in `ls -1 /opt/lxcf/`
34   do
35         if [ -e /opt/lxcf/${LXCNAME}/etc/lxcf/container_name ] ; then
36                 print_list 
37         fi
38   done
39 else
40   for LXCNAME in $*
41   do
42     if ! /usr/lib/lxcf/lxcf-parmchk-cname $LXCNAME ; then
43       echo $LXCNAME "is not a container name"
44       exit 1
45     fi
46
47     if [ ! -e /opt/lxcf/${LXCNAME} ] ; then
48       echo $LXCNAME "is the unknown container name"
49       exit 1
50     fi
51
52     if [ -e /opt/lxcf/${LXCNAME}/etc/lxcf/container_name ] ; then
53                 print_list
54     fi
55   done
56 fi
57
58 exit 0
59