[libvirt] [PATCH 7/9] virsh: domjobinfo: Add switch to print raw fields

Peter Krempa posted 9 patches 13 weeks ago

[libvirt] [PATCH 7/9] virsh: domjobinfo: Add switch to print raw fields

Posted by Peter Krempa 13 weeks ago
Introduce --rawstats which prints all statistics fields from the new API
similarly to how the virsh event handler prints them.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 tools/virsh-domain.c | 24 +++++++++++++++++++++---
 tools/virsh.pod      |  6 +++++-
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 81229fa5ca..325d748b49 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -6033,6 +6033,10 @@ static const vshCmdOptDef opts_domjobinfo[] = {
      .type = VSH_OT_BOOL,
      .help = N_("print statistics for any kind of job (even failed ones)")
     },
+    {.name = "rawstats",
+     .type = VSH_OT_BOOL,
+     .help = N_("print the raw data returned by libvirt")
+    },
     {.name = NULL}
 };

@@ -6124,6 +6128,8 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd)
     int ivalue;
     int op;
     int rc;
+    size_t i;
+    bool rawstats = vshCommandOptBool(cmd, "rawstats");

     VSH_REQUIRE_OPTION("keep-completed", "completed");

@@ -6143,9 +6149,9 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd)
         if (virshDomainJobStatsToDomainJobInfo(params, nparams, &info) < 0)
             goto cleanup;
     } else if (last_error->code == VIR_ERR_NO_SUPPORT) {
-        if (flags) {
-            vshError(ctl, "%s", _("Optional flags are not supported by the "
-                                  "daemon"));
+        if (flags != 0 || rawstats) {
+            vshError(ctl, "%s",
+                     _("Optional flags or --rawstats are not supported by the daemon"));
             goto cleanup;
         }
         vshDebug(ctl, VSH_ERR_DEBUG, "detailed statistics not supported\n");
@@ -6155,6 +6161,18 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd)
     if (rc < 0)
         goto cleanup;

+    if (rawstats) {
+        vshPrint(ctl, "Job type: %d\n\n", info.type);
+
+        for (i = 0; i < nparams; i++) {
+            g_autofree char *par = virTypedParameterToString(&params[i]);
+            vshPrint(ctl, "%s: %s\n", params[i].field, NULLSTR(par));
+        }
+
+        ret = true;
+        goto cleanup;
+    }
+
     vshPrint(ctl, "%-17s %-12s\n", _("Job type:"),
              virshDomainJobToString(info.type));

diff --git a/tools/virsh.pod b/tools/virsh.pod
index e5428976a0..951cb738a0 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1381,7 +1381,7 @@ Returns basic information about the domain.
 Abort the currently running domain job.

 =item B<domjobinfo> I<domain> [I<--completed>] [I<--keep-completed>]
-[I<--anystats>]
+[I<--anystats>] [I<--rawstats>]

 Returns information about jobs running on a domain. I<--completed> tells
 virsh to return information about a recently finished job. Statistics of
@@ -1391,6 +1391,10 @@ I<--keep-completed> is used) or when libvirtd is restarted.
 Normally only statistics for running and successful completed jobs are printed.
 I<--anystats> can be used to display statistics also for failed jobs.

+In case I<--rawstats> is used, all fields are printed as received from the
+server without any attempts to interpred the data. The "Job type:" field is
+special, since it's reported by the API and not part of stats.
+
 Note that time information returned for completed
 migrations may be completely irrelevant unless both source and
 destination hosts have synchronized time (i.e., NTP daemon is running
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 7/9] virsh: domjobinfo: Add switch to print raw fields

Posted by Eric Blake 12 weeks ago
On 11/25/19 9:01 AM, Peter Krempa wrote:
> Introduce --rawstats which prints all statistics fields from the new API
> similarly to how the virsh event handler prints them.
> 
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>   tools/virsh-domain.c | 24 +++++++++++++++++++++---
>   tools/virsh.pod      |  6 +++++-
>   2 files changed, 26 insertions(+), 4 deletions(-)
> 

> +In case I<--rawstats> is used, all fields are printed as received from the
> +server without any attempts to interpred the data. The "Job type:" field is

interpret

> +special, since it's reported by the API and not part of stats.
> +

with the typo fix,
Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list