From patchwork Tue Nov 7 11:02:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 835233 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (helo) smtp.helo=arrakis.dune.hu (client-ip=78.24.191.176; helo=arrakis.dune.hu; envelope-from=openwrt-devel-bounces@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="s0f2AX2M"; dkim-atps=neutral Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yWRPB5q0Pz9t3k for ; Tue, 7 Nov 2017 22:03:21 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 7DA65B8069B; Tue, 7 Nov 2017 12:03:16 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP; Tue, 7 Nov 2017 12:03:16 +0100 (CET) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 5262AB80215 for ; Tue, 7 Nov 2017 12:03:14 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 CL_IP_EQ_HELO_IP=-2 (check from: .gmail. - helo: .mail-lf0-f68.google. - helo-domain: .google.) FROM/MX_MATCHES_HELO(DOMAIN)=-2; rate: -7 Received: from mail-lf0-f68.google.com (mail-lf0-f68.google.com [209.85.215.68]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Tue, 7 Nov 2017 12:03:13 +0100 (CET) Received: by mail-lf0-f68.google.com with SMTP id a2so13938225lfh.11 for ; Tue, 07 Nov 2017 03:03:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=mwDQwvZK9EZcAO/lG2oYU2qOZo0Qv0AFQkWXuOq39rg=; b=s0f2AX2MECoEptlbByGDFRrZv2oPlOlBhwO2/D2rnTl8SUF2GhDUUtoBJxhytKLbyY JXJ7jCGpyzOLrciXIxtnAfAswM5FzLmFQC6Esetkrj2lIUCthHTifx4F4DhngPP0e72y F+3iyOZfpSU6Mv7JHZLMEyMn4FBmOLr5s0Xe3302Zgp2rq5/TmUQIeN1IBHnDY3AZYEE f53wdpH+vaKjJJBN5y5K7GYh7G3Q9S/grXYkNDmKrFEXdvpBrLlpWhDRJdYTWzhc0pSX AM6i+I3m29ve961lASVd3IbsX3qkjxdJTkQoe+iGMGhPgM89TeIeoI6mJBQmZgEzb2FA vNxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=mwDQwvZK9EZcAO/lG2oYU2qOZo0Qv0AFQkWXuOq39rg=; b=NbayQ0IcNH0Yo/65xp+cEhzqTp1MLjT2aRpmnpLtQ8VmBJ1JH3oa3lOHT25Yr+P9iZ yNbsw/a3URDFXuxa/Wieheaj/hLhULWtBE0SJc98MlfCS8VSTmfh5KF3+/Ic3uKGNhKH ZWUsjomJ9EAy9U6g+Ux6pvw6ohWbZhB8j11RKmkCDpPRXxv9yAyi+KSCOI+F29iOhjEO Rfm6nJ4KEZDxHTqVGnX5PRgN2+rxUYMOtPCYZZ599M/NXm2Ru8zYi6baDxH5JTobP9L7 XGtCZkYr2lDZP74sfcTKf5EiD/Ym91Ujdt8RiFU+rvJwLe6/YEMJyzqZEDB/0JUDBQmL oZqw== X-Gm-Message-State: AJaThX55nzMTwVycTmWb4Z2v+oUSi1VVOmo0dv2FimWXzkEnFEy+/Gvf M/vP2kZ48CBXgCHS2Fv9RVU= X-Google-Smtp-Source: ABhQp+Su9p0/786jJUtfIEVMtOvu9CMOUi9ph6JEJVJ5bIkhAixLTCrGgvGzMw6nSUeqVJZEYXCgJA== X-Received: by 10.25.147.209 with SMTP id w78mr7346808lfk.169.1510052591363; Tue, 07 Nov 2017 03:03:11 -0800 (PST) Received: from linux-samsung.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id q88sm171114lfi.14.2017.11.07.03.03.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Nov 2017 03:03:10 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Luka Perkov Date: Tue, 7 Nov 2017 12:02:53 +0100 Message-Id: <20171107110253.31718-1-zajec5@gmail.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Subject: [OpenWrt-Devel] [PATCH packages] rpcd-mod-lxc: add "info" ubus method (similar to the lxc-info) X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , openwrt-devel@lists.openwrt.org, lede-dev@lists.infradead.org Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" From: Rafał Miłecki 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 --- utils/rpcd-mod-lxc/files/lxc.c | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/utils/rpcd-mod-lxc/files/lxc.c b/utils/rpcd-mod-lxc/files/lxc.c index 0d52f167..6db1b311 100644 --- a/utils/rpcd-mod-lxc/files/lxc.c +++ b/utils/rpcd-mod-lxc/files/lxc.c @@ -317,6 +317,48 @@ out: } 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 rpc_lxc_rename(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) @@ -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("freeze", rpc_lxc_freeze, 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("create", rpc_lxc_create, rpc_lxc_create_policy), UBUS_METHOD("destroy", rpc_lxc_destroy, rpc_lxc_min_policy),