ia64/xen-unstable

changeset 2542:79efeae6d510

bitkeeper revision 1.1159.1.173 (41542ceeTwqddMwV79qdSnSzhkgg1Q)

Reorder domain construction so that the domain is created,
then the devices are configured and finally the boot image is
created.
author mjw@wray-m-3.hpl.hp.com
date Fri Sep 24 14:19:26 2004 +0000 (2004-09-24)
parents a8fef40fad11
children 0f827b0e0801
files tools/python/xen/xend/XendDomainInfo.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Fri Sep 24 13:43:30 2004 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Fri Sep 24 14:19:26 2004 +0000
     1.3 @@ -499,23 +499,17 @@ class XendDomainInfo:
     1.4              if self.memory is None:
     1.5                  raise VmError('missing memory size')
     1.6  
     1.7 +            self.init_domain()
     1.8              self.configure_console()
     1.9              self.configure_restart()
    1.10              self.configure_backends()
    1.11 -            image = sxp.child_value(config, 'image')
    1.12 -            if image is None:
    1.13 -                raise VmError('missing image')
    1.14 -            image_name = sxp.name(image)
    1.15 -            if image_name is None:
    1.16 -                raise VmError('missing image name')
    1.17 -            image_handler = get_image_handler(image_name)
    1.18 -            if image_handler is None:
    1.19 -                raise VmError('unknown image type: ' + image_name)
    1.20 -            image_handler(self, image)
    1.21              deferred = self.configure()
    1.22 +            def cbok(val):
    1.23 +                return self.construct_image()
    1.24              def cberr(err):
    1.25                  self.destroy()
    1.26                  return err
    1.27 +            deferred.addCallback(cbok)
    1.28              deferred.addErrback(cberr)
    1.29          except StandardError, ex:
    1.30              # Catch errors, cleanup and re-raise.
    1.31 @@ -523,6 +517,23 @@ class XendDomainInfo:
    1.32              raise
    1.33          return deferred
    1.34  
    1.35 +    def construct_image(self):
    1.36 +        """Construct the boot image for the domain.
    1.37 +
    1.38 +        @return vm
    1.39 +        """
    1.40 +        image = sxp.child_value(self.config, 'image')
    1.41 +        if image is None:
    1.42 +            raise VmError('missing image')
    1.43 +        image_name = sxp.name(image)
    1.44 +        if image_name is None:
    1.45 +            raise VmError('missing image name')
    1.46 +        image_handler = get_image_handler(image_name)
    1.47 +        if image_handler is None:
    1.48 +            raise VmError('unknown image type: ' + image_name)
    1.49 +        image_handler(self, image)
    1.50 +        return self
    1.51 +
    1.52      def config_devices(self, name):
    1.53          """Get a list of the 'device' nodes of a given type from the config.
    1.54  
    1.55 @@ -741,7 +752,7 @@ class XendDomainInfo:
    1.56          log.debug('init_domain> Created domain=%d name=%s memory=%d', dom, name, memory)
    1.57          self.setdom(dom)
    1.58  
    1.59 -    def build_domain(self, ostype, kernel, ramdisk, cmdline, vifs_n):
    1.60 +    def build_domain(self, ostype, kernel, ramdisk, cmdline):
    1.61          """Build the domain boot image.
    1.62          """
    1.63          if self.recreate or self.restore: return
    1.64 @@ -762,26 +773,25 @@ class XendDomainInfo:
    1.65              raise VmError('Building domain failed: type=%s dom=%d err=%d'
    1.66                            % (ostype, dom, err))
    1.67  
    1.68 -    def create_domain(self, ostype, kernel, ramdisk, cmdline, vifs_n):
    1.69 +    def create_domain(self, ostype, kernel, ramdisk, cmdline):
    1.70          """Create a domain. Builds the image but does not configure it.
    1.71  
    1.72          @param ostype:  OS type
    1.73          @param kernel:  kernel image
    1.74          @param ramdisk: kernel ramdisk
    1.75          @param cmdline: kernel commandline
    1.76 -        @param vifs_n:  number of network interfaces
    1.77          """
    1.78          if not self.recreate:
    1.79              if not os.path.isfile(kernel):
    1.80                  raise VmError('Kernel image does not exist: %s' % kernel)
    1.81              if ramdisk and not os.path.isfile(ramdisk):
    1.82                  raise VmError('Kernel ramdisk does not exist: %s' % ramdisk)
    1.83 -        self.init_domain()
    1.84 +        #self.init_domain()
    1.85          if self.console:
    1.86              self.console.registerChannel()
    1.87          else:
    1.88              self.console = xendConsole.console_create(self.dom, console_port=self.console_port)
    1.89 -        self.build_domain(ostype, kernel, ramdisk, cmdline, vifs_n)
    1.90 +        self.build_domain(ostype, kernel, ramdisk, cmdline)
    1.91          self.image = kernel
    1.92          self.ramdisk = ramdisk
    1.93          self.cmdline = cmdline
    1.94 @@ -1062,8 +1072,7 @@ def vm_image_linux(vm, image):
    1.95      if args:
    1.96          cmdline += " " + args
    1.97      ramdisk = sxp.child_value(image, "ramdisk", '')
    1.98 -    vifs = vm.config_devices("vif")
    1.99 -    vm.create_domain("linux", kernel, ramdisk, cmdline, len(vifs))
   1.100 +    vm.create_domain("linux", kernel, ramdisk, cmdline)
   1.101      return vm
   1.102  
   1.103  def vm_image_netbsd(vm, image):
   1.104 @@ -1087,8 +1096,7 @@ def vm_image_netbsd(vm, image):
   1.105      if args:
   1.106          cmdline += " " + args
   1.107      ramdisk = sxp.child_value(image, "ramdisk", '')
   1.108 -    vifs = vm.config_devices("vif")
   1.109 -    vm.create_domain("netbsd", kernel, ramdisk, cmdline, len(vifs))
   1.110 +    vm.create_domain("netbsd", kernel, ramdisk, cmdline)
   1.111      return vm
   1.112  
   1.113