[libvirt-php PATCH 2/2] Add binding for virDomainInterfaceAddresses.

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

 



A straight-forward 1:1 mapping to the C API. Returns array in the
following format:

array (
  0 =>
  array (
    'name' => 'vnet0',
    'hwaddr' => '52:54:00:3a:cd:94',
    'naddrs' => 1,
    'addrs' =>
    array (
      'addr' => '192.168.254.224',
      'prefix' => 24,
      'type' => 0,
    ),
  ),
)
---
 src/libvirt-domain.c | 55 ++++++++++++++++++++++++++++++++++++++++++++
 src/libvirt-domain.h |  2 ++
 src/libvirt-php.c    |  9 ++++++++
 3 files changed, 66 insertions(+)

diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 8b8bb45..877d311 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -1948,6 +1948,61 @@ PHP_FUNCTION(libvirt_domain_block_job_set_speed)
     RETURN_TRUE;
 }
 
+/*
+ * Function name:   libvirt_domain_interface_addresses
+ * Since version:   0.5.5
+ * Description:     Function is used to get network interface addresses for the domain
+ * Arguments:       @domain [resource]: libvirt domain resource, e.g. from libvirt_domain_lookup_by_*()
+ *                  @source [int]: one of the VIR_DOMAIN_ADDRESSES_SRC_* flags.
+ * Returns:         interface array of a domain holding information about addresses resembling the virDomainInterface structure, false on error
+ */
+PHP_FUNCTION(libvirt_domain_interface_addresses)
+{
+    php_libvirt_domain *domain = NULL;
+    zval *zdomain;
+    zend_long source = 0;
+
+    virDomainInterfacePtr *ifaces = NULL;
+    int count = 0;
+    size_t i, j;
+
+    GET_DOMAIN_FROM_ARGS("rl", &zdomain, &source);
+
+    if ((count = virDomainInterfaceAddresses(domain->domain, &ifaces, source, 0)) < 0) {
+        RETURN_FALSE
+        goto cleanup;
+    }
+
+    array_init(return_value);
+
+    for (i = 0; i < count; i++) {
+        zval *iface;
+        VIRT_ARRAY_INIT(iface);
+        VIRT_ADD_ASSOC_STRING(iface, "name", ifaces[i]->name);
+        VIRT_ADD_ASSOC_STRING(iface, "hwaddr", ifaces[i]->hwaddr);
+        add_assoc_long(iface, "naddrs", ifaces[i]->naddrs);
+
+        for (j = 0; j < ifaces[i]->naddrs; j++) {
+            zval *ifaddr;
+            VIRT_ARRAY_INIT(ifaddr);
+            VIRT_ADD_ASSOC_STRING(ifaddr, "addr", ifaces[i]->addrs[j].addr);
+            add_assoc_long(ifaddr, "prefix", ifaces[i]->addrs[j].prefix);
+            add_assoc_long(ifaddr, "type", ifaces[i]->addrs[j].type);
+
+            add_assoc_zval(iface, "addrs", ifaddr);
+        }
+
+        add_index_zval(return_value, i, iface);
+    }
+
+ cleanup:
+    if (ifaces && count > 0) {
+        for (i = 0; i < count; i++)
+            virDomainInterfaceFree(ifaces[i]);
+    }
+    VIR_FREE(ifaces);
+}
+
 /*
  * Function name:   libvirt_domain_interface_stats
  * Since version:   0.4.1(-1)
diff --git a/src/libvirt-domain.h b/src/libvirt-domain.h
index dc0ab46..f15237f 100644
--- a/src/libvirt-domain.h
+++ b/src/libvirt-domain.h
@@ -89,6 +89,7 @@
     PHP_FE(libvirt_domain_block_job_info,        arginfo_libvirt_domain_block_job_info)        \
     PHP_FE(libvirt_domain_block_job_abort,       arginfo_libvirt_domain_block_job_abort)       \
     PHP_FE(libvirt_domain_block_job_set_speed,   arginfo_libvirt_domain_block_job_set_speed)   \
+    PHP_FE(libvirt_domain_interface_addresses,   arginfo_libvirt_domain_interface_addresses)   \
     PHP_FE(libvirt_domain_interface_stats,       arginfo_libvirt_conn_path)                    \
     PHP_FE(libvirt_domain_get_connect,           arginfo_libvirt_conn)                         \
     PHP_FE(libvirt_domain_migrate,               arginfo_libvirt_domain_migrate)               \
@@ -179,6 +180,7 @@ PHP_FUNCTION(libvirt_domain_block_resize);
 PHP_FUNCTION(libvirt_domain_block_job_info);
 PHP_FUNCTION(libvirt_domain_block_job_abort);
 PHP_FUNCTION(libvirt_domain_block_job_set_speed);
+PHP_FUNCTION(libvirt_domain_interface_addresses);
 PHP_FUNCTION(libvirt_domain_interface_stats);
 PHP_FUNCTION(libvirt_domain_get_connect);
 PHP_FUNCTION(libvirt_domain_migrate);
diff --git a/src/libvirt-php.c b/src/libvirt-php.c
index cf8fd7f..04b7c07 100644
--- a/src/libvirt-php.c
+++ b/src/libvirt-php.c
@@ -248,6 +248,11 @@ ZEND_ARG_INFO(0, bandwidth)
 ZEND_ARG_INFO(0, flags)
 ZEND_END_ARG_INFO()
 
+ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_interface_addresses, 0, 0, 2)
+ZEND_ARG_INFO(0, domain)
+ZEND_ARG_INFO(0, source)
+ZEND_END_ARG_INFO()
+
 ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_block_job_info, 0, 0, 2)
 ZEND_ARG_INFO(0, dom)
 ZEND_ARG_INFO(0, disk)
@@ -1476,6 +1481,10 @@ PHP_MINIT_FUNCTION(libvirt)
     REGISTER_LONG_CONSTANT("VIR_DOMAIN_MEM_LIVE",   VIR_DOMAIN_MEM_LIVE, CONST_CS | CONST_PERSISTENT);
     REGISTER_LONG_CONSTANT("VIR_DOMAIN_MEM_MAXIMUM",    VIR_DOMAIN_MEM_MAXIMUM, CONST_CS | CONST_PERSISTENT);
 
+    REGISTER_LONG_CONSTANT("VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE", VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE, CONST_CS | CONST_PERSISTENT);
+    REGISTER_LONG_CONSTANT("VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT", VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT, CONST_CS | CONST_PERSISTENT);
+    REGISTER_LONG_CONSTANT("VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP", VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE, CONST_CS | CONST_PERSISTENT);
+
     /* Connect flags */
     REGISTER_LONG_CONSTANT("VIR_CONNECT_FLAG_SOUNDHW_GET_NAMES",    CONNECT_FLAG_SOUNDHW_GET_NAMES, CONST_CS | CONST_PERSISTENT);
 
-- 
2.21.0


--
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