changeset 38:16840a2375ae

Adapt to CentOS7
author atton
date Fri, 06 Nov 2015 21:51:43 +0900
parents 3b8858a63694
children 6e385ccc40bf
files newvm.py
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/newvm.py	Fri Nov 06 20:30:26 2015 +0900
+++ b/newvm.py	Fri Nov 06 21:51:43 2015 +0900
@@ -67,6 +67,15 @@
         ie_mkdir1('/var/lib/libvirt/qemu/'+dir)
         os.system("/bin/chown "+os.getlogin()+" "+ mount_point+dir)
 
+# virtinst.utils.randomMac is omitted from RHEL 7.
+import random
+def randomMAC():
+    mac = [ 0x52, 0x54, 0x00,
+            random.randint(0x00, 0xff),
+            random.randint(0x00, 0xff),
+            random.randint(0x00, 0xff) ]
+    return ':'.join(map(lambda x: "%02x" % x, mac))
+
 parser = OptionParser();
 parser.add_option("-n", "--name", dest="name",
         help="VM name");
@@ -95,9 +104,9 @@
 
 name.text = new_name
 uuid = config.find('uuid')
-uuid.text = uuidToString(randomUUID())
+uuid.text = randomUUID(0)
 mac = config.find('devices/interface/mac')
-mac.attrib['address'] = randomMAC(type='qemu')
+mac.attrib['address'] = randomMAC()
 disk = config.find('devices/disk/source')
 disk_old = disk.attrib['file']
 disk_path = os.path.dirname(disk_old)