From nobody Tue Nov 26 19:41:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566577912; cv=none; d=zoho.com; s=zohoarc; b=Hqx/6pcwLBkLxMBJ8X3L0IokrY045MtGVHT8R3B0qpYNCWIfHr7w0IbagPslpOLqxK1qWaQXhJ7MAtAfQGCboT2pNohsyB9/zPXOycDDtepm/HwFSmE59rl7oF0hs0B27wsKg6U11ZURBWMhOB6v66QAccFYrjPC92oCmbk34og= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566577912; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=GD2lblng35oMQPSQBhopm5+MLBHFaGZ5oUTI6Z1nfI4=; b=WObo4I3rBYCNto28YP/RrHpXx+oJRq91klmIa3GntRbfkg32bo8bsrBE8O/8gJU4pl6gs0HyL6viATl0dcdiYufWw4ArMgjI6RHscXJnIonWdEMeridNeairVaezsrWa0EMYbneVtmNzTd4aIVGYJv4I0Atbu+1mAxzNKawAH0A= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 156657791209036.23159132421347; Fri, 23 Aug 2019 09:31:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F2255309BDAE; Fri, 23 Aug 2019 16:31:50 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CFE11191BF; Fri, 23 Aug 2019 16:31:50 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 93F02E208; Fri, 23 Aug 2019 16:31:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7NGVbp5006901 for ; Fri, 23 Aug 2019 12:31:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8B76C5C28F; Fri, 23 Aug 2019 16:31:37 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-117-62.phx2.redhat.com [10.3.117.62]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 59A185C3FA for ; Fri, 23 Aug 2019 16:31:37 +0000 (UTC) From: Jonathon Jongsma To: libvir-list@redhat.com Date: Fri, 23 Aug 2019 11:31:23 -0500 Message-Id: <20190823163123.21683-10-jjongsma@redhat.com> In-Reply-To: <20190823163123.21683-1-jjongsma@redhat.com> References: <20190823163123.21683-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 9/9] virsh: add 'guestinfo' command X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 23 Aug 2019 16:31:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The 'guestinfo' command uses the new virDomainGetGuestInfo() API to query information about the specified domain and print it out for the user. The output is modeled roughly on the 'domstats' command. Signed-off-by: Jonathon Jongsma Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- tools/virsh-domain.c | 85 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index ccda71d7e0..977783951d 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -14038,6 +14038,85 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd) return ret; } =20 +/* + * "guestinfo" command + */ +static const vshCmdInfo info_guestinfo[] =3D { + {.name =3D "help", + .data =3D N_("query information about the guest (via agent)") + }, + {.name =3D "desc", + .data =3D N_("Use the guest agent to query various information from g= uest's " + "point of view") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_guestinfo[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), + {.name =3D "user", + .type =3D VSH_OT_BOOL, + .help =3D N_("report active users"), + }, + {.name =3D "os", + .type =3D VSH_OT_BOOL, + .help =3D N_("report operating system information"), + }, + {.name =3D "timezone", + .type =3D VSH_OT_BOOL, + .help =3D N_("report timezone information"), + }, + {.name =3D "hostname", + .type =3D VSH_OT_BOOL, + .help =3D N_("report hostname"), + }, + {.name =3D "filesystem", + .type =3D VSH_OT_BOOL, + .help =3D N_("report filesystem information"), + }, + {.name =3D NULL} +}; + +static bool +cmdGuestInfo(vshControl *ctl, const vshCmd *cmd) +{ + virDomainPtr dom; + bool ret =3D false; + virTypedParameterPtr params =3D NULL; + int nparams =3D 0; + size_t i; + unsigned int types =3D 0; + + if (vshCommandOptBool(cmd, "user")) + types |=3D VIR_DOMAIN_GUEST_INFO_USERS; + if (vshCommandOptBool(cmd, "os")) + types |=3D VIR_DOMAIN_GUEST_INFO_OS; + if (vshCommandOptBool(cmd, "timezone")) + types |=3D VIR_DOMAIN_GUEST_INFO_TIMEZONE; + if (vshCommandOptBool(cmd, "hostname")) + types |=3D VIR_DOMAIN_GUEST_INFO_HOSTNAME; + if (vshCommandOptBool(cmd, "filesystem")) + types |=3D VIR_DOMAIN_GUEST_INFO_FILESYSTEM; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (virDomainGetGuestInfo(dom, types, ¶ms, &nparams, 0) < 0) + goto cleanup; + + for (i =3D 0; i < nparams; i++) { + char *str =3D vshGetTypedParamValue(ctl, ¶ms[i]); + vshPrint(ctl, "%-20s: %s\n", params[i].field, str); + VIR_FREE(str); + } + + ret =3D true; + + cleanup: + virshDomainFree(dom); + return ret; +} + const vshCmdDef domManagementCmds[] =3D { {.name =3D "attach-device", .handler =3D cmdAttachDevice, @@ -14653,5 +14732,11 @@ const vshCmdDef domManagementCmds[] =3D { .info =3D info_domblkthreshold, .flags =3D 0 }, + {.name =3D "guestinfo", + .handler =3D cmdGuestInfo, + .opts =3D opts_guestinfo, + .info =3D info_guestinfo, + .flags =3D 0 + }, {.name =3D NULL} }; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list