<>于 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                 function get_domain_object($nameRes) {
212                         if (is_resource($nameRes))
213                                 return $nameRes;
215                         $dom=libvirt_domain_lookup_by_name($this->conn, $nameRes);
216                         if (!$dom) {
217                                 $dom=libvirt_domain_lookup_by_uuid_string($this->conn, $nameRes);
218                                 if (!$dom)
219                                         return $this->_set_last_error();
220                         }
222                         return $dom;
223                 }
</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