<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Hello all,<br>
<br>
<font color="FF0000">Issue:</font>  It is not successful to do iozone test in Linux Containers.<br>
<br>
<font color="FF0000">Test context:  </font><br>
       Hardware :P4080 -> gerald: rev 3.0, ddr=8g (FSL Powerpc)<br>
       software: sdk_1.3 rc2<br>
<font color="FF0000">Question:</font><br>
       When do -i 0 -i 1 (write/rewrite,read/re-read) test:<br>
       The memory size of host is 8G , so the maximum file size of setting can be 2*8g when doing iozone test in LXC ?<br>
       if not, the maximum file size will be ? and what is the relationship of setted maximum file size in LXC with host memory size ?or any other factors that impact iozone
<br>
       test of lxc?<br>
<br>
Look forward to your answer! Thanks a lot!<br>
<br>
<font color="FF0000">Detail information as below:</font><br>
       In LXC:<br>
            Configuration of  LXC rootfs (using busybox template)<br>
                     1.Creating device files into container rootfs<br>
                             In fun of install_busybox() add:<br>
                              # device zero<br>
                                  mknod zero c 1 5<br>
                                  chmod 666 zero<br>
    <br>
                            # hdd<br>
                                 mknod sdb b 8 0<br>
                                 mknod sdb1 b 8 1<br>
                                chmod 666 sdb<br>
                                chmod 666 sdb1<br>
                    2. Include instruction set for LXC : insert "/$rootfs/usr/bin" into install_busybox()<br>
                                install_busybox()                                                                  
<br>
                                {                                                                                  
<br>
                                     rootfs=$1                                                                      
<br>
                                      name=$2                                                                        
<br>
                                      res=0                                                               
<br>
                                      tree="\                                                             
<br>
                                     $rootfs/selinux \                                                       
<br>
                                      $rootfs/usr/bin  \<br>
                                      ......}     <br>
                                                                                       
<br>
                    3. Set mount entry of LXC : insert "/usr/bin" into copy_configure()<br>
                                copy_configure()<br>
                               {<br>
                                        libdirs="\                                                          
<br>
                                         /lib \                                                          
<br>
                                         /usr/bin \                                                                           
<br>
                                          ......     <br>
                                       for dir in $libdirs; do                                                        
<br>
                                        if [ -d $dir ]; then                                                       
<br>
                                           echo "lxc.mount.entry=$dir $rootfs$dir none ro,bind 0 0" >> $path/config<br>
                                        fi                                                                         
<br>
                                        done       <br>
                                    ......}     <br>
               Create lxc : <br>
                              lxc-create -n ctx1 -t busybox -f /usr/share/doc/lxc/examples/lxc-no-netns.conf<br>
                               lxc-start -n ctx1<br>
               Iozone test cmd  in LXC :   <br>
                              iozone -Rab /mnt/sdb1/result1.xls -i 0 -i 1 -f /mnt/sdb1/test -n 32M -g 16384M -r 64k<br>
<font color="FF6600">                                 root@ctx1:/# iozone -Rab /mnt/sdb1/result1.xls -i 0 -i 1 -f /mnt/sdb1/test -n 32M -g 16384M -r 64k<br>
                                                             iozone -Rab /mnt/sdb1/result1.xls -i 0 -i 1 -f /mnt/sdb1/test -n 32M -g 16384M -r 64k<br>
                                 Iozone: Performance Test of File I/O<br>
                               Version $Revision: 3.263 $<br>
                                 Compiled for 32 bit mode.<br>
                                 uild: linux-powerpc <br>
<br>
                                  <font color="FF6600"></font>Excel chart generation enabled<br>
                                Auto Mode<br>
                               Using minimum file size of 32768 kilobytes.<br>
                              Using maximum file size of 16777216 kilobytes.<br>
                               Record Size 64 KB<br>
                              Command line used: iozone -Rab /mnt/sdb1/result1.xls -i 0 -i 1 -f /mnt/sdb1/test -n 32M -g 16384M -r 64k<br>
                              Output is in Kbytes/sec<br>
                           Time Resolution = 0.000001 seconds.<br>
                          Processor cache line size set to 32 bytes.<br>
                               File stride size set to 17 * record size.<br>
                                                            random  random    bkwd  record  stride                                  
<br>
                                                         KB  reclen   write rewrite    read    reread    read   write    read rewrite    read   fwrite frewrite   fread  freread<br>
                                                         32768      64  490172  977157  1201181  1214717                                                                         
<br>
                                                        65536      64  493178  955101  1208728  1215113                                                                         
<br>
                                                        131072      64    8908   20254  1212673  1215599                                                                         
<br>
                                                        262144      64    6486   12719  1212478  1215329                                                                         
<br>
                                                        524288        64    6493   11205  1217592  1219668                                                                         
<br>
                                                        1048576      64    5626   10302  1216230  1218040                                                                         
<br>
                                                        <b> <font color="FF0000">
2097152      64</font></b><br>
                                                      Error writing block 29644, fd= 3<br>
<br>
                                                    iozone: interrupted</font><br>
<br>
     It is normal to do iozone test in host :<br>
<br>
    <font color="0000FF">part of  log info:</font><br>
    <font color="0000FF"> root@p4080ds:~# iozone -Rab /mnt/sdb1/result2.xls -i 0 -i 1 -f /mnt/sdb1/test -n 32M -g 16384M -r 64k<br>
    Iozone: Performance Test of File I/O<br>
         Version $Revision: 3.263 $<br>
        Compiled for 32 bit mode.<br>
        Build: linux-powerpc <br>
<br>
    Excel chart generation enabled<br>
    Auto Mode<br>
    Using minimum file size of 32768 kilobytes.<br>
    Using maximum file size of 16777216 kilobytes.<br>
    Record Size 64 KB<br>
    Command line used: iozone -Rab /mnt/sdb1/result2.xls -i 0 -i 1 -f /mnt/sdb1/test -n 32M -g 16384M -r 64k<br>
    Output is in Kbytes/sec<br>
    Time Resolution = 0.000001 seconds.<br>
    Processor cache size set to 1024 Kbytes.<br>
    Processor cache line size set to 32 bytes.<br>
    File stride size set to 17 * record size.<br>
                                                            random  random    bkwd  record  stride                                  
<br>
              KB  reclen   write rewrite    read    reread    read   write    read rewrite    read   fwrite frewrite   fread  freread<br>
           32768      64  420950  978033  1207407  1225800                                                                         
<br>
           65536      64  500316  971208  1220048  1229522                                                                         
<br>
          131072      64  170862  184546  1225121  1230135                                                                         
<br>
          262144      64   81217   96077  1227869  1229931                                                                         
<br>
          524288      64   66387   75088  1224423  1227892                                                                         
<br>
         1048576      64   59394   68065  1226510  1227980                                                                         
<br>
         2097152      64   56872   64417  1227611  1230297                                                                         
<br>
         4194304      64   55253   62806  1226647  1227713                                                                         
<br>
         8388608      64   54556   61921    65851    65912                                                                         
<br>
        16777216      64   53933   61459    64280    64327                                                                         
<br>
<br>
iozone test complete.</font><br>
<br>
Best Regards,<br>
Yuejuan.<br>
<br>
<br>
<br>
________________________________________<br>
From: lxc-devel-request@lists.sourceforge.net [lxc-devel-request@lists.sourceforge.net]<br>
Sent: Wednesday, November 21, 2012 5:04 PM<br>
To: lxc-devel@lists.sourceforge.net<br>
Subject: Lxc-devel Digest, Vol 51, Issue 13<br>
<br>
Send Lxc-devel mailing list submissions to<br>
lxc-devel@lists.sourceforge.net<br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
https://lists.sourceforge.net/lists/listinfo/lxc-devel<br>
or, via email, send a message with subject or body 'help' to<br>
lxc-devel-request@lists.sourceforge.net<br>
<br>
You can reach the person managing the list at<br>
lxc-devel-owner@lists.sourceforge.net<br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of Lxc-devel digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
1. Re: using posix shell instead of bash (Serge Hallyn)<br>
2. [PATCH] lxc-create: use posix shell instead of bash<br>
(Natanael Copa)<br>
3. Re: [PATCH] lxc-create: use posix shell instead of bash<br>
(Serge Hallyn)<br>
4. Re: [PATCH] lxc-create: use posix shell instead of bash<br>
(St?phane Graber)<br>
5. [PATCH] Rewrite lxc-ls in python (St?phane Graber)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Fri, 16 Nov 2012 08:02:35 -0600<br>
From: Serge Hallyn <serge.hallyn@canonical.com><br>
Subject: Re: [lxc-devel] using posix shell instead of bash<br>
To: Natanael Copa <ncopa@alpinelinux.org><br>
Cc: Lxc development list <lxc-devel@lists.sourceforge.net><br>
Message-ID: <20121116140235.GA17455@sergelap><br>
Content-Type: text/plain; charset=us-ascii<br>
<br>
Quoting Natanael Copa (ncopa@alpinelinux.org):<br>
> On Wed, 14 Nov 2012 09:54:58 -0600<br>
> Serge Hallyn <serge.hallyn@canonical.com> wrote:<br>
><br>
> > Successful runs of<br>
> > https://code.launchpad.net/~serge-hallyn/+junk/lxc-test with your<br>
> > patches will also be reassuring.<br>
><br>
> This is causing problems for me:<br>
><br>
> if dist[0] != "Ubuntu":<br>
> print >>sys.stderr, "This test suite does not yet support %s" % (dist[0])<br>
> sys.exit(1)<br>
<br>
Oh yeah, good point, that's worth updating :)<br>
<br>
<br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Fri, 16 Nov 2012 17:01:55 +0100<br>
From: Natanael Copa <ncopa@alpinelinux.org><br>
Subject: [lxc-devel] [PATCH] lxc-create: use posix shell instead of<br>
bash<br>
To: lxc-devel@lists.sourceforge.net<br>
Message-ID: <1353081715-31771-1-git-send-email-ncopa@alpinelinux.org><br>
<br>
- use '[ -x /path/prog ]' instead of 'type /path/prog'<br>
- avoid getopt --longoptions<br>
- add \ at after && and || when those are at end of line<br>
- make sure condition expands to empty string if variable is empty<br>
<br>
Signed-off-by: Natanael Copa <ncopa@alpinelinux.org><br>
---<br>
I have tested it with 'lxc-create -t debian ...' with busybox as /bin/sh<br>
<br>
src/lxc/lxc-create.in | 70 +++++++++++++++++++++++++++++----------------------<br>
1 file changed, 40 insertions(+), 30 deletions(-)<br>
<br>
diff --git a/src/lxc/lxc-create.in b/src/lxc/lxc-create.in<br>
index 101e489..e8056e9 100644<br>
--- a/src/lxc/lxc-create.in<br>
+++ b/src/lxc/lxc-create.in<br>
@@ -1,4 +1,4 @@<br>
-#!/bin/bash<br>
+#!/bin/sh<br>
<br>
#<br>
# lxc: linux Container library<br>
@@ -54,16 +54,26 @@ help() {<br>
echo " $(basename $0) -t ubuntu -h" >&2<br>
exit 0<br>
fi<br>
- type ${templatedir}/lxc-$lxc_template 2>/dev/null<br>
- if [ $? -eq 0 ]; then<br>
+ if [ -x ${templatedir}/lxc-$lxc_template ]; then<br>
echo >&2<br>
echo "Template-specific options (TEMPLATE_OPTIONS):" >&2<br>
${templatedir}/lxc-$lxc_template -h<br>
fi<br>
}<br>
<br>
-shortoptions='hn:f:t:B:'<br>
-longoptions='help,name:,config:,template:,backingstore:,fstype:,dir:,lvname:,vgname:,fssize:'<br>
+usage_err() {<br>
+ [ -n "$1" ] && echo "$1" >&2<br>
+ usage<br>
+ exit 1<br>
+}<br>
+<br>
+optarg_check() {<br>
+ local opt="$1" optarg="$2"<br>
+ if [ -z "$optarg" ]; then<br>
+ usage_err "option '$opt' requires an argument"<br>
+ fi<br>
+}<br>
+<br>
lxc_path=@LXCPATH@<br>
bindir=@BINDIR@<br>
templatedir=@LXCTEMPLATEDIR@<br>
@@ -73,68 +83,69 @@ fssize=500M<br>
vgname=lxc<br>
custom_rootfs=""<br>
<br>
-getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@")<br>
-if [ $? != 0 ]; then<br>
- usage<br>
- exit 1;<br>
-fi<br>
-<br>
-eval set -- "$getopt"<br>
-<br>
-while true; do<br>
- case "$1" in<br>
+while [ $# -gt 0 ]; do<br>
+ local opt="$1"<br>
+ shift<br>
+ case "$opt" in<br>
-h|--help)<br>
help<br>
exit 1<br>
;;<br>
-n|--name)<br>
- shift<br>
+ optarg_check $opt "$1"<br>
lxc_name=$1<br>
shift<br>
;;<br>
-f|--config)<br>
- shift<br>
+ optarg_check $opt "$1"<br>
lxc_config=$1<br>
shift<br>
;;<br>
-t|--template)<br>
- shift<br>
+ optarg_check $opt "$1"<br>
lxc_template=$1<br>
shift<br>
;;<br>
-B|--backingstore)<br>
- shift<br>
+ optarg_check $opt "$1"<br>
backingstore=$1<br>
shift<br>
;;<br>
--dir)<br>
- shift<br>
+ optarg_check $opt "$1"<br>
custom_rootfs=$1<br>
shift<br>
;;<br>
--lvname)<br>
- shift<br>
+ optarg_check $opt "$1"<br>
lvname=$1<br>
shift<br>
;;<br>
--vgname)<br>
- shift<br>
+ optarg_check $opt "$1"<br>
vgname=$1<br>
shift<br>
;;<br>
--fstype)<br>
- shift<br>
+ optarg_check $opt "$1"<br>
fstype=$1<br>
shift<br>
;;<br>
--fssize)<br>
- shift<br>
+ optarg_check $opt "$1"<br>
fssize=$1<br>
shift<br>
;;<br>
--)<br>
shift<br>
break;;<br>
+ -?)<br>
+ usage_err "unknown option '$opt'"<br>
+ ;;<br>
+ -*)<br>
+ # split opts -abc into -a -b -c<br>
+ set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"<br>
+ ;;<br>
*)<br>
usage<br>
exit 1<br>
@@ -200,7 +211,7 @@ rootfs="$lxc_path/$lxc_name/rootfs"<br>
<br>
if [ "$backingstore" = "_unset" -o "$backingstore" = "btrfs" ]; then<br>
# if no backing store was given, then see if btrfs would work<br>
- if which btrfs >/dev/null 2>&1 &&<br>
+ if which btrfs >/dev/null 2>&1 && \<br>
btrfs filesystem df "$lxc_path/" >/dev/null 2>&1; then<br>
backingstore="btrfs"<br>
else<br>
@@ -246,10 +257,10 @@ elif [ "$backingstore" = "btrfs" ]; then<br>
fi<br>
<br>
cleanup() {<br>
- if [ $backingstore = "lvm" ]; then<br>
+ if [ "$backingstore" = "lvm" ]; then<br>
umount $rootfs<br>
lvremove -f $rootdev<br>
- elif [ $backingstore = "btrfs" ]; then<br>
+ elif [ "$backingstore" = "btrfs" ]; then<br>
btrfs subvolume delete "$rootfs"<br>
fi<br>
${bindir}/lxc-destroy -n $lxc_name<br>
@@ -299,8 +310,7 @@ if [ ! -z $lxc_template ]; then<br>
template_path=${templatedir}/lxc-$lxc_template<br>
fi<br>
<br>
- type $template_path 2>/dev/null<br>
- if [ $? -ne 0 ]; then<br>
+ if ! [ -x "$template_path" ]; then<br>
echo "$(basename $0): unknown template '$lxc_template'" >&2<br>
cleanup<br>
fi<br>
@@ -314,7 +324,7 @@ if [ ! -z $lxc_template ]; then<br>
echo "'$lxc_template' template installed"<br>
fi<br>
<br>
-if [ $backingstore = "lvm" ]; then<br>
+if [ "$backingstore" = "lvm" ]; then<br>
echo "Unmounting LVM"<br>
umount $rootfs<br>
<br>
--<br>
1.8.0<br>
<br>
<br>
<br>
<br>
------------------------------<br>
<br>
Message: 3<br>
Date: Mon, 19 Nov 2012 10:36:46 -0600<br>
From: Serge Hallyn <serge.hallyn@canonical.com><br>
Subject: Re: [lxc-devel] [PATCH] lxc-create: use posix shell instead<br>
of bash<br>
To: Natanael Copa <ncopa@alpinelinux.org><br>
Cc: lxc-devel@lists.sourceforge.net<br>
Message-ID: <20121119163646.GA32083@serge-ThinkPad-X130e><br>
Content-Type: text/plain; charset=us-ascii<br>
<br>
Quoting Natanael Copa (ncopa@alpinelinux.org):<br>
> - use '[ -x /path/prog ]' instead of 'type /path/prog'<br>
> - avoid getopt --longoptions<br>
> - add \ at after && and || when those are at end of line<br>
> - make sure condition expands to empty string if variable is empty<br>
><br>
<br>
looks good to me, thanks.<br>
<br>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com><br>
<br>
> Signed-off-by: Natanael Copa <ncopa@alpinelinux.org><br>
> ---<br>
> I have tested it with 'lxc-create -t debian ...' with busybox as /bin/sh<br>
><br>
> src/lxc/lxc-create.in | 70 +++++++++++++++++++++++++++++----------------------<br>
> 1 file changed, 40 insertions(+), 30 deletions(-)<br>
><br>
> diff --git a/src/lxc/lxc-create.in b/src/lxc/lxc-create.in<br>
> index 101e489..e8056e9 100644<br>
> --- a/src/lxc/lxc-create.in<br>
> +++ b/src/lxc/lxc-create.in<br>
> @@ -1,4 +1,4 @@<br>
> -#!/bin/bash<br>
> +#!/bin/sh<br>
><br>
> #<br>
> # lxc: linux Container library<br>
> @@ -54,16 +54,26 @@ help() {<br>
> echo " $(basename $0) -t ubuntu -h" >&2<br>
> exit 0<br>
> fi<br>
> - type ${templatedir}/lxc-$lxc_template 2>/dev/null<br>
> - if [ $? -eq 0 ]; then<br>
> + if [ -x ${templatedir}/lxc-$lxc_template ]; then<br>
> echo >&2<br>
> echo "Template-specific options (TEMPLATE_OPTIONS):" >&2<br>
> ${templatedir}/lxc-$lxc_template -h<br>
> fi<br>
> }<br>
><br>
> -shortoptions='hn:f:t:B:'<br>
> -longoptions='help,name:,config:,template:,backingstore:,fstype:,dir:,lvname:,vgname:,fssize:'<br>
> +usage_err() {<br>
> + [ -n "$1" ] && echo "$1" >&2<br>
> + usage<br>
> + exit 1<br>
> +}<br>
> +<br>
> +optarg_check() {<br>
> + local opt="$1" optarg="$2"<br>
> + if [ -z "$optarg" ]; then<br>
> + usage_err "option '$opt' requires an argument"<br>
> + fi<br>
> +}<br>
> +<br>
> lxc_path=@LXCPATH@<br>
> bindir=@BINDIR@<br>
> templatedir=@LXCTEMPLATEDIR@<br>
> @@ -73,68 +83,69 @@ fssize=500M<br>
> vgname=lxc<br>
> custom_rootfs=""<br>
><br>
> -getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@")<br>
> -if [ $? != 0 ]; then<br>
> - usage<br>
> - exit 1;<br>
> -fi<br>
> -<br>
> -eval set -- "$getopt"<br>
> -<br>
> -while true; do<br>
> - case "$1" in<br>
> +while [ $# -gt 0 ]; do<br>
> + local opt="$1"<br>
> + shift<br>
> + case "$opt" in<br>
> -h|--help)<br>
> help<br>
> exit 1<br>
> ;;<br>
> -n|--name)<br>
> - shift<br>
> + optarg_check $opt "$1"<br>
> lxc_name=$1<br>
> shift<br>
> ;;<br>
> -f|--config)<br>
> - shift<br>
> + optarg_check $opt "$1"<br>
> lxc_config=$1<br>
> shift<br>
> ;;<br>
> -t|--template)<br>
> - shift<br>
> + optarg_check $opt "$1"<br>
> lxc_template=$1<br>
> shift<br>
> ;;<br>
> -B|--backingstore)<br>
> - shift<br>
> + optarg_check $opt "$1"<br>
> backingstore=$1<br>
> shift<br>
> ;;<br>
> --dir)<br>
> - shift<br>
> + optarg_check $opt "$1"<br>
> custom_rootfs=$1<br>
> shift<br>
> ;;<br>
> --lvname)<br>
> - shift<br>
> + optarg_check $opt "$1"<br>
> lvname=$1<br>
> shift<br>
> ;;<br>
> --vgname)<br>
> - shift<br>
> + optarg_check $opt "$1"<br>
> vgname=$1<br>
> shift<br>
> ;;<br>
> --fstype)<br>
> - shift<br>
> + optarg_check $opt "$1"<br>
> fstype=$1<br>
> shift<br>
> ;;<br>
> --fssize)<br>
> - shift<br>
> + optarg_check $opt "$1"<br>
> fssize=$1<br>
> shift<br>
> ;;<br>
> --)<br>
> shift<br>
> break;;<br>
> + -?)<br>
> + usage_err "unknown option '$opt'"<br>
> + ;;<br>
> + -*)<br>
> + # split opts -abc into -a -b -c<br>
> + set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"<br>
> + ;;<br>
> *)<br>
> usage<br>
> exit 1<br>
> @@ -200,7 +211,7 @@ rootfs="$lxc_path/$lxc_name/rootfs"<br>
><br>
> if [ "$backingstore" = "_unset" -o "$backingstore" = "btrfs" ]; then<br>
> # if no backing store was given, then see if btrfs would work<br>
> - if which btrfs >/dev/null 2>&1 &&<br>
> + if which btrfs >/dev/null 2>&1 && \<br>
> btrfs filesystem df "$lxc_path/" >/dev/null 2>&1; then<br>
> backingstore="btrfs"<br>
> else<br>
> @@ -246,10 +257,10 @@ elif [ "$backingstore" = "btrfs" ]; then<br>
> fi<br>
><br>
> cleanup() {<br>
> - if [ $backingstore = "lvm" ]; then<br>
> + if [ "$backingstore" = "lvm" ]; then<br>
> umount $rootfs<br>
> lvremove -f $rootdev<br>
> - elif [ $backingstore = "btrfs" ]; then<br>
> + elif [ "$backingstore" = "btrfs" ]; then<br>
> btrfs subvolume delete "$rootfs"<br>
> fi<br>
> ${bindir}/lxc-destroy -n $lxc_name<br>
> @@ -299,8 +310,7 @@ if [ ! -z $lxc_template ]; then<br>
> template_path=${templatedir}/lxc-$lxc_template<br>
> fi<br>
><br>
> - type $template_path 2>/dev/null<br>
> - if [ $? -ne 0 ]; then<br>
> + if ! [ -x "$template_path" ]; then<br>
> echo "$(basename $0): unknown template '$lxc_template'" >&2<br>
> cleanup<br>
> fi<br>
> @@ -314,7 +324,7 @@ if [ ! -z $lxc_template ]; then<br>
> echo "'$lxc_template' template installed"<br>
> fi<br>
><br>
> -if [ $backingstore = "lvm" ]; then<br>
> +if [ "$backingstore" = "lvm" ]; then<br>
> echo "Unmounting LVM"<br>
> umount $rootfs<br>
><br>
> --<br>
> 1.8.0<br>
><br>
><br>
> ------------------------------------------------------------------------------<br>
> Monitor your physical, virtual and cloud infrastructure from a single<br>
> web console. Get in-depth insight into apps, servers, databases, vmware,<br>
> SAP, cloud infrastructure, etc. Download 30-day Free Trial.<br>
> Pricing starts from $795 for 25 servers or applications!<br>
> http://p.sf.net/sfu/zoho_dev2dev_nov<br>
> _______________________________________________<br>
> Lxc-devel mailing list<br>
> Lxc-devel@lists.sourceforge.net<br>
> https://lists.sourceforge.net/lists/listinfo/lxc-devel<br>
<br>
<br>
<br>
------------------------------<br>
<br>
Message: 4<br>
Date: Wed, 21 Nov 2012 14:36:36 -0500<br>
From: St?phane Graber <stgraber@ubuntu.com><br>
Subject: Re: [lxc-devel] [PATCH] lxc-create: use posix shell instead<br>
of bash<br>
To: lxc-devel@lists.sourceforge.net<br>
Message-ID: <50AD2D44.3080903@ubuntu.com><br>
Content-Type: text/plain; charset="iso-8859-1"<br>
<br>
On 11/19/2012 11:36 AM, Serge Hallyn wrote:<br>
> Quoting Natanael Copa (ncopa@alpinelinux.org):<br>
>> - use '[ -x /path/prog ]' instead of 'type /path/prog'<br>
>> - avoid getopt --longoptions<br>
>> - add \ at after && and || when those are at end of line<br>
>> - make sure condition expands to empty string if variable is empty<br>
>><br>
><br>
> looks good to me, thanks.<br>
><br>
> Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com><br>
<br>
Acked-by: St?phane Graber <stgraber@ubuntu.com><br>
<br>
And pushed to staging. Thanks!<br>
<br>
><br>
>> Signed-off-by: Natanael Copa <ncopa@alpinelinux.org><br>
>> ---<br>
>> I have tested it with 'lxc-create -t debian ...' with busybox as /bin/sh<br>
>><br>
>> src/lxc/lxc-create.in | 70 +++++++++++++++++++++++++++++----------------------<br>
>> 1 file changed, 40 insertions(+), 30 deletions(-)<br>
>><br>
>> diff --git a/src/lxc/lxc-create.in b/src/lxc/lxc-create.in<br>
>> index 101e489..e8056e9 100644<br>
>> --- a/src/lxc/lxc-create.in<br>
>> +++ b/src/lxc/lxc-create.in<br>
>> @@ -1,4 +1,4 @@<br>
>> -#!/bin/bash<br>
>> +#!/bin/sh<br>
>><br>
>> #<br>
>> # lxc: linux Container library<br>
>> @@ -54,16 +54,26 @@ help() {<br>
>> echo " $(basename $0) -t ubuntu -h" >&2<br>
>> exit 0<br>
>> fi<br>
>> - type ${templatedir}/lxc-$lxc_template 2>/dev/null<br>
>> - if [ $? -eq 0 ]; then<br>
>> + if [ -x ${templatedir}/lxc-$lxc_template ]; then<br>
>> echo >&2<br>
>> echo "Template-specific options (TEMPLATE_OPTIONS):" >&2<br>
>> ${templatedir}/lxc-$lxc_template -h<br>
>> fi<br>
>> }<br>
>><br>
>> -shortoptions='hn:f:t:B:'<br>
>> -longoptions='help,name:,config:,template:,backingstore:,fstype:,dir:,lvname:,vgname:,fssize:'<br>
>> +usage_err() {<br>
>> + [ -n "$1" ] && echo "$1" >&2<br>
>> + usage<br>
>> + exit 1<br>
>> +}<br>
>> +<br>
>> +optarg_check() {<br>
>> + local opt="$1" optarg="$2"<br>
>> + if [ -z "$optarg" ]; then<br>
>> + usage_err "option '$opt' requires an argument"<br>
>> + fi<br>
>> +}<br>
>> +<br>
>> lxc_path=@LXCPATH@<br>
>> bindir=@BINDIR@<br>
>> templatedir=@LXCTEMPLATEDIR@<br>
>> @@ -73,68 +83,69 @@ fssize=500M<br>
>> vgname=lxc<br>
>> custom_rootfs=""<br>
>><br>
>> -getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@")<br>
>> -if [ $? != 0 ]; then<br>
>> - usage<br>
>> - exit 1;<br>
>> -fi<br>
>> -<br>
>> -eval set -- "$getopt"<br>
>> -<br>
>> -while true; do<br>
>> - case "$1" in<br>
>> +while [ $# -gt 0 ]; do<br>
>> + local opt="$1"<br>
>> + shift<br>
>> + case "$opt" in<br>
>> -h|--help)<br>
>> help<br>
>> exit 1<br>
>> ;;<br>
>> -n|--name)<br>
>> - shift<br>
>> + optarg_check $opt "$1"<br>
>> lxc_name=$1<br>
>> shift<br>
>> ;;<br>
>> -f|--config)<br>
>> - shift<br>
>> + optarg_check $opt "$1"<br>
>> lxc_config=$1<br>
>> shift<br>
>> ;;<br>
>> -t|--template)<br>
>> - shift<br>
>> + optarg_check $opt "$1"<br>
>> lxc_template=$1<br>
>> shift<br>
>> ;;<br>
>> -B|--backingstore)<br>
>> - shift<br>
>> + optarg_check $opt "$1"<br>
>> backingstore=$1<br>
>> shift<br>
>> ;;<br>
>> --dir)<br>
>> - shift<br>
>> + optarg_check $opt "$1"<br>
>> custom_rootfs=$1<br>
>> shift<br>
>> ;;<br>
>> --lvname)<br>
>> - shift<br>
>> + optarg_check $opt "$1"<br>
>> lvname=$1<br>
>> shift<br>
>> ;;<br>
>> --vgname)<br>
>> - shift<br>
>> + optarg_check $opt "$1"<br>
>> vgname=$1<br>
>> shift<br>
>> ;;<br>
>> --fstype)<br>
>> - shift<br>
>> + optarg_check $opt "$1"<br>
>> fstype=$1<br>
>> shift<br>
>> ;;<br>
>> --fssize)<br>
>> - shift<br>
>> + optarg_check $opt "$1"<br>
>> fssize=$1<br>
>> shift<br>
>> ;;<br>
>> --)<br>
>> shift<br>
>> break;;<br>
>> + -?)<br>
>> + usage_err "unknown option '$opt'"<br>
>> + ;;<br>
>> + -*)<br>
>> + # split opts -abc into -a -b -c<br>
>> + set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"<br>
>> + ;;<br>
>> *)<br>
>> usage<br>
>> exit 1<br>
>> @@ -200,7 +211,7 @@ rootfs="$lxc_path/$lxc_name/rootfs"<br>
>><br>
>> if [ "$backingstore" = "_unset" -o "$backingstore" = "btrfs" ]; then<br>
>> # if no backing store was given, then see if btrfs would work<br>
>> - if which btrfs >/dev/null 2>&1 &&<br>
>> + if which btrfs >/dev/null 2>&1 && \<br>
>> btrfs filesystem df "$lxc_path/" >/dev/null 2>&1; then<br>
>> backingstore="btrfs"<br>
>> else<br>
>> @@ -246,10 +257,10 @@ elif [ "$backingstore" = "btrfs" ]; then<br>
>> fi<br>
>><br>
>> cleanup() {<br>
>> - if [ $backingstore = "lvm" ]; then<br>
>> + if [ "$backingstore" = "lvm" ]; then<br>
>> umount $rootfs<br>
>> lvremove -f $rootdev<br>
>> - elif [ $backingstore = "btrfs" ]; then<br>
>> + elif [ "$backingstore" = "btrfs" ]; then<br>
>> btrfs subvolume delete "$rootfs"<br>
>> fi<br>
>> ${bindir}/lxc-destroy -n $lxc_name<br>
>> @@ -299,8 +310,7 @@ if [ ! -z $lxc_template ]; then<br>
>> template_path=${templatedir}/lxc-$lxc_template<br>
>> fi<br>
>><br>
>> - type $template_path 2>/dev/null<br>
>> - if [ $? -ne 0 ]; then<br>
>> + if ! [ -x "$template_path" ]; then<br>
>> echo "$(basename $0): unknown template '$lxc_template'" >&2<br>
>> cleanup<br>
>> fi<br>
>> @@ -314,7 +324,7 @@ if [ ! -z $lxc_template ]; then<br>
>> echo "'$lxc_template' template installed"<br>
>> fi<br>
>><br>
>> -if [ $backingstore = "lvm" ]; then<br>
>> +if [ "$backingstore" = "lvm" ]; then<br>
>> echo "Unmounting LVM"<br>
>> umount $rootfs<br>
>><br>
>> --<br>
>> 1.8.0<br>
>><br>
>><br>
>> ------------------------------------------------------------------------------<br>
>> Monitor your physical, virtual and cloud infrastructure from a single<br>
>> web console. Get in-depth insight into apps, servers, databases, vmware,<br>
>> SAP, cloud infrastructure, etc. Download 30-day Free Trial.<br>
>> Pricing starts from $795 for 25 servers or applications!<br>
>> http://p.sf.net/sfu/zoho_dev2dev_nov<br>
>> _______________________________________________<br>
>> Lxc-devel mailing list<br>
>> Lxc-devel@lists.sourceforge.net<br>
>> https://lists.sourceforge.net/lists/listinfo/lxc-devel<br>
><br>
> ------------------------------------------------------------------------------<br>
> Monitor your physical, virtual and cloud infrastructure from a single<br>
> web console. Get in-depth insight into apps, servers, databases, vmware,<br>
> SAP, cloud infrastructure, etc. Download 30-day Free Trial.<br>
> Pricing starts from $795 for 25 servers or applications!<br>
> http://p.sf.net/sfu/zoho_dev2dev_nov<br>
> _______________________________________________<br>
> Lxc-devel mailing list<br>
> Lxc-devel@lists.sourceforge.net<br>
> https://lists.sourceforge.net/lists/listinfo/lxc-devel<br>
><br>
<br>
<br>
--<br>
St?phane Graber<br>
<br>
<br>
<br>
--<br>
St?phane Graber<br>
Ubuntu developer<br>
http://www.ubuntu.com<br>
<br>
-------------- next part --------------<br>
A non-text attachment was scrubbed...<br>
Name: signature.asc<br>
Type: application/pgp-signature<br>
Size: 899 bytes<br>
Desc: OpenPGP digital signature<br>
<br>
------------------------------<br>
<br>
Message: 5<br>
Date: Wed, 21 Nov 2012 18:04:03 -0500<br>
From: St?phane Graber <stgraber@ubuntu.com><br>
Subject: [lxc-devel] [PATCH] Rewrite lxc-ls in python<br>
To: Lxc development list <lxc-devel@lists.sourceforge.net><br>
Message-ID: <50AD5DE3.5020900@ubuntu.com><br>
Content-Type: text/plain; charset="iso-8859-1"<br>
<br>
This rewrite is mostly compatible with the shell version.<br>
--active and -1 still work and behave as they used to.<br>
<br>
This adds --running, --stopped and --frozen as state filters.<br>
<br>
A new "fancy" view is also implemented (can be used with --fancy) and<br>
will show containers in a column-based interface with the following fields:<br>
- name<br>
- state<br>
- ipv4<br>
- ipv6<br>
- pid of init<br>
<br>
Signed-off-by: St?phane Graber <stgraber@ubuntu.com><br>
---<br>
.gitignore | 1 -<br>
configure.ac | 1 -<br>
doc/lxc-ls.sgml.in | 150 ++++++++++++++++++++++-----------<br>
src/lxc/Makefile.am | 2 +-<br>
src/lxc/lxc-ls | 236<br>
++++++++++++++++++++++++++++++++++++++++++++++++++++<br>
src/lxc/lxc-ls.in | 94 ---------------------<br>
6 files changed, 340 insertions(+), 144 deletions(-)<br>
create mode 100644 src/lxc/lxc-ls<br>
delete mode 100644 src/lxc/lxc-ls.in<br>
<br>
diff --git a/.gitignore b/.gitignore<br>
index d5b07e3..398e4fc 100644<br>
--- a/.gitignore<br>
+++ b/.gitignore<br>
@@ -50,7 +50,6 @@ src/lxc/lxc-freeze<br>
src/lxc/lxc-info<br>
src/lxc/lxc-init<br>
src/lxc/lxc-kill<br>
-src/lxc/lxc-ls<br>
src/lxc/lxc-monitor<br>
src/lxc/lxc-netstat<br>
src/lxc/lxc-ps<br>
diff --git a/configure.ac b/configure.ac<br>
index b6fa365..5f0cc0b 100644<br>
--- a/configure.ac<br>
+++ b/configure.ac<br>
@@ -257,7 +257,6 @@ AC_CONFIG_FILES([<br>
src/Makefile<br>
src/lxc/Makefile<br>
src/lxc/lxc-ps<br>
- src/lxc/lxc-ls<br>
src/lxc/lxc-netstat<br>
src/lxc/lxc-checkconfig<br>
src/lxc/lxc-setcap<br>
diff --git a/doc/lxc-ls.sgml.in b/doc/lxc-ls.sgml.in<br>
index f5f6573..138908d 100644<br>
--- a/doc/lxc-ls.sgml.in<br>
+++ b/doc/lxc-ls.sgml.in<br>
@@ -49,8 +49,14 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston,<br>
MA 02111-1307 USA<br>
<refsynopsisdiv><br>
<cmdsynopsis><br>
<command>lxc-ls</command><br>
+ <arg choice="opt">-1</arg><br>
<arg choice="opt">--active</arg><br>
- <arg choice="opt">ls option</arg><br>
+ <arg choice="opt">--frozen</arg><br>
+ <arg choice="opt">--running</arg><br>
+ <arg choice="opt">--stopped</arg><br>
+ <arg choice="opt">--fancy</arg><br>
+ <arg choice="opt">--fancy-format</arg><br>
+ <arg choice="opt">filter</arg><br>
</cmdsynopsis><br>
</refsynopsisdiv><br>
@@ -65,77 +71,127 @@ Foundation, Inc., 59 Temple Place, Suite 330,<br>
Boston, MA 02111-1307 USA<br>
<refsect1><br>
<title>Options</title><br>
<variablelist><br>
+ <varlistentry><br>
+ <term><br>
+ <option><optional>-1</optional></option><br>
+ </term><br>
+ <listitem><br>
+ <para><br>
+ Show one entry per line. (default when /dev/stdout isn't a tty)<br>
+ </para><br>
+ </listitem><br>
+ </varlistentry><br>
<varlistentry><br>
- <term><br>
- <option><optional>--active</optional></option><br>
- </term><br>
- <listitem><br>
- <para><br>
- List active containers.<br>
- </para><br>
- </listitem><br>
+ <term><br>
+ <option><optional>--active</optional></option><br>
+ </term><br>
+ <listitem><br>
+ <para><br>
+ List only active containers (same as --frozen --running).<br>
+ </para><br>
+ </listitem><br>
</varlistentry><br>
<varlistentry><br>
- <term><br>
- <option><optional>ls options</optional></option><br>
- </term><br>
- <listitem><br>
- <para><br>
- The option passed to <command>lxc-ls</command> are the<br>
- same as the <command>ls</command> command.<br>
- </para><br>
- </listitem><br>
+ <term><br>
+ <option><optional>--frozen</optional></option><br>
+ </term><br>
+ <listitem><br>
+ <para><br>
+ List only frozen containers.<br>
+ </para><br>
+ </listitem><br>
</varlistentry><br>
- </variablelist><br>
+ <varlistentry><br>
+ <term><br>
+ <option><optional>--running</optional></option><br>
+ </term><br>
+ <listitem><br>
+ <para><br>
+ List only running containers.<br>
+ </para><br>
+ </listitem><br>
+ </varlistentry><br>
- </refsect1><br>
+ <varlistentry><br>
+ <term><br>
+ <option><optional>--stopped</optional></option><br>
+ </term><br>
+ <listitem><br>
+ <para><br>
+ List only stopped containers.<br>
+ </para><br>
+ </listitem><br>
+ </varlistentry><br>
- <refsect1><br>
- <title>Examples</title><br>
- <variablelist><br>
<varlistentry><br>
- <term>lxc-ls -l</term><br>
- <listitem><br>
- <para><br>
- list all the container and their permissions.<br>
- </para><br>
- </listitem><br>
+ <term><br>
+ <option><optional>--fancy</optional></option><br>
+ </term><br>
+ <listitem><br>
+ <para><br>
+ Use a fancy, column-based output.<br>
+ </para><br>
+ </listitem><br>
</varlistentry><br>
<varlistentry><br>
- <term>lxc-ls --active -1</term><br>
- <listitem><br>
- <para><br>
- list active containers and display the list in one column.<br>
- </para><br>
- </listitem><br>
+ <term><br>
+ <option><optional>--fancy-format</optional></option><br>
+ </term><br>
+ <listitem><br>
+ <para><br>
+ Comma separate list of column to show in the fancy output.<br>
+ Valid values are: name, state, ipv4, ipv6 and pid<br>
+ Default is: name,state,ipv4,ipv6<br>
+ </para><br>
+ </listitem><br>
</varlistentry><br>
+ <varlistentry><br>
+ <term><br>
+ <option><optional>filter</optional></option><br>
+ </term><br>
+ <listitem><br>
+ <para><br>
+ The filter passed to <command>lxc-ls</command> will be<br>
+ applied to the container name. The format is a regular<br>
expression.<br>
+ </para><br>
+ </listitem><br>
+ </varlistentry><br>
</variablelist><br>
</refsect1><br>
<refsect1><br>
- <title>See Also</title><br>
-<br>
- <simpara> - <citerefentry><br>
- <refentrytitle>ls</refentrytitle><br>
- <manvolnum>1</manvolnum><br>
- </citerefentry>,<br>
- </simpara><br>
+ <title>Examples</title><br>
+ <variablelist><br>
+ <varlistentry><br>
+ <term>lxc-ls --fancy</term><br>
+ <listitem><br>
+ <para><br>
+ list all the containers, listing one per line along with its<br>
+ name, state, ipv4 and ipv6 addresses.<br>
+ </para><br>
+ </listitem><br>
+ </varlistentry><br>
+ <varlistentry><br>
+ <term>lxc-ls --active -1</term><br>
+ <listitem><br>
+ <para><br>
+ list active containers and display the list in one column.<br>
+ </para><br>
+ </listitem><br>
+ </varlistentry><br>
+ </variablelist><br>
</refsect1><br>
- &seealso;<br>
-<br>
<refsect1><br>
<title>Author</title><br>
- <para>Daniel Lezcano <email>daniel.lezcano@free.fr</email></para><br>
+ <para>St?phane Graber <email>stgraber@ubuntu.com</email></para><br>
</refsect1><br>
-<br>
</refentry><br>
<!-- Keep this comment at the end of the file<br>
diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am<br>
index 7d86ad6..9219ba6 100644<br>
--- a/src/lxc/Makefile.am<br>
+++ b/src/lxc/Makefile.am<br>
@@ -87,7 +87,6 @@ liblxc_so_LDADD = -lutil $(CAP_LIBS) $(APPARMOR_LIBS)<br>
$(SECCOMP_LIBS) -lrt<br>
bin_SCRIPTS = \<br>
lxc-ps \<br>
lxc-netstat \<br>
- lxc-ls \<br>
lxc-checkconfig \<br>
lxc-setcap \<br>
lxc-setuid \<br>
@@ -98,6 +97,7 @@ bin_SCRIPTS = \<br>
lxc-destroy<br>
if ENABLE_PYTHON<br>
+ bin_SCRIPTS += lxc-ls<br>
bin_SCRIPTS += lxc-start-ephemeral<br>
endif<br>
diff --git a/src/lxc/lxc-ls b/src/lxc/lxc-ls<br>
new file mode 100644<br>
index 0000000..8a1d1ed<br>
--- /dev/null<br>
+++ b/src/lxc/lxc-ls<br>
@@ -0,0 +1,236 @@<br>
+#!/usr/bin/python3<br>
+#<br>
+# lxc-ls: List containers<br>
+#<br>
+# This python implementation is based on the work done in the original<br>
+# shell implementation done by Serge Hallyn in Ubuntu (and other<br>
contributors)<br>
+#<br>
+# (C) Copyright Canonical Ltd. 2012<br>
+#<br>
+# Authors:<br>
+# St?phane Graber <stgraber@ubuntu.com><br>
+#<br>
+# This library is free software; you can redistribute it and/or<br>
+# modify it under the terms of the GNU Lesser General Public<br>
+# License as published by the Free Software Foundation; either<br>
+# version 2.1 of the License, or (at your option) any later version.<br>
+#<br>
+# This library is distributed in the hope that it will be useful,<br>
+# but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br>
+# Lesser General Public License for more details.<br>
+#<br>
+# You should have received a copy of the GNU Lesser General Public<br>
+# License along with this library; if not, write to the Free Software<br>
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA<br>
+#<br>
+<br>
+# NOTE: To remove once the API is stabilized<br>
+import warnings<br>
+warnings.filterwarnings("ignore", "The python-lxc API isn't yet stable")<br>
+<br>
+import argparse<br>
+import gettext<br>
+import lxc<br>
+import re<br>
+import sys<br>
+<br>
+_ = gettext.gettext<br>
+gettext.textdomain("lxc-ls")<br>
+<br>
+<br>
+# Functions used later on<br>
+def batch(iterable, cols=1):<br>
+ import math<br>
+<br>
+ length = len(iterable)<br>
+ lines = math.ceil(length / cols)<br>
+<br>
+ for line in range(lines):<br>
+ fields = []<br>
+ for col in range(cols):<br>
+ index = line + (col * lines)<br>
+ if index < length:<br>
+ fields.append(iterable[index])<br>
+ yield fields<br>
+<br>
+<br>
+def getTerminalSize():<br>
+ import os<br>
+ env = os.environ<br>
+<br>
+ def ioctl_GWINSZ(fd):<br>
+ try:<br>
+ import fcntl<br>
+ import termios<br>
+ import struct<br>
+ cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ,<br>
+ '1234'))<br>
+ return cr<br>
+ except:<br>
+ return<br>
+<br>
+ cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)<br>
+ if not cr:<br>
+ try:<br>
+ fd = os.open(os.ctermid(), os.O_RDONLY)<br>
+ cr = ioctl_GWINSZ(fd)<br>
+ os.close(fd)<br>
+ except:<br>
+ pass<br>
+<br>
+ if not cr:<br>
+ cr = (env.get('LINES', 25), env.get('COLUMNS', 80))<br>
+<br>
+ return int(cr[1]), int(cr[0])<br>
+<br>
+# Begin parsing the command line<br>
+parser = argparse.ArgumentParser(description=_("LXC: List containers"),<br>
+<br>
formatter_class=argparse.RawTextHelpFormatter)<br>
+<br>
+parser.add_argument("-1", dest="one", action="store_true",<br>
+ help=_("list one container per line (default when<br>
piped)"))<br>
+<br>
+parser.add_argument("--active", action="store_true",<br>
+ help=_("list only active containers "<br>
+ "(same as --running --frozen)"))<br>
+<br>
+parser.add_argument("--frozen", dest="state", action="append_const",<br>
+ const="FROZEN", help=_("list only frozen containers"))<br>
+<br>
+parser.add_argument("--running", dest="state", action="append_const",<br>
+ const="RUNNING", help=_("list only running<br>
containers"))<br>
+<br>
+parser.add_argument("--stopped", dest="state", action="append_const",<br>
+ const="STOPPED", help=_("list only stopped<br>
containers"))<br>
+<br>
+parser.add_argument("--fancy", action="store_true",<br>
+ help=_("use fancy output"))<br>
+<br>
+parser.add_argument("--fancy-format", type=str,<br>
default="name,state,ipv4,ipv6",<br>
+ help=_("comma separated list of fields to show"))<br>
+<br>
+parser.add_argument("filter", metavar='FILTER', type=str, nargs="?",<br>
+ help=_("regexp to be applied on the container list"))<br>
+<br>
+args = parser.parse_args()<br>
+<br>
+# --active is the same as --running --frozen<br>
+if args.active:<br>
+ if not args.state:<br>
+ args.state = []<br>
+ args.state += ["RUNNING", "FROZEN"]<br>
+<br>
+# If the output is piped, default to --one<br>
+if not sys.stdout.isatty():<br>
+ args.one = True<br>
+<br>
+# Turn args.fancy_format into a list<br>
+args.fancy_format = args.fancy_format.strip().split(",")<br>
+<br>
+# List of containers, stored as dictionaries<br>
+containers = []<br>
+for container in lxc.list_containers(as_object=True):<br>
+ # Filter by status<br>
+ if args.state and container.state not in args.state:<br>
+ continue<br>
+<br>
+ # Apply filter<br>
+ if args.filter and not re.match(args.filter, container.name):<br>
+ continue<br>
+<br>
+ entry = {}<br>
+ entry['name'] = container.name<br>
+<br>
+ # Nothing more is needed if we're not printing some fancy output<br>
+ if not args.fancy:<br>
+ containers.append(entry)<br>
+ continue<br>
+<br>
+ # Some extra field we may want<br>
+ if 'state' in args.fancy_format:<br>
+ entry['state'] = container.state<br>
+ if 'pid' in args.fancy_format:<br>
+ entry['pid'] = "-"<br>
+ if container.init_pid != -1:<br>
+ entry['pid'] = str(container.init_pid)<br>
+<br>
+ # Get the IPs<br>
+ for protocol in ('ipv4', 'ipv6'):<br>
+ if protocol in args.fancy_format:<br>
+ entry[protocol] = "-"<br>
+ ips = container.get_ips(protocol=protocol, timeout=1)<br>
+ if ips:<br>
+ entry[protocol] = ", ".join(ips)<br>
+<br>
+ containers.append(entry)<br>
+<br>
+<br>
+# Print the list<br>
+## Standard list with one entry per line<br>
+if not args.fancy and args.one:<br>
+ for container in sorted(containers,<br>
+ key=lambda container: container['name']):<br>
+ print(container['name'])<br>
+ sys.exit(0)<br>
+<br>
+## Standard list with multiple entries per line<br>
+if not args.fancy and not args.one:<br>
+ # Get the longest name and extra simple list<br>
+ field_maxlength = 0<br>
+ container_names = []<br>
+ for container in containers:<br>
+ if len(container['name']) > field_maxlength:<br>
+ field_maxlength = len(container['name'])<br>
+ container_names.append(container['name'])<br>
+<br>
+ # Figure out how many we can put per line<br>
+ width = getTerminalSize()[0]<br>
+<br>
+ entries = int(width / (field_maxlength + 2))<br>
+ if entries == 0:<br>
+ entries = 1<br>
+<br>
+ for line in batch(sorted(container_names), entries):<br>
+ line_format = ""<br>
+ for index in range(len(line)):<br>
+ line_format += "{line[%s]:%s}" % (index, field_maxlength + 2)<br>
+<br>
+ print(line_format.format(line=line))<br>
+<br>
+## Fancy listing<br>
+if args.fancy:<br>
+ field_maxlength = {}<br>
+<br>
+ # Get the maximum length per field<br>
+ for field in args.fancy_format:<br>
+ field_maxlength[field] = len(field)<br>
+<br>
+ for container in containers:<br>
+ for field in args.fancy_format:<br>
+ if len(container[field]) > field_maxlength[field]:<br>
+ field_maxlength[field] = len(container[field])<br>
+<br>
+ # Generate the line format string based on the maximum length and<br>
+ # a 2 character padding<br>
+ line_format = ""<br>
+ index = 0<br>
+ for field in args.fancy_format:<br>
+ line_format += "{fields[%s]:%s}" % (index,<br>
field_maxlength[field] + 2)<br>
+ index += 1<br>
+<br>
+ # Get the line length minus the padding of the last field<br>
+ line_length = -2<br>
+ for field in field_maxlength:<br>
+ line_length += field_maxlength[field] + 2<br>
+<br>
+ # Print header<br>
+ print(line_format.format(fields=[header.upper()<br>
+ for header in args.fancy_format]))<br>
+ print("-" * line_length)<br>
+<br>
+ # Print the entries<br>
+ for container in sorted(containers,<br>
+ key=lambda container: container['name']):<br>
+ fields = [container[field] for field in args.fancy_format]<br>
+ print(line_format.format(fields=fields))<br>
diff --git a/src/lxc/lxc-ls.in b/src/lxc/lxc-ls.in<br>
deleted file mode 100644<br>
index f26572d..0000000<br>
--- a/src/lxc/lxc-ls.in<br>
+++ /dev/null<br>
@@ -1,94 +0,0 @@<br>
-#!/bin/bash<br>
-<br>
-#<br>
-# lxc: linux Container library<br>
-<br>
-# This library is free software; you can redistribute it and/or<br>
-# modify it under the terms of the GNU Lesser General Public<br>
-# License as published by the Free Software Foundation; either<br>
-# version 2.1 of the License, or (at your option) any later version.<br>
-<br>
-# This library is distributed in the hope that it will be useful,<br>
-# but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br>
-# Lesser General Public License for more details.<br>
-<br>
-# You should have received a copy of the GNU Lesser General Public<br>
-# License along with this library; if not, write to the Free Software<br>
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA<br>
-<br>
-lxc_path=@LXCPATH@<br>
-<br>
-usage()<br>
-{<br>
- echo "usage: $(basename $0) [--active] [--] [LS_OPTIONS...]" >&2<br>
-}<br>
-<br>
-help() {<br>
- usage<br>
- echo >&2<br>
- echo "List containers existing on the system." >&2<br>
- echo >&2<br>
- echo " --active list active containers" >&2<br>
- echo " LS_OPTIONS ls command options (see \`ls --help')" >&2<br>
-}<br>
-<br>
-get_parent_cgroup()<br>
-{<br>
- local hierarchies hierarchy fields subsystems init_cgroup mountpoint<br>
-<br>
- parent_cgroup=""<br>
-<br>
- # Obtain a list of hierarchies that contain one or more subsystems<br>
- hierarchies=$(tail -n +2 /proc/cgroups | cut -f 2)<br>
-<br>
- # Iterate through the list until a suitable hierarchy is found<br>
- for hierarchy in $hierarchies; do<br>
- # Obtain information about the init process in the hierarchy<br>
- fields=$(grep -E "^$hierarchy:" /proc/1/cgroup | head -n 1)<br>
- if [ -z "$fields" ]; then continue; fi<br>
- fields=${fields#*:}<br>
-<br>
- # Get a comma-separated list of the hierarchy's subsystems<br>
- subsystems=${fields%:*}<br>
-<br>
- # Get the cgroup of the init process in the hierarchy<br>
- init_cgroup=${fields#*:}<br>
-<br>
- # Get the filesystem mountpoint of the hierarchy<br>
- mountpoint=$(grep -E "^[^ ]+ [^ ]+ cgroup ([^ ]+,)?$subsystems(,[^<br>
]+)? " /proc/self/mounts | cut -d ' ' -f 2)<br>
- if [ -z "$mountpoint" ]; then continue; fi<br>
-<br>
- # Return the absolute path to the containers' parent cgroup<br>
- # (do not append '/lxc' if the hierarchy contains the 'ns' subsystem)<br>
- if [[ ",$subsystems," == *,ns,* ]]; then<br>
- parent_cgroup="${mountpoint}${init_cgroup%/}"<br>
- else<br>
- parent_cgroup="${mountpoint}${init_cgroup%/}/lxc"<br>
- fi<br>
- break<br>
- done<br>
-}<br>
-<br>
-directory=$(readlink -f "$lxc_path")<br>
-<br>
-for i in "$@"; do<br>
- case $i in<br>
- --help)<br>
- help; exit;;<br>
- --active)<br>
- get_parent_cgroup; directory="$parent_cgroup"; shift;;<br>
- --)<br>
- shift; break;;<br>
- *)<br>
- break;;<br>
- esac<br>
-done<br>
-<br>
-containers=""<br>
-if [ ! -z "$directory" ]; then<br>
- containers=$(find $directory -mindepth 1 -maxdepth 1 -type d -printf<br>
"%f\n" 2>/dev/null)<br>
-fi<br>
-<br>
-cd "$directory"<br>
-ls -d $@ -- $containers<br>
--<br>
1.8.0<br>
<br>
<br>
-------------- next part --------------<br>
A non-text attachment was scrubbed...<br>
Name: signature.asc<br>
Type: application/pgp-signature<br>
Size: 899 bytes<br>
Desc: OpenPGP digital signature<br>
<br>
------------------------------<br>
<br>
------------------------------------------------------------------------------<br>
Monitor your physical, virtual and cloud infrastructure from a single<br>
web console. Get in-depth insight into apps, servers, databases, vmware,<br>
SAP, cloud infrastructure, etc. Download 30-day Free Trial.<br>
Pricing starts from $795 for 25 servers or applications!<br>
http://p.sf.net/sfu/zoho_dev2dev_nov<br>
<br>
------------------------------<br>
<br>
_______________________________________________<br>
Lxc-devel mailing list<br>
Lxc-devel@lists.sourceforge.net<br>
https://lists.sourceforge.net/lists/listinfo/lxc-devel<br>
<br>
<br>
End of Lxc-devel Digest, Vol 51, Issue 13<br>
*****************************************<br>
<br>
</div>
</body>
</html>