]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc-info: Allow printing IP addresses
authorStéphane Graber <stgraber@ubuntu.com>
Fri, 27 Sep 2013 04:23:09 +0000 (00:23 -0400)
committerStéphane Graber <stgraber@ubuntu.com>
Fri, 27 Sep 2013 13:31:17 +0000 (09:31 -0400)
This adds a new -i flag to lxc-info to print the container's IP
addresses using get_ips().

Example:
$ lxc-info -n lxc-dev -s -p -i
state:  RUNNING
pid:    21331
ip:     10.0.3.165
ip:     2607:f2c0:f00f:2751:e9ca:842f:efa9:97d1
ip:     2607:f2c0:f00f:2751:216:3eff:fe3a:f1c1

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
doc/lxc-info.sgml.in
src/lxc/lxc_info.c

index c6fc624ba3e169977c479da592d691b16bbc5e38..819d5cae1af17cc162d40fe003495dada0bd5eb2 100644 (file)
@@ -51,6 +51,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
       <arg choice="opt">-c <replaceable>KEY</replaceable></arg>
       <arg choice="opt">-s</arg>
       <arg choice="opt">-p</arg>
+      <arg choice="opt">-i</arg>
       <arg choice="opt">-t <replaceable>state</replaceable></arg>
     </cmdsynopsis>
   </refsynopsisdiv>
@@ -112,6 +113,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
         </listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term>
+          <option><optional>-i</optional></option>
+        </term>
+        <listitem>
+          <para>
+            Just print the container's IP addresses.
+          </para>
+        </listitem>
+      </varlistentry>
+
       <varlistentry>
         <term>
           <option><optional>-t <replaceable>state</replaceable></optional></option>
index ab3aacff4f71d4b20bfa0e52160fd594eabdd2bf..23cf789506c0be958ff99b4fc8dcc4aacd1579db 100644 (file)
@@ -20,6 +20,7 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
+
 #include <stdio.h>
 #include <stdbool.h>
 #include <stdlib.h>
@@ -34,6 +35,7 @@
 #include "commands.h"
 #include "arguments.h"
 
+static bool ips;
 static bool state;
 static bool pid;
 static char *test_state = NULL;
@@ -48,6 +50,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
                key[keys] = arg;
                keys++;
                break;
+       case 'i': ips = true; break;
        case 's': state = true; break;
        case 'p': pid = true; break;
        case 't': test_state = arg; break;
@@ -57,6 +60,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
 
 static const struct option my_longopts[] = {
        {"config", required_argument, 0, 'c'},
+       {"ips", no_argument, 0, 'i'},
        {"state", no_argument, 0, 's'},
        {"pid", no_argument, 0, 'p'},
        {"state-is", required_argument, 0, 't'},
@@ -73,6 +77,7 @@ lxc-info display some information about a container with the identifier NAME\n\
 Options :\n\
   -n, --name=NAME       NAME for name of the container\n\
   -c, --config=KEY      show configuration variable KEY from running container\n\
+  -i, --ips             shows the IP addresses\n\
   -p, --pid             shows the process id of the init container\n\
   -s, --state           shows the state of the container\n\
   -t, --state-is=STATE  test if current state is STATE\n\
@@ -99,14 +104,14 @@ int main(int argc, char *argv[])
        if (!c)
                return -1;
 
-       if (!state && !pid && keys <= 0)
-               state = pid = true;
+       if (!state && !pid && !ips && keys <= 0)
+               state = pid = ips = true;
 
        if (state || test_state) {
                if (test_state)
                        return strcmp(c->state(c), test_state) != 0;
 
-               printf("state:%10s\n", c->state(c));
+               printf("state: \t%s\n", c->state(c));
        }
 
        if (pid) {
@@ -114,7 +119,18 @@ int main(int argc, char *argv[])
 
                initpid = c->init_pid(c);
                if (initpid >= 0)
-                       printf("pid:%10d\n", initpid);
+                       printf("pid: \t%d\n", initpid);
+       }
+
+       if (ips) {
+               char **addresses = c->get_ips(c, NULL, NULL, 0);
+               char *address;
+               i = 0;
+               while (addresses[i]) {
+                       address = addresses[i];
+                       printf("ip: \t%s\n", address);
+                       i++;
+               }
        }
 
        for(i = 0; i < keys; i++) {