]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
allow lxc-info to get running container configuration
authorDwight Engen <dwight.engen@oracle.com>
Mon, 1 Jul 2013 16:38:23 +0000 (12:38 -0400)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Mon, 1 Jul 2013 21:47:04 +0000 (16:47 -0500)
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
doc/lxc-info.sgml.in
src/lxc/lxc_info.c

index ba0a044d110432a46ae4c2d1480f8d7071dbf1ab..39cd4d1720d818c81fc696451bf7cb04260db5a8 100644 (file)
@@ -48,9 +48,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
     <cmdsynopsis>
       <command>lxc-info</command>
       <arg choice="req">-n <replaceable>name</replaceable></arg>
-      <arg choice="req">-s</arg>
-      <arg choice="req">-p</arg>
-      <arg choice="req">-t <replaceable>state</replaceable></arg>
+      <arg choice="opt">-c <replaceable>KEY</replaceable></arg>
+      <arg choice="opt">-s</arg>
+      <arg choice="opt">-p</arg>
+      <arg choice="opt">-t <replaceable>state</replaceable></arg>
     </cmdsynopsis>
   </refsynopsisdiv>
 
@@ -77,6 +78,18 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
         </listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term>
+          <option><optional>-c <replaceable>KEY</replaceable></optional></option>
+        </term>
+        <listitem>
+          <para>
+            Print a configuration key from the running container. This option
+            may be given mulitple times to print out multiple key = value pairs.
+          </para>
+        </listitem>
+      </varlistentry>
+
       <varlistentry>
         <term>
           <option><optional>-s</optional></option>
@@ -135,6 +148,15 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
         </listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term>lxc-info -n foo -c lxc.network.0.veth.pair</term>
+        <listitem>
+          <para>
+            prints the veth pair name of foo.
+          </para>
+        </listitem>
+      </varlistentry>
+
     </variablelist>
   </refsect1>
 
index f86626d9787e5044f6e6a0ebeb900cadfcaa8704..b8d1c1873c446b4c97676cbba47b40dfd5cf6414 100644 (file)
 static bool state;
 static bool pid;
 static char *test_state = NULL;
+static char **key = NULL;
+static int keys = 0;
 
 static int my_parser(struct lxc_arguments* args, int c, char* arg)
 {
        switch (c) {
+       case 'c':
+               key = realloc(key, keys+1 * sizeof(key[0]));
+               key[keys] = arg;
+               keys++;
+               break;
        case 's': state = true; break;
        case 'p': pid = true; break;
        case 't': test_state = arg; break;
@@ -48,6 +55,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
 }
 
 static const struct option my_longopts[] = {
+       {"config", required_argument, 0, 'c'},
        {"state", no_argument, 0, 's'},
        {"pid", no_argument, 0, 'p'},
        {"state-is", required_argument, 0, 't'},
@@ -63,8 +71,9 @@ lxc-info display some information about a container with the identifier NAME\n\
 \n\
 Options :\n\
   -n, --name=NAME       NAME for name of the container\n\
-  -s, --state           shows the state of the container\n\
+  -c, --config=KEY      show configuration variable KEY from running container\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\
                         returns success if it matches, false otherwise\n",
        .options  = my_longopts,
@@ -74,7 +83,7 @@ Options :\n\
 
 int main(int argc, char *argv[])
 {
-       int ret;
+       int ret,i;
 
        ret = lxc_arguments_parse(&my_args, argc, argv);
        if (ret)
@@ -84,7 +93,7 @@ int main(int argc, char *argv[])
                         my_args.progname, my_args.quiet, my_args.lxcpath[0]))
                return 1;
 
-       if (!state && !pid)
+       if (!state && !pid && keys <= 0)
                state = pid = true;
 
        if (state || test_state) {
@@ -105,5 +114,17 @@ int main(int argc, char *argv[])
                        printf("pid:%10d\n", initpid);
        }
 
+       for(i = 0; i < keys; i++) {
+               char *val;
+
+               val = lxc_cmd_get_config_item(my_args.name, key[i], my_args.lxcpath[0]);
+               if (val) {
+                       printf("%s = %s\n", key[i], val);
+                       free(val);
+               } else {
+                       fprintf(stderr, "%s unset or invalid\n", key[i]);
+               }
+       }
+
        return 0;
 }