ia64/xen-unstable

changeset 6943:191ffe9a9967

Use XendDomainInfo.getDomain, getName to decouple XendDomain from the internals
of XendDomainInfo, prior to changing those internals.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Sat Sep 17 21:00:33 2005 +0100 (2005-09-17)
parents fb1fa3a4106f
children 702e7f173465
files tools/python/xen/xend/XendDomain.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomain.py	Sat Sep 17 20:23:53 2005 +0100
     1.2 +++ b/tools/python/xen/xend/XendDomain.py	Sat Sep 17 21:00:33 2005 +0100
     1.3 @@ -55,7 +55,7 @@ def is_dead(dom):
     1.4  class XendDomainDict(dict):
     1.5      def get_by_name(self, name):
     1.6          try:
     1.7 -            return filter(lambda d: d.name == name, self.values())[0]
     1.8 +            return filter(lambda d: d.getName() == name, self.values())[0]
     1.9          except IndexError, err:
    1.10              return None
    1.11  
    1.12 @@ -94,7 +94,7 @@ class XendDomain:
    1.13          @return: domain objects
    1.14          """
    1.15          doms = self.list()
    1.16 -        doms.sort(lambda x, y: cmp(x.name, y.name))
    1.17 +        doms.sort(lambda x, y: cmp(x.getName(), y.getName()))
    1.18          return doms
    1.19  
    1.20      def list_names(self):
    1.21 @@ -103,7 +103,7 @@ class XendDomain:
    1.22          @return: domain names
    1.23          """
    1.24          doms = self.list_sorted()
    1.25 -        return map(lambda x: x.name, doms)
    1.26 +        return map(lambda x: x.getName(), doms)
    1.27  
    1.28      def onReleaseDomain(self):
    1.29          self.reap()
    1.30 @@ -183,12 +183,13 @@ class XendDomain:
    1.31          @param info:   domain info object
    1.32          @param notify: send a domain created event if true
    1.33          """
    1.34 -        if info.domid in self.domains:
    1.35 +        if info.getDomain() in self.domains:
    1.36              notify = False
    1.37 -        self.domains[info.domid] = info
    1.38 +        self.domains[info.getDomain()] = info
    1.39          info.exportToDB(save=True)
    1.40          if notify:
    1.41 -            eserver.inject('xend.domain.create', [info.name, info.domid])
    1.42 +            eserver.inject('xend.domain.create', [info.getName(),
    1.43 +                                                  info.getDomain()])
    1.44  
    1.45      def _delete_domain(self, id, notify=True):
    1.46          """Remove a domain from the tables.
    1.47 @@ -202,7 +203,8 @@ class XendDomain:
    1.48              info.cleanup()
    1.49              info.delete()
    1.50              if notify:
    1.51 -                eserver.inject('xend.domain.died', [info.name, info.domid])
    1.52 +                eserver.inject('xend.domain.died', [info.getName(),
    1.53 +                                                    info.getDomain()])
    1.54          # XXX this should not be needed
    1.55          for domdb in self.dbmap.values():
    1.56              if not domdb.has_key("xend"):
    1.57 @@ -227,13 +229,13 @@ class XendDomain:
    1.58              dominfo = self.domains.get(domid)
    1.59              if not dominfo or dominfo.is_terminated():
    1.60                  continue
    1.61 -            log.debug('domain died name=%s domid=%d', dominfo.name, domid)
    1.62 +            log.debug('domain died name=%s domid=%d', dominfo.getName(), domid)
    1.63              if d['crashed'] and xroot.get_enable_dump():
    1.64                  self.domain_dumpcore(domid)
    1.65              if d['shutdown']:
    1.66                  reason = shutdown_reason(d['shutdown_reason'])
    1.67 -                log.debug('shutdown name=%s id=%d reason=%s', dominfo.name,
    1.68 -                          domid, reason)
    1.69 +                log.debug('shutdown name=%s id=%d reason=%s',
    1.70 +                          dominfo.getName(), domid, reason)
    1.71                  if reason == 'suspend':
    1.72                      dominfo.state_set("suspended")
    1.73                      continue
    1.74 @@ -248,11 +250,11 @@ class XendDomain:
    1.75          # Remove entries for domains that no longer exist.
    1.76          # Update entries for existing domains.
    1.77          for d in self.domains.values():
    1.78 -            info = doms.get(d.domid)
    1.79 +            info = doms.get(d.getDomain())
    1.80              if info:
    1.81                  d.update(info)
    1.82              elif not d.restart_pending():
    1.83 -                self._delete_domain(d.domid)
    1.84 +                self._delete_domain(d.getDomain())
    1.85  
    1.86      def update_domain(self, id):
    1.87          """Update information for a single domain.
    1.88 @@ -281,20 +283,23 @@ class XendDomain:
    1.89  
    1.90          @param dominfo: domain object
    1.91          """
    1.92 -        log.info("Restarting domain: name=%s id=%s", dominfo.name, dominfo.domid)
    1.93 +        log.info("Restarting domain: name=%s id=%s", dominfo.getName(),
    1.94 +                 dominfo.getDomain())
    1.95          eserver.inject("xend.domain.restart",
    1.96 -                       [dominfo.name, dominfo.domid, "begin"])
    1.97 +                       [dominfo.getName(), dominfo.getDomain(), "begin"])
    1.98          try:
    1.99              dominfo.restart()
   1.100 -            log.info('Restarted domain name=%s id=%s', dominfo.name, dominfo.domid)
   1.101 +            log.info('Restarted domain name=%s id=%s', dominfo.getName(),
   1.102 +                     dominfo.getDomain())
   1.103              eserver.inject("xend.domain.restart",
   1.104 -                           [dominfo.name, dominfo.domid, "success"])
   1.105 -            self.domain_unpause(dominfo.domid)
   1.106 +                           [dominfo.getName(), dominfo.getDomain(),
   1.107 +                            "success"])
   1.108 +            self.domain_unpause(dominfo.getDomain())
   1.109          except Exception, ex:
   1.110              log.exception("Exception restarting domain: name=%s id=%s",
   1.111 -                          dominfo.name, dominfo.domid)
   1.112 +                          dominfo.getName(), dominfo.getDomain())
   1.113              eserver.inject("xend.domain.restart",
   1.114 -                           [dominfo.name, dominfo.domid, "fail"])
   1.115 +                           [dominfo.getName(), dominfo.getDomain(), "fail"])
   1.116          return dominfo
   1.117  
   1.118      def domain_configure(self, vmconfig):
   1.119 @@ -376,9 +381,10 @@ class XendDomain:
   1.120          @param id: domain id
   1.121          """
   1.122          dominfo = self.domain_lookup(id)
   1.123 -        eserver.inject('xend.domain.unpause', [dominfo.name, dominfo.domid])
   1.124 +        eserver.inject('xend.domain.unpause', [dominfo.getName(),
   1.125 +                                               dominfo.getDomain()])
   1.126          try:
   1.127 -            return xc.domain_unpause(dom=dominfo.domid)
   1.128 +            return xc.domain_unpause(dom=dominfo.getDomain())
   1.129          except Exception, ex:
   1.130              raise XendError(str(ex))
   1.131      
   1.132 @@ -388,9 +394,10 @@ class XendDomain:
   1.133          @param id: domain id
   1.134          """
   1.135          dominfo = self.domain_lookup(id)
   1.136 -        eserver.inject('xend.domain.pause', [dominfo.name, dominfo.domid])
   1.137 +        eserver.inject('xend.domain.pause', [dominfo.getName(),
   1.138 +                                             dominfo.getDomain()])
   1.139          try:
   1.140 -            return xc.domain_pause(dom=dominfo.domid)
   1.141 +            return xc.domain_pause(dom=dominfo.getDomain())
   1.142          except Exception, ex:
   1.143              raise XendError(str(ex))
   1.144      
   1.145 @@ -406,8 +413,9 @@ class XendDomain:
   1.146          @param reason: shutdown type: poweroff, reboot, suspend, halt
   1.147          """
   1.148          dominfo = self.domain_lookup(id)
   1.149 -        self.domain_restart_schedule(dominfo.domid, reason, force=True)
   1.150 -        eserver.inject('xend.domain.shutdown', [dominfo.name, dominfo.domid, reason])
   1.151 +        self.domain_restart_schedule(dominfo.getDomain(), reason, force=True)
   1.152 +        eserver.inject('xend.domain.shutdown', [dominfo.getName(),
   1.153 +                                                dominfo.getDomain(), reason])
   1.154          if reason == 'halt':
   1.155              reason = 'poweroff'
   1.156          val = dominfo.shutdown(reason)
   1.157 @@ -431,13 +439,13 @@ class XendDomain:
   1.158              if not dominfo.shutdown_pending:
   1.159                  # domain doesn't need shutdown
   1.160                  continue
   1.161 -            id = dominfo.domid
   1.162 +            id = dominfo.getDomain()
   1.163              left = dominfo.shutdown_time_left(SHUTDOWN_TIMEOUT)
   1.164              if left <= 0:
   1.165                  # Shutdown expired - destroy domain.
   1.166                  try:
   1.167                      log.info("Domain shutdown timeout expired: name=%s id=%s",
   1.168 -                             dominfo.name, id)
   1.169 +                             dominfo.getName(), id)
   1.170                      self.domain_destroy(id, reason=
   1.171                                          dominfo.shutdown_pending['reason'])
   1.172                  except Exception:
   1.173 @@ -462,15 +470,16 @@ class XendDomain:
   1.174          restart = (force and reason == 'reboot') or dominfo.restart_needed(reason)
   1.175          if restart:
   1.176              log.info('Scheduling restart for domain: name=%s id=%s',
   1.177 -                     dominfo.name, dominfo.domid)
   1.178 +                     dominfo.getName(), dominfo.getDomain())
   1.179              eserver.inject("xend.domain.restart",
   1.180 -                           [dominfo.name, dominfo.domid, "schedule"])
   1.181 +                           [dominfo.getName(), dominfo.getDomain(),
   1.182 +                            "schedule"])
   1.183              dominfo.restarting()
   1.184          else:
   1.185              log.info('Cancelling restart for domain: name=%s id=%s',
   1.186 -                     dominfo.name, dominfo.domid)
   1.187 +                     dominfo.getName(), dominfo.getDomain())
   1.188              eserver.inject("xend.domain.restart",
   1.189 -                           [dominfo.name, dominfo.domid, "cancel"])
   1.190 +                           [dominfo.getName(), dominfo.getDomain(), "cancel"])
   1.191              dominfo.restart_cancel()
   1.192  
   1.193      def domain_restarts(self):
   1.194 @@ -480,12 +489,12 @@ class XendDomain:
   1.195          for dominfo in self.domains.values():
   1.196              if not dominfo.restart_pending():
   1.197                  continue
   1.198 -            info = doms.get(dominfo.domid)
   1.199 +            info = doms.get(dominfo.getDomain())
   1.200              if info:
   1.201                  # Don't execute restart for domains still running.
   1.202                  continue
   1.203              # Remove it from the restarts.
   1.204 -            log.info('restarting: %s' % dominfo.name)
   1.205 +            log.info('restarting: %s' % dominfo.getName())
   1.206              self.domain_restart(dominfo)
   1.207  
   1.208      def domain_destroy(self, domid, reason='halt'):
   1.209 @@ -520,13 +529,14 @@ class XendDomain:
   1.210  
   1.211          # temporarily rename domain for localhost migration
   1.212          if dst == "localhost":
   1.213 -            dominfo.name = "tmp-" + dominfo.name
   1.214 +            dominfo.setName("tmp-" + dominfo.getName())
   1.215  
   1.216          try:
   1.217              XendCheckpoint.save(self, sock.fileno(), dominfo, live)
   1.218          except:
   1.219              if dst == "localhost":
   1.220 -                dominfo.name = string.replace(dominfo.name, "tmp-", "", 1)
   1.221 +                dominfo.setName(
   1.222 +                    string.replace(dominfo.getName(), "tmp-", "", 1))
   1.223              raise
   1.224          
   1.225          return None
   1.226 @@ -560,7 +570,7 @@ class XendDomain:
   1.227          """
   1.228          dominfo = self.domain_lookup(id)
   1.229          try:
   1.230 -            return xc.domain_pincpu(dominfo.domid, vcpu, cpumap)
   1.231 +            return xc.domain_pincpu(dominfo.getDomain(), vcpu, cpumap)
   1.232          except Exception, ex:
   1.233              raise XendError(str(ex))
   1.234  
   1.235 @@ -569,8 +579,10 @@ class XendDomain:
   1.236          """
   1.237          dominfo = self.domain_lookup(id)
   1.238          try:
   1.239 -            return xc.bvtsched_domain_set(dom=dominfo.domid, mcuadv=mcuadv,
   1.240 -                                          warpback=warpback, warpvalue=warpvalue, 
   1.241 +            return xc.bvtsched_domain_set(dom=dominfo.getDomain(),
   1.242 +                                          mcuadv=mcuadv,
   1.243 +                                          warpback=warpback,
   1.244 +                                          warpvalue=warpvalue, 
   1.245                                            warpl=warpl, warpu=warpu)
   1.246          except Exception, ex:
   1.247              raise XendError(str(ex))
   1.248 @@ -580,7 +592,7 @@ class XendDomain:
   1.249          """
   1.250          dominfo = self.domain_lookup(id)
   1.251          try:
   1.252 -            return xc.bvtsched_domain_get(dominfo.domid)
   1.253 +            return xc.bvtsched_domain_get(dominfo.getDomain())
   1.254          except Exception, ex:
   1.255              raise XendError(str(ex))
   1.256      
   1.257 @@ -590,7 +602,8 @@ class XendDomain:
   1.258          """
   1.259          dominfo = self.domain_lookup(id)
   1.260          try:
   1.261 -            return xc.sedf_domain_set(dominfo.domid, period, slice, latency, extratime, weight)
   1.262 +            return xc.sedf_domain_set(dominfo.getDomain(), period, slice,
   1.263 +                                      latency, extratime, weight)
   1.264          except Exception, ex:
   1.265              raise XendError(str(ex))
   1.266  
   1.267 @@ -599,7 +612,7 @@ class XendDomain:
   1.268          """
   1.269          dominfo = self.domain_lookup(id)
   1.270          try:
   1.271 -            return xc.sedf_domain_get(dominfo.domid)
   1.272 +            return xc.sedf_domain_get(dominfo.getDomain())
   1.273          except Exception, ex:
   1.274              raise XendError(str(ex))
   1.275  
   1.276 @@ -689,7 +702,7 @@ class XendDomain:
   1.277          """
   1.278          dominfo = self.domain_lookup(id)
   1.279          try:
   1.280 -            return xc.shadow_control(dominfo.domid, op)
   1.281 +            return xc.shadow_control(dominfo.getDomain(), op)
   1.282          except Exception, ex:
   1.283              raise XendError(str(ex))
   1.284  
   1.285 @@ -703,7 +716,8 @@ class XendDomain:
   1.286          dominfo = self.domain_lookup(id)
   1.287          maxmem = int(mem) * 1024
   1.288          try:
   1.289 -            return xc.domain_setmaxmem(dominfo.domid, maxmem_kb = maxmem)
   1.290 +            return xc.domain_setmaxmem(dominfo.getDomain(),
   1.291 +                                       maxmem_kb = maxmem)
   1.292          except Exception, ex:
   1.293              raise XendError(str(ex))
   1.294  
   1.295 @@ -735,12 +749,13 @@ class XendDomain:
   1.296          @param id: domain
   1.297          """
   1.298          dominfo = self.domain_lookup(id)
   1.299 -        corefile = "/var/xen/dump/%s.%s.core"% (dominfo.name, dominfo.domid)
   1.300 +        corefile = "/var/xen/dump/%s.%s.core" % (dominfo.getName(),
   1.301 +                                                 dominfo.getDomain())
   1.302          try:
   1.303 -            xc.domain_dumpcore(dom=dominfo.domid, corefile=corefile)
   1.304 +            xc.domain_dumpcore(dom=dominfo.getDomain(), corefile=corefile)
   1.305          except Exception, ex:
   1.306              log.warning("Dumpcore failed, id=%s name=%s: %s",
   1.307 -                        dominfo.domid, dominfo.name, ex)
   1.308 +                        dominfo.getDomain(), dominfo.getName(), ex)
   1.309          
   1.310  def instance():
   1.311      """Singleton constructor. Use this instead of the class constructor.