Package virtualization :: Module util
[hide private]
[frames] | no frames]

Source Code for Module virtualization.util

 1  # 
 2  # Copyright (c) 2008--2013 Red Hat, Inc. 
 3  # 
 4  # This software is licensed to you under the GNU General Public License, 
 5  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
 6  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
 8  # along with this software; if not, see 
 9  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
10  # 
11  # Red Hat trademarks are not licensed under GPLv2. No permission is 
12  # granted to use or replicate Red Hat trademarks that are incorporated 
13  # in this software or its documentation. 
14  # 
15   
16  import random 
17  from virtualization.errors import UUIDError 
18   
19 -def generate_uuid():
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
25 -def hyphenize_uuid(uuid):
26 # Determine whether the string is already hyphenized. 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
41 -def dehyphenize_uuid(uuid):
42 if uuid is None: 43 return uuid 44 45 return uuid.replace('-', '')
46
47 -def is_host_uuid(uuid):
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
54 -def is_fully_virt(domain):
55 """ 56 Returns true if the given domain is a fully-virt domain. 57 """ 58 return domain.OSType().lower() == 'hvm'
59