WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] XendDomainInfo.py, XendDomain.py:

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] XendDomainInfo.py, XendDomain.py:
From: BitKeeper Bot <riel@xxxxxxxxxxx>
Date: Mon, 06 Jun 2005 17:51:41 +0000
Delivery-date: Thu, 09 Jun 2005 17:06:42 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: Xen Development List <xen-devel@xxxxxxxxxxxxxxxxxxx>
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
ChangeSet 1.1662.1.10, 2005/06/06 18:51:41+01:00, cl349@xxxxxxxxxxxxxxxxxxxx

        XendDomainInfo.py, XendDomain.py:
          Add uuids for domains.
        uuid.py:
          new file
        Signed-off-by: Mike Wray <mike.wray@xxxxxx>
        Signed-off-by: Christian Limpach <Christian.Limpach@xxxxxxxxxxxx>



 XendDomain.py     |    8 ++++--
 XendDomainInfo.py |   25 ++++++++++++--------
 uuid.py           |   65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+), 13 deletions(-)


diff -Nru a/tools/python/xen/xend/XendDomain.py 
b/tools/python/xen/xend/XendDomain.py
--- a/tools/python/xen/xend/XendDomain.py       2005-06-09 13:07:40 -04:00
+++ b/tools/python/xen/xend/XendDomain.py       2005-06-09 13:07:40 -04:00
@@ -125,7 +125,8 @@
         @param info:      domain info from xen
         @return: domain
         """
-        dominfo = XendDomainInfo.recreate(savedinfo, info)
+        uuid = sxp.child_value(savedinfo, 'uuid')
+        dominfo = XendDomainInfo.recreate(savedinfo, info, uuid)
         self.domains[dominfo.id] = dominfo
         self.sync_domain(dominfo)
         return dominfo
@@ -295,7 +296,8 @@
         @param vmconfig: vm configuration
         """
         config = sxp.child_value(vmconfig, 'config')
-        dominfo = XendDomainInfo.restore(config)
+        uuid = sxp.child_value(vmconfig, 'uuid')
+        dominfo = XendDomainInfo.restore(config, uuid=uuid)
         self._add_domain(dominfo)
         return dominfo
 
@@ -329,7 +331,7 @@
                 info = self.xen_domain(id)
                 if info:
                     log.info("Creating entry for unknown domain: id=%d", id)
-                    dominfo = XendDomainInfo.recreate(None, info, unknown=True)
+                    dominfo = XendDomainInfo.recreate(None, info)
                     self._add_domain(dominfo)
             except Exception, ex:
                 log.exception("Error creating domain info: id=%d", id)
diff -Nru a/tools/python/xen/xend/XendDomainInfo.py 
b/tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py   2005-06-09 13:07:40 -04:00
+++ b/tools/python/xen/xend/XendDomainInfo.py   2005-06-09 13:07:40 -04:00
@@ -29,6 +29,8 @@
 from XendError import XendError, VmError
 from xen.xend.XendRoot import get_component
 
+from xen.xend.uuid import getUuid
+
 """Flag for a block device backend domain."""
 SIF_BLK_BE_DOMAIN = (1<<4)
 
@@ -143,12 +145,16 @@
     """
     MINIMUM_RESTART_TIME = 20
 
-    def _create(cls):
-        """Create a vm object.
+    def _create(cls, uuid=None):
+        """Create a vm object with a uuid.
 
+        @param uuid uuid to use (generated if None)
         @return vm
         """
+        if uuid is None:
+            uuid = getUuid()
         vm = cls()
+        vm.uuid = uuid
         return vm
 
     _create = classmethod(_create)
@@ -167,17 +173,14 @@
 
     create = classmethod(create)
 
-    def recreate(cls, savedinfo, info, unknown=False):
+    def recreate(cls, savedinfo, info, uuid=None):
         """Create the VM object for an existing domain.
 
         @param savedinfo: saved info from the domain DB
         @param info:      domain info from xc
         @type  info:      xc domain dict
         """
-        if unknown:
-            vm = cls._create()
-        else:
-            vm = cls()
+        vm = cls._create(uuid=uuid)
 
         log.debug('savedinfo=' + prettyprintstring(savedinfo))
         log.debug('info=' + str(info))
@@ -209,12 +212,12 @@
 
     recreate = classmethod(recreate)
 
-    def restore(cls, config):
+    def restore(cls, config, uuid=None):
         """Create a domain and a VM object to do a restore.
 
         @param config:    domain configuration
         """
-        vm = cls._create()
+        vm = cls._create(uuid=uuid)
         dom = xc.domain_create()
         vm.setdom(dom)
         vm.dom_construct(vm.id, config)
@@ -227,6 +230,7 @@
         self.restore = 0
         
         self.config = None
+        self.uuid = None
         self.id = None
         self.cpu_weight = 1
         self.start_time = None
@@ -365,7 +369,8 @@
                 ['id', self.id],
                 ['name', self.name],
                 ['memory', self.memory] ]
-
+        if self.uuid:
+            sxpr.append(['uuid', self.uuid])
         if self.info:
             sxpr.append(['maxmem', self.info['maxmem_kb']/1024 ])
             run   = (self.info['running']  and 'r') or '-'
diff -Nru a/tools/python/xen/xend/uuid.py b/tools/python/xen/xend/uuid.py
--- /dev/null   Wed Dec 31 16:00:00 196900
+++ b/tools/python/xen/xend/uuid.py     2005-06-09 13:07:40 -04:00
@@ -0,0 +1,65 @@
+"""Universal(ly) Unique Identifiers (UUIDs).
+"""
+import commands
+import random
+
+def uuidgen(random=True):
+    """Generate a UUID using the command uuidgen.
+
+    If random is true (default) generates a random uuid.
+    If random is false generates a time-based uuid.
+    """
+    cmd = "uuidgen"
+    if random:
+        cmd += " -r"
+    else:
+        cmd += " -t"
+    return commands.getoutput(cmd)
+
+class UuidFactoryUuidgen:
+
+    """A uuid factory using uuidgen."""
+
+    def __init__(self):
+        pass
+
+    def getUuid(self):
+        return uuidgen()
+
+class UuidFactoryRandom:
+
+    """A random uuid factory."""
+
+    def __init__(self):
+        f = file("/dev/urandom", "r")
+        seed = f.read(16)
+        f.close()
+        self.rand = random.Random(seed)
+
+    def randBytes(self, n):
+        return [ self.rand.randint(0, 255) for i in range(0, n) ]
+
+    def getUuid(self):
+        bytes = self.randBytes(16)
+        # Encode the variant.
+        bytes[6] = (bytes[6] & 0x0f) | 0x40
+        bytes[8] = (bytes[8] & 0x3f) | 0x80
+        f = "%02x"
+        return ( "-".join([f*4, f*2, f*2, f*2, f*6]) % tuple(bytes) )
+
+def getFactory():
+    """Get the factory to use for creating uuids.
+    This is so it's easy to change the uuid factory.
+    For example, for testing we might want repeatable uuids
+    rather than the random ones we normally use.
+    """
+    global uuidFactory
+    try:
+        uuidFactory
+    except:
+        #uuidFactory = UuidFactoryUuidgen()
+        uuidFactory = UuidFactoryRandom()
+    return uuidFactory
+
+def getUuid():
+    return getFactory().getUuid()

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>