From 1839128ad1a2c14b06cd83acde07448d396b5aba Mon Sep 17 00:00:00 2001 From: KasuganoSoras Date: Wed, 10 Oct 2018 02:12:21 +0800 Subject: [PATCH] =?UTF-8?q?[+]=20=E4=BF=AE=E5=A4=8D=E6=89=8B=E6=BB=91bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复了手滑写错的bug 增加了 example 的注释 --- example.php | 7 ++++++- libvirt/libvirt.php | 7 +++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/example.php b/example.php index 7a06d8a..fd5471f 100644 --- a/example.php +++ b/example.php @@ -1,7 +1,12 @@ setHost("192.168.3.181", 22, "/data/libvirt/"); +// Use the username 'root' and the password '123456' login to server. $Libvirt->connect("root", "123456"); -print_r($Libvirt->dumpxml("centos")); \ No newline at end of file +// Print the virtual machine centos's config file. +echo $Libvirt->dumpxml("centos"); \ No newline at end of file diff --git a/libvirt/libvirt.php b/libvirt/libvirt.php index fa3f165..f164778 100644 --- a/libvirt/libvirt.php +++ b/libvirt/libvirt.php @@ -427,9 +427,12 @@ class Libvirt { * @param $newMac 新的网卡 MAC * */ - public function changeMac($server, $newMac) { + public function changeMac($server, $newMac = "") { $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); $this->uploadFile(__DIR__ . "/{$server}.xml", $this->libpath . "/{$server}.xml"); @unlink(__DIR__ . "/{$server}.xml");