}
static int lxc_default_config_path_get(lua_State *L) {
- const char *lxcpath = lxc_get_default_config_path();
+ const char *lxcpath = lxc_get_global_config_item("lxc.lxcpath");
lua_pushstring(L, lxcpath);
return 1;
/* If no lxcpaths were given, use default */
if (!args->lxcpath_cnt) {
- ret = lxc_arguments_lxcpath_add(args, default_lxc_path());
+ ret = lxc_arguments_lxcpath_add(args, lxc_global_config_value("lxc.lxcpath"));
if (ret < 0)
return ret;
}
return -1;
*p = '\0';
} else
- zfsroot = default_zfs_root();
+ zfsroot = lxc_global_config_value("lxc.zfsroot");
ret = snprintf(option, MAXPATHLEN, "-omountpoint=%s/%s/rootfs",
lxcpath, nname);
pid_t pid;
if (!specs || !specs->zfs.zfsroot)
- zfsroot = default_zfs_root();
+ zfsroot = lxc_global_config_value("lxc.zfsroot");
else
zfsroot = specs->zfs.zfsroot;
orig->type);
return -1;
}
- vg = default_lvm_vg();
+ vg = lxc_global_config_value("lxc.lvm_vg");
len = strlen("/dev/") + strlen(vg) + strlen(cname) + 2;
if ((new->src = malloc(len)) == NULL)
return -1;
return -1;
}
} else {
- if (do_lvm_create(new->src, size, default_lvm_thin_pool()) < 0) {
+ if (do_lvm_create(new->src, size, lxc_global_config_value("lxc.lvm_thin_pool")) < 0) {
ERROR("Error creating new lvm blockdev");
return -1;
}
vg = specs->lvm.vg;
if (!vg)
- vg = default_lvm_vg();
+ vg = lxc_global_config_value("lxc.lvm_vg");
thinpool = specs->lvm.thinpool;
if (!thinpool)
- thinpool = default_lvm_thin_pool();
+ thinpool = lxc_global_config_value("lxc.lvm_thin_pool");
/* /dev/$vg/$lv */
if (specs->lvm.lv)
int saved_errno;
errno = 0;
- cgroup_use = default_cgroup_use();
+ cgroup_use = lxc_global_config_value("lxc.cgroup.use");
if (!cgroup_use && errno != 0)
return NULL;
if (cgroup_use) {
int ret;
if (!inpath) {
- lxcpath = default_lxc_path();
+ lxcpath = lxc_global_config_value("lxc.lxcpath");
if (!lxcpath) {
ERROR("Out of memory getting lxcpath");
return -1;
return -1;
}
- lxcpath = default_lxc_path();
+ lxcpath = lxc_global_config_value("lxc.lxcpath");
if (!lxcpath) {
ERROR("Out of memory");
return -1;
lxcpath = LOGPATH;
/* try LOGPATH if lxcpath is the default */
- if (strcmp(lxcpath, default_lxc_path()) == 0)
+ if (strcmp(lxcpath, lxc_global_config_value("lxc.lxcpath")) == 0)
ret = _lxc_log_set_file(name, NULL, 0);
/* try in lxcpath */
struct lxc_config_items {
char *name;
- const char *(*fn)(void);
};
static struct lxc_config_items items[] =
{
- { .name = "lxc.lxcpath", .fn = &lxc_get_default_config_path, },
- { .name = "lxc.lvm_vg", .fn = &lxc_get_default_lvm_vg, },
- { .name = "lxc.lvm_thin_pool", .fn = &lxc_get_default_lvm_thin_pool, },
- { .name = "lxc.zfsroot", .fn = &lxc_get_default_zfs_root, },
+ { .name = "lxc.default_config", },
+ { .name = "lxc.lxcpath", },
+ { .name = "lxc.lvm_vg", },
+ { .name = "lxc.lvm_thin_pool", },
+ { .name = "lxc.zfsroot", },
{ .name = NULL, },
};
list_config_items();
for (i = &items[0]; i->name; i++) {
if (strcmp(argv[1], i->name) == 0) {
- printf("%s\n", i->fn());
+ printf("%s\n", lxc_get_global_config_item(i->name));
exit(0);
}
}
return ret;
}
-const char *lxc_get_default_config_path(void)
+const char *lxc_get_global_config_item(const char *key)
{
- return default_lxc_path();
-}
-
-const char *lxc_get_default_lvm_vg(void)
-{
- return default_lvm_vg();
-}
-
-const char *lxc_get_default_lvm_thin_pool(void)
-{
- return default_lvm_thin_pool();
-}
-
-const char *lxc_get_default_zfs_root(void)
-{
- return default_zfs_root();
+ return lxc_global_config_value(key);
}
const char *lxc_get_version(void)
if (configpath)
c->config_path = strdup(configpath);
else
- c->config_path = strdup(default_lxc_path());
+ c->config_path = strdup(lxc_global_config_value("lxc.lxcpath"));
if (!c->config_path) {
fprintf(stderr, "Out of memory");
struct lxc_container *c;
if (!lxcpath)
- lxcpath = default_lxc_path();
+ lxcpath = lxc_global_config_value("lxc.lxcpath");
dir = opendir(lxcpath);
if (!dir) {
struct lxc_container *c;
if (!lxcpath)
- lxcpath = default_lxc_path();
+ lxcpath = lxc_global_config_value("lxc.lxcpath");
lxcpath_len = strlen(lxcpath);
if (cret)
*/
int lxc_get_wait_states(const char **states);
-/*!
- * \brief Determine path to default configuration file.
- *
- * \return Static string representing full path to default configuration
- * file.
- *
- * \note Returned string must not be freed.
- */
-const char *lxc_get_default_config_path(void);
-
-/*!
- * \brief Determine default LVM volume group.
- *
- * \return Static string representing default volume group,
- * or \c NULL on error.
- *
- * \note Returned string must not be freed.
- */
-const char *lxc_get_default_lvm_vg(void);
-
-/*!
- * \brief Determine default LVM thin pool.
- *
- * \return Static string representing default lvm thin pool,
- * or \c NULL on error.
- *
- * \note Returned string must not be freed.
- */
-const char *lxc_get_default_lvm_thin_pool(void);
-
-/*!
- * \brief Determine default ZFS root.
+/*
+ * \brief Get the value for a global config key
*
- * \return Static string representing default ZFS root,
- * or \c NULL on error.
+ * \param key The name of the config key
*
- * \note Returned string must not be freed.
+ * \return String representing the current value for the key.
*/
-const char *lxc_get_default_zfs_root(void);
+const char *lxc_get_global_config_item(const char *key);
/*!
* \brief Determine version of LXC.
* default value is available
*/
if (getuid() == 0)
- cgroup_pattern = default_cgroup_pattern();
+ cgroup_pattern = lxc_global_config_value("lxc.cgroup.pattern");
if (!cgroup_pattern)
cgroup_pattern = "%n";
#define DEFAULT_THIN_POOL "lxc"
#define DEFAULT_ZFSROOT "lxc"
-static const char *lxc_global_config_value(const char *option_name)
+const char *lxc_global_config_value(const char *option_name)
{
static const char * const options[][2] = {
{ "lxc.lvm_vg", DEFAULT_VG },
return values[i];
}
-const char *default_lvm_vg(void)
-{
- return lxc_global_config_value("lxc.lvm_vg");
-}
-
-const char *default_lvm_thin_pool(void)
-{
- return lxc_global_config_value("lxc.lvm_thin_pool");
-}
-
-const char *default_zfs_root(void)
-{
- return lxc_global_config_value("lxc.zfsroot");
-}
-
-const char *default_lxc_path(void)
-{
- return lxc_global_config_value("lxc.lxcpath");
-}
-
-const char *default_cgroup_use(void)
-{
- return lxc_global_config_value("lxc.cgroup.use");
-}
-
-const char *default_cgroup_pattern(void)
-{
- return lxc_global_config_value("lxc.cgroup.pattern");
-}
-
const char *get_rundir()
{
const char *rundir;
extern void remove_trailing_slashes(char *p);
extern const char *get_rundir(void);
-/*
- * Return a buffer containing the default container path.
- * Caller must NOT free this buffer, since it may be static.
- */
-extern const char *default_lxc_path(void);
-extern const char *default_zfs_root(void);
-extern const char *default_lvm_vg(void);
-extern const char *default_lvm_thin_pool(void);
-extern const char *default_cgroup_use(void);
-extern const char *default_cgroup_pattern(void);
+extern const char *lxc_global_config_value(const char *option_name);
+
/* Define getline() if missing from the C library */
#ifndef HAVE_GETLINE
#ifdef HAVE_FGETLN
}
static PyObject *
-LXC_get_default_config_path(PyObject *self, PyObject *args)
+LXC_get_global_config_item(PyObject *self, PyObject *args, PyObject *kwds)
{
- return PyUnicode_FromString(lxc_get_default_config_path());
+ static char *kwlist[] = {"key", NULL};
+ char* key = NULL;
+
+ if (! PyArg_ParseTupleAndKeywords(args, kwds, "s|", kwlist,
+ &key))
+ return NULL;
+
+ return PyUnicode_FromString(lxc_get_global_config_item(key));
}
static PyObject *
{"attach_run_shell", (PyCFunction)LXC_attach_run_shell, METH_O,
"Starts up a shell when attaching, to use as the run parameter for "
"attach or attach_wait"},
- {"get_default_config_path", (PyCFunction)LXC_get_default_config_path,
- METH_NOARGS,
+ {"get_global_config_item", (PyCFunction)LXC_get_global_config_item,
+ METH_VARARGS|METH_KEYWORDS,
"Returns the current LXC config path"},
{"get_version", (PyCFunction)LXC_get_version, METH_NOARGS,
"Returns the current LXC library version"},
warnings.warn("The python-lxc API isn't yet stable "
"and may change at any point in the future.", Warning, 2)
-default_config_path = _lxc.get_default_config_path()
+default_config_path = _lxc.get_global_config_item("lxc.lxcpath")
version = _lxc.get_version()
c->destroy(c);
lxc_container_put(c);
}
- snprintf(snappath, 1024, "%ssnaps/%s", lxc_get_default_config_path(), MYNAME);
+ snprintf(snappath, 1024, "%ssnaps/%s", lxc_get_global_config_item("lxc.lxcpath"), MYNAME);
c = lxc_container_new("snap0", snappath);
if (c) {
if (c->is_defined(c))
struct stat sb;
int ret;
char path[1024];
- snprintf(path, 1024, "%ssnaps/%s/snap0/rootfs", lxc_get_default_config_path(), MYNAME);
+ snprintf(path, 1024, "%ssnaps/%s/snap0/rootfs", lxc_get_global_config_item("lxc.lxcpath"), MYNAME);
ret = stat(path, &sb);
if (ret != 0) {
fprintf(stderr, "%s: %d: snapshot was not actually created\n", __FILE__, __LINE__);