rpcd-mod-lxc: add "info" ubus method (similar to the lxc-info)
This method allows getting basic info about a queried container. It's based on the lxc-info command-line tool. Example output: > ubus call lxc info '{ "name": "foo" }' { "name": "foo", "state": "RUNNING", "pid": 2946, "ips": [ "192.168.0.124" ] } Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Approved-by: Luka Perkov <luka@openwrt.org>
This commit is contained in:
parent
91dc4e824d
commit
f2a725ba2d
1 changed files with 43 additions and 0 deletions
|
@ -316,6 +316,48 @@ out:
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
rpc_lxc_info(struct ubus_context *ctx, struct ubus_object *obj,
|
||||||
|
struct ubus_request_data *req, const char *method,
|
||||||
|
struct blob_attr *msg)
|
||||||
|
{
|
||||||
|
struct blob_attr *tb[__RPC_LXC_RENAME_MAX];
|
||||||
|
struct rpc_lxc *l = NULL;
|
||||||
|
char **addresses;
|
||||||
|
void *k;
|
||||||
|
pid_t initpid;
|
||||||
|
|
||||||
|
blobmsg_parse(rpc_lxc_min_policy, __RPC_LXC_MAX, tb, blob_data(msg), blob_len(msg));
|
||||||
|
|
||||||
|
l = rpc_lxc_init(tb);
|
||||||
|
if (!l)
|
||||||
|
return UBUS_STATUS_INVALID_ARGUMENT;
|
||||||
|
blob_buf_init(&buf, 0);
|
||||||
|
|
||||||
|
blobmsg_add_string(&buf, "name", l->container->name);
|
||||||
|
|
||||||
|
blobmsg_add_string(&buf, "state", l->container->state(l->container));
|
||||||
|
|
||||||
|
initpid = l->container->init_pid(l->container);
|
||||||
|
if (initpid >= 0)
|
||||||
|
blobmsg_add_u32(&buf, "pid", initpid);
|
||||||
|
|
||||||
|
k = blobmsg_open_array(&buf, "ips");
|
||||||
|
addresses = l->container->get_ips(l->container, NULL, NULL, 0);
|
||||||
|
if (addresses) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; addresses[i]; i++)
|
||||||
|
blobmsg_add_string(&buf, "ip", addresses[i]);
|
||||||
|
}
|
||||||
|
blobmsg_close_array(&buf, k);
|
||||||
|
|
||||||
|
ubus_send_reply(ctx, req, buf.head);
|
||||||
|
rpc_lxc_done(l);
|
||||||
|
|
||||||
|
return UBUS_STATUS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
rpc_lxc_rename(struct ubus_context *ctx, struct ubus_object *obj,
|
rpc_lxc_rename(struct ubus_context *ctx, struct ubus_object *obj,
|
||||||
struct ubus_request_data *req, const char *method,
|
struct ubus_request_data *req, const char *method,
|
||||||
|
@ -480,6 +522,7 @@ rpc_lxc_api_init(const struct rpc_daemon_ops *o, struct ubus_context *ctx)
|
||||||
UBUS_METHOD("stop", rpc_lxc_stop, rpc_lxc_min_policy),
|
UBUS_METHOD("stop", rpc_lxc_stop, rpc_lxc_min_policy),
|
||||||
UBUS_METHOD("freeze", rpc_lxc_freeze, rpc_lxc_min_policy),
|
UBUS_METHOD("freeze", rpc_lxc_freeze, rpc_lxc_min_policy),
|
||||||
UBUS_METHOD("unfreeze", rpc_lxc_unfreeze, rpc_lxc_min_policy),
|
UBUS_METHOD("unfreeze", rpc_lxc_unfreeze, rpc_lxc_min_policy),
|
||||||
|
UBUS_METHOD("info", rpc_lxc_info, rpc_lxc_min_policy),
|
||||||
UBUS_METHOD("rename", rpc_lxc_rename, rpc_lxc_rename_policy),
|
UBUS_METHOD("rename", rpc_lxc_rename, rpc_lxc_rename_policy),
|
||||||
UBUS_METHOD("create", rpc_lxc_create, rpc_lxc_create_policy),
|
UBUS_METHOD("create", rpc_lxc_create, rpc_lxc_create_policy),
|
||||||
UBUS_METHOD("destroy", rpc_lxc_destroy, rpc_lxc_min_policy),
|
UBUS_METHOD("destroy", rpc_lxc_destroy, rpc_lxc_min_policy),
|
||||||
|
|
Loading…
Reference in a new issue