[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Move initDomain out of image.py and into XendDomainInfo. The only thing that



# HG changeset patch
# User emellor@ewan
# Node ID f5e33f4d0238cfee9e0b759fe959706b21f179d1
# Parent  4be4126911dcddc8efab7e8076ca4cca95d4f169
Move initDomain out of image.py and into XendDomainInfo.  The only thing that
needed any of the state of image.py was the bootloader code, which says there,
but all the rest was doing something that belonged more properly in
XendDomainInfo, with all the other generic domain initialisation code.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>

diff -r 4be4126911dc -r f5e33f4d0238 tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py   Thu Sep 22 16:50:29 2005
+++ b/tools/python/xen/xend/XendDomainInfo.py   Thu Sep 22 16:52:07 2005
@@ -706,32 +706,14 @@
         """
         # todo - add support for scheduling params?
         try:
-            # Initial domain create.
             if 'image' not in self.info:
                 raise VmError('Missing image in configuration')
 
-            self.image = ImageHandler.create(self, self.info['image'],
+            self.image = ImageHandler.create(self,
+                                             self.info['image'],
                                              self.info['device'])
 
-            log.debug('XendDomainInfo.construct: '
-                      'calling initDomain(%s %s %s %s %s)',
-                      str(self.domid),
-                      str(self.info['memory_KiB']),
-                      str(self.info['ssidref']),
-                      str(self.info['cpu']),
-                      str(self.info['cpu_weight']))
-
-            self.setDomid(self.image.initDomain(self.domid,
-                                                self.info['memory_KiB'],
-                                                self.info['ssidref'],
-                                                self.info['cpu'],
-                                                self.info['cpu_weight'],
-                                                self.info['bootloader']))
-            
-            self.info['start_time'] = time.time()
-
-            log.debug('init_domain> Created domain=%d name=%s memory=%d',
-                      self.domid, self.info['name'], self.info['memory_KiB'])
+            self.initDomain()
 
             # Create domain devices.
             self.construct_image()
@@ -744,6 +726,38 @@
             traceback.print_exc()
             self.destroy()
             raise
+
+
+    def initDomain(self):
+        log.debug('XendDomainInfo.initDomain: %s %s %s %s)',
+                  str(self.domid),
+                  str(self.info['memory_KiB']),
+                  str(self.info['ssidref']),
+                  str(self.info['cpu_weight']))
+
+        self.domid = xc.domain_create(dom = self.domid or 0,
+                                      ssidref = self.info['ssidref'])
+        if self.domid <= 0:
+            raise VmError('Creating domain failed: name=%s' %
+                          self.vm.getName())
+
+        if self.info['bootloader']:
+            self.image.handleBootloading()
+
+        xc.domain_setcpuweight(self.domid, self.info['cpu_weight'])
+        m = self.image.getDomainMemory(self.info['memory_KiB'])
+        xc.domain_setmaxmem(self.domid, m)
+        xc.domain_memory_increase_reservation(self.domid, m, 0, 0)
+
+        cpu = self.info['cpu']
+        if cpu is not None and cpu != -1:
+            xc.domain_pincpu(self.domid, 0, 1 << cpu)
+
+        self.info['start_time'] = time.time()
+
+        log.debug('init_domain> Created domain=%d name=%s memory=%d',
+                  self.domid, self.info['name'], self.info['memory_KiB'])
+
 
     def configure_vcpus(self, vcpus):
         d = {}
diff -r 4be4126911dc -r f5e33f4d0238 tools/python/xen/xend/image.py
--- a/tools/python/xen/xend/image.py    Thu Sep 22 16:50:29 2005
+++ b/tools/python/xen/xend/image.py    Thu Sep 22 16:52:07 2005
@@ -36,9 +36,6 @@
 class ImageHandler:
     """Abstract base class for image handlers.
 
-    initDomain() is called to initialise the domain memory and parse
-    the configuration.
-    
     createImage() is called to configure and build the domain from its
     kernel image and ramdisk etc.
 
@@ -132,6 +129,12 @@
                         ("image/cmdline", self.cmdline),
                         ("image/ramdisk", self.ramdisk))
 
+
+    def handleBootloading():
+        self.unlink(self.kernel)
+        self.unlink(self.ramdisk)
+
+
     def unlink(self, f):
         if not f: return
         try:
@@ -139,37 +142,6 @@
         except OSError, ex:
             log.warning("error removing bootloader file '%s': %s", f, ex)
 
-    def initDomain(self, dom, memory, ssidref, cpu, cpu_weight, bootloading):
-        """Initial domain create.
-
-        @param memory In KiB
-        @return domain id
-        """
-
-        mem_kb = self.getDomainMemory(memory)
-        dom = xc.domain_create(dom = dom or 0, ssidref = ssidref)
-        # if bootloader, unlink here. But should go after buildDomain() ?
-        if bootloading:
-            self.unlink(self.kernel)
-            self.unlink(self.ramdisk)
-        if dom <= 0:
-            raise VmError('Creating domain failed: name=%s' %
-                          self.vm.getName())
-        if cpu is None:
-            cpu = -1;
-        log.debug("initDomain: cpu=%d mem_kb=%d ssidref=%d dom=%d", cpu, 
mem_kb, ssidref, dom)
-        xc.domain_setcpuweight(dom, cpu_weight)
-        xc.domain_setmaxmem(dom, mem_kb)
-
-        try:
-            xc.domain_memory_increase_reservation(dom, mem_kb, 0, 0)
-        except:
-            xc.domain_destroy(dom)
-            raise
-
-        if cpu != -1:
-            xc.domain_pincpu(dom, 0, 1<<int(cpu))
-        return dom
 
     def createImage(self):
         """Entry point to create domain memory image.

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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.