PHP script to create domain

Go To StackoverFlow.com

-2

Ok I want to create domain using libvirt-php.Here is the code.

< ?php

$credentials = array(VIR_CRED_AUTHNAME=>'root',VIR_CRED_PASSPHRASE=>'root');
$conn = libvirt_connect("xen:///", FALSE, $credentials); 
$name="oneiric";
$arch="i386";
$memMB=1024;
$maxmemMB=1536;
$vcpus=2;
$iso_image="/root/onericGUI.iso";
$disk1 = array(
                     "path" => "/var/libvirt/images/vm.img",
                "driver" => "raw",
                "bus" => "ide",
                "dev" => "hda",
                "size" => "10G",
                "flags" => VIR_DOMAIN_DISK_FILE | VIR_DOMAIN_DISK_ACCESS_ALL                     ); $disks = array( $disk1 );

$network1 = array(
                            'mac' => '00:11:22:33:44:55',
                            'network' => 'default',
                            'model' => 'e1000'
                        );

    $networks = array( $network1 ); $flags=DOMAIN_FLAG_FEATURE_ACPI;

$newdom=libvirt_domain_new($conn, $name, $arch, $memMB, $maxmemMB, $vcpus, $iso_image, $disks, $networks, $flags);
print_r($newdom);    ?> 

Every thing all right but the problem is only at $flags . I have passed

  1. DOMAIN_FLAG_FEATURE_ACPI
  2. DOMAIN_FLAG_FEATURE_APIC
  3. DOMAIN_FLAG_FEATURE_PAE
  4. DOMAIN_FLAG_CLOCK
  5. DOMAIN_FLAG_SOUND_AC97, all options Indevedually but when I execute it it shows me following warning:

Notice: Use of undefined constant DOMAIN_FLAG_FEATURE_ACPI - assumed 'DOMAIN_FLAG_FEATURE_ACPI' in /opt/lampp/htdocs/xampp/xen/create_vm.php on line 32

Warning: libvirt_domain_new() expects parameter 10 to be long, string given in /opt/lampp/htdocs/xampp/xen/create_vm.php on line 34

Warning: libvirt_domain_new() [function.libvirt-domain-new]: Invalid arguments in /opt/lampp/htdocs/xampp/xen/create_vm.php on line 34

2012-04-04 17:55
by Alee
Ugh, please don't post a picture of your code. Post the actual code - Matt Ball 2012-04-04 17:58
Add your code as text, not an image - kba 2012-04-04 17:58
Can you copy and paste the code please rather than using a screenshot? Screenshots can't be indexed by search engines and if other people are looking for a solution to your problem, this will pose a problem - Flukey 2012-04-04 17:58
Here's the image in better resolution, until he posts the code: http://i.stack.imgur.com/mtDWq.pn - Ashley Davies 2012-04-04 17:59
are you afraid someone might steal the code ? - Baba 2012-04-04 18:28
no.. wait I am posting i - Alee 2012-04-04 18:29
Now I think its clear to understand - Alee 2012-04-04 18:35


1

You have defined $flags as a string, but a long is required. I'm guessing what you wanted to was assign $flags the value of the constant DOMAIN_FLAG_FEATURE_ACPI, but instead you defined it as a literal string containing DOMAIN_FLAG_FEATURE_ACPI itself as text.

$flags = DOMAIN_FLAG_FEATURE_ACPI;
2012-04-04 17:59
by kba
Sorry I am doing some mistake in the code. Its not $flags = DOMAINFLAGFEATUREACPI; but actually its $flags = VIRDOMAINFLAGFEATURE_ACPI; > > After correcting the code another warning generated which is :

Warning: libvirtdomainnew() [function.libvirt-domain-new http://localhost/xampp/xen/function.libvirt-domain-new]: Domain not found: xenUnifiedDomainLookupByUUID in /opt/lampp/htdocs/xampp/xen/create_vm.php on line 3 - Alee 2012-04-07 17:31



1

The message:

Domain not found: xenUnifiedDomainLookupByUUID in /opt/lampp/htdocs/xampp/xen/create_vm.php on line 32

is coming from libvirt itself, not libvirt-php. It seems that there's an error on libvirt connecting to your Xen instance.

2012-09-12 16:07
by Michal Novotny
Ads