[lxc-devel] [PATCH 2/2] allow lxc-info to get running container configuration
Dwight Engen
dwight.engen at oracle.com
Mon Jul 1 16:38:23 UTC 2013
Signed-off-by: Dwight Engen <dwight.engen at oracle.com>
---
doc/lxc-info.sgml.in | 28 +++++++++++++++++++++++++---
src/lxc/lxc_info.c | 27 ++++++++++++++++++++++++---
2 files changed, 49 insertions(+), 6 deletions(-)
diff --git a/doc/lxc-info.sgml.in b/doc/lxc-info.sgml.in
index ba0a044..39cd4d1 100644
--- a/doc/lxc-info.sgml.in
+++ b/doc/lxc-info.sgml.in
@@ -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>
@@ -79,6 +80,18 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
<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>
</term>
<listitem>
@@ -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>
diff --git a/src/lxc/lxc_info.c b/src/lxc/lxc_info.c
index f86626d..b8d1c18 100644
--- a/src/lxc/lxc_info.c
+++ b/src/lxc/lxc_info.c
@@ -36,10 +36,17 @@
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;
}
--
1.8.1.4
More information about the lxc-devel
mailing list