Skip to content

Commit

Permalink
Implement debug support using libvirt_logfile_set() API function
Browse files Browse the repository at this point in the history
This is a very useful patch to implement the debug logging for libvirt-php
module. The debug logging can be turned on using the libvirt_logfile_set()
API function that accepts both filename and maximum log file size in KiB.
Debug support have to be compiled into the module which is enabled by in
this version with default set to logging disabled.

Also, version number in the PHPInfo() has been changed from 0.4.1 to
0.4.2.

Signed-off-by: Michal Novotny <minovotn@redhat.com>
  • Loading branch information
Michal Novotny committed Jun 20, 2011
1 parent 9f1207b commit 31bca38
Show file tree
Hide file tree
Showing 6 changed files with 741 additions and 168 deletions.
47 changes: 44 additions & 3 deletions examples/libvirt.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ class Libvirt {
private $conn;
private $last_error;

function Libvirt($uri = false) {
function Libvirt($uri = false, $debug=false) {
if ($debug)
$this->set_logfile($debug);
if ($uri != false)
$this->connect($uri);
}
Expand All @@ -14,6 +16,14 @@ function _set_last_error()
return false;
}

function set_logfile($filename)
{
if (!libvirt_logfile_set($filename))
return $this->_set_last_error();

return true;
}

function connect($uri = 'null') {
$this->conn=libvirt_connect($uri, false);
if ($this->conn==false)
Expand Down Expand Up @@ -122,6 +132,13 @@ function domain_send_keys($domain, $keys) {
return ($tmp) ? $tmp : $this->_set_last_error();
}

function domain_send_pointer_event($domain, $x, $y, $clicked = 1) {
$dom = $this->get_domain_object($domain);

$tmp = libvirt_domain_send_pointer_event($dom, $this->get_hostname(), $x, $y, $clicked, true);
return ($tmp) ? $tmp : $this->_set_last_error();
}

function domain_disk_remove($domain, $dev) {
$dom = $this->get_domain_object($domain);

Expand Down Expand Up @@ -212,7 +229,7 @@ function get_xpath($domain, $xpath, $inactive = false) {
return $tmp;
}

function get_cdrom_stats($domain) {
function get_cdrom_stats($domain, $sort=true) {
$dom = $this->get_domain_object($domain);

$buses = $this->get_xpath($dom, '//domain/devices/disk[@device="cdrom"]/target/@bus', false);
Expand All @@ -229,13 +246,25 @@ function get_cdrom_stats($domain) {
$this->_set_last_error();
}

if ($sort) {
for ($i = 0; $i < sizeof($ret); $i++) {
for ($ii = 0; $ii < sizeof($ret); $ii++) {
if (strcmp($ret[$i]['device'], $ret[$ii]['device']) < 0) {
$tmp = $ret[$i];
$ret[$i] = $ret[$ii];
$ret[$ii] = $tmp;
}
}
}
}

unset($buses);
unset($disks);

return $ret;
}

function get_disk_stats($domain) {
function get_disk_stats($domain, $sort=true) {
$dom = $this->get_domain_object($domain);

$buses = $this->get_xpath($dom, '//domain/devices/disk[@device="disk"]/target/@bus', false);
Expand All @@ -253,6 +282,18 @@ function get_disk_stats($domain) {
$this->_set_last_error();
}

if ($sort) {
for ($i = 0; $i < sizeof($ret); $i++) {
for ($ii = 0; $ii < sizeof($ret); $ii++) {
if (strcmp($ret[$i]['device'], $ret[$ii]['device']) < 0) {
$tmp = $ret[$i];
$ret[$i] = $ret[$ii];
$ret[$ii] = $tmp;
}
}
}
}

unset($buses);
unset($disks);

Expand Down
Loading

0 comments on commit 31bca38

Please sign in to comment.