ia64/xen-unstable

changeset 1975:186316f8fc21

bitkeeper revision 1.1108.24.2 (4108d1f8mh1HwCuBJAKjn8UuBU4wTA)

Change to supporting reference to domain by name or id and
make xm tools use names.
author mjw@wray-m-3.hpl.hp.com
date Thu Jul 29 10:31:20 2004 +0000 (2004-07-29)
parents 7d853b31485c
children 696863c77c79
files tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/server/SrvDomain.py tools/python/xen/xend/server/SrvDomainDir.py tools/python/xen/xend/server/blkif.py tools/python/xen/xend/server/controller.py tools/python/xen/xend/server/netif.py tools/python/xen/xend/sxp.py tools/python/xen/xm/create.py tools/python/xen/xm/destroy.py tools/python/xen/xm/main.py tools/python/xen/xm/shutdown.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomain.py	Tue Jul 27 12:27:28 2004 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomain.py	Thu Jul 29 10:31:20 2004 +0000
     1.3 @@ -39,15 +39,23 @@ class XendDomain:
     1.4      dbpath = "domain"
     1.5  
     1.6      """Table of domain info indexed by domain id."""
     1.7 -    domain = {}
     1.8 +    domain_by_id = {}
     1.9 +    domain_by_name = {}
    1.10      
    1.11      """Table of domains to restart, indexed by domain id."""
    1.12 -    restarts = {}
    1.13 +    restarts_by_id = {}
    1.14 +    restarts_by_name = {}
    1.15  
    1.16      """Table of delayed calls."""
    1.17      schedule = {}
    1.18      
    1.19      def __init__(self):
    1.20 +        # Hack alert. Python does not support mutual imports, but XendDomainInfo
    1.21 +        # needs access to the XendDomain instance to look up domains. Attempting
    1.22 +        # to import XendDomain from XendDomainInfo causes unbounded recursion.
    1.23 +        # So we stuff the XendDomain instance (self) into XendDomainInfo's
    1.24 +        # namespace as 'xd'.
    1.25 +        XendDomainInfo.xd = self
    1.26          # Table of domain info indexed by domain id.
    1.27          self.db = XendDB.XendDB(self.dbpath)
    1.28          self.domain_db = self.db.fetchall("")
    1.29 @@ -173,7 +181,8 @@ class XendDomain:
    1.30          @return: deferred
    1.31          """
    1.32          def cbok(dominfo):
    1.33 -            self.domain[dominfo.id] = dominfo
    1.34 +            self.domain_by_id[dominfo.id] = dominfo
    1.35 +            self.domain_by_name[dominfo.name] = dominfo
    1.36              if dominfo.restart_pending():
    1.37                  self.domain_restart_add(dominfo)
    1.38          
    1.39 @@ -181,17 +190,17 @@ class XendDomain:
    1.40          deferred.addCallback(cbok)
    1.41          return deferred
    1.42  
    1.43 -    def _add_domain(self, id, info, notify=1):
    1.44 +    def _add_domain(self, info, notify=1):
    1.45          """Add a domain entry to the tables.
    1.46  
    1.47 -        @param id:     domain id
    1.48          @param info:   domain info object
    1.49          @param notify: send a domain created event if true
    1.50          """
    1.51 -        self.domain[id] = info
    1.52 -        self.domain_db[id] = info.sxpr()
    1.53 -        self.sync_domain(id)
    1.54 -        if notify: eserver.inject('xend.domain.created', id)
    1.55 +        self.domain_by_id[info.id] = info
    1.56 +        self.domain_db[info.id] = info.sxpr()
    1.57 +        self.domain_by_name[info.name] = info
    1.58 +        self.sync_domain(info.id)
    1.59 +        if notify: eserver.inject('xend.domain.created', info.name)
    1.60  
    1.61      def _delete_domain(self, id, notify=1):
    1.62          """Remove a domain from the tables.
    1.63 @@ -199,9 +208,12 @@ class XendDomain:
    1.64          @param id:     domain id
    1.65          @param notify: send a domain died event if true
    1.66          """
    1.67 -        if id in self.domain:
    1.68 -            if notify: eserver.inject('xend.domain.died', id)
    1.69 -            del self.domain[id]
    1.70 +        if id in self.domain_by_id:
    1.71 +            info = self.domain_by_id[id]
    1.72 +            if notify: eserver.inject('xend.domain.died', info.name)
    1.73 +            if info.name in self.domain_by_name:
    1.74 +                del self.domain_by_name[info.name]
    1.75 +            del self.domain_by_id[id]
    1.76          if id in self.domain_db:
    1.77              del self.domain_db[id]
    1.78              self.db.delete(id)
    1.79 @@ -229,7 +241,7 @@ class XendDomain:
    1.80                  if reason in ['poweroff', 'reboot']:
    1.81                      self.domain_restart_schedule(id, reason)
    1.82              self.final_domain_destroy(id)
    1.83 -        if len(self.restarts):
    1.84 +        if self.domain_restarts_exist():
    1.85              self.domain_restarts_schedule()
    1.86  
    1.87      def refresh(self):
    1.88 @@ -243,14 +255,14 @@ class XendDomain:
    1.89          for d in domlist:
    1.90              id = str(d['dom'])
    1.91              doms[id] = d
    1.92 -            if id not in self.domain:
    1.93 +            if id not in self.domain_by_id:
    1.94                  savedinfo = None
    1.95                  deferred = XendDomainInfo.vm_recreate(savedinfo, d)
    1.96                  def cbok(dominfo):
    1.97 -                    self._add_domain(dominfo.id, dominfo)
    1.98 +                    self._add_domain(dominfo)
    1.99                  deferred.addCallback(cbok)
   1.100          # Remove entries for domains that no longer exist.
   1.101 -        for d in self.domain.values():
   1.102 +        for d in self.domain_by_id.values():
   1.103              info = doms.get(d.id)
   1.104              if info:
   1.105                  d.update(info)
   1.106 @@ -263,7 +275,7 @@ class XendDomain:
   1.107  
   1.108          @param id: domain id
   1.109          """
   1.110 -        dominfo = self.domain.get(id)
   1.111 +        dominfo = self.domain_by_id.get(id)
   1.112          if dominfo:
   1.113              self.domain_db[id] = dominfo.sxpr()
   1.114              self.sync_domain(id)
   1.115 @@ -283,17 +295,25 @@ class XendDomain:
   1.116                  raise
   1.117                  pass
   1.118          else:
   1.119 -            d = self.domain.get(id)
   1.120 +            d = self.domain_by_id.get(id)
   1.121              if d:
   1.122                  d.update(dominfo[0])
   1.123  
   1.124      def domain_ls(self):
   1.125 +        """Get list of domain names.
   1.126 +
   1.127 +        @return: domain names
   1.128 +        """
   1.129 +        self.refresh()
   1.130 +        return self.domain_by_name.keys()
   1.131 +
   1.132 +    def domain_ls_ids(self):
   1.133          """Get list of domain ids.
   1.134  
   1.135 -        @return: domain ids
   1.136 +        @return: domain names
   1.137          """
   1.138          self.refresh()
   1.139 -        return self.domain.keys()
   1.140 +        return self.domain_by_id.keys()
   1.141  
   1.142      def domains(self):
   1.143          """Get list of domain objects.
   1.144 @@ -301,7 +321,7 @@ class XendDomain:
   1.145          @return: domain objects
   1.146          """
   1.147          self.refresh()
   1.148 -        return self.domain.values()
   1.149 +        return self.domain_by_id.values()
   1.150      
   1.151      def domain_create(self, config):
   1.152          """Create a domain from a configuration.
   1.153 @@ -310,7 +330,7 @@ class XendDomain:
   1.154          @return: deferred
   1.155          """
   1.156          def cbok(dominfo):
   1.157 -            self._add_domain(dominfo.id, dominfo)
   1.158 +            self._add_domain(dominfo)
   1.159              return dominfo
   1.160          deferred = XendDomainInfo.vm_create(config)
   1.161          deferred.addCallback(cbok)
   1.162 @@ -323,7 +343,7 @@ class XendDomain:
   1.163          @return: deferred
   1.164          """
   1.165          def cbok(dominfo):
   1.166 -            self._add_domain(dominfo.id, dominfo)
   1.167 +            self._add_domain(dominfo)
   1.168              return dominfo
   1.169          log.info("Restarting domain: id=%s name=%s", dominfo.id, dominfo.name)
   1.170          deferred = dominfo.restart()
   1.171 @@ -338,15 +358,14 @@ class XendDomain:
   1.172          @param config: configuration
   1.173          @return: deferred
   1.174          """
   1.175 -        log.debug('domain_configure> id=%s config=%s', id, str(config))
   1.176 -        dom = int(id)
   1.177 -        dominfo = self.domain_get(dom)
   1.178 +        dominfo = self.domain_get(id)
   1.179          if not dominfo:
   1.180              raise XendError("Invalid domain: " + str(id))
   1.181 +        log.debug('domain_configure> id=%s config=%s', id, str(config))
   1.182          if dominfo.config:
   1.183 -            raise XendError("Domain already configured: " + str(id))
   1.184 +            raise XendError("Domain already configured: " + dominfo.name)
   1.185          def cbok(dominfo):
   1.186 -            self._add_domain(dominfo.id, dominfo)
   1.187 +            self._add_domain(dominfo)
   1.188              return dominfo
   1.189          deferred = dominfo.construct(config)
   1.190          deferred.addCallback(cbok)
   1.191 @@ -361,7 +380,7 @@ class XendDomain:
   1.192          """
   1.193          
   1.194          def cbok(dominfo):
   1.195 -            self._add_domain(dominfo.id, dominfo)
   1.196 +            self._add_domain(dominfo)
   1.197              return dominfo
   1.198          deferred = XendDomainInfo.vm_restore(src, progress=progress)
   1.199          deferred.addCallback(cbok)
   1.200 @@ -375,25 +394,39 @@ class XendDomain:
   1.201          """
   1.202          id = str(id)
   1.203          self.refresh_domain(id)
   1.204 -        return self.domain.get(id)
   1.205 -    
   1.206 +        return self.domain_by_id.get(id)
   1.207 +
   1.208 +    def domain_lookup(self, name):
   1.209 +        name = str(name)
   1.210 +        dominfo = self.domain_by_name.get(name) or self.domain_by_id.get(name)
   1.211 +        if dominfo:
   1.212 +            return dominfo
   1.213 +        raise XendError('invalid domain:' + name)
   1.214 +
   1.215 +    def domain_exists(self, name):
   1.216 +        name = str(name)
   1.217 +        if self.domain_by_name.get(name) or self.domain_by_id.get(name):
   1.218 +            return 1
   1.219 +        else:
   1.220 +            return 0
   1.221 +
   1.222      def domain_unpause(self, id):
   1.223          """Unpause domain execution.
   1.224  
   1.225          @param id: domain id
   1.226          """
   1.227 -        dom = int(id)
   1.228 -        eserver.inject('xend.domain.unpause', id)
   1.229 -        return xc.domain_unpause(dom=dom)
   1.230 +        dominfo = self.domain_lookup(id)
   1.231 +        eserver.inject('xend.domain.unpause', dominfo.name)
   1.232 +        return xc.domain_unpause(dom=dominfo.dom)
   1.233      
   1.234      def domain_pause(self, id):
   1.235          """Pause domain execution.
   1.236  
   1.237          @param id: domain id
   1.238          """
   1.239 -        dom = int(id)
   1.240 -        eserver.inject('xend.domain.pause', id)
   1.241 -        return xc.domain_pause(dom=dom)
   1.242 +        dominfo = self.domain_lookup(id)
   1.243 +        eserver.inject('xend.domain.pause', dominfo.name)
   1.244 +        return xc.domain_pause(dom=dominfo.dom)
   1.245      
   1.246      def domain_shutdown(self, id, reason='poweroff'):
   1.247          """Shutdown domain (nicely).
   1.248 @@ -406,18 +439,15 @@ class XendDomain:
   1.249          @param id:     domain id
   1.250          @param reason: shutdown type: poweroff, reboot, suspend, halt
   1.251          """
   1.252 -        dom = int(id)
   1.253 -        id = str(id)
   1.254 -        if dom <= 0:
   1.255 -            return 0
   1.256 +        dominfo = self.domain_lookup(id)
   1.257          if reason == 'halt':
   1.258 -            self.domain_restart_cancel(id)
   1.259 +            self.domain_restart_cancel(dominfo.id)
   1.260          else:
   1.261 -            self.domain_restart_schedule(id, reason, force=1)
   1.262 -        eserver.inject('xend.domain.shutdown', [id, reason])
   1.263 +            self.domain_restart_schedule(dominfo.id, reason, force=1)
   1.264 +        eserver.inject('xend.domain.shutdown', [dominfo.name, reason])
   1.265          if reason == 'halt':
   1.266              reason = 'poweroff'
   1.267 -        val = xend.domain_shutdown(dom, reason)
   1.268 +        val = xend.domain_shutdown(dominfo.id, reason)
   1.269          self.refresh_schedule()
   1.270          return val
   1.271  
   1.272 @@ -428,10 +458,10 @@ class XendDomain:
   1.273          @param reason: shutdown reason
   1.274          """
   1.275          log.debug('domain_restart_schedule> %s %s %d', id, reason, force)
   1.276 -        dominfo = self.domain.get(id)
   1.277 +        dominfo = self.domain_lookup(id)
   1.278          if not dominfo:
   1.279              return
   1.280 -        if id in self.restarts:
   1.281 +        if dominfo.id in self.restarts_by_id:
   1.282              return
   1.283          restart = (force and reason == 'reboot') or dominfo.restart_needed(reason)
   1.284          if restart:
   1.285 @@ -439,8 +469,9 @@ class XendDomain:
   1.286              self.domain_restart_add(dominfo)
   1.287  
   1.288      def domain_restart_add(self, dominfo):
   1.289 -        self.restarts[dominfo.id] = dominfo
   1.290 -        log.info('Scheduling restart for domain: id=%s name=%s', dominfo.id, dominfo.name)
   1.291 +        self.restarts_by_name[dominfo.name] = dominfo
   1.292 +        self.restarts_by_id[dominfo.id] = dominfo
   1.293 +        log.info('Scheduling restart for domain: name=%s id=%s', dominfo.name, dominfo.id)
   1.294          self.domain_restarts_schedule()
   1.295              
   1.296      def domain_restart_cancel(self, id):
   1.297 @@ -448,53 +479,57 @@ class XendDomain:
   1.298  
   1.299          @param id: domain id
   1.300          """
   1.301 -        dominfo = self.restarts.get(id)
   1.302 +        dominfo = self.restarts_by_id.get(id) or self.restarts_by_name.get(id)
   1.303          if dominfo:
   1.304 -            log.info('Cancelling restart for domain: id=%s name=%s', dominfo.id, dominfo.name)
   1.305 +            log.info('Cancelling restart for domain: name=%s id=%s', dominfo.name, dominfo.id)
   1.306              dominfo.restart_cancel()
   1.307 -            del self.restarts[id]
   1.308 +            del self.restarts_by_id[dominfo.id]
   1.309 +            del self.restarts_by_name[dominfo.name]
   1.310  
   1.311      def domain_restarts(self):
   1.312          """Execute any scheduled domain restarts for domains that have gone.
   1.313          """
   1.314          self.domain_restarts_cancel()
   1.315 -        for id in self.restarts.keys():
   1.316 -            if id in self.domain:
   1.317 +        for dominfo in self.restarts_by_id.values():
   1.318 +            if dominfo.id in self.domain_by_id:
   1.319                  # Don't execute restart for domains still running.
   1.320                  continue
   1.321 -            dominfo = self.restarts[id]
   1.322              # Remove it from the restarts.
   1.323 -            del self.restarts[id]
   1.324 +            del self.restarts_by_id[dominfo.id]
   1.325 +            del self.restarts_by_name[dominfo.name]
   1.326              try:
   1.327                  def cbok(dominfo):
   1.328 -                    log.info('Restarted domain id=%s as %s', id, dominfo.id)
   1.329 +                    log.info('Restarted domain name=%s id=%s', dominfo.name, dominfo.id)
   1.330                      self.domain_unpause(dominfo.id)
   1.331                  def cberr(err):
   1.332 -                    log.exception("Delayed exception restarting domain: id=%s", id)
   1.333 +                    log.exception("Delayed exception restarting domain: name=%s id=%s",
   1.334 +                                  dominfo.name, dominfo.id)
   1.335                  deferred = self.domain_restart(dominfo)
   1.336                  deferred.addCallback(cbok)
   1.337                  deferred.addErrback(cberr)
   1.338              except:
   1.339 -                log.exception("Exception restarting domain: id=%s", id)
   1.340 -        if len(self.restarts):
   1.341 +                log.exception("Exception restarting domain: name=%s id=%s",
   1.342 +                              dominfo.name, dominfo.id)
   1.343 +        if self.domain_restarts_exist():
   1.344              # Run again later if any restarts remain.
   1.345              self.refresh_schedule(delay=5)
   1.346 +
   1.347 +    def domain_restarts_exist(self):
   1.348 +        return len(self.restarts_by_id)
   1.349          
   1.350      def final_domain_destroy(self, id):
   1.351          """Final destruction of a domain..
   1.352  
   1.353          @param id: domain id
   1.354          """
   1.355 -        dom = int(id)
   1.356 -        if dom <= 0:
   1.357 -            return 0
   1.358 -        log.info('Destroying domain: id=%s', str(id))
   1.359 -        eserver.inject('xend.domain.destroy', id)
   1.360 -        dominfo = self.domain.get(id)
   1.361 +        dominfo = self.domain_lookup(id)
   1.362 +        log.info('Destroying domain: name=%s', dominfo.name)
   1.363 +        eserver.inject('xend.domain.destroy', dominfo.name)
   1.364          if dominfo:
   1.365              val = dominfo.destroy()
   1.366          else:
   1.367 -            val = xc.domain_destroy(dom=dom)
   1.368 +            #todo
   1.369 +            val = xc.domain_destroy(dom=dominfo.dom)
   1.370          return val       
   1.371  
   1.372      def domain_destroy(self, id, reason='halt'):
   1.373 @@ -504,7 +539,6 @@ class XendDomain:
   1.374  
   1.375          @param id: domain id
   1.376          """
   1.377 -        id = str(id)
   1.378          if reason == 'halt':
   1.379              self.domain_restart_cancel(id)
   1.380          elif reason == 'reboot':
   1.381 @@ -522,9 +556,9 @@ class XendDomain:
   1.382          # Need a cancel too?
   1.383          # Don't forget to cancel restart for it.
   1.384          print 'domain_migrate>', id, dst
   1.385 -        dom = int(id)
   1.386 +        dominfo = self.domain_lookup(id)
   1.387          xmigrate = XendMigrate.instance()
   1.388 -        val = xmigrate.migrate_begin(dom, dst)
   1.389 +        val = xmigrate.migrate_begin(dominfo.id, dst)
   1.390          print 'domain_migrate<', val
   1.391          return val
   1.392  
   1.393 @@ -536,9 +570,9 @@ class XendDomain:
   1.394          @param progress: output progress if true
   1.395          @return: deferred
   1.396          """
   1.397 -        dom = int(id)
   1.398 +        dominfo = self.domain_lookup(id)
   1.399          xmigrate = XendMigrate.instance()
   1.400 -        return xmigrate.save_begin(dom, dst)
   1.401 +        return xmigrate.save_begin(dominfo.id, dst)
   1.402      
   1.403      def domain_pincpu(self, dom, cpu):
   1.404          """Pin a domain to a cpu.
   1.405 @@ -546,156 +580,149 @@ class XendDomain:
   1.406          @param dom: domain
   1.407          @param cpu: cpu number
   1.408          """
   1.409 -        dom = int(dom)
   1.410 -        return xc.domain_pincpu(dom, cpu)
   1.411 +        dominfo = self.domain_lookup(id)
   1.412 +        return xc.domain_pincpu(itn(dominfo.id), cpu)
   1.413  
   1.414 -    def domain_cpu_bvt_set(self, dom, mcuadv, warp, warpl, warpu):
   1.415 +    def domain_cpu_bvt_set(self, id, mcuadv, warp, warpl, warpu):
   1.416          """Set BVT (Borrowed Virtual Time) scheduler parameters for a domain.
   1.417          """
   1.418 -        dom = int(dom)
   1.419 -        return xc.bvtsched_domain_set(dom=dom, mcuadv=mcuadv,
   1.420 +        dominfo = self.domain_lookup(id)
   1.421 +        return xc.bvtsched_domain_set(dom=dominfo.dom, mcuadv=mcuadv,
   1.422                                        warp=warp, warpl=warpl, warpu=warpu)
   1.423  
   1.424 -    def domain_cpu_bvt_get(self, dom):
   1.425 +    def domain_cpu_bvt_get(self, id):
   1.426          """Get BVT (Borrowed Virtual Time) scheduler parameters for a domain.
   1.427          """
   1.428 -        dom = int(dom)
   1.429 -        return xc.bvtsched_domain_get(dom)
   1.430 +        dominfo = self.domain_lookup(id)
   1.431 +        return xc.bvtsched_domain_get(dominfo.dom)
   1.432      
   1.433 -    def domain_cpu_fbvt_set(self, dom, mcuadv, warp, warpl, warpu):
   1.434 +    def domain_cpu_fbvt_set(self, id, mcuadv, warp, warpl, warpu):
   1.435          """Set FBVT (Fair Borrowed Virtual Time) scheduler parameters for a domain.
   1.436          """
   1.437 -        dom = int(dom)
   1.438 -        return xc.fbvtsched_domain_set(dom=dom, mcuadv=mcuadv,
   1.439 +        dominfo = self.domain_lookup(id)
   1.440 +        return xc.fbvtsched_domain_set(dom=dominfo.dom, mcuadv=mcuadv,
   1.441                                         warp=warp, warpl=warpl, warpu=warpu)
   1.442  
   1.443 -    def domain_cpu_fbvt_get(self, dom):
   1.444 +    def domain_cpu_fbvt_get(self, id):
   1.445          """Get FBVT (Fair Borrowed Virtual Time) scheduler parameters for a domain.
   1.446          """
   1.447 -        dom = int(dom)
   1.448 -        return xc.fbvtsched_domain_get(dom)
   1.449 +        dominfo = self.domain_lookup(id)
   1.450 +        return xc.fbvtsched_domain_get(dominfo.dom)
   1.451          
   1.452 -    def domain_cpu_atropos_set(self, dom, period, slice, latency, xtratime):
   1.453 +    def domain_cpu_atropos_set(self, id, period, slice, latency, xtratime):
   1.454          """Set Atropos scheduler parameters for a domain.
   1.455          """
   1.456 -        dom = int(dom)
   1.457 -        return xc.atropos_domain_set(dom, period, slice, latency, xtratime)
   1.458 +        dominfo = self.domain_lookup(id)
   1.459 +        return xc.atropos_domain_set(dominfo.dom, period, slice, latency, xtratime)
   1.460  
   1.461 -    def domain_cpu_atropos_get(self, dom):
   1.462 +    def domain_cpu_atropos_get(self, id):
   1.463          """Get Atropos scheduler parameters for a domain.
   1.464          """
   1.465 -        dom = int(dom)
   1.466 -        return xc.atropos_domain_get(dom)
   1.467 +        dominfo = self.domain_lookup(id)
   1.468 +        return xc.atropos_domain_get(dominfo.dom)
   1.469  
   1.470 -    def domain_device_create(self, dom, devconfig):
   1.471 +    def domain_device_create(self, id, devconfig):
   1.472          """Create a new device for a domain.
   1.473  
   1.474 -        @param dom:       domain id
   1.475 +        @param id:       domain id
   1.476          @param devconfig: device configuration
   1.477          @return: deferred
   1.478          """
   1.479 -        dom = int(dom)
   1.480 -        dominfo = self.domain_get(dom)
   1.481 -        if not dominfo:
   1.482 -            raise XendError("invalid domain:" + str(dom))
   1.483 +        dominfo = self.domain_lookup(id)
   1.484          self.refresh_schedule()
   1.485          val = dominfo.device_create(devconfig)
   1.486          self.update_domain(dominfo.id)
   1.487          return val
   1.488  
   1.489 -    def domain_device_destroy(self, dom, type, idx):
   1.490 +    def domain_device_destroy(self, id, type, idx):
   1.491          """Destroy a device.
   1.492  
   1.493 -        @param dom:  domain id
   1.494 +        @param id:  domain id
   1.495          @param type: device type
   1.496          @param idx:  device index
   1.497          """
   1.498 -        dom = int(dom)
   1.499 -        dominfo = self.domain_get(dom)
   1.500 -        if not dominfo:
   1.501 -            raise XendError("invalid domain:" + str(dom))
   1.502 +        dominfo = self.domain_lookup(id)
   1.503          self.refresh_schedule()
   1.504          val = dominfo.device_destroy(type, idx)
   1.505          self.update_domain(dominfo.id)
   1.506          return val
   1.507  
   1.508 -    def domain_devtype_ls(self, dom, type):
   1.509 +    def domain_devtype_ls(self, id, type):
   1.510          """Get list of device indexes for a domain.
   1.511  
   1.512 -        @param dom:  domain
   1.513 +        @param id:  domain
   1.514          @param type: device type
   1.515          @return: device indexes
   1.516          """
   1.517 -        dominfo = self.domain_get(dom)
   1.518 -        if not dominfo: return None
   1.519 +        dominfo = self.domain_lookup(id)
   1.520          devs = dominfo.get_devices(type)
   1.521 -        return range(0, len(devs))
   1.522 +        #return range(0, len(devs))
   1.523 +        return devs
   1.524  
   1.525 -    def domain_devtype_get(self, dom, type, idx):
   1.526 +    def domain_devtype_get(self, id, type, idx):
   1.527          """Get a device from a domain.
   1.528  
   1.529 -        @param dom:  domain
   1.530 +        @param id:  domain
   1.531          @param type: device type
   1.532          @param idx:  device index
   1.533          @return: device object (or None)
   1.534          """
   1.535 -        dominfo = self.domain_get(dom)
   1.536 -        if not dominfo: return None
   1.537 +        dominfo = self.domain_lookup(id)
   1.538          return dominfo.get_device_by_index(type, idx)
   1.539  
   1.540 -    def domain_vif_ls(self, dom):
   1.541 +    def domain_vif_ls(self, id):
   1.542          """Get list of virtual network interface (vif) indexes for a domain.
   1.543  
   1.544 -        @param dom: domain
   1.545 +        @param id: domain
   1.546          @return: vif indexes
   1.547          """
   1.548 -        return self.domain_devtype_ls(dom, 'vif')
   1.549 +        return self.domain_devtype_ls(id, 'vif')
   1.550  
   1.551 -    def domain_vif_get(self, dom, vif):
   1.552 +    def domain_vif_get(self, id, vif):
   1.553          """Get a virtual network interface (vif) from a domain.
   1.554  
   1.555 -        @param dom: domain
   1.556 +        @param id: domain
   1.557          @param vif: vif index
   1.558          @return: vif device object (or None)
   1.559          """
   1.560 -        return self.domain_devtype_get(dom, 'vif', vif)
   1.561 +        return self.domain_devtype_get(id, 'vif', vif)
   1.562  
   1.563 -    def domain_vbd_ls(self, dom):
   1.564 +    def domain_vbd_ls(self, id):
   1.565          """Get list of virtual block device (vbd) indexes for a domain.
   1.566  
   1.567 -        @param dom: domain
   1.568 +        @param id: domain
   1.569          @return: vbd indexes
   1.570          """
   1.571 -        return self.domain_devtype_ls(dom, 'vbd')
   1.572 +        return self.domain_devtype_ls(id, 'vbd')
   1.573  
   1.574 -    def domain_vbd_get(self, dom, vbd):
   1.575 +    def domain_vbd_get(self, id, vbd):
   1.576          """Get a virtual block device (vbd) from a domain.
   1.577  
   1.578 -        @param dom: domain
   1.579 +        @param id: domain
   1.580          @param vbd: vbd index
   1.581          @return: vbd device (or None)
   1.582          """
   1.583 -        return self.domain_devtype_get(dom, 'vbd', vbd)
   1.584 +        return self.domain_devtype_get(id, 'vbd', vbd)
   1.585  
   1.586 -    def domain_shadow_control(self, dom, op):
   1.587 +    def domain_shadow_control(self, id, op):
   1.588          """Shadow page control.
   1.589  
   1.590 -        @param dom: domain
   1.591 +        @param id: domain
   1.592          @param op:  operation
   1.593          """
   1.594 -        dom = int(dom)
   1.595 -        return xc.shadow_control(dom, op)
   1.596 +        dominfo = self.domain_lookup(id)
   1.597 +        return xc.shadow_control(dominfo.dom, op)
   1.598  
   1.599 -    def domain_maxmem_set(self, dom, mem):
   1.600 +    def domain_maxmem_set(self, id, mem):
   1.601          """Set the memory limit for a domain.
   1.602  
   1.603          @param dom: domain
   1.604          @param mem: memory limit (in MB)
   1.605          @return: 0 on success, -1 on error
   1.606          """
   1.607 -        dom = int(dom)
   1.608 +        dominfo = self.domain_lookup(id)
   1.609          maxmem = int(mem) * 1024
   1.610 -        return xc.domain_setmaxmem(dom, maxmem_kb = maxmem)
   1.611 +        return xc.domain_setmaxmem(dominfo.dom, maxmem_kb = maxmem)
   1.612  
   1.613  
   1.614  def instance():
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Tue Jul 27 12:27:28 2004 +0000
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Jul 29 10:31:20 2004 +0000
     2.3 @@ -193,8 +193,8 @@ config_handlers = {}
     2.4  def add_config_handler(name, h):
     2.5      """Add a handler for a config field.
     2.6  
     2.7 -    name     field name
     2.8 -    h        handler: fn(vm, config, field, index)
     2.9 +    @param name:     field name
    2.10 +    @param h:        handler: fn(vm, config, field, index)
    2.11      """
    2.12      config_handlers[name] = h
    2.13  
    2.14 @@ -212,16 +212,15 @@ image_handlers = {}
    2.15  
    2.16  def add_image_handler(name, h):
    2.17      """Add a handler for an image type
    2.18 -    name     image type
    2.19 -    h        handler: fn(config, name, memory, image)
    2.20 +    @param name:     image type
    2.21 +    @param h:        handler: fn(config, name, memory, image)
    2.22      """
    2.23      image_handlers[name] = h
    2.24  
    2.25  def get_image_handler(name):
    2.26      """Get the handler for an image type.
    2.27 -    name     image type
    2.28 -
    2.29 -    returns handler or None
    2.30 +    @param name:     image type
    2.31 +    @return: handler or None
    2.32      """
    2.33      return image_handlers.get(name)
    2.34  
    2.35 @@ -233,17 +232,16 @@ device_handlers = {}
    2.36  def add_device_handler(name, h):
    2.37      """Add a handler for a device type.
    2.38  
    2.39 -    name      device type
    2.40 -    h         handler: fn(vm, dev)
    2.41 +    @param name:     device type
    2.42 +    @param h:        handler: fn(vm, dev)
    2.43      """
    2.44      device_handlers[name] = h
    2.45  
    2.46  def get_device_handler(name):
    2.47      """Get the handler for a device type.
    2.48  
    2.49 -    name      device type
    2.50 -
    2.51 -    returns handler or None
    2.52 +    @param name :     device type
    2.53 +    @return; handler or None
    2.54      """
    2.55      return device_handlers.get(name)
    2.56  
    2.57 @@ -252,10 +250,9 @@ def vm_create(config):
    2.58      If a vm has been partially created and there is an error it
    2.59      is destroyed.
    2.60  
    2.61 -    config    configuration
    2.62 -
    2.63 -    returns Deferred
    2.64 -    raises VmError for invalid configuration
    2.65 +    @param config    configuration
    2.66 +    @return: Deferred
    2.67 +    @raise: VmError for invalid configuration
    2.68      """
    2.69      vm = XendDomainInfo()
    2.70      return vm.construct(config)
    2.71 @@ -314,21 +311,27 @@ def vm_restore(src, progress=0):
    2.72      return deferred
    2.73      
    2.74  def dom_get(dom):
    2.75 +    """Get info from xen for an existing domain.
    2.76 +
    2.77 +    @param dom: domain id
    2.78 +    @return: info or None
    2.79 +    """
    2.80      domlist = xc.domain_getinfo(dom=dom)
    2.81      if domlist and dom == domlist[0]['dom']:
    2.82          return domlist[0]
    2.83      return None
    2.84      
    2.85 +def append_deferred(dlist, v):
    2.86 +    """Append a value to a deferred list if it is a deferred.
    2.87  
    2.88 -def append_deferred(dlist, v):
    2.89 +    @param dlist: list of deferreds
    2.90 +    @param v: value to add
    2.91 +    """
    2.92      if isinstance(v, defer.Deferred):
    2.93          dlist.append(v)
    2.94  
    2.95  def _vm_configure1(val, vm):
    2.96      d = vm.create_devices()
    2.97 -    def cbok(x):
    2.98 -        return x
    2.99 -    d.addCallback(cbok)
   2.100      d.addCallback(_vm_configure2, vm)
   2.101      return d
   2.102  
   2.103 @@ -348,7 +351,7 @@ class XendDomainInfo:
   2.104  
   2.105      """Minimum time between domain restarts in seconds.
   2.106      """
   2.107 -    MINIMUM_RESTART_TIME = 10
   2.108 +    MINIMUM_RESTART_TIME = 20
   2.109  
   2.110      def __init__(self):
   2.111          self.recreate = 0
   2.112 @@ -363,6 +366,7 @@ class XendDomainInfo:
   2.113          self.cmdline = None
   2.114          self.console = None
   2.115          self.devices = {}
   2.116 +        self.device_index = {}
   2.117          self.configs = []
   2.118          self.info = None
   2.119          self.ipaddrs = []
   2.120 @@ -378,9 +382,13 @@ class XendDomainInfo:
   2.121          self.console_port = None
   2.122  
   2.123      def setdom(self, dom):
   2.124 +        """Set the domain id.
   2.125 +
   2.126 +        @param dom: domain id
   2.127 +        """
   2.128          self.dom = int(dom)
   2.129          self.id = str(dom)
   2.130 -    
   2.131 +
   2.132      def update(self, info):
   2.133          """Update with  info from xc.domain_getinfo().
   2.134          """
   2.135 @@ -437,13 +445,39 @@ class XendDomainInfo:
   2.136              sxpr.append(['config', self.config])
   2.137          return sxpr
   2.138  
   2.139 +    def check_name(self, name):
   2.140 +        """Check if a vm name is valid. Valid names start with a non-digit
   2.141 +        and contain alphabetic characters, digits, or characters in '_-.'.
   2.142 +        The same name cannot be used for more than one vm at the same time.
   2.143 +
   2.144 +        @param name: name
   2.145 +        @raise: VMerror if invalid
   2.146 +        """
   2.147 +        if name is None or name == '':
   2.148 +            raise VmError('missing vm name')
   2.149 +        if name[0] in string.digits:
   2.150 +            raise VmError('invalid vm name')
   2.151 +        for c in name:
   2.152 +            if c in string.digits: continue
   2.153 +            if c in '_-.': continue
   2.154 +            if c in string.ascii_letters: continue
   2.155 +            raise VmError('invalid vm name')
   2.156 +        # See comment in XendDomain constructor about 'xd'.
   2.157 +        if xd.domain_exists(name):
   2.158 +            raise VmError('vm name clash: ' + name)
   2.159 +        
   2.160      def construct(self, config):
   2.161 +        """Construct the vm instance from its configuration.
   2.162 +
   2.163 +        @param config: configuration
   2.164 +        @return: deferred
   2.165 +        @raise: VmError on error
   2.166 +        """
   2.167          # todo - add support for scheduling params?
   2.168          self.config = config
   2.169          try:
   2.170              self.name = sxp.child_value(config, 'name')
   2.171 -            if self.name is None:
   2.172 -                raise VmError('missing domain name')
   2.173 +            self.check_name(self.name)
   2.174              self.memory = int(sxp.child_value(config, 'memory'))
   2.175              if self.memory is None:
   2.176                  raise VmError('missing memory size')
   2.177 @@ -462,12 +496,9 @@ class XendDomainInfo:
   2.178                  raise VmError('unknown image type: ' + image_name)
   2.179              image_handler(self, image)
   2.180              deferred = self.configure()
   2.181 -            def cbok(x):
   2.182 -                return x
   2.183              def cberr(err):
   2.184                  self.destroy()
   2.185                  return err
   2.186 -            deferred.addCallback(cbok)
   2.187              deferred.addErrback(cberr)
   2.188          except StandardError, ex:
   2.189              # Catch errors, cleanup and re-raise.
   2.190 @@ -478,8 +509,10 @@ class XendDomainInfo:
   2.191      def config_devices(self, name):
   2.192          """Get a list of the 'device' nodes of a given type from the config.
   2.193  
   2.194 -        name	device type
   2.195 -        return list of device configs
   2.196 +        @param name: device type
   2.197 +        @type  name: string
   2.198 +        @return: device configs
   2.199 +        @rtype: list
   2.200          """
   2.201          devices = []
   2.202          for d in sxp.children(self.config, 'device'):
   2.203 @@ -490,31 +523,57 @@ class XendDomainInfo:
   2.204          return devices
   2.205  
   2.206      def config_device(self, type, idx):
   2.207 +        """Get a device config from the device nodes of a given type
   2.208 +        from the config.
   2.209 +
   2.210 +        @param type: device type
   2.211 +        @type  type: string
   2.212 +        @param idx: index
   2.213 +        @type  idx: int
   2.214 +        @return config or None
   2.215 +        """
   2.216          devs = self.config_devices(type)
   2.217          if 0 <= idx < len(devs):
   2.218              return devs[idx]
   2.219          else:
   2.220              return None
   2.221  
   2.222 +    def next_device_index(self, type):
   2.223 +        """Get the next index for a given device type.
   2.224 +
   2.225 +        @param type: device type
   2.226 +        @type  type: string
   2.227 +        @return device index
   2.228 +        @rtype: int
   2.229 +        """
   2.230 +        idx = self.device_index.get(type, 0)
   2.231 +        self.device_index[type] = idx + 1
   2.232 +        return idx
   2.233 +
   2.234      def add_device(self, type, dev):
   2.235          """Add a device to a virtual machine.
   2.236  
   2.237 -        dev      device to add
   2.238 +        @param type: device type
   2.239 +        @param dev:  device to add
   2.240          """
   2.241          dl = self.devices.get(type, [])
   2.242          dl.append(dev)
   2.243          self.devices[type] = dl
   2.244  
   2.245      def get_devices(self, type):
   2.246 +        """Get a list of the devices of a given type.
   2.247 +
   2.248 +        @param type: device type
   2.249 +        @return: devices
   2.250 +        """
   2.251          val = self.devices.get(type, [])
   2.252          return val
   2.253  
   2.254      def get_device_by_id(self, type, id):
   2.255          """Get the device with the given id.
   2.256  
   2.257 -        id       device id
   2.258 -
   2.259 -        returns  device or None
   2.260 +        @param id:       device id
   2.261 +        @return:  device or None
   2.262          """
   2.263          dl = self.get_devices(type)
   2.264          for d in dl:
   2.265 @@ -525,20 +584,20 @@ class XendDomainInfo:
   2.266      def get_device_by_index(self, type, idx):
   2.267          """Get the device with the given index.
   2.268  
   2.269 -        idx       device index
   2.270 -
   2.271 -        returns  device or None
   2.272 +        @param idx: device index
   2.273 +        @return:  device or None
   2.274          """
   2.275 +        idx = str(idx)
   2.276          dl = self.get_devices(type)
   2.277 -        if 0 <= idx < len(dl):
   2.278 -            return dl[idx]
   2.279 -        else:
   2.280 -            return None
   2.281 +        for d in dl:
   2.282 +            if d.getidx() == idx:
   2.283 +                return d
   2.284 +        return None
   2.285  
   2.286      def add_config(self, val):
   2.287          """Add configuration data to a virtual machine.
   2.288  
   2.289 -        val      data to add
   2.290 +        @param val: data to add
   2.291          """
   2.292          self.configs.append(val)
   2.293  
   2.294 @@ -661,11 +720,11 @@ class XendDomainInfo:
   2.295      def create_domain(self, ostype, kernel, ramdisk, cmdline, vifs_n):
   2.296          """Create a domain. Builds the image but does not configure it.
   2.297  
   2.298 -        ostype  OS type
   2.299 -        kernel  kernel image
   2.300 -        ramdisk kernel ramdisk
   2.301 -        cmdline kernel commandline
   2.302 -        vifs_n  number of network interfaces
   2.303 +        @param ostype:  OS type
   2.304 +        @param kernel:  kernel image
   2.305 +        @param ramdisk: kernel ramdisk
   2.306 +        @param cmdline: kernel commandline
   2.307 +        @param vifs_n:  number of network interfaces
   2.308          """
   2.309          if not self.recreate:
   2.310              if not os.path.isfile(kernel):
   2.311 @@ -685,8 +744,8 @@ class XendDomainInfo:
   2.312      def create_devices(self):
   2.313          """Create the devices for a vm.
   2.314  
   2.315 -        returns Deferred
   2.316 -        raises VmError for invalid devices
   2.317 +        @return: Deferred
   2.318 +        @raise: VmError for invalid devices
   2.319          """
   2.320          dlist = []
   2.321          devices = sxp.children(self.config, 'device')
   2.322 @@ -730,16 +789,17 @@ class XendDomainInfo:
   2.323          """
   2.324          dev = self.get_device_by_index(type, idx)
   2.325          if not dev:
   2.326 -            raise VmError('invalid device: %s %d' % (type, idx))
   2.327 +            raise VmError('invalid device: %s %s' % (type, idx))
   2.328          devs = self.devices.get(type)
   2.329 -        if 0 <= idx < len(devs):
   2.330 -            del devs[idx]
   2.331 -        dev_config = self.config_device(type, idx)
   2.332 +        index = devs.index(dev)
   2.333 +        dev_config = self.config_device(type, index)
   2.334          if dev_config:
   2.335              self.config.remove(['device', dev_config])
   2.336          dev.destroy()
   2.337  
   2.338      def configure_console(self):
   2.339 +        """Configure the vm console port.
   2.340 +        """
   2.341          x = sxp.child_value(self.config, 'console')
   2.342          if x:
   2.343              try:
   2.344 @@ -749,12 +809,20 @@ class XendDomainInfo:
   2.345              self.console_port = port
   2.346  
   2.347      def configure_restart(self):
   2.348 +        """Configure the vm restart mode.
   2.349 +        """
   2.350          r = sxp.child_value(self.config, 'restart', RESTART_ONREBOOT)
   2.351          if r not in restart_modes:
   2.352              raise VmError('invalid restart mode: ' + str(r))
   2.353          self.restart_mode = r;
   2.354  
   2.355      def restart_needed(self, reason):
   2.356 +        """Determine if the vm needs to be restarted when shutdown
   2.357 +        for the given reason.
   2.358 +
   2.359 +        @param reason: shutdown reason
   2.360 +        @return 1 if needs restaert, 0 otherwise
   2.361 +        """
   2.362          if self.restart_mode == RESTART_NEVER:
   2.363              return 0
   2.364          if self.restart_mode == RESTART_ALWAYS:
   2.365 @@ -764,12 +832,18 @@ class XendDomainInfo:
   2.366          return 0
   2.367  
   2.368      def restart_cancel(self):
   2.369 +        """Cancel a vm restart.
   2.370 +        """
   2.371          self.restart_state = None
   2.372  
   2.373      def restarting(self):
   2.374 +        """Put the vm into restart mode.
   2.375 +        """
   2.376          self.restart_state = STATE_RESTART_PENDING
   2.377  
   2.378      def restart_pending(self):
   2.379 +        """Test if the vm has a pending restart.
   2.380 +        """
   2.381          return self.restart_state == STATE_RESTART_PENDING
   2.382  
   2.383      def restart_check(self):
   2.384 @@ -781,7 +855,7 @@ class XendDomainInfo:
   2.385          if self.restart_time is not None:
   2.386              tdelta = tnow - self.restart_time
   2.387              if tdelta < self.MINIMUM_RESTART_TIME:
   2.388 -                msg = 'VM %d restarting too fast' % self.dom
   2.389 +                msg = 'VM %s restarting too fast' % self.name
   2.390                  log.error(msg)
   2.391                  raise VmError(msg)
   2.392          self.restart_time = tnow
   2.393 @@ -830,17 +904,17 @@ class XendDomainInfo:
   2.394          """
   2.395          if self.blkif_backend:
   2.396              d = defer.Deferred()
   2.397 -            d.callback(1)
   2.398 +            d.callback(self)
   2.399          else:
   2.400              d = xend.blkif_create(self.dom, recreate=self.recreate)
   2.401          d.addCallback(_vm_configure1, self)
   2.402          return d
   2.403  
   2.404      def dom_configure(self, dom):
   2.405 -        """Configure a domain.
   2.406 +        """Configure a vm for an existing domain.
   2.407  
   2.408 -        dom    domain id
   2.409 -        returns deferred
   2.410 +        @param dom:    domain id
   2.411 +        @return: deferred
   2.412          """
   2.413          d = dom_get(dom)
   2.414          if not d:
   2.415 @@ -860,6 +934,8 @@ class XendDomainInfo:
   2.416          return deferred
   2.417  
   2.418      def configure_fields(self):
   2.419 +        """Process the vm configuration fields using the registered handlers.
   2.420 +        """
   2.421          dlist = []
   2.422          index = {}
   2.423          for field in sxp.children(self.config):
   2.424 @@ -880,11 +956,10 @@ class XendDomainInfo:
   2.425  def vm_image_linux(vm, image):
   2.426      """Create a VM for a linux image.
   2.427  
   2.428 -    name      vm name
   2.429 -    memory    vm memory
   2.430 -    image     image config
   2.431 -
   2.432 -    returns vm
   2.433 +    @param name:      vm name
   2.434 +    @param memory:    vm memory
   2.435 +    @param image:     image config
   2.436 +    @return: vm
   2.437      """
   2.438      kernel = sxp.child_value(image, "kernel")
   2.439      cmdline = ""
   2.440 @@ -905,11 +980,10 @@ def vm_image_linux(vm, image):
   2.441  def vm_image_netbsd(vm, image):
   2.442      """Create a VM for a bsd image.
   2.443  
   2.444 -    name      vm name
   2.445 -    memory    vm memory
   2.446 -    image     image config
   2.447 -
   2.448 -    returns vm
   2.449 +    @param name:     vm name
   2.450 +    @param memory:    vm memory
   2.451 +    @param image:     image config
   2.452 +    @return: vm
   2.453      """
   2.454      #todo: Same as for linux. Is that right? If so can unify them.
   2.455      kernel = sxp.child_value(image, "kernel")
   2.456 @@ -932,13 +1006,14 @@ def vm_image_netbsd(vm, image):
   2.457  def vm_dev_vif(vm, val, index):
   2.458      """Create a virtual network interface (vif).
   2.459  
   2.460 -    vm        virtual machine
   2.461 -    val       vif config
   2.462 -    index     vif index
   2.463 +    @param vm:        virtual machine
   2.464 +    @param val:       vif config
   2.465 +    @param index:     vif index
   2.466 +    @return: deferred
   2.467      """
   2.468      if vm.netif_backend:
   2.469          raise VmError('vif: vif in netif backend domain')
   2.470 -    vif = index #todo
   2.471 +    vif = vm.next_device_index('vif')
   2.472      vmac = sxp.child_value(val, "mac")
   2.473      xend.netif_create(vm.dom, recreate=vm.recreate)
   2.474      log.debug("Creating vif dom=%d vif=%d mac=%s", vm.dom, vif, str(vmac))
   2.475 @@ -954,13 +1029,14 @@ def vm_dev_vif(vm, val, index):
   2.476  def vm_dev_vbd(vm, val, index):
   2.477      """Create a virtual block device (vbd).
   2.478  
   2.479 -    vm        virtual machine
   2.480 -    val       vbd config
   2.481 -    index     vbd index
   2.482 +    @param vm:        virtual machine
   2.483 +    @param val:       vbd config
   2.484 +    @param index:     vbd index
   2.485 +    @return: deferred
   2.486      """
   2.487      if vm.blkif_backend:
   2.488          raise VmError('vbd: vbd in blkif backend domain')
   2.489 -    vdev = index
   2.490 +    vdev = vm.next_device_index('vif')
   2.491      uname = sxp.child_value(val, 'uname')
   2.492      if not uname:
   2.493          raise VmError('vbd: Missing uname')
   2.494 @@ -978,6 +1054,8 @@ def vm_dev_vbd(vm, val, index):
   2.495      return defer
   2.496  
   2.497  def parse_pci(val):
   2.498 +    """Parse a pci field.
   2.499 +    """
   2.500      if isinstance(val, types.StringType):
   2.501          radix = 10
   2.502          if val.startswith('0x') or val.startswith('0X'):
   2.503 @@ -988,6 +1066,13 @@ def parse_pci(val):
   2.504      return v
   2.505  
   2.506  def vm_dev_pci(vm, val, index):
   2.507 +    """Add a pci device.
   2.508 +
   2.509 +    @param vm: virtual machine
   2.510 +    @param val: device configuration
   2.511 +    @param index: device index
   2.512 +    @return: 0 on success
   2.513 +    """
   2.514      bus = sxp.child_value(val, 'bus')
   2.515      if not bus:
   2.516          raise VmError('pci: Missing bus')
   2.517 @@ -1013,78 +1098,21 @@ def vm_dev_pci(vm, val, index):
   2.518      return rc
   2.519      
   2.520  
   2.521 -def vm_field_vfr(vm, config, val, index):
   2.522 -    """Handle a vfr field in a config.
   2.523 +def vm_field_ignore(vm, config, val, index):
   2.524 +    """Dummy config field handler used for fields with built-in handling.
   2.525  
   2.526 -    vm        virtual machine
   2.527 -    config    vm config
   2.528 -    val       vfr field
   2.529 -    """
   2.530 -    # Get the rules and add them.
   2.531 -    # (vfr (vif (id foo) (ip x.x.x.x)) ... ) 
   2.532 -    list = sxp.children(val, 'vif')
   2.533 -    ipaddrs = []
   2.534 -    for v in list:
   2.535 -        id = sxp.child_value(v, 'id')
   2.536 -        if id is None:
   2.537 -            raise VmError('vfr: missing vif id')
   2.538 -        id = int(id)
   2.539 -        dev = vm.get_device_by_index('vif', id)
   2.540 -        if not dev:
   2.541 -            raise VmError('vfr: invalid vif id %d' % id)
   2.542 -        vif = sxp.child_value(dev, 'vif')
   2.543 -        ip = sxp.child_value(v, 'ip')
   2.544 -        if not ip:
   2.545 -            raise VmError('vfr: missing ip address')
   2.546 -        ipaddrs.append(ip);
   2.547 -        # todo: Configure the ipaddrs.
   2.548 -    vm.ipaddrs = ipaddrs
   2.549 -
   2.550 -def vnet_bridge(vnet, vmac, dom, idx):
   2.551 -    """Add the device for the vif to the bridge for its vnet.
   2.552 +    @param vm:        virtual machine
   2.553 +    @param config:    vm config
   2.554 +    @param val:       vfr field
   2.555 +    @param index:     field index
   2.556      """
   2.557 -    vif = "vif%d.%d" % (dom, idx)
   2.558 -    try:
   2.559 -        cmd = "(vif.conn (vif %s) (vnet %s) (vmac %s))" % (vif, vnet, vmac)
   2.560 -        log.debug("vnet_bridge> %s", cmd)
   2.561 -        out = file("/proc/vnet/policy", "wb")
   2.562 -        out.write(cmd)
   2.563 -        err = out.close()
   2.564 -        log.debug("vnet_bridge> err=%d", err)
   2.565 -    except IOError, ex:
   2.566 -        log.exception("vnet_bridge>")
   2.567 -    
   2.568 -def vm_field_vnet(vm, config, val, index):
   2.569 -    """Handle a vnet field in a config.
   2.570 -
   2.571 -    vm        virtual machine
   2.572 -    config    vm config
   2.573 -    val       vnet field
   2.574 -    index     index
   2.575 -    """
   2.576 -    # Get the vif children. For each vif look up the vif device
   2.577 -    # with the given id and configure its vnet.
   2.578 -    # (vnet (vif (id foo) (vnet 2) (mac x:x:x:x:x:x)) ... )
   2.579 -    vif_vnets = sxp.children(val, 'vif')
   2.580 -    for v in vif_vnets:
   2.581 -        id = sxp.child_value(v, 'id')
   2.582 -        if id is None:
   2.583 -            raise VmError('vnet: missing vif id')
   2.584 -        dev = vm.get_device_by_id('vif', id)
   2.585 -        #vnet = sxp.child_value(v, 'vnet', 1)
   2.586 -        #mac = sxp.child_value(dev, 'mac')
   2.587 -        #vif = sxp.child_value(dev, 'vif')
   2.588 -        #vnet_bridge(vnet, mac, vm.dom, 0)
   2.589 -        #vm.add_config([ 'vif.vnet', ['id', id], ['vnet', vnet], ['mac', mac]])
   2.590 -
   2.591 -def vm_field_ignore(vm, config, val, index):
   2.592      pass
   2.593  
   2.594 -# Register image handlers for linux and bsd.
   2.595 +# Register image handlers.
   2.596  add_image_handler('linux',  vm_image_linux)
   2.597  add_image_handler('netbsd', vm_image_netbsd)
   2.598  
   2.599 -# Register device handlers for vifs and vbds.
   2.600 +# Register device handlers.
   2.601  add_device_handler('vif',  vm_dev_vif)
   2.602  add_device_handler('vbd',  vm_dev_vbd)
   2.603  add_device_handler('pci',  vm_dev_pci)
   2.604 @@ -1098,6 +1126,4 @@ add_config_handler('image',   vm_field_i
   2.605  add_config_handler('device',  vm_field_ignore)
   2.606  add_config_handler('backend', vm_field_ignore)
   2.607  
   2.608 -# Register config handlers for vfr and vnet.
   2.609 -add_config_handler('vfr',  vm_field_vfr)
   2.610 -add_config_handler('vnet', vm_field_vnet)
   2.611 +# Register other config handlers.
     3.1 --- a/tools/python/xen/xend/server/SrvDomain.py	Tue Jul 27 12:27:28 2004 +0000
     3.2 +++ b/tools/python/xen/xend/server/SrvDomain.py	Thu Jul 29 10:31:20 2004 +0000
     3.3 @@ -22,9 +22,9 @@ class SrvDomain(SrvDir):
     3.4  
     3.5      def op_configure(self, op, req):
     3.6          fn = FormFn(self.xd.domain_configure,
     3.7 -                    [['dom', 'int'],
     3.8 +                    [['dom', 'str'],
     3.9                       ['config', 'sxpr']])
    3.10 -        deferred = fn(req.args, {'dom': self.dom.id})
    3.11 +        deferred = fn(req.args, {'dom': self.dom.name})
    3.12          deferred.addErrback(self._op_configure_err, req)
    3.13          return deferred
    3.14  
    3.15 @@ -33,35 +33,35 @@ class SrvDomain(SrvDir):
    3.16          return str(err)
    3.17          
    3.18      def op_unpause(self, op, req):
    3.19 -        val = self.xd.domain_unpause(self.dom.id)
    3.20 +        val = self.xd.domain_unpause(self.dom.name)
    3.21          return val
    3.22          
    3.23      def op_pause(self, op, req):
    3.24 -        val = self.xd.domain_pause(self.dom.id)
    3.25 +        val = self.xd.domain_pause(self.dom.name)
    3.26          return val
    3.27  
    3.28      def op_shutdown(self, op, req):
    3.29          fn = FormFn(self.xd.domain_shutdown,
    3.30 -                    [['dom', 'int'],
    3.31 +                    [['dom', 'str'],
    3.32                       ['reason', 'str']])
    3.33 -        val = fn(req.args, {'dom': self.dom.id})
    3.34 +        val = fn(req.args, {'dom': self.dom.name})
    3.35          req.setResponseCode(http.ACCEPTED)
    3.36          req.setHeader("Location", "%s/.." % req.prePathURL())
    3.37          return val
    3.38  
    3.39      def op_destroy(self, op, req):
    3.40          fn = FormFn(self.xd.domain_destroy,
    3.41 -                    [['dom', 'int'],
    3.42 +                    [['dom', 'str'],
    3.43                       ['reason', 'str']])
    3.44 -        val = fn(req.args, {'dom': self.dom.id})
    3.45 +        val = fn(req.args, {'dom': self.dom.name})
    3.46          req.setHeader("Location", "%s/.." % req.prePathURL())
    3.47          return val
    3.48  
    3.49      def op_save(self, op, req):
    3.50          fn = FormFn(self.xd.domain_save,
    3.51 -                    [['dom', 'int'],
    3.52 +                    [['dom', 'str'],
    3.53                       ['file', 'str']])
    3.54 -        deferred = fn(req.args, {'dom': self.dom.id})
    3.55 +        deferred = fn(req.args, {'dom': self.dom.name})
    3.56          deferred.addCallback(self._op_save_cb, req)
    3.57          deferred.addErrback(self._op_save_err, req)
    3.58          return deferred
    3.59 @@ -75,9 +75,9 @@ class SrvDomain(SrvDir):
    3.60          
    3.61      def op_migrate(self, op, req):
    3.62          fn = FormFn(self.xd.domain_migrate,
    3.63 -                    [['dom', 'int'],
    3.64 +                    [['dom', 'str'],
    3.65                       ['destination', 'str']])
    3.66 -        deferred = fn(req.args, {'dom': self.dom.id})
    3.67 +        deferred = fn(req.args, {'dom': self.dom.name})
    3.68          print 'op_migrate>', deferred
    3.69          deferred.addCallback(self._op_migrate_cb, req)
    3.70          deferred.addErrback(self._op_migrate_err, req)
    3.71 @@ -99,99 +99,85 @@ class SrvDomain(SrvDir):
    3.72          req.setResponseCode(http.BAD_REQUEST, "Error: "+ str(err))
    3.73          return str(err)
    3.74  
    3.75 -    def op_device_create(self, op, req):
    3.76 -        fn = FormFn(self.xd.domain_device_create,
    3.77 -                    [['dom', 'int'],
    3.78 -                     ['config', 'sxpr']])
    3.79 -        d = fn(req.args, {'dom': self.dom.id})
    3.80 -        return d
    3.81 -
    3.82 -    def op_device_destroy(self, op, req):
    3.83 -        fn = FormFn(self.xd.domain_device_destroy,
    3.84 -                    [['dom', 'int'],
    3.85 -                     ['type', 'str'],
    3.86 -                     ['index', 'int']])
    3.87 -        val = fn(req.args, {'dom': self.dom.id})
    3.88 -        return val
    3.89 -                
    3.90      def op_pincpu(self, op, req):
    3.91          fn = FormFn(self.xd.domain_pincpu,
    3.92 -                    [['dom', 'int'],
    3.93 +                    [['dom', 'str'],
    3.94                       ['cpu', 'int']])
    3.95 -        val = fn(req.args, {'dom': self.dom.id})
    3.96 +        val = fn(req.args, {'dom': self.dom.name})
    3.97          return val
    3.98  
    3.99      def op_cpu_bvt_set(self, op, req):
   3.100          fn = FormFn(self.xd.domain_cpu_bvt_set,
   3.101 -                    [['dom', 'int'],
   3.102 +                    [['dom', 'str'],
   3.103                       ['mcuadv', 'int'],
   3.104                       ['warp', 'int'],
   3.105                       ['warpl', 'int'],
   3.106                       ['warpu', 'int']])
   3.107 -        val = fn(req.args, {'dom': self.dom.id})
   3.108 +        val = fn(req.args, {'dom': self.dom.name})
   3.109          return val
   3.110      
   3.111      def op_cpu_fbvt_set(self, op, req):
   3.112          fn = FormFn(self.xd.domain_cpu_fbvt_set,
   3.113 -                    [['dom', 'int'],
   3.114 +                    [['dom', 'str'],
   3.115                       ['mcuadv', 'int'],
   3.116                       ['warp', 'int'],
   3.117                       ['warpl', 'int'],
   3.118                       ['warpu', 'int']])
   3.119 -        val = fn(req.args, {'dom': self.dom.id})
   3.120 +        val = fn(req.args, {'dom': self.dom.name})
   3.121          return val
   3.122  
   3.123      def op_cpu_atropos_set(self, op, req):
   3.124          fn = FormFn(self.xd.domain_cpu_atropos_set,
   3.125 -                    [['dom', 'int'],
   3.126 +                    [['dom', 'str'],
   3.127                       ['period', 'int'],
   3.128                       ['slice', 'int'],
   3.129                       ['latency', 'int'],
   3.130                       ['xtratime', 'int']])
   3.131 -        val = fn(req.args, {'dom': self.dom.id})
   3.132 +        val = fn(req.args, {'dom': self.dom.name})
   3.133          return val
   3.134  
   3.135      def op_maxmem_set(self, op, req):
   3.136          fn = FormFn(self.xd.domain_maxmem_set,
   3.137 -                    [['dom', 'int'],
   3.138 +                    [['dom', 'str'],
   3.139                       ['memory', 'int']])
   3.140 -        val = fn(req.args, {'dom': self.dom.id})
   3.141 +        val = fn(req.args, {'dom': self.dom.name})
   3.142          return val
   3.143  
   3.144 +    def op_device_create(self, op, req):
   3.145 +        fn = FormFn(self.xd.domain_device_create,
   3.146 +                    [['dom', 'str'],
   3.147 +                     ['config', 'sxpr']])
   3.148 +        d = fn(req.args, {'dom': self.dom.name})
   3.149 +        return d
   3.150 +
   3.151 +    def op_device_destroy(self, op, req):
   3.152 +        fn = FormFn(self.xd.domain_device_destroy,
   3.153 +                    [['dom', 'str'],
   3.154 +                     ['type', 'str'],
   3.155 +                     ['idx', 'str']])
   3.156 +        val = fn(req.args, {'dom': self.dom.name})
   3.157 +        return val
   3.158 +                
   3.159      def op_vifs(self, op, req):
   3.160 -        return self.xd.domain_vif_ls(self.dom.id)
   3.161 +        devs = self.xd.domain_vif_ls(self.dom.name)
   3.162 +        return [ dev.sxpr() for dev in devs ]
   3.163  
   3.164      def op_vif(self, op, req):
   3.165          fn = FormFn(self.xd.domain_vif_get,
   3.166 -                    [['dom', 'int'],
   3.167 -                     ['vif', 'int']])
   3.168 -        val = fn(req.args, {'dom': self.dom.id})
   3.169 +                    [['dom', 'str'],
   3.170 +                     ['vif', 'str']])
   3.171 +        val = fn(req.args, {'dom': self.dom.name})
   3.172          return val
   3.173  
   3.174      def op_vbds(self, op, req):
   3.175 -        return self.xd.domain_vbd_ls(self.dom.id)
   3.176 +        devs = self.xd.domain_vbd_ls(self.dom.name)
   3.177 +        return [ dev.sxpr() for dev in devs ]
   3.178  
   3.179      def op_vbd(self, op, req):
   3.180          fn = FormFn(self.xd.domain_vbd_get,
   3.181 -                    [['dom', 'int'],
   3.182 -                     ['vbd', 'int']])
   3.183 -        val = fn(req.args, {'dom': self.dom.id})
   3.184 -        return val
   3.185 -
   3.186 -    def op_vbd_add(self, op, req):
   3.187 -        fn = FormFn(self.xd.domain_vbd_add,
   3.188 -                    [['dom', 'int'],
   3.189 -                     ['uname', 'str'],
   3.190 -                     ['dev', 'str'],
   3.191 -                     ['mode', 'str']])
   3.192 -        val = fn(req.args, {'dom': self.dom.id})
   3.193 -        return val
   3.194 -
   3.195 -    def op_vbd_remove(self, op, req):
   3.196 -        fn = FormFn(self.xd.domain_vbd_remove,
   3.197 -                    [['dom', 'int'],
   3.198 -                     ['dev', 'str']])
   3.199 -        val = fn(req.args, {'dom': self.dom.id})
   3.200 +                    [['dom', 'str'],
   3.201 +                     ['vbd', 'str']])
   3.202 +        val = fn(req.args, {'dom': self.dom.name})
   3.203          return val
   3.204  
   3.205      def render_POST(self, req):
     4.1 --- a/tools/python/xen/xend/server/SrvDomainDir.py	Tue Jul 27 12:27:28 2004 +0000
     4.2 +++ b/tools/python/xen/xend/server/SrvDomainDir.py	Thu Jul 29 10:31:20 2004 +0000
     4.3 @@ -24,7 +24,7 @@ class SrvDomainDir(SrvDir):
     4.4  
     4.5      def domain(self, x):
     4.6          val = None
     4.7 -        dom = self.xd.domain_get(x)
     4.8 +        dom = self.xd.domain_lookup(x)
     4.9          if not dom:
    4.10              raise XendError('No such domain ' + str(x))
    4.11          val = SrvDomain(dom)
    4.12 @@ -74,7 +74,7 @@ class SrvDomainDir(SrvDir):
    4.13      def _op_create_cb(self, dominfo, configstring, req):
    4.14          """Callback to handle deferred domain creation.
    4.15          """
    4.16 -        dom = dominfo.id
    4.17 +        dom = dominfo.name
    4.18          domurl = "%s/%s" % (req.prePathURL(), dom)
    4.19          req.setResponseCode(http.CREATED, "created")
    4.20          req.setHeader("Location", domurl)
    4.21 @@ -112,7 +112,7 @@ class SrvDomainDir(SrvDir):
    4.22          return deferred
    4.23  
    4.24      def _op_restore_cb(self, dominfo, req):
    4.25 -        dom = dominfo.id
    4.26 +        dom = dominfo.name
    4.27          domurl = "%s/%s" % (req.prePathURL(), dom)
    4.28          req.setResponseCode(http.CREATED)
    4.29          req.setHeader("Location", domurl)
    4.30 @@ -159,12 +159,12 @@ class SrvDomainDir(SrvDir):
    4.31              sxp.show(domains, out=req)
    4.32          else:
    4.33              domains = self.xd.domains()
    4.34 -            domains.sort(lambda x, y: cmp(x.id, y.id))
    4.35 +            domains.sort(lambda x, y: cmp(x.name, y.name))
    4.36              req.write('<ul>')
    4.37              for d in domains:
    4.38                 req.write('<li><a href="%s%s"> Domain %s</a>'
    4.39 -                         % (url, d.id, d.id))
    4.40 -               req.write('name=%s' % d.name)
    4.41 +                         % (url, d.name, d.name))
    4.42 +               req.write('id=%s' % d.id)
    4.43                 req.write('memory=%d'% d.memory)
    4.44                 req.write('</li>')
    4.45              req.write('</ul>')
     5.1 --- a/tools/python/xen/xend/server/blkif.py	Tue Jul 27 12:27:28 2004 +0000
     5.2 +++ b/tools/python/xen/xend/server/blkif.py	Thu Jul 29 10:31:20 2004 +0000
     5.3 @@ -215,7 +215,7 @@ class BlkDev(controller.Dev):
     5.4      """
     5.5  
     5.6      def __init__(self, ctrl, vdev, mode, segment):
     5.7 -        controller.Dev.__init__(self, ctrl)
     5.8 +        controller.Dev.__init__(self,  segment['device'], ctrl)
     5.9          self.vdev = vdev
    5.10          self.mode = mode
    5.11          self.device = segment['device']
    5.12 @@ -227,7 +227,11 @@ class BlkDev(controller.Dev):
    5.13          return 'w' not in self.mode
    5.14  
    5.15      def sxpr(self):
    5.16 -        val = ['blkdev', ['vdev', self.vdev], ['mode', self.mode] ]
    5.17 +        val = ['blkdev',
    5.18 +               ['idx', self.idx],
    5.19 +               ['vdev', self.vdev],
    5.20 +               ['device', self.device],
    5.21 +               ['mode', self.mode]]
    5.22          return val
    5.23  
    5.24      def destroy(self):
     6.1 --- a/tools/python/xen/xend/server/controller.py	Tue Jul 27 12:27:28 2004 +0000
     6.2 +++ b/tools/python/xen/xend/server/controller.py	Thu Jul 29 10:31:20 2004 +0000
     6.3 @@ -327,10 +327,14 @@ class Dev:
     6.4      """Abstract class for a device attached to a device controller.
     6.5      """
     6.6      
     6.7 -    def __init__(self, controller):
     6.8 +    def __init__(self, idx, controller):
     6.9 +        self.idx = str(idx)
    6.10          self.controller = controller
    6.11          self.props = {}
    6.12  
    6.13 +    def getidx(self):
    6.14 +        return self.idx
    6.15 +
    6.16      def setprop(self, k, v):
    6.17          self.props[k] = v
    6.18  
     7.1 --- a/tools/python/xen/xend/server/netif.py	Tue Jul 27 12:27:28 2004 +0000
     7.2 +++ b/tools/python/xen/xend/server/netif.py	Thu Jul 29 10:31:20 2004 +0000
     7.3 @@ -112,7 +112,7 @@ class NetDev(controller.Dev):
     7.4      """
     7.5  
     7.6      def __init__(self, ctrl, vif, config):
     7.7 -        controller.Dev.__init__(self, ctrl)
     7.8 +        controller.Dev.__init__(self, vif, ctrl)
     7.9          self.vif = vif
    7.10          self.evtchn = None
    7.11          self.configure(config)
    7.12 @@ -140,7 +140,10 @@ class NetDev(controller.Dev):
    7.13      def sxpr(self):
    7.14          vif = str(self.vif)
    7.15          mac = self.get_mac()
    7.16 -        val = ['vif', ['idx', vif], ['mac', mac]]
    7.17 +        val = ['vif',
    7.18 +               ['idx', self.idx],
    7.19 +               ['vif', vif],
    7.20 +               ['mac', mac]]
    7.21          if self.bridge:
    7.22              val.append(['bridge', self.bridge])
    7.23          if self.script:
     8.1 --- a/tools/python/xen/xend/sxp.py	Tue Jul 27 12:27:28 2004 +0000
     8.2 +++ b/tools/python/xen/xend/sxp.py	Thu Jul 29 10:31:20 2004 +0000
     8.3 @@ -366,10 +366,11 @@ def show(sxpr, out=sys.stdout):
     8.4              show(x, out)
     8.5              i += 1
     8.6          out.write(k_list_close)
     8.7 +    elif isinstance(sxpr, (types.IntType, types.FloatType)):
     8.8 +        out.write(str(sxpr))
     8.9      elif isinstance(sxpr, types.StringType) and atomp(sxpr):
    8.10          out.write(sxpr)
    8.11      else:
    8.12 -        #out.write("'" + str(sxpr) + "'")
    8.13          out.write(repr(str(sxpr)))
    8.14  
    8.15  def show_xml(sxpr, out=sys.stdout):
     9.1 --- a/tools/python/xen/xm/create.py	Tue Jul 27 12:27:28 2004 +0000
     9.2 +++ b/tools/python/xen/xm/create.py	Thu Jul 29 10:31:20 2004 +0000
     9.3 @@ -402,7 +402,7 @@ def make_domain(opts, config):
     9.4      except XendError, ex:
     9.5          opts.err(str(ex))
     9.6  
     9.7 -    dom = int(sxp.child_value(dominfo, 'id'))
     9.8 +    dom = sxp.child_value(dominfo, 'name')
     9.9      console_info = sxp.child(dominfo, 'console')
    9.10      if console_info:
    9.11          console_port = int(sxp.child_value(console_info, 'console_port'))
    9.12 @@ -411,8 +411,8 @@ def make_domain(opts, config):
    9.13      
    9.14      if server.xend_domain_unpause(dom) < 0:
    9.15          server.xend_domain_destroy(dom)
    9.16 -        opts.err("Failed to unpause domain %d" % dom)
    9.17 -    opts.info("Started domain %d, console on port %d"
    9.18 +        opts.err("Failed to unpause domain %s" % dom)
    9.19 +    opts.info("Started domain %s, console on port %d"
    9.20                % (dom, console_port))
    9.21      return (dom, console_port)
    9.22  
    10.1 --- a/tools/python/xen/xm/destroy.py	Tue Jul 27 12:27:28 2004 +0000
    10.2 +++ b/tools/python/xen/xm/destroy.py	Thu Jul 29 10:31:20 2004 +0000
    10.3 @@ -27,14 +27,10 @@ def main(argv):
    10.4          return
    10.5      if len(args) < 1: opts.err('Missing domain')
    10.6      dom = args[0]
    10.7 -    try:
    10.8 -        domid = int(dom)
    10.9 -    except:
   10.10 -        opts.err('Invalid domain: ' + dom)
   10.11      if opts.vals.reboot:
   10.12          mode = 'reboot'
   10.13      else:
   10.14          mode = 'halt'
   10.15 -    server.xend_domain_destroy(domid, mode)
   10.16 +    server.xend_domain_destroy(dom, mode)
   10.17      
   10.18          
    11.1 --- a/tools/python/xen/xm/main.py	Tue Jul 27 12:27:28 2004 +0000
    11.2 +++ b/tools/python/xen/xm/main.py	Thu Jul 29 10:31:20 2004 +0000
    11.3 @@ -246,10 +246,10 @@ class ProgList(Prog):
    11.4                  use_long = 1
    11.5                  
    11.6          if n == 0:
    11.7 -            doms = map(int, server.xend_domains())
    11.8 +            doms = server.xend_domains()
    11.9              doms.sort()
   11.10          else:
   11.11 -            doms = map(int, params)
   11.12 +            doms = params
   11.13              
   11.14          if use_long:
   11.15              self.long_list(doms)
   11.16 @@ -257,22 +257,27 @@ class ProgList(Prog):
   11.17              self.brief_list(doms)
   11.18  
   11.19      def brief_list(self, doms):
   11.20 -        print 'Dom  Name             Mem(MB)  CPU  State  Time(s)'
   11.21 +        print 'Name              Id  Mem(MB)  CPU  State  Time(s)  Console'
   11.22          for dom in doms:
   11.23              info = server.xend_domain(dom)
   11.24              d = {}
   11.25 -            d['dom'] = int(dom)
   11.26 +            d['dom'] = int(sxp.child_value(info, 'id', '-1'))
   11.27              d['name'] = sxp.child_value(info, 'name', '??')
   11.28              d['mem'] = int(sxp.child_value(info, 'memory', '0'))
   11.29              d['cpu'] = int(sxp.child_value(info, 'cpu', '0'))
   11.30              d['state'] = sxp.child_value(info, 'state', '??')
   11.31              d['cpu_time'] = float(sxp.child_value(info, 'cpu_time', '0'))
   11.32 -            print ("%(dom)-4d %(name)-16s %(mem)7d  %(cpu)3d  %(state)5s  %(cpu_time)7.1f" % d)
   11.33 +            console = sxp.child(info, 'console')
   11.34 +            if console:
   11.35 +                d['port'] = sxp.child_value(console, 'console_port')
   11.36 +            else:
   11.37 +                d['port'] = ''
   11.38 +            print ("%(name)-16s %(dom)3d  %(mem)7d  %(cpu)3d  %(state)5s  %(cpu_time)7.1f    %(port)4s"
   11.39 +                   % d)
   11.40  
   11.41      def long_list(self, doms):
   11.42          for dom in doms:
   11.43              info = server.xend_domain(dom)
   11.44 -            print '\nDomain %d' % dom
   11.45              PrettyPrint.prettyprint(info)
   11.46  
   11.47  xm.prog(ProgList)
    12.1 --- a/tools/python/xen/xm/shutdown.py	Tue Jul 27 12:27:28 2004 +0000
    12.2 +++ b/tools/python/xen/xm/shutdown.py	Thu Jul 29 10:31:20 2004 +0000
    12.3 @@ -9,6 +9,8 @@ import time
    12.4  from xen.xend.XendClient import server
    12.5  from xen.xm.opts import *
    12.6  
    12.7 +DOM0 = 'Domain-0'
    12.8 +
    12.9  gopts = Opts(use="""[options] [DOM]
   12.10  
   12.11  Shutdown one or more domains gracefully.
   12.12 @@ -35,11 +37,9 @@ gopts.opt('reboot', short='R',
   12.13            use='Shutdown and reboot.')
   12.14  
   12.15  def shutdown(opts, doms, mode, wait):
   12.16 -    def domains():
   12.17 -        return [ int(a) for a in server.xend_domains() ]
   12.18 -    if doms == None: doms = domains()
   12.19 -    if 0 in doms:
   12.20 -        doms.remove(0)
   12.21 +    if doms == None: doms = server.xend_domains()
   12.22 +    if DOM0 in doms:
   12.23 +        doms.remove(DOM0)
   12.24      for d in doms:
   12.25          server.xend_domain_shutdown(d, mode)
   12.26      if wait:
   12.27 @@ -50,7 +50,7 @@ def shutdown(opts, doms, mode, wait):
   12.28                  if d in alive: continue
   12.29                  dead.append(d)
   12.30              for d in dead:
   12.31 -                opts.info("Domain %d terminated" % d)
   12.32 +                opts.info("Domain %s terminated" % d)
   12.33                  doms.remove(d)
   12.34              time.sleep(1)
   12.35          opts.info("All domains terminated")
   12.36 @@ -76,13 +76,8 @@ def main_all(opts, args):
   12.37  def main_dom(opts, args):
   12.38      if len(args) < 1: opts.err('Missing domain')
   12.39      dom = args[0]
   12.40 -    try:
   12.41 -        domid = int(dom)
   12.42 -    except:
   12.43 -        opts.err('Invalid domain: ' + dom)
   12.44 -        
   12.45      mode = shutdown_mode(opts)  
   12.46 -    shutdown(opts, [ domid ], mode, opts.vals.wait)
   12.47 +    shutdown(opts, [ dom ], mode, opts.vals.wait)
   12.48      
   12.49  def main(argv):
   12.50      opts = gopts
   12.51 @@ -90,7 +85,6 @@ def main(argv):
   12.52      if opts.vals.help:
   12.53          opts.usage()
   12.54          return
   12.55 -    print 'shutdown.main>', len(args), args
   12.56      if opts.vals.all:
   12.57          main_all(opts, args)
   12.58      else: