On Mon, Nov 04, 2013 at 05:35:07PM -0500, Dwight Engen wrote: > Signed-off-by: Dwight Engen <dwight.en...@oracle.com>
I first got pretty confused between get_config_item and cmd_get_config_item but once I got my brain to parse this all properly, it looks fine :) Acked-by: Stéphane Graber <stgra...@ubuntu.com> > --- > src/lua-lxc/core.c | 25 +++++++++++++++++++++++++ > src/lua-lxc/lxc.lua | 8 ++++++++ > src/lua-lxc/test/apitest.lua | 7 +++++++ > 3 files changed, 40 insertions(+) > > diff --git a/src/lua-lxc/core.c b/src/lua-lxc/core.c > index ea19cc3..9492c07 100644 > --- a/src/lua-lxc/core.c > +++ b/src/lua-lxc/core.c > @@ -30,6 +30,7 @@ > #include <unistd.h> > #include <libgen.h> > #include <lxc/lxccontainer.h> > +#include <lxc/commands.h> > > #if LUA_VERSION_NUM < 502 > #define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l)) > @@ -417,6 +418,29 @@ static int lxc_default_config_path_get(lua_State *L) { > return 1; > } > > +static int cmd_get_config_item(lua_State *L) > +{ > + int arg_cnt = lua_gettop(L); > + const char *name = luaL_checkstring(L, 1); > + const char *key = luaL_checkstring(L, 2); > + const char *lxcpath = NULL; > + char *value; > + > + if (arg_cnt > 2) > + lxcpath = luaL_checkstring(L, 3); > + > + value = lxc_cmd_get_config_item(name, key, lxcpath); > + if (!value) > + goto not_found; > + > + lua_pushstring(L, value); > + return 1; > + > +not_found: > + lua_pushnil(L); > + return 1; > +} > + > /* utility functions */ > static int lxc_util_usleep(lua_State *L) { > usleep((useconds_t)luaL_checkunsigned(L, 1)); > @@ -432,6 +456,7 @@ static int lxc_util_dirname(lua_State *L) { > static luaL_Reg lxc_lib_methods[] = { > {"version_get", lxc_version_get}, > {"default_config_path_get", lxc_default_config_path_get}, > + {"cmd_get_config_item", cmd_get_config_item}, > {"container_new", container_new}, > {"usleep", lxc_util_usleep}, > {"dirname", lxc_util_dirname}, > diff --git a/src/lua-lxc/lxc.lua b/src/lua-lxc/lxc.lua > index 265e991..44e4bf1 100755 > --- a/src/lua-lxc/lxc.lua > +++ b/src/lua-lxc/lxc.lua > @@ -385,6 +385,14 @@ function M.default_config_path_get() > return core.default_config_path_get() > end > > +function M.cmd_get_config_item(name, item, lxcpath) > + if (lxcpath) then > + return core.cmd_get_config_item(name, item, lxcpath) > + else > + return core.cmd_get_config_item(name, item) > + end > +end > + > lxc_path = core.default_config_path_get() > > return M > diff --git a/src/lua-lxc/test/apitest.lua b/src/lua-lxc/test/apitest.lua > index f957ca4..f299b6a 100755 > --- a/src/lua-lxc/test/apitest.lua > +++ b/src/lua-lxc/test/apitest.lua > @@ -217,6 +217,12 @@ function test_container_cgroup() > assert(container:set_cgroup_item("memory.limit_in_bytes", "-1")) > end > > +function test_container_cmd() > + log(0, "Test get config from running container...") > + veth_pair = lxc.cmd_get_config_item(optarg["n"], > "lxc.network.0.veth.pair") > + log(0, " veth.pair:%s", veth_pair) > +end > + > function test_config_items() > log(0, "Test set/clear configuration items...") > > @@ -325,6 +331,7 @@ test_container_start() > test_container_started() > > test_container_cgroup() > +test_container_cmd() > > test_container_freeze() > test_container_frozen() > -- > 1.8.3.1 > > > ------------------------------------------------------------------------------ > November Webinars for C, C++, Fortran Developers > Accelerate application performance with scalable programming models. Explore > techniques for threading, error checking, porting, and tuning. Get the most > from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk > _______________________________________________ > Lxc-devel mailing list > Lxc-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/lxc-devel -- Stéphane Graber Ubuntu developer http://www.ubuntu.com
signature.asc
Description: Digital signature
------------------------------------------------------------------------------ November Webinars for C, C++, Fortran Developers Accelerate application performance with scalable programming models. Explore techniques for threading, error checking, porting, and tuning. Get the most from the latest Intel processors and coprocessors. See abstracts and register http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel