ia64/xen-unstable

changeset 13164:63bd462b1f45

Add a function for creating a domain from an existing XendConfig, and use that
on reboot, rather than writing out sxp and reparsing.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Thu Dec 21 17:39:32 2006 +0000 (2006-12-21)
parents 2ae2204bbef3
children f1ddc050d848
files tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomain.py	Thu Dec 21 17:38:02 2006 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomain.py	Thu Dec 21 17:39:32 2006 +0000
     1.3 @@ -869,6 +869,26 @@ class XendDomain:
     1.4              self.domains_lock.release()
     1.5  
     1.6  
     1.7 +    def domain_create_from_dict(self, config_dict):
     1.8 +        """Create a domain from a configuration dictionary.
     1.9 +
    1.10 +        @param config_dict: configuration
    1.11 +        @rtype: XendDomainInfo
    1.12 +        """
    1.13 +        self.domains_lock.acquire()
    1.14 +        try:
    1.15 +            self._refresh()
    1.16 +
    1.17 +            dominfo = XendDomainInfo.create_from_dict(config_dict)
    1.18 +            self._add_domain(dominfo)
    1.19 +            self.domain_sched_credit_set(dominfo.getDomid(),
    1.20 +                                         dominfo.getWeight(),
    1.21 +                                         dominfo.getCap())
    1.22 +            return dominfo
    1.23 +        finally:
    1.24 +            self.domains_lock.release()
    1.25 +
    1.26 +
    1.27      def domain_new(self, config):
    1.28          """Create a domain from a configuration but do not start it.
    1.29          
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Thu Dec 21 17:38:02 2006 +0000
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Dec 21 17:39:32 2006 +0000
     2.3 @@ -81,13 +81,12 @@ log = logging.getLogger("xend.XendDomain
     2.4  
     2.5  def create(config):
     2.6      """Creates and start a VM using the supplied configuration. 
     2.7 -    (called from XMLRPCServer directly)
     2.8  
     2.9      @param config: A configuration object involving lists of tuples.
    2.10      @type  config: list of lists, eg ['vm', ['image', 'xen.gz']]
    2.11  
    2.12      @rtype:  XendDomainInfo
    2.13 -    @return: A up and running XendDomainInfo instance
    2.14 +    @return: An up and running XendDomainInfo instance
    2.15      @raise VmError: Invalid configuration or failure to start.
    2.16      """
    2.17  
    2.18 @@ -102,6 +101,28 @@ def create(config):
    2.19  
    2.20      return vm
    2.21  
    2.22 +def create_from_dict(config_dict):
    2.23 +    """Creates and start a VM using the supplied configuration. 
    2.24 +
    2.25 +    @param config_dict: An configuration dictionary.
    2.26 +
    2.27 +    @rtype:  XendDomainInfo
    2.28 +    @return: An up and running XendDomainInfo instance
    2.29 +    @raise VmError: Invalid configuration or failure to start.
    2.30 +    """
    2.31 +
    2.32 +    log.debug("XendDomainInfo.create_from_dict(%s)",
    2.33 +              scrub_password(config_dict))
    2.34 +    vm = XendDomainInfo(XendConfig.XendConfig(xapi = config_dict))
    2.35 +    try:
    2.36 +        vm.start()
    2.37 +    except:
    2.38 +        log.exception('Domain construction failed')
    2.39 +        vm.destroy()
    2.40 +        raise
    2.41 +
    2.42 +    return vm
    2.43 +
    2.44  def recreate(info, priv):
    2.45      """Create the VM object for an existing domain.  The domain must not
    2.46      be dying, as the paths in the store should already have been removed,
    2.47 @@ -1051,12 +1072,6 @@ class XendDomainInfo:
    2.48          """
    2.49          from xen.xend import XendDomain
    2.50          
    2.51 -        config = self.sxpr()
    2.52 -
    2.53 -        if self._infoIsSet('cpus') and len(self.info['cpus']) != 0:
    2.54 -            config.append(['cpus', reduce(lambda x, y: str(x) + "," + str(y),
    2.55 -                                          self.info['cpus'])])
    2.56 -
    2.57          if self._readVm(RESTART_IN_PROGRESS):
    2.58              log.error('Xend failed during restart of domain %s.  '
    2.59                        'Refusing to restart to avoid loops.',
    2.60 @@ -1097,7 +1112,8 @@ class XendDomainInfo:
    2.61  
    2.62              new_dom = None
    2.63              try:
    2.64 -                new_dom = XendDomain.instance().domain_create(config)
    2.65 +                new_dom = XendDomain.instance().domain_create_from_dict(
    2.66 +                    self.info)
    2.67                  new_dom.unpause()
    2.68                  rst_cnt = self._readVm('xend/restart_count')
    2.69                  rst_cnt = int(rst_cnt) + 1