Re: [PATCH] test_driver: implement virDomainInterfaceAddresses

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

 



On 5/22/19 10:10 PM, Ilias Stamatis wrote:
Ignore @source in the case of the test driver and return fixed private
IPv4 addresses for all the interfaces defined in the domain.

Signed-off-by: Ilias Stamatis <stamatis.iliass@xxxxxxxxx>
---

The default config of the test driver has no guest interfaces defined,
so this must be tested with a custom config.

Maybe it would be a good idea to add one or more guest interfaces in the
default config. I could send an additional patch for this.

  src/test/test_driver.c | 71 ++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 71 insertions(+)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index a4c17ef0df..3a81f51a88 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -3220,6 +3220,76 @@ static int testDomainBlockStats(virDomainPtr domain,
      return ret;
  }

+static int
+testDomainInterfaceAddresses(virDomainPtr dom,
+                             virDomainInterfacePtr **ifaces,
+                             unsigned int source ATTRIBUTE_UNUSED,
+                             unsigned int flags)
+{
+    size_t i;
+    size_t ifaces_count = 0;
+    int ret = -1;
+    char ipaddr[32];
+    char macaddr[VIR_MAC_STRING_BUFLEN];
+    virDomainObjPtr vm = NULL;
+    virDomainInterfacePtr iface = NULL;
+    virDomainInterfacePtr *ifaces_ret = NULL;
+
+    virCheckFlags(0, -1);
+
+    if (!(vm = testDomObjFromDomain(dom)))
+        goto cleanup;
+
+    if (virDomainObjCheckActive(vm) < 0)
+        goto cleanup;
+
+    if (VIR_ALLOC_N(ifaces_ret, vm->def->nnets) < 0)
+        goto cleanup;
+
+    for (i = 0; i < vm->def->nnets; i++) {
+        if (VIR_ALLOC(iface) < 0)
+            goto cleanup;
+
+        if (VIR_STRDUP(iface->name, vm->def->nets[i]->ifname) < 0)
+            goto cleanup;
+
+        virMacAddrFormat(&(vm->def->nets[i]->mac), macaddr);
+        if (VIR_STRDUP(iface->hwaddr, macaddr) < 0)
+            goto cleanup;
+
+        if (VIR_ALLOC(iface->addrs) < 0)
+            goto cleanup;
+
+        iface->addrs[0].type = VIR_IP_ADDR_TYPE_IPV4;
+        iface->addrs[0].prefix = 24;
+
+        sprintf(ipaddr, "192.168.0.%ld", 100 + (i % 155));

Thinking about this again in terms of your net-dhcp-leases path you posted the other day, and sorry for bringing it up so late, should we have a special case for interfaces that are from a libvirt network with defined IP range? I mean, if there's:

  <interface type='network>
    <source network='default'/>
  </interface>

  <network connections='1' ipv6='yes'>
    <name>default</name>
    <ip address='192.168.122.1' netmask='255.255.255.0'>
      <dhcp>
        <range start='192.168.122.2' end='192.168.122.254'/>
      </dhcp>
    </ip>
  </network>

it's a bit funny to find reported IP address out of the range.

Michal

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



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux