ia64/xen-unstable
changeset 5347:9f893f674211
bitkeeper revision 1.1662.1.10 (42a48d2dOYGp10ZpkS7A_bvbZcKyOw)
XendDomainInfo.py, XendDomain.py:
Add uuids for domains.
uuid.py:
new file
Signed-off-by: Mike Wray <mike.wray@hp.com>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
XendDomainInfo.py, XendDomain.py:
Add uuids for domains.
uuid.py:
new file
Signed-off-by: Mike Wray <mike.wray@hp.com>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author | cl349@firebug.cl.cam.ac.uk |
---|---|
date | Mon Jun 06 17:51:41 2005 +0000 (2005-06-06) |
parents | cf712d7c809c |
children | c768bf758ce1 |
files | .rootkeys tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/uuid.py |
line diff
1.1 --- a/.rootkeys Mon Jun 06 17:20:16 2005 +0000 1.2 +++ b/.rootkeys Mon Jun 06 17:51:41 2005 +0000 1.3 @@ -875,6 +875,7 @@ 4266169eI_oX3YBjwaeC0V-THBRnjg tools/pyt 1.4 4294a1bf8rMUcddot-B2-pOxORimOg tools/python/xen/xend/server/relocate.py 1.5 41ee5e8dq9NtihbL4nWKjuSLOhXPUg tools/python/xen/xend/server/usbif.py 1.6 40c9c469LNxLVizOUpOjEaTKKCm8Aw tools/python/xen/xend/sxp.py 1.7 +42a48d152jkT7ykQT_LWKnS-ojV_ZA tools/python/xen/xend/uuid.py 1.8 40d05079aFRp6NQdo5wIh5Ly31c0cg tools/python/xen/xm/__init__.py 1.9 40cf2937gKQcATgXKGtNeWb1PDH5nA tools/python/xen/xm/create.py 1.10 40f552eariuUSB9TWqCPnDLz5zvxMw tools/python/xen/xm/destroy.py
2.1 --- a/tools/python/xen/xend/XendDomain.py Mon Jun 06 17:20:16 2005 +0000 2.2 +++ b/tools/python/xen/xend/XendDomain.py Mon Jun 06 17:51:41 2005 +0000 2.3 @@ -125,7 +125,8 @@ class XendDomain: 2.4 @param info: domain info from xen 2.5 @return: domain 2.6 """ 2.7 - dominfo = XendDomainInfo.recreate(savedinfo, info) 2.8 + uuid = sxp.child_value(savedinfo, 'uuid') 2.9 + dominfo = XendDomainInfo.recreate(savedinfo, info, uuid) 2.10 self.domains[dominfo.id] = dominfo 2.11 self.sync_domain(dominfo) 2.12 return dominfo 2.13 @@ -295,7 +296,8 @@ class XendDomain: 2.14 @param vmconfig: vm configuration 2.15 """ 2.16 config = sxp.child_value(vmconfig, 'config') 2.17 - dominfo = XendDomainInfo.restore(config) 2.18 + uuid = sxp.child_value(vmconfig, 'uuid') 2.19 + dominfo = XendDomainInfo.restore(config, uuid=uuid) 2.20 self._add_domain(dominfo) 2.21 return dominfo 2.22 2.23 @@ -329,7 +331,7 @@ class XendDomain: 2.24 info = self.xen_domain(id) 2.25 if info: 2.26 log.info("Creating entry for unknown domain: id=%d", id) 2.27 - dominfo = XendDomainInfo.recreate(None, info, unknown=True) 2.28 + dominfo = XendDomainInfo.recreate(None, info) 2.29 self._add_domain(dominfo) 2.30 except Exception, ex: 2.31 log.exception("Error creating domain info: id=%d", id)
3.1 --- a/tools/python/xen/xend/XendDomainInfo.py Mon Jun 06 17:20:16 2005 +0000 3.2 +++ b/tools/python/xen/xend/XendDomainInfo.py Mon Jun 06 17:51:41 2005 +0000 3.3 @@ -29,6 +29,8 @@ from xen.xend.XendLogging import log 3.4 from XendError import XendError, VmError 3.5 from xen.xend.XendRoot import get_component 3.6 3.7 +from xen.xend.uuid import getUuid 3.8 + 3.9 """Flag for a block device backend domain.""" 3.10 SIF_BLK_BE_DOMAIN = (1<<4) 3.11 3.12 @@ -143,12 +145,16 @@ class XendDomainInfo: 3.13 """ 3.14 MINIMUM_RESTART_TIME = 20 3.15 3.16 - def _create(cls): 3.17 - """Create a vm object. 3.18 + def _create(cls, uuid=None): 3.19 + """Create a vm object with a uuid. 3.20 3.21 + @param uuid uuid to use (generated if None) 3.22 @return vm 3.23 """ 3.24 + if uuid is None: 3.25 + uuid = getUuid() 3.26 vm = cls() 3.27 + vm.uuid = uuid 3.28 return vm 3.29 3.30 _create = classmethod(_create) 3.31 @@ -167,17 +173,14 @@ class XendDomainInfo: 3.32 3.33 create = classmethod(create) 3.34 3.35 - def recreate(cls, savedinfo, info, unknown=False): 3.36 + def recreate(cls, savedinfo, info, uuid=None): 3.37 """Create the VM object for an existing domain. 3.38 3.39 @param savedinfo: saved info from the domain DB 3.40 @param info: domain info from xc 3.41 @type info: xc domain dict 3.42 """ 3.43 - if unknown: 3.44 - vm = cls._create() 3.45 - else: 3.46 - vm = cls() 3.47 + vm = cls._create(uuid=uuid) 3.48 3.49 log.debug('savedinfo=' + prettyprintstring(savedinfo)) 3.50 log.debug('info=' + str(info)) 3.51 @@ -209,12 +212,12 @@ class XendDomainInfo: 3.52 3.53 recreate = classmethod(recreate) 3.54 3.55 - def restore(cls, config): 3.56 + def restore(cls, config, uuid=None): 3.57 """Create a domain and a VM object to do a restore. 3.58 3.59 @param config: domain configuration 3.60 """ 3.61 - vm = cls._create() 3.62 + vm = cls._create(uuid=uuid) 3.63 dom = xc.domain_create() 3.64 vm.setdom(dom) 3.65 vm.dom_construct(vm.id, config) 3.66 @@ -227,6 +230,7 @@ class XendDomainInfo: 3.67 self.restore = 0 3.68 3.69 self.config = None 3.70 + self.uuid = None 3.71 self.id = None 3.72 self.cpu_weight = 1 3.73 self.start_time = None 3.74 @@ -365,7 +369,8 @@ class XendDomainInfo: 3.75 ['id', self.id], 3.76 ['name', self.name], 3.77 ['memory', self.memory] ] 3.78 - 3.79 + if self.uuid: 3.80 + sxpr.append(['uuid', self.uuid]) 3.81 if self.info: 3.82 sxpr.append(['maxmem', self.info['maxmem_kb']/1024 ]) 3.83 run = (self.info['running'] and 'r') or '-'
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/tools/python/xen/xend/uuid.py Mon Jun 06 17:51:41 2005 +0000 4.3 @@ -0,0 +1,65 @@ 4.4 +"""Universal(ly) Unique Identifiers (UUIDs). 4.5 +""" 4.6 +import commands 4.7 +import random 4.8 + 4.9 +def uuidgen(random=True): 4.10 + """Generate a UUID using the command uuidgen. 4.11 + 4.12 + If random is true (default) generates a random uuid. 4.13 + If random is false generates a time-based uuid. 4.14 + """ 4.15 + cmd = "uuidgen" 4.16 + if random: 4.17 + cmd += " -r" 4.18 + else: 4.19 + cmd += " -t" 4.20 + return commands.getoutput(cmd) 4.21 + 4.22 +class UuidFactoryUuidgen: 4.23 + 4.24 + """A uuid factory using uuidgen.""" 4.25 + 4.26 + def __init__(self): 4.27 + pass 4.28 + 4.29 + def getUuid(self): 4.30 + return uuidgen() 4.31 + 4.32 +class UuidFactoryRandom: 4.33 + 4.34 + """A random uuid factory.""" 4.35 + 4.36 + def __init__(self): 4.37 + f = file("/dev/urandom", "r") 4.38 + seed = f.read(16) 4.39 + f.close() 4.40 + self.rand = random.Random(seed) 4.41 + 4.42 + def randBytes(self, n): 4.43 + return [ self.rand.randint(0, 255) for i in range(0, n) ] 4.44 + 4.45 + def getUuid(self): 4.46 + bytes = self.randBytes(16) 4.47 + # Encode the variant. 4.48 + bytes[6] = (bytes[6] & 0x0f) | 0x40 4.49 + bytes[8] = (bytes[8] & 0x3f) | 0x80 4.50 + f = "%02x" 4.51 + return ( "-".join([f*4, f*2, f*2, f*2, f*6]) % tuple(bytes) ) 4.52 + 4.53 +def getFactory(): 4.54 + """Get the factory to use for creating uuids. 4.55 + This is so it's easy to change the uuid factory. 4.56 + For example, for testing we might want repeatable uuids 4.57 + rather than the random ones we normally use. 4.58 + """ 4.59 + global uuidFactory 4.60 + try: 4.61 + uuidFactory 4.62 + except: 4.63 + #uuidFactory = UuidFactoryUuidgen() 4.64 + uuidFactory = UuidFactoryRandom() 4.65 + return uuidFactory 4.66 + 4.67 +def getUuid(): 4.68 + return getFactory().getUuid()