1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import random
17 from virtualization.errors import UUIDError
18
20 """Generate a random UUID and return it."""
21
22 uuid_list = [ random.randint(0, 255) for _ in range(0, 16) ]
23 return ("%02x" * 16) % tuple(uuid_list)
24
26
27 if len(uuid) == 36 and len(uuid.replace('-', '')) == 32:
28 return uuid[:]
29
30 if len(uuid) != 32:
31 raise UUIDError("UUID %s is not 32 characters long." % (uuid,))
32
33 formatstr = "%s-%s-%s-%s-%s"
34 new_uuid = formatstr % (uuid[0:8],
35 uuid[8:12],
36 uuid[12:16],
37 uuid[16:20],
38 uuid[20:])
39 return new_uuid
40
42 if uuid is None:
43 return uuid
44
45 return uuid.replace('-', '')
46
48 """
49 Returns true if the given UUID represents a host. We can tell because
50 host UUIDs are always 0.
51 """
52 return int(eval("0x" + dehyphenize_uuid(uuid))) == 0
53
55 """
56 Returns true if the given domain is a fully-virt domain.
57 """
58 return domain.OSType().lower() == 'hvm'
59