ia64/xen-unstable

changeset 7056:8874b5004ef4

Move ImageHandler registration into image.py from XendDomainInfo.py. Move
ImageHandler.create and findImageHandlerClass to the module level, and inline
addImageHandlerClass. Move ImageHandler.kernel, ramdisk, cmdline, and flags,
which seem inadvertently to have been declared as class variables, and make
them instance variables instead.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Sat Sep 24 20:36:15 2005 +0100 (2005-09-24)
parents 9f50bd7a478f
children b5ab24152d56
files tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/image.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Fri Sep 23 17:17:22 2005 +0100
     1.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Sat Sep 24 20:36:15 2005 +0100
     1.3 @@ -34,6 +34,7 @@ from xen.util.blkif import blkdev_uname_
     1.4  
     1.5  from xen.xend.server.channel import EventChannel
     1.6  
     1.7 +from xen.xend import image
     1.8  from xen.xend import sxp
     1.9  from xen.xend.XendBootloader import bootloader
    1.10  from xen.xend.XendLogging import log
    1.11 @@ -734,9 +735,9 @@ class XendDomainInfo:
    1.12          if 'image' not in self.info:
    1.13              raise VmError('Missing image in configuration')
    1.14  
    1.15 -        self.image = ImageHandler.create(self,
    1.16 -                                         self.info['image'],
    1.17 -                                         self.info['device'])
    1.18 +        self.image = image.create(self,
    1.19 +                                  self.info['image'],
    1.20 +                                  self.info['device'])
    1.21  
    1.22          if self.domid <= 0:
    1.23              raise VmError('Creating domain failed: name=%s' %
    1.24 @@ -1086,19 +1087,6 @@ class XendDomainInfo:
    1.25  
    1.26  
    1.27  #============================================================================
    1.28 -# Register image handlers.
    1.29 -
    1.30 -from image import          \
    1.31 -     addImageHandlerClass, \
    1.32 -     ImageHandler,         \
    1.33 -     LinuxImageHandler,    \
    1.34 -     VmxImageHandler
    1.35 -
    1.36 -addImageHandlerClass(LinuxImageHandler)
    1.37 -addImageHandlerClass(VmxImageHandler)
    1.38 -
    1.39 -
    1.40 -#============================================================================
    1.41  # Register device controllers and their device config types.
    1.42  
    1.43  """A map from device-class names to the subclass of DevController that
     2.1 --- a/tools/python/xen/xend/image.py	Fri Sep 23 17:17:22 2005 +0100
     2.2 +++ b/tools/python/xen/xend/image.py	Sat Sep 24 20:36:15 2005 +0100
     2.3 @@ -33,6 +33,15 @@ xc = xen.lowlevel.xc.new()
     2.4  
     2.5  MAX_GUEST_CMDLINE = 1024
     2.6  
     2.7 +
     2.8 +def create(vm, imageConfig, deviceConfig):
     2.9 +    """Create an image handler for a vm.
    2.10 +
    2.11 +    @return ImageHandler instance
    2.12 +    """
    2.13 +    return findImageHandlerClass(imageConfig)(vm, imageConfig, deviceConfig)
    2.14 +
    2.15 +
    2.16  class ImageHandler:
    2.17      """Abstract base class for image handlers.
    2.18  
    2.19 @@ -48,64 +57,19 @@ class ImageHandler:
    2.20  
    2.21      The method destroy() is called when the domain is destroyed.
    2.22      The default is to do nothing.
    2.23 -    
    2.24 -    """
    2.25 -
    2.26 -    #======================================================================
    2.27 -    # Class vars and methods.
    2.28 -
    2.29 -    """Table of image handler classes for virtual machine images.
    2.30 -    Indexed by image type.
    2.31      """
    2.32 -    imageHandlerClasses = {}
    2.33 -
    2.34 -    def addImageHandlerClass(cls, h):
    2.35 -        """Add a handler class for an image type
    2.36 -        @param h:        handler: ImageHandler subclass
    2.37 -        """
    2.38 -        cls.imageHandlerClasses[h.ostype] = h
    2.39 -
    2.40 -    addImageHandlerClass = classmethod(addImageHandlerClass)
    2.41 -
    2.42 -    def findImageHandlerClass(cls, image):
    2.43 -        """Find the image handler class for an image config.
    2.44 -
    2.45 -        @param image config
    2.46 -        @return ImageHandler subclass or None
    2.47 -        """
    2.48 -        ty = sxp.name(image)
    2.49 -        if ty is None:
    2.50 -            raise VmError('missing image type')
    2.51 -        imageClass = cls.imageHandlerClasses.get(ty)
    2.52 -        if imageClass is None:
    2.53 -            raise VmError('unknown image type: ' + ty)
    2.54 -        return imageClass
    2.55 -
    2.56 -    findImageHandlerClass = classmethod(findImageHandlerClass)
    2.57 -
    2.58 -    def create(cls, vm, imageConfig, deviceConfig):
    2.59 -        """Create an image handler for a vm.
    2.60 -
    2.61 -        @return ImageHandler instance
    2.62 -        """
    2.63 -        imageClass = cls.findImageHandlerClass(imageConfig)
    2.64 -        return imageClass(vm, imageConfig, deviceConfig)
    2.65 -
    2.66 -    create = classmethod(create)
    2.67 -
    2.68 -    #======================================================================
    2.69 -    # Instance vars and methods.
    2.70  
    2.71      ostype = None
    2.72  
    2.73 -    kernel = None
    2.74 -    ramdisk = None
    2.75 -    cmdline = None
    2.76 -
    2.77 -    flags = 0
    2.78  
    2.79      def __init__(self, vm, imageConfig, deviceConfig):
    2.80          self.vm = vm
    2.81 +
    2.82 +        self.kernel = None
    2.83 +        self.ramdisk = None
    2.84 +        self.cmdline = None
    2.85 +        self.flags = 0
    2.86 +
    2.87          self.configure(imageConfig, deviceConfig)
    2.88  
    2.89      def configure(self, imageConfig, _):
    2.90 @@ -197,7 +161,6 @@ class ImageHandler:
    2.91          if d.has_key('console_mfn'):
    2.92              self.vm.setConsoleRef(d.get('console_mfn'))
    2.93  
    2.94 -addImageHandlerClass = ImageHandler.addImageHandlerClass
    2.95  
    2.96  class LinuxImageHandler(ImageHandler):
    2.97  
    2.98 @@ -425,3 +388,28 @@ class VmxImageHandler(ImageHandler):
    2.99              return 16 * 1024
   2.100          else:
   2.101              return (1 + ((mem_mb + 3) >> 2)) * 4
   2.102 +
   2.103 +
   2.104 +"""Table of image handler classes for virtual machine images.  Indexed by
   2.105 +image type.
   2.106 +"""
   2.107 +imageHandlerClasses = {}
   2.108 +
   2.109 +
   2.110 +for h in LinuxImageHandler, VmxImageHandler:
   2.111 +    imageHandlerClasses[h.ostype] = h
   2.112 +
   2.113 +
   2.114 +def findImageHandlerClass(image):
   2.115 +    """Find the image handler class for an image config.
   2.116 +
   2.117 +    @param image config
   2.118 +    @return ImageHandler subclass or None
   2.119 +    """
   2.120 +    ty = sxp.name(image)
   2.121 +    if ty is None:
   2.122 +        raise VmError('missing image type')
   2.123 +    imageClass = imageHandlerClasses.get(ty)
   2.124 +    if imageClass is None:
   2.125 +        raise VmError('unknown image type: ' + ty)
   2.126 +    return imageClass