ia64/xen-unstable

changeset 14523:1fc6efdab399

Fix the handling of the transient flag.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Thu Mar 22 18:40:20 2007 +0000 (2007-03-22)
parents abd9ae4f1f17
children 2d918219f234
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 Mar 22 18:37:37 2007 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomain.py	Thu Mar 22 18:40:20 2007 +0000
     1.3 @@ -34,7 +34,7 @@ import xen.lowlevel.xc
     1.4  
     1.5  from xen.xend import XendOptions, XendCheckpoint, XendDomainInfo
     1.6  from xen.xend.PrettyPrint import prettyprint
     1.7 -from xen.xend.XendConfig import XendConfig
     1.8 +from xen.xend import XendConfig
     1.9  from xen.xend.XendError import XendError, XendInvalidDomain, VmError
    1.10  from xen.xend.XendError import VMBadState
    1.11  from xen.xend.XendLogging import log
    1.12 @@ -191,6 +191,10 @@ class XendDomain:
    1.13                          self._managed_domain_register(new_dom)
    1.14                      else:
    1.15                          self._managed_domain_register(running_dom)
    1.16 +                        for key in XendConfig.XENAPI_CFG_TYPES.keys():
    1.17 +                            if key not in XendConfig.LEGACY_XENSTORE_VM_PARAMS and \
    1.18 +                                   key in dom:
    1.19 +                                running_dom.info[key] = dom[key]
    1.20                  except Exception:
    1.21                      log.exception("Failed to create reference to managed "
    1.22                                    "domain: %s" % dom_name)
    1.23 @@ -316,7 +320,7 @@ class XendDomain:
    1.24          for dom_uuid in dom_uuids:
    1.25              try:
    1.26                  cfg_file = self._managed_config_path(dom_uuid)
    1.27 -                cfg = XendConfig(filename = cfg_file)
    1.28 +                cfg = XendConfig.XendConfig(filename = cfg_file)
    1.29                  if cfg.get('uuid') != dom_uuid:
    1.30                      # something is wrong with the SXP
    1.31                      log.error("UUID mismatch in stored configuration: %s" %
    1.32 @@ -414,7 +418,7 @@ class XendDomain:
    1.33          running_domids = [d['domid'] for d in running if d['dying'] != 1]
    1.34          for domid, dom in self.domains.items():
    1.35              if domid not in running_domids and domid != DOM0_ID:
    1.36 -                self.remove_domain(dom, domid)
    1.37 +                self._remove_domain(dom, domid)
    1.38  
    1.39  
    1.40      def add_domain(self, info):
    1.41 @@ -433,6 +437,16 @@ class XendDomain:
    1.42              self._managed_domain_register(info)
    1.43  
    1.44      def remove_domain(self, info, domid = None):
    1.45 +        """Remove the domain from the list of running domains, taking the
    1.46 +        domains_lock first.
    1.47 +        """
    1.48 +        self.domains_lock.acquire()
    1.49 +        try:
    1.50 +            self._remove_domain(info, domid)
    1.51 +        finally:
    1.52 +            self.domains_lock.release()
    1.53 +
    1.54 +    def _remove_domain(self, info, domid = None):
    1.55          """Remove the domain from the list of running domains
    1.56          
    1.57          @requires: Expects to be protected by the domains_lock.
    1.58 @@ -683,7 +697,7 @@ class XendDomain:
    1.59          self.domains_lock.acquire()
    1.60          try:
    1.61              try:
    1.62 -                xeninfo = XendConfig(xapi = xenapi_vm)
    1.63 +                xeninfo = XendConfig.XendConfig(xapi = xenapi_vm)
    1.64                  dominfo = XendDomainInfo.createDormant(xeninfo)
    1.65                  log.debug("Creating new managed domain: %s: %s" %
    1.66                            (dominfo.getName(), dominfo.get_uuid()))
    1.67 @@ -906,7 +920,7 @@ class XendDomain:
    1.68          self.domains_lock.acquire()
    1.69          try:
    1.70              try:
    1.71 -                domconfig = XendConfig(sxp_obj = config)
    1.72 +                domconfig = XendConfig.XendConfig(sxp_obj = config)
    1.73                  dominfo = XendDomainInfo.createDormant(domconfig)
    1.74                  log.debug("Creating new managed domain: %s" %
    1.75                            dominfo.getName())
    1.76 @@ -971,18 +985,34 @@ class XendDomain:
    1.77                      raise VMBadState("Domain is still running",
    1.78                                       POWER_STATE_NAMES[DOM_STATE_HALTED],
    1.79                                       POWER_STATE_NAMES[dominfo.state])
    1.80 -
    1.81 -                log.info("Domain %s (%s) deleted." %
    1.82 -                         (dominfo.getName(), dominfo.info.get('uuid')))
    1.83 -
    1.84 -                self._managed_domain_unregister(dominfo)
    1.85 -                self.remove_domain(dominfo)
    1.86 -                XendDevices.destroy_device_state(dominfo)
    1.87 +                
    1.88 +                self._domain_delete_by_info(dominfo)
    1.89              except Exception, ex:
    1.90                  raise XendError(str(ex))
    1.91          finally:
    1.92              self.domains_lock.release()
    1.93 -        
    1.94 +
    1.95 +
    1.96 +    def domain_delete_by_dominfo(self, dominfo):
    1.97 +        """Only for use by XendDomainInfo.
    1.98 +        """
    1.99 +        self.domains_lock.acquire()
   1.100 +        try:
   1.101 +            self._domain_delete_by_info(dominfo)
   1.102 +        finally:
   1.103 +            self.domains_lock.release()
   1.104 +
   1.105 +
   1.106 +    def _domain_delete_by_info(self, dominfo):
   1.107 +        """Expects to be protected by domains_lock.
   1.108 +        """
   1.109 +        log.info("Domain %s (%s) deleted." %
   1.110 +                 (dominfo.getName(), dominfo.info.get('uuid')))
   1.111 +                
   1.112 +        self._managed_domain_unregister(dominfo)
   1.113 +        self._remove_domain(dominfo)
   1.114 +        XendDevices.destroy_device_state(dominfo)
   1.115 +
   1.116  
   1.117      def domain_configure(self, config):
   1.118          """Configure an existing domain.
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Thu Mar 22 18:37:37 2007 +0000
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Mar 22 18:40:20 2007 +0000
     2.3 @@ -660,7 +660,6 @@ class XendDomainInfo:
     2.4          vm_config = dict(zip(augment_entries, vm_config))
     2.5          
     2.6          for arg in augment_entries:
     2.7 -            xapicfg = arg
     2.8              val = vm_config[arg]
     2.9              if val != None:
    2.10                  if arg in XendConfig.LEGACY_CFG_TO_XENAPI_CFG:
    2.11 @@ -1651,6 +1650,12 @@ class XendDomainInfo:
    2.12  
    2.13          self._cleanup_phantom_devs(paths)
    2.14  
    2.15 +        if "transient" in self.info["other_config"] \
    2.16 +           and bool(self.info["other_config"]["transient"]):
    2.17 +            from xen.xend import XendDomain
    2.18 +            XendDomain.instance().domain_delete_by_dominfo(self)
    2.19 +
    2.20 +
    2.21      def destroyDomain(self):
    2.22          log.debug("XendDomainInfo.destroyDomain(%s)", str(self.domid))
    2.23  
    2.24 @@ -1662,26 +1667,17 @@ class XendDomainInfo:
    2.25                  self.domid = None
    2.26                  for state in DOM_STATES_OLD:
    2.27                      self.info[state] = 0
    2.28 +                self._stateSet(DOM_STATE_HALTED)
    2.29          except:
    2.30              log.exception("XendDomainInfo.destroy: xc.domain_destroy failed.")
    2.31  
    2.32          from xen.xend import XendDomain
    2.33 -
    2.34 -        if "transient" in self.info["other_config"]\
    2.35 -           and bool(self.info["other_config"]["transient"]):
    2.36 -            xendDomainInstance = XendDomain.instance()
    2.37 -            
    2.38 -            xendDomainInstance.domains_lock.acquire()
    2.39 -            xendDomainInstance._refresh(refresh_shutdown = False)
    2.40 -            xendDomainInstance.domains_lock.release()
    2.41 -            
    2.42 -            xendDomainInstance.domain_delete(self.info["name_label"])
    2.43 -        else:
    2.44 -            XendDomain.instance().remove_domain(self)
    2.45 +        XendDomain.instance().remove_domain(self)
    2.46  
    2.47          self.cleanupDomain()
    2.48          self._cleanup_phantom_devs(paths)
    2.49  
    2.50 +
    2.51      def resumeDomain(self):
    2.52          log.debug("XendDomainInfo.resumeDomain(%s)", str(self.domid))
    2.53