[libvirt] Need Help To Destroy Virtual Machines

Michal Privoznik mprivozn at redhat.com
Tue Apr 3 14:55:35 UTC 2012


On 03.04.2012 16:42, Ali Raza Memon wrote:
> Hello...!
> I am using libvirt-php for controlling my xen virtual machines. For this
> I have installed libvirt-php along with xampp server.
> Now I need to create a web based controll panel application which shows
> me running vms, and some options like Shutdown, Pause, Create, Destroy.
> My aim is, when I click Destroy button the selected vm should be
> destroyed. For this I have used the following php-script:
> 
> <?php
>     
>     $conn=libvirt_connect("xen:///");
>     $name=libvirt_domain_lookup_by_id($conn,4); // Here '4' is the id of
> my running vm
>     $dest=libvirt_domain_destroy($name);
>     echo $dest;
> 
> ?>  
> 
> 
> When I execute this it shows me following warning:
> 
> *Warning: libvirt_domain_destroy() [function.libvirt-domain-destroy]:
> operation virDomainDestroy forbidden for read only access in
> /opt/lampp/htdocs/xampp/xen/test.php on line 5
> *
> 
> So, Could you please help me to solve this?
> 
> ! Thank You !
> 

You need to pass credentials array:

$credentials = array(VIR_CRED_AUTHNAME=>'root',VIR_CRED_PASSPHRASE=>'super_secret_password');
$conn = libvirt_connect("xen:///", FALSE, $credentials); // FALSE means you want read-write connection

You can find examplese here:

http://phplibvirt.cybersales.cz/doc/function.libvirt-connect.html

Michal




More information about the libvir-list mailing list