[libvirt] [libvirt-php][PATCH 0/2] Couple of example fixes

Pushed under "I'm the PHP master" rule. Michal Privoznik (2): examples: Sort domains examples: Die early if getting a screenshot fails examples/index.php | 2 +- examples/libvirt.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) -- 2.8.4

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

Our index.php has a capability to fetch a screenshot for a domain. However, if there's a libvirt error, it just prints it out and continue executing the rest of the script even though it is not supposed to. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- examples/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/index.php b/examples/index.php index 1ba8193..363fadd 100644 --- a/examples/index.php +++ b/examples/index.php @@ -17,7 +17,7 @@ $tmp = $lv->domain_get_screenshot($_GET['uuid'], 0); if (!$tmp) { - echo $lv->get_last_error().'<br/>'; + die($lv->get_last_error().'<br/>'); } else { Header('Content-Type: ' . $tmp['mime']); die($tmp['data']); -- 2.8.4

On Wed, Sep 21, 2016 at 05:33:50PM +0200, Michal Privoznik wrote:
Pushed under "I'm the PHP master" rule.
LOL, ACK series, then, I guess =D
Michal Privoznik (2): examples: Sort domains examples: Die early if getting a screenshot fails
examples/index.php | 2 +- examples/libvirt.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-)
-- 2.8.4
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
participants (2)
-
Martin Kletzander
-
Michal Privoznik