Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Could you tell me how to create a new domain?
From PHP API Reference guide: http://libvirt.org/php/api-reference.html
I have seen these functions:

(i)   libvirt_image_create($conn, $name, $size, $format)
(ii)   libvirt_domain_new($conn, $name, $arch, $memMB, $maxmemMB, $vcpus, $iso_image, $disks, $networks, $flags)
(iii) libvirt_domain_create($res)
(iv)  libvirt_domain_create_xml($conn, $xml)

The problem I am facing is that i dont know the steps to create a new domain. Either I have to create a new image first using libvirt_image_create .... or something else.

share|improve this question

1 Answer 1

Hi I'll comment on this as I'm the developer and maintainer of libvirt-php.

libvirt_image_create($conn, $name, $size, $format)

This API is only for creation of the virtual machine image (the virtual disk for the virtual machine). It doesn't do kind of domain (virtual machine) creation. You don't need it if you use PXE/network boot and similar.


libvirt_domain_new($conn, $name, $arch, $memMB, $maxmemMB, $vcpus,
    $iso_image, $disks, $networks, $flags)

This is for installation of the new virtual machine. First of all, you need to connect to libvirt daemon instance using libvirt_connect(). The return value of libvirt_connect() is the pointer/resource you need to pass as the first argument of this function. Then, you have to provide a virtual machine name, architecture (i686 or x86_64), initial and maximum memory in Megabytes (see the system specifications for operating system you want to install there first), number of VCPUs, ISO image to install this from (for PXE boot you don't require this and you can pass 'false' there), array of disk information (may be false too) and network cards.

The flags are optional and you don't have to pass them. Please refer to examples directory of the libvirt-php installation for real-world example - this is better than something written in here. Installation itself is a complex task so that's why it requires too many information


libvirt_domain_create($res)

This creates the domain identified by a resource. The resource is basically already existing domain found by libvirt_domain_lookup_*() API functions.


libvirt_domain_create_xml($conn, $xml)

This creates one time domain that's not persistent. This domain is just run once as based on the libvirt XML file.

For format of libvirt XML files please refer to libvirt documentation, not libvirt-php.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.