OSDN Git Service

/usr/lib/lxcf is moved to /usr/lib64/lxcf.
[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 # check root
20 if [ ${EUID:-${UID}} != 0 ]; then
21     echo "error: Because you are not root, you cannot execute this command. "
22     exit 1
23 fi
24
25 print_list() {
26         LNAME=`cut -d ' ' -f 1 /opt/lxcf/${LXCNAME}/etc/lxcf/container_name`
27         LMODEL=`cut -d ' ' -f 2 /opt/lxcf/${LXCNAME}/etc/lxcf/container_name`
28         LSTATE=`LANG=C virsh -c lxc:/// list | /usr/bin/awk '($2 == "'${LXCNAME}'"){print $3}'`
29         if [ -z "${LSTATE}"  ]; then
30                 LSTATE="stopped";
31         fi
32         LPATH=`readlink -f /opt/lxcf/${LXCNAME}`
33         printf "%s\t%s    \t%s\t  %s\n" ${LNAME} ${LMODEL} ${LSTATE} ${LPATH}
34 }
35
36 printf "Name\tMode    \tState\t  Path\n"
37 echo   "------------------------------------------------------"
38
39 if [ $# -eq 0 ] ; then
40   for LXCNAME in `ls -1 /opt/lxcf/`
41   do
42         if [ -e /opt/lxcf/${LXCNAME}/etc/lxcf/container_name ] ; then
43                 print_list 
44         fi
45   done
46 else
47   for LXCNAME in $*
48   do
49     if ! /usr/lib64/lxcf/lxcf-parmchk-cname $LXCNAME ; then
50       echo "error:" $LXCNAME "is not a container name"
51       echo "        The container name must be alphanumeric character, \"-\", and \"_\"."
52       exit 1
53     fi
54
55     if [ ! -e /opt/lxcf/${LXCNAME} ] ; then
56       echo "error:" $LXCNAME "is the unknown container name"
57       exit 1
58     fi
59
60     if [ -e /opt/lxcf/${LXCNAME}/etc/lxcf/container_name ] ; then
61                 print_list
62     fi
63   done
64 fi
65
66 exit 0
67