[libvirt] [libvirt-php] API to add/remove disk to/from domain

Michal Novotny minovotn at redhat.com
Fri Apr 1 11:18:50 UTC 2011


On 04/01/2011 11:11 AM, Conor Murphy wrote:
> Hi,
>
> How do I add/remove a disk to a domain using the libvirt-php API?
>
> Thanks,
> Conor
>
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
Hi Conor,
you have to edit the domain XML file manually, there's no API yet.
Please see the example scripts in the examples directory of the cloned
repository. On the main page there is option to edit the domain XML
description but you have to have the domain stopped (not running) to
change the domain XML description.

Adding the new disk is done using the:

    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/home/mig/images/kvm/winxp.img'/>
      <target dev='hda' bus='ide'/>
    </disk>

definition where /driver/@type is the type of the driver to be used for
the image - raw is the standard image but you can also put qcow2 image
there if supported by your hypervisor/emulator (e.g. QEMU). By target
you can define the device presented to the guest and bus type (i.e. IDE
or SCSI) and after this you can start up the guest with the
configuration mentioned there. You can pass the address element there as
well but you don't have to since it's generated automatically when omited.

Michal

-- 
Michal Novotny <minovotn at redhat.com>, RHCE
Virtualization Team (xen userspace), Red Hat




More information about the libvir-list mailing list