mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
virtinst: util: Simplify randomUUID
This commit is contained in:
@@ -1452,7 +1452,7 @@ class vmmCreate(vmmGObjectUI):
|
|||||||
|
|
||||||
# Generate UUID (makes customize dialog happy)
|
# Generate UUID (makes customize dialog happy)
|
||||||
try:
|
try:
|
||||||
guest.uuid = virtinst.util.uuidToString(virtinst.util.randomUUID())
|
guest.uuid = virtinst.util.randomUUID(guest.conn)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.err.show_err(_("Error setting UUID: %s") % str(e))
|
self.err.show_err(_("Error setting UUID: %s") % str(e))
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -493,7 +493,7 @@ class LibvirtWorker:
|
|||||||
if extraargs:
|
if extraargs:
|
||||||
self.__guest.installer.extraarags = 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":
|
if config.get_os_type() != "generic":
|
||||||
self.__guest.os_type = config.get_os_type()
|
self.__guest.os_type = config.get_os_type()
|
||||||
|
|||||||
@@ -430,7 +430,7 @@ def find_keymap_from_etc_default():
|
|||||||
|
|
||||||
def generate_uuid(conn):
|
def generate_uuid(conn):
|
||||||
for ignore in range(256):
|
for ignore in range(256):
|
||||||
uuid = uuidToString(randomUUID(), conn=conn)
|
uuid = randomUUID(conn=conn)
|
||||||
if not vm_uuid_collision(conn, uuid):
|
if not vm_uuid_collision(conn, uuid):
|
||||||
return uuid
|
return uuid
|
||||||
|
|
||||||
@@ -565,20 +565,12 @@ def randomMAC(typ, conn=None):
|
|||||||
return ':'.join(["%02x" % x for x in mac])
|
return ':'.join(["%02x" % x for x in mac])
|
||||||
|
|
||||||
|
|
||||||
# the following three functions are from xend/uuid.py and are thus
|
def randomUUID(conn):
|
||||||
# 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):
|
|
||||||
if conn and hasattr(conn, "_virtinst__fake_conn_predictable"):
|
if conn and hasattr(conn, "_virtinst__fake_conn_predictable"):
|
||||||
# Testing hack
|
# Testing hack
|
||||||
return "00000000-1111-2222-3333-444444444444"
|
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,
|
return "-".join(["%02x" * 4, "%02x" * 2, "%02x" * 2, "%02x" * 2,
|
||||||
"%02x" * 6]) % tuple(u)
|
"%02x" * 6]) % tuple(u)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user