[libvirt] [libvirt-php][PATCH 1/2] examples: Sort domains

Michal Privoznik mprivozn at redhat.com
Wed Sep 21 15:33:51 UTC 2016


In the examples/index.php we list all domains/networks/.. defined
for the connection we have. However, the objects are printed out
in the order as provided by libvirt, so basically a random order.
It may be more user friendly if we sort the array of objects
before printing it out.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 examples/libvirt.php | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/examples/libvirt.php b/examples/libvirt.php
index f65c50e..286bf4d 100644
--- a/examples/libvirt.php
+++ b/examples/libvirt.php
@@ -426,6 +426,8 @@ class Libvirt {
 
     function get_storagepools() {
         $tmp = libvirt_list_storagepools($this->conn);
+        if ($tmp)
+            sort($tmp, SORT_NATURAL);
         return ($tmp) ? $tmp : $this->_set_last_error();
     }
 
@@ -635,6 +637,8 @@ class Libvirt {
 
     function get_domains() {
         $tmp = libvirt_list_domains($this->conn);
+        if ($tmp)
+            sort($tmp, SORT_NATURAL);
         return ($tmp) ? $tmp : $this->_set_last_error();
     }
 
@@ -645,6 +649,8 @@ class Libvirt {
 
     function get_networks($type = VIR_NETWORKS_ALL) {
         $tmp = libvirt_list_networks($this->conn, $type);
+        if ($tmp)
+            sort($tmp, SORT_NATURAL);
         return ($tmp) ? $tmp : $this->_set_last_error();
     }
 
@@ -714,6 +720,8 @@ class Libvirt {
 
     function get_node_devices($dev = false) {
         $tmp = ($dev == false) ? libvirt_list_nodedevs($this->conn) : libvirt_list_nodedevs($this->conn, $dev);
+        if ($tmp)
+            sort($tmp, SORT_NATURAL);
         return ($tmp) ? $tmp : $this->_set_last_error();
     }
 
-- 
2.8.4




More information about the libvir-list mailing list