mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-08 15:13:11 -06:00
virtinst: util: Simplify randomUUID
This commit is contained in:
parent
1771f6a300
commit
02733ecff4
@ -1452,7 +1452,7 @@ class vmmCreate(vmmGObjectUI):
|
||||
|
||||
# Generate UUID (makes customize dialog happy)
|
||||
try:
|
||||
guest.uuid = virtinst.util.uuidToString(virtinst.util.randomUUID())
|
||||
guest.uuid = virtinst.util.randomUUID(guest.conn)
|
||||
except Exception, e:
|
||||
self.err.show_err(_("Error setting UUID: %s") % str(e))
|
||||
return None
|
||||
|
@ -493,7 +493,7 @@ class LibvirtWorker:
|
||||
if extraargs:
|
||||
self.__guest.installer.extraarags = extraargs
|
||||
|
||||
self.__guest.uuid = virtinst.util.uuidToString(virtinst.util.randomUUID())
|
||||
self.__guest.uuid = virtinst.util.randomUUID(self.__conn)
|
||||
|
||||
if config.get_os_type() != "generic":
|
||||
self.__guest.os_type = config.get_os_type()
|
||||
|
@ -430,7 +430,7 @@ def find_keymap_from_etc_default():
|
||||
|
||||
def generate_uuid(conn):
|
||||
for ignore in range(256):
|
||||
uuid = uuidToString(randomUUID(), conn=conn)
|
||||
uuid = randomUUID(conn=conn)
|
||||
if not vm_uuid_collision(conn, uuid):
|
||||
return uuid
|
||||
|
||||
@ -565,20 +565,12 @@ def randomMAC(typ, conn=None):
|
||||
return ':'.join(["%02x" % x for x in mac])
|
||||
|
||||
|
||||
# the following three functions are from xend/uuid.py and are thus
|
||||
# available under the LGPL,
|
||||
# Copyright 2005 Mike Wray <mike.wray@hp.com>
|
||||
# Copyright 2005 XenSource Ltd
|
||||
def randomUUID():
|
||||
"""Generate a random UUID."""
|
||||
return [random.randint(0, 255) for ignore in range(0, 16)]
|
||||
|
||||
|
||||
def uuidToString(u, conn=None):
|
||||
def randomUUID(conn):
|
||||
if conn and hasattr(conn, "_virtinst__fake_conn_predictable"):
|
||||
# Testing hack
|
||||
return "00000000-1111-2222-3333-444444444444"
|
||||
|
||||
u = [random.randint(0, 255) for ignore in range(0, 16)]
|
||||
return "-".join(["%02x" * 4, "%02x" * 2, "%02x" * 2, "%02x" * 2,
|
||||
"%02x" * 6]) % tuple(u)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user