[libvirt PATCH v4 2/5] virsh: add interface information to guestinfo command

zhanglei posted 5 patches 4 years, 3 months ago
[libvirt PATCH v4 2/5] virsh: add interface information to guestinfo command
Posted by zhanglei 4 years, 3 months ago
The new parameter group returns information about network interfaces

Signed-off-by: zhanglei <zhanglei@smartx.com>
---
 docs/manpages/virsh.rst | 12 ++++++++++--
 src/libvirt-domain.c    |  2 +-
 tools/virsh-domain.c    |  6 ++++++
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst
index 4c5341d00d..1c60eae607 100644
--- a/docs/manpages/virsh.rst
+++ b/docs/manpages/virsh.rst
@@ -2700,7 +2700,7 @@ guestinfo
 ::
 
    guestinfo domain [--user] [--os] [--timezone] [--hostname] [--filesystem]
-      [--disk]
+      [--disk] [--interface]
 
 Print information about the guest from the point of view of the guest agent.
 Note that this command requires a guest agent to be configured and running in
@@ -2711,7 +2711,7 @@ are supported by the guest agent. You can limit the types of information that
 are returned by specifying one or more flags.  If a requested information
 type is not supported, the processes will provide an exit code of 1.
 Available information types flags are *--user*, *--os*,
-*--timezone*, *--hostname*, *--filesystem* and *--disk*.
+*--timezone*, *--hostname*, *--filesystem*, *--disk* and *--interface*.
 
 Note that depending on the hypervisor type and the version of the guest agent
 running within the domain, not all of the following information may be
@@ -2779,6 +2779,14 @@ returned:
 * ``disk.<num>.alias`` - the device alias of the disk (e.g. sda)
 * ``disk.<num>.guest_alias`` - optional alias assigned to the disk
 
+*--interface* returns:
+* ``if.count`` - the number of interfaces defined on this domain
+* ``if.<num>.name`` - name in the guest (e.g. ``eth0``) for interface <num>
+* ``if.<num>.hwaddr`` - hardware address in the guest for interface <num>
+* ``if.<num>.addr.count`` - the number of IP addresses of interface <num>
+* ``if.<num>.addr.<num1>.type`` - the IP address type of addr <num1> (e.g. ipv4)
+* ``if.<num>.addr.<num1>.addr`` - the IP address of addr <num1>
+* ``if.<num>.addr.<num1>.prefix`` - the prefix of IP address of addr <num1>
 
 guestvcpus
 ----------
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index fdc0780ae0..ce7cafde36 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -12580,7 +12580,7 @@ virDomainSetVcpu(virDomainPtr domain,
  *      "hostname" - the hostname of the domain
  *
  * VIR_DOMAIN_GUEST_INFO_INTERFACES:
- *  Returns information about the interfaces within the domain. the typed
+ *  Returns information about the interfaces within the domain. The typed
  *  parameter keys are in this format:
  *
  *      "if.count" - the number of interfaces defined on this domain
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index dbddefb4a5..bce03b3de5 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -13999,6 +13999,10 @@ static const vshCmdOptDef opts_guestinfo[] = {
      .type = VSH_OT_BOOL,
      .help = N_("report disk information"),
     },
+    {.name = "interface",
+     .type = VSH_OT_BOOL,
+     .help = N_("report interface information"),
+    },
     {.name = NULL}
 };
 
@@ -14024,6 +14028,8 @@ cmdGuestInfo(vshControl *ctl, const vshCmd *cmd)
         types |= VIR_DOMAIN_GUEST_INFO_FILESYSTEM;
     if (vshCommandOptBool(cmd, "disk"))
         types |= VIR_DOMAIN_GUEST_INFO_DISKS;
+    if (vshCommandOptBool(cmd, "interface"))
+        types |= VIR_DOMAIN_GUEST_INFO_INTERFACES;
 
     if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
         return false;
-- 
2.31.1

Re: [libvirt PATCH v4 2/5] virsh: add interface information to guestinfo command
Posted by Ján Tomko 4 years, 3 months ago
On a Friday in 2021, zhanglei wrote:
>The new parameter group returns information about network interfaces
>
>Signed-off-by: zhanglei <zhanglei@smartx.com>
>---
> docs/manpages/virsh.rst | 12 ++++++++++--
> src/libvirt-domain.c    |  2 +-
> tools/virsh-domain.c    |  6 ++++++
> 3 files changed, 17 insertions(+), 3 deletions(-)
>
>diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
>index fdc0780ae0..ce7cafde36 100644
>--- a/src/libvirt-domain.c
>+++ b/src/libvirt-domain.c
>@@ -12580,7 +12580,7 @@ virDomainSetVcpu(virDomainPtr domain,
>  *      "hostname" - the hostname of the domain
>  *
>  * VIR_DOMAIN_GUEST_INFO_INTERFACES:
>- *  Returns information about the interfaces within the domain. the typed
>+ *  Returns information about the interfaces within the domain. The typed

This is fixing up the text added in patch 1/5. I have squashed the
change there.

Jano

>  *  parameter keys are in this format:
>  *
>  *      "if.count" - the number of interfaces defined on this domain