add [gs]et_cgroup_item to lua api

fix up api test to run and add test for new [gs]et_cgroup_item

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
Dwight Engen 2013-10-31 16:38:22 -04:00 committed by Serge Hallyn
parent b12e1cb533
commit 80ee22284b
3 changed files with 64 additions and 0 deletions

View File

@ -282,6 +282,29 @@ static int container_clear_config_item(lua_State *L)
return 1; return 1;
} }
static int container_get_cgroup_item(lua_State *L)
{
struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
const char *key = luaL_checkstring(L, 2);
int len;
char *value;
len = c->get_cgroup_item(c, key, NULL, 0);
if (len <= 0)
goto not_found;
value = alloca(sizeof(char)*len + 1);
if (c->get_cgroup_item(c, key, value, len + 1) != len)
goto not_found;
lua_pushstring(L, value);
return 1;
not_found:
lua_pushnil(L);
return 1;
}
static int container_get_config_item(lua_State *L) static int container_get_config_item(lua_State *L)
{ {
struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME); struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
@ -305,6 +328,16 @@ not_found:
return 1; return 1;
} }
static int container_set_cgroup_item(lua_State *L)
{
struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
const char *key = luaL_checkstring(L, 2);
const char *value = luaL_checkstring(L, 3);
lua_pushboolean(L, !!c->set_cgroup_item(c, key, value));
return 1;
}
static int container_set_config_item(lua_State *L) static int container_set_config_item(lua_State *L)
{ {
struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME); struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
@ -361,6 +394,8 @@ static luaL_Reg lxc_container_methods[] =
{"config_file_name", container_config_file_name}, {"config_file_name", container_config_file_name},
{"load_config", container_load_config}, {"load_config", container_load_config},
{"save_config", container_save_config}, {"save_config", container_save_config},
{"get_cgroup_item", container_get_cgroup_item},
{"set_cgroup_item", container_set_cgroup_item},
{"get_config_path", container_get_config_path}, {"get_config_path", container_get_config_path},
{"set_config_path", container_set_config_path}, {"set_config_path", container_set_config_path},
{"get_config_item", container_get_config_item}, {"get_config_item", container_get_config_item},

View File

@ -189,6 +189,10 @@ function container:clear_config_item(key)
return self.core:clear_config_item(key) return self.core:clear_config_item(key)
end end
function container:get_cgroup_item(key)
return self.core:get_cgroup_item(key)
end
function container:get_config_item(key) function container:get_config_item(key)
local value local value
local vals = {} local vals = {}
@ -209,6 +213,10 @@ function container:get_config_item(key)
return vals return vals
end end
function container:set_cgroup_item(key, value)
return self.core:set_cgroup_item(key, value)
end
function container:set_config_item(key, value) function container:set_config_item(key, value)
return self.core:set_config_item(key, value) return self.core:set_config_item(key, value)
end end
@ -410,6 +418,14 @@ function M.containers_running(names_only)
return containers return containers
end end
function M.version_get()
return core.version_get()
end
function M.default_config_path_get()
return core.default_config_path_get()
end
lxc_path = core.default_config_path_get() lxc_path = core.default_config_path_get()
cgroup_path = cgroup_path_get() cgroup_path = cgroup_path_get()

View File

@ -206,6 +206,17 @@ function test_container_in_cfglist(should_find)
end end
end end
function test_container_cgroup()
log(0, "Test get/set cgroup items...")
max_mem = container:get_cgroup_item("memory.max_usage_in_bytes")
saved_limit = container:get_cgroup_item("memory.limit_in_bytes")
assert(saved_limit ~= max_mem)
assert(container:set_cgroup_item("memory.limit_in_bytes", max_mem))
assert(container:get_cgroup_item("memory.limit_in_bytes") ~= saved_limit)
assert(container:set_cgroup_item("memory.limit_in_bytes", "-1"))
end
function test_config_items() function test_config_items()
log(0, "Test set/clear configuration items...") log(0, "Test set/clear configuration items...")
@ -313,6 +324,8 @@ test_config_network(0)
test_container_start() test_container_start()
test_container_started() test_container_started()
test_container_cgroup()
test_container_freeze() test_container_freeze()
test_container_frozen() test_container_frozen()
test_container_unfreeze() test_container_unfreeze()