direct-io.hg

changeset 1778:e4a326567073

bitkeeper revision 1.1080 (40f50d9aaH0Dd_smhBdPvYcIQFbsoA)

Improved error handling in xend and XendClient.
author mjw@wray-m-3.hpl.hp.com
date Wed Jul 14 10:40:26 2004 +0000 (2004-07-14)
parents e91945007886
children f48283c49033
files .rootkeys tools/python/xen/xend/XendClient.py tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/XendError.py tools/python/xen/xend/server/SrvBase.py tools/python/xen/xend/server/SrvConsole.py tools/python/xen/xend/server/SrvConsoleDir.py tools/python/xen/xend/server/SrvDaemon.py tools/python/xen/xend/server/SrvDir.py tools/python/xen/xend/server/SrvDmesg.py tools/python/xen/xend/server/SrvDomain.py tools/python/xen/xend/server/SrvDomainDir.py tools/python/xen/xend/server/SrvNode.py tools/python/xen/xend/server/domain.py tools/python/xen/xend/server/netif.py
line diff
     1.1 --- a/.rootkeys	Wed Jul 14 07:45:24 2004 +0000
     1.2 +++ b/.rootkeys	Wed Jul 14 10:40:26 2004 +0000
     1.3 @@ -240,6 +240,7 @@ 40eee3a0sPO-WUu34uHUXOC7HliDGw tools/pyt
     1.4  40c9c468fSl3H3IypyT0ppkbb0ZT9A tools/python/xen/xend/XendDomain.py
     1.5  40c9c468bbKq3uC7_fuNUkiMMjArdw tools/python/xen/xend/XendDomainConfig.py
     1.6  40c9c4685ykq87_n1kVUbMr9flx9fg tools/python/xen/xend/XendDomainInfo.py
     1.7 +40f50d99YiiaMI1fZBh1VCDFLD57qg tools/python/xen/xend/XendError.py
     1.8  40c9c46854nsHmuxHQHncKk5rAs5NA tools/python/xen/xend/XendMigrate.py
     1.9  40c9c468M96gA1EYDvNa5w5kQNYLFA tools/python/xen/xend/XendNode.py
    1.10  40c9c4686jruMyZIqiaZRMiMoqMJtg tools/python/xen/xend/XendRoot.py
     2.1 --- a/tools/python/xen/xend/XendClient.py	Wed Jul 14 07:45:24 2004 +0000
     2.2 +++ b/tools/python/xen/xend/XendClient.py	Wed Jul 14 10:40:26 2004 +0000
     2.3 @@ -13,6 +13,8 @@ import types
     2.4  from StringIO import StringIO
     2.5  import urlparse
     2.6  
     2.7 +from twisted.protocols import http
     2.8 +
     2.9  from encode import *
    2.10  import sxp
    2.11  import PrettyPrint
    2.12 @@ -121,9 +123,9 @@ def xend_request(url, method, data=None)
    2.13      resp = conn.getresponse()
    2.14      if DEBUG: print resp.status, resp.reason
    2.15      if DEBUG: print resp.msg.headers
    2.16 -    if resp.status in [204, 404]:
    2.17 +    if resp.status in [ http.NO_CONTENT ]:
    2.18          return None
    2.19 -    if resp.status not in [200, 201, 202, 203]:
    2.20 +    if resp.status not in [ http.OK, http.CREATED, http.ACCEPTED ]:
    2.21          raise XendError(resp.reason)
    2.22      pin = sxp.Parser()
    2.23      data = resp.read()
    2.24 @@ -135,7 +137,7 @@ def xend_request(url, method, data=None)
    2.25      val = pin.get_val()
    2.26      #if isinstance(val, types.ListType) and sxp.name(val) == 'val':
    2.27      #    val = val[1]
    2.28 -    if isinstance(val, types.ListType) and sxp.name(val) == 'err':
    2.29 +    if isinstance(val, types.ListType) and sxp.name(val) == 'xend.err':
    2.30          raise XendError(val[1])
    2.31      if DEBUG: print '**val='; sxp.show(val); print
    2.32      return val
     3.1 --- a/tools/python/xen/xend/XendDomain.py	Wed Jul 14 07:45:24 2004 +0000
     3.2 +++ b/tools/python/xen/xend/XendDomain.py	Wed Jul 14 10:40:26 2004 +0000
     3.3 @@ -21,6 +21,7 @@ import XendDomainInfo
     3.4  import XendConsole
     3.5  import XendMigrate
     3.6  import EventServer
     3.7 +from XendError import XendError
     3.8  
     3.9  from xen.xend.server import SrvDaemon
    3.10  xend = SrvDaemon.instance()
    3.11 @@ -324,9 +325,9 @@ class XendDomain:
    3.12          dom = int(id)
    3.13          dominfo = self.domain_get(dom)
    3.14          if not dominfo:
    3.15 -            raise ValueError("Invalid domain: " + str(id))
    3.16 +            raise XendError("Invalid domain: " + str(id))
    3.17          if dominfo.config:
    3.18 -            raise ValueError("Domain already configured: " + str(id))
    3.19 +            raise XendError("Domain already configured: " + str(id))
    3.20          def fn(dominfo):
    3.21              self._add_domain(dominfo.id, dominfo)
    3.22              return dominfo
    3.23 @@ -575,7 +576,7 @@ class XendDomain:
    3.24          dom = int(dom)
    3.25          dominfo = self.domain_get(dom)
    3.26          if not dominfo:
    3.27 -            raise ValueError("invalid domain:" + str(dom))
    3.28 +            raise XendError("invalid domain:" + str(dom))
    3.29          self.refresh_schedule()
    3.30          return dominfo.device_create(devconfig)
    3.31  
    3.32 @@ -589,7 +590,7 @@ class XendDomain:
    3.33          dom = int(dom)
    3.34          dominfo = self.domain_get(dom)
    3.35          if not dominfo:
    3.36 -            raise ValueError("invalid domain:" + str(dom))
    3.37 +            raise XendError("invalid domain:" + str(dom))
    3.38          self.refresh_schedule()
    3.39          return dominfo.device_destroy(type, idx)
    3.40  
     4.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Wed Jul 14 07:45:24 2004 +0000
     4.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Wed Jul 14 10:40:26 2004 +0000
     4.3 @@ -29,6 +29,8 @@ xendConsole = XendConsole.instance()
     4.4  import server.SrvDaemon
     4.5  xend = server.SrvDaemon.instance()
     4.6  
     4.7 +from XendError import VmError
     4.8 +
     4.9  """Flag for a block device backend domain."""
    4.10  SIF_BLK_BE_DOMAIN = (1<<4)
    4.11  
    4.12 @@ -58,16 +60,6 @@ def shutdown_reason(code):
    4.13      """
    4.14      return shutdown_reasons.get(code, "?")
    4.15  
    4.16 -class VmError(ValueError):
    4.17 -    """Vm construction error."""
    4.18 -
    4.19 -    def __init__(self, value):
    4.20 -        self.value = value
    4.21 -
    4.22 -    def __str__(self):
    4.23 -        return self.value
    4.24 -
    4.25 -
    4.26  def blkdev_name_to_number(name):
    4.27      """Take the given textual block-device name (e.g., '/dev/sda1',
    4.28      'hda') and return the device number used by the OS. """
    4.29 @@ -410,7 +402,11 @@ class XendDomainInfo:
    4.30                  self.autorestart = 1
    4.31              self.configure_backends()
    4.32              image = sxp.child_value(config, 'image')
    4.33 +            if image is None:
    4.34 +                raise VmError('missing image')
    4.35              image_name = sxp.name(image)
    4.36 +            if image_name is None:
    4.37 +                raise VmError('missing image name')
    4.38              image_handler = get_image_handler(image_name)
    4.39              if image_handler is None:
    4.40                  raise VmError('unknown image type: ' + image_name)
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/python/xen/xend/XendError.py	Wed Jul 14 10:40:26 2004 +0000
     5.3 @@ -0,0 +1,14 @@
     5.4 +
     5.5 +class XendError(ValueError):
     5.6 +    
     5.7 +    def __init__(self, value):
     5.8 +        self.value = value
     5.9 +
    5.10 +    def __str__(self):
    5.11 +        return self.value
    5.12 +
    5.13 +class VmError(XendError):
    5.14 +    """Vm construction error."""
    5.15 +
    5.16 +    pass
    5.17 +
     6.1 --- a/tools/python/xen/xend/server/SrvBase.py	Wed Jul 14 07:45:24 2004 +0000
     6.2 +++ b/tools/python/xen/xend/server/SrvBase.py	Wed Jul 14 10:40:26 2004 +0000
     6.3 @@ -10,12 +10,15 @@ import StringIO
     6.4  from twisted.internet import defer
     6.5  #defer.Deferred.debug = 1
     6.6  from twisted.internet import reactor
     6.7 +from twisted.protocols import http
     6.8  from twisted.web import error
     6.9  from twisted.web import resource
    6.10  from twisted.web import server
    6.11  
    6.12  from xen.xend import sxp
    6.13  from xen.xend import PrettyPrint
    6.14 +from xen.xend.Args import ArgError
    6.15 +from xen.xend.XendError import XendError
    6.16  
    6.17  def uri_pathlist(p):
    6.18      """Split a path into a list.
    6.19 @@ -86,33 +89,45 @@ class SrvBase(resource.Resource):
    6.20          """
    6.21          op = req.args.get('op')
    6.22          if op is None or len(op) != 1:
    6.23 -            req.setResponseCode(404, "Invalid")
    6.24 +            req.setResponseCode(http.NOT_ACCEPTABLE, "Invalid request")
    6.25              return ''
    6.26          op = op[0]
    6.27          op_method = self.get_op_method(op)
    6.28          if op_method is None:
    6.29 -            req.setResponseCode(501, "Not implemented")
    6.30 +            req.setResponseCode(http.NOT_IMPLEMENTED, "Operation not implemented: " + op)
    6.31              req.setHeader("Content-Type", "text/plain")
    6.32 -            req.write("Not implemented: " + op)
    6.33 +            req.write("Operation not implemented: " + op)
    6.34              return ''
    6.35          else:
    6.36 +            return self._perform(op, op_method, req)
    6.37 +
    6.38 +    def _perform(self, op, op_method, req):
    6.39 +        try:
    6.40              val = op_method(op, req)
    6.41 -            if isinstance(val, defer.Deferred):
    6.42 -                val.addCallback(self._cb_perform, req, 1)
    6.43 -                return server.NOT_DONE_YET
    6.44 -            else:
    6.45 -                self._cb_perform(val, req, 0)
    6.46 -                return ''
    6.47 +        except Exception, err:
    6.48 +            return self._perform_err(err, req)
    6.49 +            
    6.50 +        if isinstance(val, defer.Deferred):
    6.51 +            val.addCallback(self._perform_cb, req, dfr=1)
    6.52 +            val.addErrback(self._perform_err, req, dfr=1)
    6.53 +            return server.NOT_DONE_YET
    6.54 +        else:
    6.55 +            self._perform_cb(val, req, 0)
    6.56 +            return ''
    6.57  
    6.58 -    def _cb_perform(self, val, req, dfr):
    6.59 +    def _perform_cb(self, val, req, dfr):
    6.60          """Callback to complete the request.
    6.61          May be called from a Deferred.
    6.62 +
    6.63 +        @param err: the error
    6.64 +        @param req: request causing the error
    6.65 +        @param dfr: deferred flag
    6.66          """
    6.67          if isinstance(val, error.ErrorPage):
    6.68              req.write(val.render(req))
    6.69          elif self.use_sxp(req):
    6.70              req.setHeader("Content-Type", sxp.mime_type)
    6.71 -            sxp.show(val, req)
    6.72 +            sxp.show(val, out=req)
    6.73          else:
    6.74              req.write('<html><head></head><body>')
    6.75              self.print_path(req)
    6.76 @@ -126,6 +141,34 @@ class SrvBase(resource.Resource):
    6.77          if dfr:
    6.78              req.finish()
    6.79  
    6.80 +    def _perform_err(self, err, req, dfr=0):
    6.81 +        """Error callback to complete a request.
    6.82 +        May be called from a Deferred.
    6.83 +
    6.84 +        @param err: the error
    6.85 +        @param req: request causing the error
    6.86 +        @param dfr: deferred flag
    6.87 +        """
    6.88 +        if not (isinstance(err, ArgError) or
    6.89 +                isinstance(err, sxp.ParseError) or
    6.90 +                isinstance(err, XendError)):
    6.91 +            if dfr:
    6.92 +                return err
    6.93 +            else:
    6.94 +                raise
    6.95 +        if self.use_sxp(req):
    6.96 +            req.setHeader("Content-Type", sxp.mime_type)
    6.97 +            sxp.show(['xend.err', str(err)], out=req)
    6.98 +        else:
    6.99 +            req.setHeader("Content-Type", "text/plain")
   6.100 +            req.write('Error in ')
   6.101 +            req.write(op)
   6.102 +            req.write(': ')
   6.103 +            req.write(str(err))
   6.104 +        if dfr:
   6.105 +            req.finish()
   6.106 +        
   6.107 +
   6.108      def print_path(self, req):
   6.109          """Print the path with hyperlinks.
   6.110          """
     7.1 --- a/tools/python/xen/xend/server/SrvConsole.py	Wed Jul 14 07:45:24 2004 +0000
     7.2 +++ b/tools/python/xen/xend/server/SrvConsole.py	Wed Jul 14 10:40:26 2004 +0000
     7.3 @@ -21,19 +21,22 @@ class SrvConsole(SrvDir):
     7.4          return self.perform(req)
     7.5          
     7.6      def render_GET(self, req):
     7.7 -        if self.use_sxp(req):
     7.8 -            req.setHeader("Content-Type", sxp.mime_type)
     7.9 -            sxp.show(self.info.sxpr(), out=req)
    7.10 -        else:
    7.11 -            req.write('<html><head></head><body>')
    7.12 -            self.print_path(req)
    7.13 -            #self.ls()
    7.14 -            req.write('<p>%s</p>' % self.info)
    7.15 -            req.write('<p><a href="%s">Connect to domain %d</a></p>'
    7.16 -                      % (self.info.uri(), self.info.dom2))
    7.17 -            self.form(req)
    7.18 -            req.write('</body></html>')
    7.19 -        return ''
    7.20 +        try:
    7.21 +            if self.use_sxp(req):
    7.22 +                req.setHeader("Content-Type", sxp.mime_type)
    7.23 +                sxp.show(self.info.sxpr(), out=req)
    7.24 +            else:
    7.25 +                req.write('<html><head></head><body>')
    7.26 +                self.print_path(req)
    7.27 +                #self.ls()
    7.28 +                req.write('<p>%s</p>' % self.info)
    7.29 +                req.write('<p><a href="%s">Connect to domain %d</a></p>'
    7.30 +                          % (self.info.uri(), self.info.dom2))
    7.31 +                self.form(req)
    7.32 +                req.write('</body></html>')
    7.33 +            return ''
    7.34 +        except Exception, ex:
    7.35 +            self._perform_err(ex, req)
    7.36  
    7.37      def form(self, req):
    7.38          req.write('<form method="post" action="%s">' % req.prePathURL())
     8.1 --- a/tools/python/xen/xend/server/SrvConsoleDir.py	Wed Jul 14 07:45:24 2004 +0000
     8.2 +++ b/tools/python/xen/xend/server/SrvConsoleDir.py	Wed Jul 14 10:40:26 2004 +0000
     8.3 @@ -31,17 +31,20 @@ class SrvConsoleDir(SrvDir):
     8.4          return v
     8.5  
     8.6      def render_GET(self, req):
     8.7 -        if self.use_sxp(req):
     8.8 -            req.setHeader("Content-Type", sxp.mime_type)
     8.9 -            self.ls_console(req, 1)
    8.10 -        else:
    8.11 -            req.write("<html><head></head><body>")
    8.12 -            self.print_path(req)
    8.13 -            self.ls(req)
    8.14 -            self.ls_console(req)
    8.15 -            #self.form(req.wfile)
    8.16 -            req.write("</body></html>")
    8.17 -        return ''
    8.18 +        try:
    8.19 +            if self.use_sxp(req):
    8.20 +                req.setHeader("Content-Type", sxp.mime_type)
    8.21 +                self.ls_console(req, 1)
    8.22 +            else:
    8.23 +                req.write("<html><head></head><body>")
    8.24 +                self.print_path(req)
    8.25 +                self.ls(req)
    8.26 +                self.ls_console(req)
    8.27 +                #self.form(req.wfile)
    8.28 +                req.write("</body></html>")
    8.29 +            return ''
    8.30 +        except Exception, ex:
    8.31 +            self._perform_err(ex, req)
    8.32  
    8.33      def ls_console(self, req, use_sxp=0):
    8.34          url = req.prePathURL()
     9.1 --- a/tools/python/xen/xend/server/SrvDaemon.py	Wed Jul 14 07:45:24 2004 +0000
     9.2 +++ b/tools/python/xen/xend/server/SrvDaemon.py	Wed Jul 14 10:40:26 2004 +0000
     9.3 @@ -31,6 +31,7 @@ from xen.xend import sxp
     9.4  from xen.xend import PrettyPrint
     9.5  from xen.xend import EventServer
     9.6  eserver = EventServer.instance()
     9.7 +from xen.xend.XendError import XendError
     9.8  
     9.9  from xen.xend.server import SrvServer
    9.10  
    9.11 @@ -114,7 +115,7 @@ class MgmtProtocol(protocol.DatagramProt
    9.12          """
    9.13          print name, req
    9.14          dom = sxp.child_value(req, 'domain')
    9.15 -        if not dom: raise ValueError('Missing domain')
    9.16 +        if not dom: raise XendError('Missing domain')
    9.17          dom = int(dom)
    9.18          console_port = sxp.child_value(req, 'console_port')
    9.19          if console_port:
    9.20 @@ -131,11 +132,11 @@ class MgmtProtocol(protocol.DatagramProt
    9.21      def op_console_disconnect(self, name, req):
    9.22          id = sxp.child_value(req, 'id')
    9.23          if not id:
    9.24 -            raise ValueError('Missing console id')
    9.25 +            raise XendError('Missing console id')
    9.26          id = int(id)
    9.27          console = self.daemon.get_console(id)
    9.28          if not console:
    9.29 -            raise ValueError('Invalid console id')
    9.30 +            raise XendError('Invalid console id')
    9.31          if console.conn:
    9.32              console.conn.loseConnection()
    9.33          return ['ok']
    9.34 @@ -340,7 +341,7 @@ class EventProtocol(protocol.Protocol):
    9.35           return 'op_' + name.replace('.', '_')
    9.36  
    9.37      def operror(self, name, req):
    9.38 -        raise NotImplementedError('Invalid operation: ' +name)
    9.39 +        raise XendError('Invalid operation: ' +name)
    9.40  
    9.41      def dispatch(self, req):
    9.42          op_name = sxp.name(req)
    9.43 @@ -371,7 +372,7 @@ class EventProtocol(protocol.Protocol):
    9.44      def op_console_disconnect(self, name, req):
    9.45          id = sxp.child_value(req, 'id')
    9.46          if not id:
    9.47 -            raise ValueError('Missing console id')
    9.48 +            raise XendError('Missing console id')
    9.49          self.daemon.console_disconnect(id)
    9.50          return ['ok']
    9.51  
    9.52 @@ -707,7 +708,7 @@ class Daemon:
    9.53          """
    9.54          ctrl = self.blkifCF.getInstanceByDom(dom)
    9.55          if not ctrl:
    9.56 -            raise ValueError('No blkif controller: %d' % dom)
    9.57 +            raise XendError('No blkif controller: %d' % dom)
    9.58          print 'blkif_dev_create>', dom, vdev, mode, segment
    9.59          d = ctrl.attachDevice(vdev, mode, segment, recreate=recreate)
    9.60          return d
    9.61 @@ -740,7 +741,7 @@ class Daemon:
    9.62          """
    9.63          ctrl = self.netifCF.getInstanceByDom(dom)
    9.64          if not ctrl:
    9.65 -            raise ValueError('No netif controller: %d' % dom)
    9.66 +            raise XendError('No netif controller: %d' % dom)
    9.67          d = ctrl.attachDevice(vif, config, recreate=recreate)
    9.68          return d
    9.69  
    9.70 @@ -769,7 +770,7 @@ class Daemon:
    9.71          """
    9.72          console = self.get_console(id)
    9.73          if not console:
    9.74 -            raise ValueError('Invalid console id')
    9.75 +            raise XendError('Invalid console id')
    9.76          console.disconnect()
    9.77  
    9.78      def domain_shutdown(self, dom, reason):
    9.79 @@ -777,7 +778,7 @@ class Daemon:
    9.80          """
    9.81          ctrl = self.domainCF.getInstanceByDom(dom)
    9.82          if not ctrl:
    9.83 -            raise ValueError('No domain controller: %d' % dom)
    9.84 +            raise XendError('No domain controller: %d' % dom)
    9.85          ctrl.shutdown(reason)
    9.86          return 0
    9.87          
    10.1 --- a/tools/python/xen/xend/server/SrvDir.py	Wed Jul 14 07:45:24 2004 +0000
    10.2 +++ b/tools/python/xen/xend/server/SrvDir.py	Wed Jul 14 10:40:26 2004 +0000
    10.3 @@ -1,9 +1,20 @@
    10.4  # Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
    10.5  
    10.6 +from twisted.protocols import http
    10.7  from twisted.web import error
    10.8 +
    10.9  from xen.xend import sxp
   10.10 +from xen.xend.XendError import XendError
   10.11 +
   10.12  from SrvBase import SrvBase
   10.13  
   10.14 +class SrvError(error.ErrorPage):
   10.15 +
   10.16 +    def render(self, request):
   10.17 +        val = error.ErrorPage.render(self, request)
   10.18 +        request.setResponseCode(self.code, self.brief)
   10.19 +        return val
   10.20 +
   10.21  class SrvConstructor:
   10.22      """Delayed constructor for sub-servers.
   10.23      Does not import the sub-server class or create the object until needed.
   10.24 @@ -38,11 +49,17 @@ class SrvDir(SrvBase):
   10.25          self.table = {}
   10.26          self.order = []
   10.27  
   10.28 +    def noChild(self, msg):
   10.29 +        return SrvError(http.NOT_FOUND, msg, msg)
   10.30 +
   10.31      def getChild(self, x, req):
   10.32          if x == '': return self
   10.33 -        val = self.get(x)
   10.34 +        try:
   10.35 +            val = self.get(x)
   10.36 +        except XendError, ex:
   10.37 +            return self.noChild(str(ex))
   10.38          if val is None:
   10.39 -            return error.NoResource('Not found')
   10.40 +            return self.noChild('Not found ' + str(x))
   10.41          else:
   10.42              return val
   10.43  
   10.44 @@ -59,16 +76,19 @@ class SrvDir(SrvBase):
   10.45          self.order.append(x)
   10.46  
   10.47      def render_GET(self, req):
   10.48 -        if self.use_sxp(req):
   10.49 -            req.setHeader("Content-type", sxp.mime_type)
   10.50 -            self.ls(req, 1)
   10.51 -        else:
   10.52 -            req.write('<html><head></head><body>')
   10.53 -            self.print_path(req)
   10.54 -            self.ls(req)
   10.55 -            self.form(req)
   10.56 -            req.write('</body></html>')
   10.57 -        return ''
   10.58 +        try:
   10.59 +            if self.use_sxp(req):
   10.60 +                req.setHeader("Content-type", sxp.mime_type)
   10.61 +                self.ls(req, 1)
   10.62 +            else:
   10.63 +                req.write('<html><head></head><body>')
   10.64 +                self.print_path(req)
   10.65 +                self.ls(req)
   10.66 +                self.form(req)
   10.67 +                req.write('</body></html>')
   10.68 +            return ''
   10.69 +        except Exception, ex:
   10.70 +            self._perform_err(ex, req)
   10.71              
   10.72      def ls(self, req, use_sxp=0):
   10.73          url = req.prePathURL()
    11.1 --- a/tools/python/xen/xend/server/SrvDmesg.py	Wed Jul 14 07:45:24 2004 +0000
    11.2 +++ b/tools/python/xen/xend/server/SrvDmesg.py	Wed Jul 14 10:40:26 2004 +0000
    11.3 @@ -14,16 +14,19 @@ class SrvDmesg(SrvDir):
    11.4          self.xd = XendDmesg.instance()
    11.5  
    11.6      def render_GET(self, req):
    11.7 -        if self.use_sxp(req):
    11.8 -            req.setHeader("Content-Type", sxp.mime_type)
    11.9 -            sxp.show(['dmesg'] + self.info(), out=req)
   11.10 -        else:
   11.11 -            req.write('<html><head></head><body>')
   11.12 -            req.write('<pre>')
   11.13 -            self.print_path(req)
   11.14 -            req.write(self.info()[0])
   11.15 -            req.write('</pre></body></html>')
   11.16 -        return ''
   11.17 +        try:
   11.18 +            if self.use_sxp(req):
   11.19 +                req.setHeader("Content-Type", sxp.mime_type)
   11.20 +                sxp.show(['dmesg'] + self.info(), out=req)
   11.21 +            else:
   11.22 +                req.write('<html><head></head><body>')
   11.23 +                req.write('<pre>')
   11.24 +                self.print_path(req)
   11.25 +                req.write(self.info()[0])
   11.26 +                req.write('</pre></body></html>')
   11.27 +            return ''
   11.28 +        except Exception, ex:
   11.29 +            self._perform_err(ex, req)
   11.30              
   11.31      def info(self):
   11.32          return self.xd.info()
    12.1 --- a/tools/python/xen/xend/server/SrvDomain.py	Wed Jul 14 07:45:24 2004 +0000
    12.2 +++ b/tools/python/xen/xend/server/SrvDomain.py	Wed Jul 14 10:40:26 2004 +0000
    12.3 @@ -100,15 +100,8 @@ class SrvDomain(SrvDir):
    12.4          fn = FormFn(self.xd.domain_device_create,
    12.5                      [['dom', 'int'],
    12.6                       ['config', 'sxpr']])
    12.7 -        try:
    12.8 -            d = fn(req.args, {'dom': self.dom.id})
    12.9 -            d.addErrback(self._op_device_create_err, req)
   12.10 -            return d
   12.11 -        except ValueError, ex:
   12.12 -            return ['err', str(ex)]
   12.13 -
   12.14 -    def _op_device_create_err(self, err, req):
   12.15 -        return ['err', str(err)]
   12.16 +        d = fn(req.args, {'dom': self.dom.id})
   12.17 +        return d
   12.18  
   12.19      def op_device_destroy(self, op, req):
   12.20          fn = FormFn(self.xd.domain_device_destroy,
    13.1 --- a/tools/python/xen/xend/server/SrvDomainDir.py	Wed Jul 14 07:45:24 2004 +0000
    13.2 +++ b/tools/python/xen/xend/server/SrvDomainDir.py	Wed Jul 14 10:40:26 2004 +0000
    13.3 @@ -9,6 +9,7 @@ from twisted.web import error
    13.4  from xen.xend import sxp
    13.5  from xen.xend import XendDomain
    13.6  from xen.xend.Args import FormFn
    13.7 +from xen.xend.XendError import XendError
    13.8  
    13.9  from SrvDir import SrvDir
   13.10  from SrvDomain import SrvDomain
   13.11 @@ -23,13 +24,10 @@ class SrvDomainDir(SrvDir):
   13.12  
   13.13      def domain(self, x):
   13.14          val = None
   13.15 -        try:
   13.16 -            dom = self.xd.domain_get(x)
   13.17 -            if not dom: raise KeyError('No such domain')
   13.18 -            val = SrvDomain(dom)
   13.19 -        except KeyError, ex:
   13.20 -            print 'SrvDomainDir>', ex
   13.21 -            pass
   13.22 +        dom = self.xd.domain_get(x)
   13.23 +        if not dom:
   13.24 +            raise XendError('No such domain ' + str(x))
   13.25 +        val = SrvDomain(dom)
   13.26          return val
   13.27  
   13.28      def get(self, x):
   13.29 @@ -44,6 +42,7 @@ class SrvDomainDir(SrvDir):
   13.30          Expects the domain config in request parameter 'config' in SXP format.
   13.31          """
   13.32          ok = 0
   13.33 +        errmsg = ''
   13.34          try:
   13.35              configstring = req.args.get('config')[0]
   13.36              print 'config:', configstring
   13.37 @@ -55,12 +54,12 @@ class SrvDomainDir(SrvDir):
   13.38          except Exception, ex:
   13.39              print 'op_create> Exception in config', ex
   13.40              traceback.print_exc()
   13.41 +            errmsg = 'Configuration error ' + str(ex)
   13.42 +        except sxp.ParseError, ex:
   13.43 +            errmsg = 'Invalid configuration ' + str(ex)
   13.44          if not ok:
   13.45 -            req.setResponseCode(http.BAD_REQUEST, "Invalid configuration")
   13.46 -            return "Invalid configuration"
   13.47 -            return error.ErrorPage(http.BAD_REQUEST,
   13.48 -                                   "Invalid",
   13.49 -                                   "Invalid configuration")
   13.50 +            req.setResponseCode(http.BAD_REQUEST, errmsg)
   13.51 +            return errmsg
   13.52          try:
   13.53              deferred = self.xd.domain_create(config)
   13.54              deferred.addCallback(self._op_create_cb, configstring, req)
   13.55 @@ -71,10 +70,6 @@ class SrvDomainDir(SrvDir):
   13.56              traceback.print_exc()
   13.57              req.setResponseCode(http.BAD_REQUEST, "Error creating domain: " + str(ex))
   13.58              return str(ex)
   13.59 -            #return error.ErrorPage(http.BAD_REQUEST,
   13.60 -            #                       "Error creating domain",
   13.61 -            #                       str(ex))
   13.62 -                                   
   13.63  
   13.64      def _op_create_cb(self, dominfo, configstring, req):
   13.65          """Callback to handle deferred domain creation.
   13.66 @@ -113,7 +108,7 @@ class SrvDomainDir(SrvDir):
   13.67                      [['file', 'str']])
   13.68          deferred = fn(req.args)
   13.69          deferred.addCallback(self._op_restore_cb, req)
   13.70 -        deferred.addErrback(self._op_restore_err, req)
   13.71 +        #deferred.addErrback(self._op_restore_err, req)
   13.72          return deferred
   13.73  
   13.74      def _op_restore_cb(self, dominfo, req):
   13.75 @@ -140,17 +135,20 @@ class SrvDomainDir(SrvDir):
   13.76          return self.perform(req)
   13.77  
   13.78      def render_GET(self, req):
   13.79 -        if self.use_sxp(req):
   13.80 -            req.setHeader("Content-Type", sxp.mime_type)
   13.81 -            self.ls_domain(req, 1)
   13.82 -        else:
   13.83 -            req.write("<html><head></head><body>")
   13.84 -            self.print_path(req)
   13.85 -            self.ls(req)
   13.86 -            self.ls_domain(req)
   13.87 -            self.form(req)
   13.88 -            req.write("</body></html>")
   13.89 -        return ''
   13.90 +        try:
   13.91 +            if self.use_sxp(req):
   13.92 +                req.setHeader("Content-Type", sxp.mime_type)
   13.93 +                self.ls_domain(req, 1)
   13.94 +            else:
   13.95 +                req.write("<html><head></head><body>")
   13.96 +                self.print_path(req)
   13.97 +                self.ls(req)
   13.98 +                self.ls_domain(req)
   13.99 +                self.form(req)
  13.100 +                req.write("</body></html>")
  13.101 +            return ''
  13.102 +        except Exception, ex:
  13.103 +            self._perform_err(ex, req)
  13.104  
  13.105      def ls_domain(self, req, use_sxp=0):
  13.106          url = req.prePathURL()
    14.1 --- a/tools/python/xen/xend/server/SrvNode.py	Wed Jul 14 07:45:24 2004 +0000
    14.2 +++ b/tools/python/xen/xend/server/SrvNode.py	Wed Jul 14 10:40:26 2004 +0000
    14.3 @@ -45,22 +45,25 @@ class SrvNode(SrvDir):
    14.4          return self.perform(req)
    14.5  
    14.6      def render_GET(self, req):
    14.7 -        if self.use_sxp(req):
    14.8 -            req.setHeader("Content-Type", sxp.mime_type)
    14.9 -            sxp.show(['node'] + self.info(), out=req)
   14.10 -        else:
   14.11 -            url = req.prePathURL()
   14.12 -            if not url.endswith('/'):
   14.13 -                url += '/'
   14.14 -            req.write('<html><head></head><body>')
   14.15 -            self.print_path(req)
   14.16 -            req.write('<ul>')
   14.17 -            for d in self.info():
   14.18 -                req.write('<li> %10s: %s' % (d[0], str(d[1])))
   14.19 -            req.write('<li><a href="' +url + 'dmesg">Xen dmesg output</a>')
   14.20 -            req.write('</ul>')
   14.21 -            req.write('</body></html>')
   14.22 -        return ''
   14.23 +        try:
   14.24 +            if self.use_sxp(req):
   14.25 +                req.setHeader("Content-Type", sxp.mime_type)
   14.26 +                sxp.show(['node'] + self.info(), out=req)
   14.27 +            else:
   14.28 +                url = req.prePathURL()
   14.29 +                if not url.endswith('/'):
   14.30 +                    url += '/'
   14.31 +                req.write('<html><head></head><body>')
   14.32 +                self.print_path(req)
   14.33 +                req.write('<ul>')
   14.34 +                for d in self.info():
   14.35 +                    req.write('<li> %10s: %s' % (d[0], str(d[1])))
   14.36 +                req.write('<li><a href="' + url + 'dmesg">Xen dmesg output</a>')
   14.37 +                req.write('</ul>')
   14.38 +                req.write('</body></html>')
   14.39 +            return ''
   14.40 +        except Exception, ex:
   14.41 +            self._perform_err(ex, req)
   14.42              
   14.43      def info(self):
   14.44          return self.xn.info()
    15.1 --- a/tools/python/xen/xend/server/domain.py	Wed Jul 14 07:45:24 2004 +0000
    15.2 +++ b/tools/python/xen/xend/server/domain.py	Wed Jul 14 10:40:26 2004 +0000
    15.3 @@ -1,5 +1,7 @@
    15.4  # Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
    15.5  
    15.6 +from xen.xend.XendError import XendError
    15.7 +
    15.8  import channel
    15.9  import controller
   15.10  from messages import *
   15.11 @@ -57,6 +59,6 @@ class DomainController(controller.Contro
   15.12          """
   15.13          msgtype = self.reasons.get(reason)
   15.14          if not msgtype:
   15.15 -            raise ValueError('invalid reason:' + reason)
   15.16 +            raise XendError('invalid reason:' + reason)
   15.17          msg = packMsg(msgtype, {})
   15.18          self.writeRequest(msg)
    16.1 --- a/tools/python/xen/xend/server/netif.py	Wed Jul 14 07:45:24 2004 +0000
    16.2 +++ b/tools/python/xen/xend/server/netif.py	Wed Jul 14 10:40:26 2004 +0000
    16.3 @@ -8,6 +8,7 @@ from twisted.internet import defer
    16.4  from xen.xend import sxp
    16.5  from xen.xend import PrettyPrint
    16.6  from xen.xend import Vifctl
    16.7 +from xen.xend.XendError import XendError
    16.8  
    16.9  import channel
   16.10  import controller
   16.11 @@ -123,9 +124,9 @@ class NetDev(controller.Dev):
   16.12          self.ipaddr = None
   16.13          
   16.14          vmac = sxp.child_value(config, 'mac')
   16.15 -        if not vmac: raise ValueError("invalid mac")
   16.16 +        if not vmac: raise XendError("invalid mac")
   16.17          mac = [ int(x, 16) for x in vmac.split(':') ]
   16.18 -        if len(mac) != 6: raise ValueError("invalid mac")
   16.19 +        if len(mac) != 6: raise XendError("invalid mac")
   16.20          self.mac = mac
   16.21  
   16.22          self.bridge = sxp.child_value(config, 'bridge')