-3

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

Ali R. Memon
  • 121
  • 1
  • 1
  • 12

2 Answers2

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;
kba
  • 19,333
  • 5
  • 62
  • 89
  • Sorry I am doing some mistake in the code. Its not $flags = DOMAIN_FLAG_FEATURE_ACPI; but actually its $flags = VIR_DOMAIN_FLAG_FEATURE_ACPI; > > After correcting the code another warning generated which is : Warning: libvirt_domain_new() [function.libvirt-domain-new ]: Domain not found: xenUnifiedDomainLookupByUUID in /opt/lampp/htdocs/xampp/xen/create_vm.php on line 32 – Ali R. Memon Apr 07 '12 at 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.