[+] 修复手滑bug
修复了手滑写错的bug 增加了 example 的注释
This commit is contained in:
parent
9ad82c2268
commit
1839128ad1
@ -1,7 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
Header("Content-type: text/plain");
|
Header("Content-type: text/plain");
|
||||||
|
// Include Libvirt libraries
|
||||||
include("libvirt/libvirt.php");
|
include("libvirt/libvirt.php");
|
||||||
|
// Instantiation Libvirt
|
||||||
$Libvirt = new Libvirt();
|
$Libvirt = new Libvirt();
|
||||||
|
// Connect to 192.168.3.181:22 and set libvirt root at /data/libvirt/
|
||||||
$Libvirt->setHost("192.168.3.181", 22, "/data/libvirt/");
|
$Libvirt->setHost("192.168.3.181", 22, "/data/libvirt/");
|
||||||
|
// Use the username 'root' and the password '123456' login to server.
|
||||||
$Libvirt->connect("root", "123456");
|
$Libvirt->connect("root", "123456");
|
||||||
print_r($Libvirt->dumpxml("centos"));
|
// Print the virtual machine centos's config file.
|
||||||
|
echo $Libvirt->dumpxml("centos");
|
@ -427,9 +427,12 @@ class Libvirt {
|
|||||||
* @param $newMac 新的网卡 MAC
|
* @param $newMac 新的网卡 MAC
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function changeMac($server, $newMac) {
|
public function changeMac($server, $newMac = "") {
|
||||||
$data = $this->dumpxml($server);
|
$data = $this->dumpxml($server);
|
||||||
$data = preg_replace("/address='([A-Za-z0-9\:]+)'/", "address='" . $Libvirt->randomMac() . "'", $data);
|
if($newMac == "") {
|
||||||
|
$newMac = $this->randomMac();
|
||||||
|
}
|
||||||
|
$data = preg_replace("/address='([A-Za-z0-9\:]+)'/", "address='{$newMac}'", $data);
|
||||||
@file_put_contents(__DIR__ . "/{$server}.xml", $data);
|
@file_put_contents(__DIR__ . "/{$server}.xml", $data);
|
||||||
$this->uploadFile(__DIR__ . "/{$server}.xml", $this->libpath . "/{$server}.xml");
|
$this->uploadFile(__DIR__ . "/{$server}.xml", $this->libpath . "/{$server}.xml");
|
||||||
@unlink(__DIR__ . "/{$server}.xml");
|
@unlink(__DIR__ . "/{$server}.xml");
|
||||||
|
Loading…
Reference in New Issue
Block a user