Created
June 17, 2014 14:23
-
-
Save Akkiesoft/fd33d0c0c0e6da73a34e to your computer and use it in GitHub Desktop.
libvirtな仮想マシンのXMLのUUIDとMACアドレスを適当に書き換えるPHPスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$file = $argv[1]; | |
$xml = simplexml_load_file($file); | |
# uniqidはそれほどいい感じでないので、いい感じのコマンドを活用する | |
$uuid = exec("uuidgen"); | |
$xml->uuid = $uuid; | |
foreach($xml->devices->interface as $interface) { | |
# uniqidはそれほどいい感じでないので、ハッシュにしていい感じにする | |
$newmac = wordwrap(hash("sha256", uniqid(mt_rand())), 2, ":", true); | |
# Vendor ID + New random ID | |
$newmac = "52:54:00:" . substr($newmac, 0, 8); | |
$interface->mac->attributes()->address = $newmac; | |
} | |
# ディスクのパスを変えたいときは例えばこんなかんじで | |
# foreach($xml->devices->disk as $disk) { | |
# $disk->source->attributes()->file = str_replace("/var/lib/libvirt/images", "/path/to/new/data/store", $disk->source->attributes()->file); | |
# } | |
# 上書きが嫌だったら適当にprefixつけたらよさげ | |
$xml->asXml($file); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment