#define CONTAINER_TYPENAME "lxc.container"
+/* Max Lua arguments for function */
+#define MAXVARS 200
+
static int container_new(lua_State *L)
{
struct lxc_container *c;
return 1;
}
+static int container_rename(lua_State *L)
+{
+ struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
+ const char *new_name;
+ int argc = lua_gettop(L);
+
+ if (argc > 1) {
+ new_name = luaL_checkstring(L, 2);
+ lua_pushboolean(L, !!c->rename(c, new_name));
+ } else
+ lua_pushnil(L);
+ return 1;
+}
+
static int container_freeze(lua_State *L)
{
struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
return 1;
}
+static int container_get_interfaces(lua_State *L)
+{
+ struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
+ char **ifaces;
+ int i;
+
+ ifaces = c->get_interfaces(c);
+
+ if (!ifaces){
+ lua_pushnil(L);
+ return 1;
+ }
+
+ for (i = 0; ifaces[i]; i++);
+
+ /* protect LUA stack form overflow */
+ if (i > MAXVARS || !lua_checkstack(L, i)){
+ for (i = 0; ifaces[i]; i++)
+ free(ifaces[i]);
+ lua_pushnil(L);
+ return 1;
+ }
+ for (i = 0; ifaces[i]; i++){
+ lua_pushstring(L, ifaces[i]);
+ free(ifaces[i]);
+ }
+ return i;
+}
+
+static int container_get_ips(lua_State *L)
+{
+ struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
+ int argc = lua_gettop(L);
+ char **addresses;
+ char *iface = NULL, *family = NULL;
+ int i, scope = 0;
+
+ if (argc > 1)
+ iface = (char *)luaL_checkstring(L, 2);
+ if (argc > 2)
+ family = (char *)luaL_checkstring(L, 3);
+ if (argc > 3)
+ scope = luaL_checkinteger(L, 4);
+
+ addresses = c->get_ips(c, iface, family, scope);
+
+ if (!addresses){
+ lua_pushnil(L);
+ return 1;
+ }
+
+ for (i = 0; addresses[i]; i++);
+
+ /* protect LUA stack form overflow */
+ if (i > MAXVARS || !lua_checkstack(L, i)){
+ for (i = 0; addresses[i]; i++)
+ free(addresses[i]);
+ lua_pushnil(L);
+ return 1;
+ }
+ for (i = 0; addresses[i]; i++){
+ lua_pushstring(L, addresses[i]);
+ free(addresses[i]);
+ }
+ return i;
+}
+
static luaL_Reg lxc_container_methods[] =
{
{"attach", container_attach},
{"stop", container_stop},
{"shutdown", container_shutdown},
{"wait", container_wait},
+ {"rename", container_rename},
{"config_file_name", container_config_file_name},
{"load_config", container_load_config},
{"set_config_item", container_set_config_item},
{"clear_config_item", container_clear_config_item},
{"get_keys", container_get_keys},
+ {"get_interfaces", container_get_interfaces},
+ {"get_ips", container_get_ips},
{NULL, NULL}
};
return self.core:destroy()
end
+-- return nil if name missing
+function container:rename(name)
+ return self.core:rename(name)
+end
+
function container:get_config_path()
return self.core:get_config_path()
end
return ktab
end
+-- return nil or more args
+function container:get_interfaces()
+ return self.core:get_interfaces()
+end
+
+-- return nil or more args
+function container:get_ips(...)
+ return self.core:get_ips(...)
+end
+
function container:load_config(alt_path)
if (alt_path) then
return self.core:load_config(alt_path)