ia64/xen-unstable

changeset 6951:f7a09745ca56

Remove the complexity of the config_handlers mechanism in favour of a simple
configure_maxmem method. The config_handlers mechanism was trying to be a
general configuration-registration framework, but that functionality was
unused and confusing.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Sun Sep 18 18:21:12 2005 +0100 (2005-09-18)
parents 3dec22f380be
children 578a73fdeb2f
files tools/python/xen/xend/XendDomainInfo.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Sun Sep 18 18:18:52 2005 +0100
     1.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Sun Sep 18 18:21:12 2005 +0100
     1.3 @@ -883,7 +883,7 @@ class XendDomainInfo:
     1.4          """Configure a vm.
     1.5  
     1.6          """
     1.7 -        self.configure_fields()
     1.8 +        self.configure_maxmem()
     1.9          self.create_devices()
    1.10          self.create_blkif()
    1.11  
    1.12 @@ -895,20 +895,14 @@ class XendDomainInfo:
    1.13          """
    1.14          return
    1.15  
    1.16 -    def configure_fields(self):
    1.17 -        """Process the vm configuration fields using the registered handlers.
    1.18 -        """
    1.19 -        index = {}
    1.20 -        for field in sxp.children(self.config):
    1.21 -            field_name = sxp.name(field)
    1.22 -            field_index = index.get(field_name, 0)
    1.23 -            field_handler = config_handlers.get(field_name)
    1.24 -            # Ignore unknown fields. Warn?
    1.25 -            if field_handler:
    1.26 -                v = field_handler(self, self.config, field, field_index)
    1.27 -            else:
    1.28 -                log.warning("Unknown config field %s", field_name)
    1.29 -            index[field_name] = field_index + 1
    1.30 +    def configure_maxmem(self):
    1.31 +        try:
    1.32 +            maxmem = int(sxp.child_value(self.config, 'maxmem', self.memory))
    1.33 +            xc.domain_setmaxmem(self.domid, maxmem_kb = maxmem * 1024)
    1.34 +        except:
    1.35 +            raise VmError("invalid maxmem: " +
    1.36 +                          sxp.child_value(self.config, 'maxmem'))
    1.37 +
    1.38  
    1.39      def vcpu_hotplug(self, vcpu, state):
    1.40          """Disable or enable VCPU in domain.
    1.41 @@ -980,26 +974,6 @@ class XendDomainInfo:
    1.42                  self.vcpu_hotplug(vcpu, 0)
    1.43  
    1.44  
    1.45 -def vm_field_ignore(_, _1, _2, _3):
    1.46 -    """Dummy config field handler used for fields with built-in handling.
    1.47 -    Matches the signature required by config_handlers.
    1.48 -    """
    1.49 -    pass
    1.50 -
    1.51 -
    1.52 -def vm_field_maxmem(vm, _1, val, _2):
    1.53 -    """Config field handler to configure vm memory limit.  Matches the
    1.54 -    signature required by config_handlers.
    1.55 -    """
    1.56 -    maxmem = sxp.child0(val)
    1.57 -    if maxmem is None:
    1.58 -        maxmem = vm.memory
    1.59 -    try:
    1.60 -        maxmem = int(maxmem)
    1.61 -    except:
    1.62 -        raise VmError("invalid maxmem: " + str(maxmem))
    1.63 -    xc.domain_setmaxmem(vm.domid, maxmem_kb = maxmem * 1024)
    1.64 -
    1.65  
    1.66  #============================================================================
    1.67  # Register image handlers.
    1.68 @@ -1014,31 +988,6 @@ addImageHandlerClass(LinuxImageHandler)
    1.69  addImageHandlerClass(VmxImageHandler)
    1.70  
    1.71  
    1.72 -"""Table of handlers for field configuration.
    1.73 -
    1.74 -field_name[String]: fn(vm, config, field, index) -> value(ignored)
    1.75 -"""
    1.76 -config_handlers = {
    1.77 -    
    1.78 -    # Ignore the fields we already handle.
    1.79 -    
    1.80 -    'name':       vm_field_ignore,
    1.81 -    'memory':     vm_field_ignore,
    1.82 -    'ssidref':    vm_field_ignore,
    1.83 -    'cpu':        vm_field_ignore,
    1.84 -    'cpu_weight': vm_field_ignore,
    1.85 -    'restart':    vm_field_ignore,
    1.86 -    'image':      vm_field_ignore,
    1.87 -    'device':     vm_field_ignore,
    1.88 -    'backend':    vm_field_ignore,
    1.89 -    'vcpus':      vm_field_ignore,
    1.90 -    'bootloader': vm_field_ignore,
    1.91 -    
    1.92 -    # Register other config handlers.
    1.93 -    'maxmem':     vm_field_maxmem
    1.94 -    }
    1.95 -
    1.96 -
    1.97  #============================================================================
    1.98  # Register device controllers and their device config types.
    1.99