[libvirt-php][PATCH 11/14] examples: Show screenshot only for active domains

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

 



Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 examples/index.php   | 12 +++++++-----
 examples/libvirt.php |  5 +++++
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/examples/index.php b/examples/index.php
index dbaa1bf..bdeb506 100644
--- a/examples/index.php
+++ b/examples/index.php
@@ -668,16 +668,16 @@
              "<th>State</th>" .
              "<th>ID / VNC port</th>";
 
-        if (($tmp['active'] > 0) && ($lv->supports('screenshot')))
+        if ($lv->supports('screenshot'))
             echo "<th>Domain screenshot</th>";
 
 		echo "<th>Action</th>" .
             "</tr>";
 
-        $active = $tmp['active'];
         foreach ($doms as $name) {
             $dom = $lv->get_domain_object($name);
             $uuid = libvirt_domain_get_uuid_string($dom);
+            $active = $lv->domain_is_active($dom);
             $info = $lv->domain_get_info($dom);
             $mem = number_format($info['memory'] / 1024, 2, '.', ' ').' MB';
             $cpu = $info['nrVirtCpu'];
@@ -716,8 +716,10 @@
                  "<td>$spaces$state$spaces</td>" .
                  "<td align=\"center\">$spaces$id / $vnc$spaces</td>";
 
-            if (($active > 0) && ($lv->supports('screenshot')))
-                echo "<td align=\"center\"><img src=\"?action=get-screenshot&uuid=$uuid&width=120\" id=\"screenshot$i\"></td>";
+            if ($lv->supports('screenshot') && $active)
+                echo "<td align=\"center\"><img src=\"?action=get-screenshot&uuid=$uuid&width=120\" id=\"screenshot$id\"></td>";
+            else
+                echo "<td>$spaces</td>";
 
             echo "<td align=\"center\">$spaces";
 
@@ -735,7 +737,7 @@
 
             echo "$spaces" .
                   "</td>" .
-                  "</tr>";
+                  "</tr>\n";
         }
         echo "</table>";
 
diff --git a/examples/libvirt.php b/examples/libvirt.php
index 2cab7a8..c30f06a 100644
--- a/examples/libvirt.php
+++ b/examples/libvirt.php
@@ -1162,5 +1162,10 @@ class Libvirt {
         $tmp = libvirt_node_get_info($this->conn);
         return ($tmp) ? $tmp : $this->_set_last_error();
     }
+
+    function domain_is_active($domain) {
+        $dom = $this->get_domain_object($domain);
+        return libvirt_domain_is_active($dom);
+    }
 }
 ?>
-- 
2.8.4

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