Commit a7487bbb authored by Michal Privoznik's avatar Michal Privoznik

examples: Rework a bit to resolve some warnings

Not only you should not use virDomain object as index to an array
in PHP where only strings and integers are allowed, you should
avoid mixing types passed to domain_get_info(). At some point a
domain name is passed, then virDomain is passed ...
Signed-off-by: 's avatarMichal Privoznik <mprivozn@redhat.com>
parent 66efb192
......@@ -511,14 +511,14 @@
}
}
$res = $lv->get_domain_object($domName);
$dom = $lv->domain_get_info($res);
$mem = number_format($dom['memory'] / 1024, 2, '.', ' ').' MB';
$cpu = $dom['nrVirtCpu'];
$state = $lv->domain_state_translate($dom['state']);
$id = $lv->domain_get_id($res);
$arch = $lv->domain_get_arch($res);
$vnc = $lv->domain_get_vnc_port($res);
$dom = $lv->get_domain_object($domName);
$info = $lv->domain_get_info($dom);
$mem = number_format($info['memory'] / 1024, 2, '.', ' ').' MB';
$cpu = $info['nrVirtCpu'];
$state = $lv->domain_state_translate($info['state']);
$id = $lv->domain_get_id($dom);
$arch = $lv->domain_get_arch($dom);
$vnc = $lv->domain_get_vnc_port($dom);
if (!$id)
$id = 'N/A';
......@@ -662,7 +662,6 @@
}
$doms = $lv->get_domains();
$domkeys = array_keys($doms);
echo "<table>
<tr>
<th>Name</th>
......@@ -682,23 +681,21 @@
echo "
<th>Action</th>
</tr>";
$active = $tmp['active'];
for ($i = 0; $i < sizeof($doms); $i++) {
$name = $doms[$i];
$res = $lv->get_domain_by_name($name);
$uuid = libvirt_domain_get_uuid_string($res);
$dom = $lv->domain_get_info($name);
$mem = number_format($dom['memory'] / 1024, 2, '.', ' ').' MB';
$cpu = $dom['nrVirtCpu'];
$state = $lv->domain_state_translate($dom['state']);
$id = $lv->domain_get_id($res);
$arch = $lv->domain_get_arch($res);
$vnc = $lv->domain_get_vnc_port($res);
$nics = $lv->get_network_cards($res);
if (($diskcnt = $lv->get_disk_count($res)) > 0) {
$disks = $diskcnt.' / '.$lv->get_disk_capacity($res);
$diskdesc = 'Current physical size: '.$lv->get_disk_capacity($res, true);
foreach ($doms as $name) {
$dom = $lv->get_domain_object($name);
$uuid = libvirt_domain_get_uuid_string($dom);
$info = $lv->domain_get_info($dom);
$mem = number_format($info['memory'] / 1024, 2, '.', ' ').' MB';
$cpu = $info['nrVirtCpu'];
$state = $lv->domain_state_translate($info['state']);
$id = $lv->domain_get_id($dom);
$arch = $lv->domain_get_arch($dom);
$vnc = $lv->domain_get_vnc_port($dom);
$nics = $lv->get_network_cards($dom);
if (($diskcnt = $lv->get_disk_count($dom)) > 0) {
$disks = $diskcnt.' / '.$lv->get_disk_capacity($dom);
$diskdesc = 'Current physical size: '.$lv->get_disk_capacity($dom, true);
}
else {
$disks = '-';
......
......@@ -767,44 +767,17 @@
return libvirt_domain_get_name($res);
}
function domain_get_info_call($name = false, $name_override = false) {
$ret = array();
if ($name != false) {
$dom = $this->get_domain_object($name);
if (!$dom)
return false;
if ($name_override)
$name = $name_override;
$ret[$name] = libvirt_domain_get_info($dom);
return $ret;
}
else {
$doms = libvirt_list_domains($this->conn);
foreach ($doms as $dom) {
$tmp = $this->domain_get_name($dom);
$ret[$tmp] = libvirt_domain_get_info($dom);
}
}
ksort($ret);
return $ret;
}
function domain_get_info($name = false, $name_override = false) {
function domain_get_info($dom) {
if (!$this->allow_cached)
return $this->domain_get_info_call($name, $name_override);
return libvirt_domain_get_info($dom);
$domname = $name_override ? $name_override : $name;
$domkey = $name_override ? $name_override : $this->domain_get_name($name);
if (!array_key_exists($domkey, $this->dominfos)) {
$tmp = $this->domain_get_info_call($name, $name_override);
$this->dominfos[$domkey] = $tmp[$domname];
$domname = libvirt_domain_get_name($dom);
if (!array_key_exists($domname, $this->dominfos)) {
$info = libvirt_domain_get_info($dom);
$this->dominfos[$domname] = $info;
}
return $this->dominfos[$domkey];
return $this->dominfos[$domname];
}
function get_last_error() {
......@@ -940,8 +913,7 @@
$dom = $this->get_domain_object($domain);
if (!$dom)
return false;
$tmp = $this->domain_get_info( $domain, $name );
$tmp = $this->domain_get_info($dom);
if (!$tmp)
return $this->_set_last_error();
$ret = ( ($tmp['state'] == VIR_DOMAIN_RUNNING) || ($tmp['state'] == VIR_DOMAIN_BLOCKED) );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment