Commit 8ac18377 by S.Çağlar Onur Committed by Stéphane Graber

export lxc_cmd_get_config_item via API and use in lxc-info

This allows external users to query network related config items from the running containers. changes since v1: - function name change Signed-off-by: 's avatarS.Çağlar Onur <caglar@10ur.org> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent 4deda3b5
......@@ -139,7 +139,7 @@ static unsigned long long str_size_humanize(char *iobuf, size_t iobufsz)
return val;
}
static void print_net_stats(const char *name, const char *lxcpath)
static void print_net_stats(struct lxc_container *c)
{
int rc,netnr;
unsigned long long rx_bytes = 0, tx_bytes = 0;
......@@ -149,7 +149,7 @@ static void print_net_stats(const char *name, const char *lxcpath)
for(netnr = 0; ;netnr++) {
sprintf(buf, "lxc.network.%d.type", netnr);
type = lxc_cmd_get_config_item(name, buf, lxcpath);
type = c->get_running_config_item(c, buf);
if (!type)
break;
......@@ -159,7 +159,7 @@ static void print_net_stats(const char *name, const char *lxcpath)
sprintf(buf, "lxc.network.%d.link", netnr);
}
free(type);
ifname = lxc_cmd_get_config_item(name, buf, lxcpath);
ifname = c->get_running_config_item(c, buf);
if (!ifname)
return;
printf("%-15s %s\n", "Link:", ifname);
......@@ -326,7 +326,7 @@ static int print_info(const char *name, const char *lxcpath)
if (stats) {
print_stats(c);
print_net_stats(name, lxcpath);
print_net_stats(c);
}
for(i = 0; i < keys; i++) {
......
......@@ -1738,6 +1738,19 @@ static int lxcapi_get_config_item(struct lxc_container *c, const char *key, char
return ret;
}
static char* lxcapi_get_running_config_item(struct lxc_container *c, const char *key)
{
char *ret;
if (!c || !c->lxc_conf)
return NULL;
if (container_mem_lock(c))
return NULL;
ret = lxc_cmd_get_config_item(c->name, key, c->get_config_path(c));
container_mem_unlock(c);
return ret;
}
static int lxcapi_get_keys(struct lxc_container *c, const char *key, char *retv, int inlen)
{
if (!key)
......@@ -3259,6 +3272,7 @@ struct lxc_container *lxc_container_new(const char *name, const char *configpath
c->clear_config = lxcapi_clear_config;
c->clear_config_item = lxcapi_clear_config_item;
c->get_config_item = lxcapi_get_config_item;
c->get_running_config_item = lxcapi_get_running_config_item;
c->get_cgroup_item = lxcapi_get_cgroup_item;
c->set_cgroup_item = lxcapi_set_cgroup_item;
c->get_config_path = lxcapi_get_config_path;
......
......@@ -410,6 +410,19 @@ struct lxc_container {
*/
int (*get_config_item)(struct lxc_container *c, const char *key, char *retv, int inlen);
/*!
* \brief Retrieve the value of a config item from running container.
*
* \param c Container.
* \param key Name of option to get.
*
* \return the item or NULL on error.
*
* \note Returned string must be freed by the caller.
*/
char* (*get_running_config_item)(struct lxc_container *c, const char *key);
/*!
* \brief Retrieve a list of config item keys given a key
* prefix.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment