[libvirt] using php-libvirt libvirt_domain_is_active function
Osier Yang
jyang at redhat.com
Mon Nov 14 04:43:19 UTC 2011
<>? 2011?11?13? 23:37, Eduard B ??:
> Hi All,
>
> Im trying to figure how to use libvirt_domain_is_active but I'm unable
> to find what I am doing wrong.
> I tested it with php-libvirt-0.4.4 an with 0.4.3 but i have the same
> problem
>
> Im using libvirt-0.9.6-2.fc16.x86_64 with the following code
>
> Can someone point me in the right direction with the use of
> libvirt_domain_is_active ?
> Thanks
>
> ------8<------CODE --------8<------------------------------------
>
> print_r ( libvirt_version() );
>
> $domains=libvirt_list_domains($conn);
> print_r ($domains);
>
> foreach ( $domains as $domain ) {
> print "$domain\n";
> print libvirt_domain_is_active($domain);
libvirt_domain_is_active() wants a arg of resource type here. See
the codes in examples/libvirt-php.c to get how to do it:
<snip>
211
<http://libvirt.org/git/?p=libvirt-php.git;a=blob;f=examples/libvirt.php;h=21e11d246a598dbb8024503cec8197080f53a402;hb=HEAD#l211>
function get_domain_object($nameRes) {
212
<http://libvirt.org/git/?p=libvirt-php.git;a=blob;f=examples/libvirt.php;h=21e11d246a598dbb8024503cec8197080f53a402;hb=HEAD#l212>
if (is_resource($nameRes))
213
<http://libvirt.org/git/?p=libvirt-php.git;a=blob;f=examples/libvirt.php;h=21e11d246a598dbb8024503cec8197080f53a402;hb=HEAD#l213>
return $nameRes;
214
<http://libvirt.org/git/?p=libvirt-php.git;a=blob;f=examples/libvirt.php;h=21e11d246a598dbb8024503cec8197080f53a402;hb=HEAD#l214>
215
<http://libvirt.org/git/?p=libvirt-php.git;a=blob;f=examples/libvirt.php;h=21e11d246a598dbb8024503cec8197080f53a402;hb=HEAD#l215>
$dom=libvirt_domain_lookup_by_name($this->conn, $nameRes);
216
<http://libvirt.org/git/?p=libvirt-php.git;a=blob;f=examples/libvirt.php;h=21e11d246a598dbb8024503cec8197080f53a402;hb=HEAD#l216>
if (!$dom) {
217
<http://libvirt.org/git/?p=libvirt-php.git;a=blob;f=examples/libvirt.php;h=21e11d246a598dbb8024503cec8197080f53a402;hb=HEAD#l217>
$dom=libvirt_domain_lookup_by_uuid_string($this->conn, $nameRes);
218
<http://libvirt.org/git/?p=libvirt-php.git;a=blob;f=examples/libvirt.php;h=21e11d246a598dbb8024503cec8197080f53a402;hb=HEAD#l218>
if (!$dom)
219
<http://libvirt.org/git/?p=libvirt-php.git;a=blob;f=examples/libvirt.php;h=21e11d246a598dbb8024503cec8197080f53a402;hb=HEAD#l219>
return $this->_set_last_error();
220
<http://libvirt.org/git/?p=libvirt-php.git;a=blob;f=examples/libvirt.php;h=21e11d246a598dbb8024503cec8197080f53a402;hb=HEAD#l220>
}
221
<http://libvirt.org/git/?p=libvirt-php.git;a=blob;f=examples/libvirt.php;h=21e11d246a598dbb8024503cec8197080f53a402;hb=HEAD#l221>
222
<http://libvirt.org/git/?p=libvirt-php.git;a=blob;f=examples/libvirt.php;h=21e11d246a598dbb8024503cec8197080f53a402;hb=HEAD#l222>
return $dom;
223
<http://libvirt.org/git/?p=libvirt-php.git;a=blob;f=examples/libvirt.php;h=21e11d246a598dbb8024503cec8197080f53a402;hb=HEAD#l223>
}
</snip>
what you want might be something like:
foreach ($domains as $domname) {
$domobj = get_domain_object($domname);
print "$domain: " . libvirt_domain_is_active($domobj);
}
Osier
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20111114/8d554551/attachment-0001.htm>
More information about the libvir-list
mailing list