[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v2 2/5] virsh: Expose virDomainGetInterfacesAddresses



---
 tools/virsh.c   |   41 +++++++++++++++++++++++++++++++++++++++++
 tools/virsh.pod |    9 +++++++++
 2 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index a117424..fe52af0 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -1637,6 +1637,46 @@ cleanup:
 }
 #undef DOMBLKSTAT_LEGACY_PRINT
 
+/* "domifaddr" command
+ */
+static const vshCmdInfo info_domifaddr[] = {
+    {"help", N_("get network interfaces addresses for a domain")},
+    {"desc", N_("Get network interfaces addresses for a running domain")},
+    {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_domifaddr[] = {
+    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
+    {NULL, 0, 0, NULL}
+};
+
+static bool
+cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd)
+{
+    virDomainPtr dom = NULL;
+    unsigned int flags = 0;
+    char *xml = NULL;
+    bool ret = false;
+
+    if (!vshConnectionUsability(ctl, ctl->conn))
+        return false;
+
+    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+        return false;
+
+    if (!(xml = virDomainGetInterfacesAddresses(dom, flags)))
+        goto cleanup;
+
+    vshPrint(ctl, "%s", xml);
+
+    ret = true;
+cleanup:
+    VIR_FREE(xml);
+    virDomainFree(dom);
+    return ret;
+}
+
+
 /* "domifstat" command
  */
 static const vshCmdInfo info_domifstat[] = {
@@ -17841,6 +17881,7 @@ static const vshCmdDef domMonitoringCmds[] = {
     {"domblkstat", cmdDomblkstat, opts_domblkstat, info_domblkstat, 0},
     {"domcontrol", cmdDomControl, opts_domcontrol, info_domcontrol, 0},
     {"domif-getlink", cmdDomIfGetLink, opts_domif_getlink, info_domif_getlink, 0},
+    {"domifaddr", cmdDomIfAddr, opts_domifaddr, info_domifaddr, 0},
     {"domiflist", cmdDomiflist, opts_domiflist, info_domiflist, 0},
     {"domifstat", cmdDomIfstat, opts_domifstat, info_domifstat, 0},
     {"dominfo", cmdDominfo, opts_dominfo, info_dominfo, 0},
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 839c156..b53ef8c 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -563,6 +563,15 @@ B<Explanation of fields> (fields appear in the folowing order):
   flush_total_times - total time flush operations took (ns)
     <-- other fields provided by hypervisor -->
 
+=item B<domifaddr> I<domain>
+
+Get a list of interfaces of domain among with their IP and hardware addresses.
+Note, that interface name can be driver dependent meaning it can be name within
+guest OS or the name you would see in domain XML. Moreover, the whole command
+may require a guest agent to be configured for the queried domain under some
+drivers, notably qemu. To match interfaces from guest to host use MAC address
+or IP address range.
+
 =item B<domifstat> I<domain> I<interface-device>
 
 Get network interface stats for a running domain.
-- 
1.7.8.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]