好的我想使用libvirt-php创建域。这是代码。
< ?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); ?>
每件事情都可以,但问题只出在 $ flags 。 我通过了
- DOMAIN_FLAG_FEATURE_ACPI
- DOMAIN_FLAG_FEATURE_APIC
- DOMAIN_FLAG_FEATURE_PAE
- DOMAIN_FLAG_CLOCK
- DOMAIN_FLAG_SOUND_AC97, 所有选项不确定但是当我执行它时会向我显示以下警告:
醇>注意:使用未定义的常量DOMAIN_FLAG_FEATURE_ACPI - 在第32行的/opt/lampp/htdocs/xampp/xen/create_vm.php中假定为“DOMAIN_FLAG_FEATURE_ACPI”
警告:libvirt_domain_new()期望参数10为long,第34行的/opt/lampp/htdocs/xampp/xen/create_vm.php中给出字符串
警告:libvirt_domain_new()[function.libvirt-domain-new]:第34行/opt/lampp/htdocs/xampp/xen/create_vm.php中的参数无效
答案 0 :(得分:1)
您已将$flags
定义为字符串,但需要很长时间。我猜你想要的是为$flags
分配常量DOMAIN_FLAG_FEATURE_ACPI
的值,而是将其定义为包含DOMAIN_FLAG_FEATURE_ACPI
本身作为文本的文字字符串。
$flags = DOMAIN_FLAG_FEATURE_ACPI;
答案 1 :(得分:1)
消息:
未找到域:第32行/opt/lampp/htdocs/xampp/xen/create_vm.php中的xenUnifiedDomainLookupByUUID
来自libvirt本身,而不是libvirt-php。似乎libvirt连接到Xen实例时出错。