ia64/xen-unstable

changeset 2866:e123be8ad5cc

bitkeeper revision 1.1159.155.7 (41896362-2P6ibesMBXM0pV5gks0Bw)

Apply changes from Mike Wray:
- Get domain creation errors returned to the caller.
- Add logging for domain create failures.
author cl349@freefall.cl.cam.ac.uk
date Wed Nov 03 23:01:54 2004 +0000 (2004-11-03)
parents 8a60d9e79b3c
children aeaa8b6b072d
files tools/python/xen/xend/server/SrvBase.py tools/python/xen/xend/server/SrvDomainDir.py
line diff
     1.1 --- a/tools/python/xen/xend/server/SrvBase.py	Wed Nov 03 22:51:40 2004 +0000
     1.2 +++ b/tools/python/xen/xend/server/SrvBase.py	Wed Nov 03 23:01:54 2004 +0000
     1.3 @@ -8,17 +8,18 @@ import types
     1.4  import StringIO
     1.5  
     1.6  from twisted.internet import defer
     1.7 -#defer.Deferred.debug = 1
     1.8  from twisted.internet import reactor
     1.9  from twisted.protocols import http
    1.10  from twisted.web import error
    1.11  from twisted.web import resource
    1.12  from twisted.web import server
    1.13 +from twisted.python.failure import Failure
    1.14  
    1.15  from xen.xend import sxp
    1.16  from xen.xend import PrettyPrint
    1.17  from xen.xend.Args import ArgError
    1.18  from xen.xend.XendError import XendError
    1.19 +from xen.xend.XendLogging import log
    1.20  
    1.21  def uri_pathlist(p):
    1.22      """Split a path into a list.
    1.23 @@ -105,17 +106,17 @@ class SrvBase(resource.Resource):
    1.24          try:
    1.25              val = op_method(op, req)
    1.26          except Exception, err:
    1.27 -            return self._perform_err(err, req)
    1.28 +            return self._perform_err(err, op, req)
    1.29              
    1.30          if isinstance(val, defer.Deferred):
    1.31 -            val.addCallback(self._perform_cb, req, dfr=1)
    1.32 -            val.addErrback(self._perform_err, req, dfr=1)
    1.33 +            val.addCallback(self._perform_cb, op, req, dfr=1)
    1.34 +            val.addErrback(self._perform_err, op, req, dfr=1)
    1.35              return server.NOT_DONE_YET
    1.36          else:
    1.37 -            self._perform_cb(val, req, 0)
    1.38 +            self._perform_cb(val, op, req, dfr=0)
    1.39              return ''
    1.40  
    1.41 -    def _perform_cb(self, val, req, dfr):
    1.42 +    def _perform_cb(self, val, op, req, dfr=0):
    1.43          """Callback to complete the request.
    1.44          May be called from a Deferred.
    1.45  
    1.46 @@ -141,7 +142,7 @@ class SrvBase(resource.Resource):
    1.47          if dfr:
    1.48              req.finish()
    1.49  
    1.50 -    def _perform_err(self, err, req, dfr=0):
    1.51 +    def _perform_err(self, err, op, req, dfr=0):
    1.52          """Error callback to complete a request.
    1.53          May be called from a Deferred.
    1.54  
    1.55 @@ -149,13 +150,16 @@ class SrvBase(resource.Resource):
    1.56          @param req: request causing the error
    1.57          @param dfr: deferred flag
    1.58          """
    1.59 -        if not (isinstance(err, ArgError) or
    1.60 -                isinstance(err, sxp.ParseError) or
    1.61 -                isinstance(err, XendError)):
    1.62 +        if isinstance(err, Failure):
    1.63 +            err = err.getErrorMessage()
    1.64 +        elif not (isinstance(err, ArgError) or
    1.65 +                  isinstance(err, sxp.ParseError) or
    1.66 +                  isinstance(err, XendError)):
    1.67              if dfr:
    1.68                  return err
    1.69              else:
    1.70                  raise
    1.71 +        log.exception("op=%s: %s", op, str(err))
    1.72          if self.use_sxp(req):
    1.73              req.setHeader("Content-Type", sxp.mime_type)
    1.74              sxp.show(['xend.err', str(err)], out=req)
     2.1 --- a/tools/python/xen/xend/server/SrvDomainDir.py	Wed Nov 03 22:51:40 2004 +0000
     2.2 +++ b/tools/python/xen/xend/server/SrvDomainDir.py	Wed Nov 03 23:01:54 2004 +0000
     2.3 @@ -11,6 +11,7 @@ from xen.xend import sxp
     2.4  from xen.xend import XendDomain
     2.5  from xen.xend.Args import FormFn
     2.6  from xen.xend.XendError import XendError
     2.7 +from xen.xend.XendLogging import log
     2.8  
     2.9  from SrvDir import SrvDir
    2.10  from SrvDomain import SrvDomain
    2.11 @@ -59,18 +60,15 @@ class SrvDomainDir(SrvDir):
    2.12          except sxp.ParseError, ex:
    2.13              errmsg = 'Invalid configuration ' + str(ex)
    2.14          if not ok:
    2.15 -            req.setResponseCode(http.BAD_REQUEST, errmsg)
    2.16 -            return errmsg
    2.17 +            raise XendError(errmsg)
    2.18          try:
    2.19              deferred = self.xd.domain_create(config)
    2.20              deferred.addCallback(self._op_create_cb, configstring, req)
    2.21 -            deferred.addErrback(self._op_create_err, req)
    2.22              return deferred
    2.23          except Exception, ex:
    2.24              print 'op_create> Exception creating domain:'
    2.25              traceback.print_exc()
    2.26 -            req.setResponseCode(http.BAD_REQUEST, "Error creating domain: " + str(ex))
    2.27 -            return str(ex)
    2.28 +            raise XendError("Error creating domain: " + str(ex))
    2.29  
    2.30      def _op_create_cb(self, dominfo, configstring, req):
    2.31          """Callback to handle deferred domain creation.
    2.32 @@ -92,27 +90,15 @@ class SrvDomainDir(SrvDir):
    2.33              out.close()
    2.34              return val
    2.35  
    2.36 -    def _op_create_err(self, err, req):
    2.37 -        """Callback to handle errors in deferred domain creation.
    2.38 -        """
    2.39 -        if isinstance(err, Failure):
    2.40 -            err = err.getErrorMessage()
    2.41 -        print 'op_create> Deferred Exception creating domain:', err
    2.42 -        traceback.print_exc()
    2.43 -        req.setResponseCode(http.BAD_REQUEST, "Error creating domain: " + str(err))
    2.44 -        return str(err)
    2.45 -
    2.46      def op_restore(self, op, req):
    2.47          """Restore a domain from file.
    2.48  
    2.49          @return: deferred
    2.50          """
    2.51 -        #todo: return is deferred. May need ok and err callbacks.
    2.52          fn = FormFn(self.xd.domain_restore,
    2.53                      [['file', 'str']])
    2.54          deferred = fn(req.args)
    2.55          deferred.addCallback(self._op_restore_cb, req)
    2.56 -        #deferred.addErrback(self._op_restore_err, req)
    2.57          return deferred
    2.58  
    2.59      def _op_restore_cb(self, dominfo, req):
    2.60 @@ -130,13 +116,6 @@ class SrvDomainDir(SrvDir):
    2.61              out.close()
    2.62              return val
    2.63  
    2.64 -    def _op_restore_err(self, err, req):
    2.65 -        if isinstance(err, Failure):
    2.66 -            err = err.getErrorMessage()
    2.67 -        print 'op_create> Deferred Exception restoring domain:', err
    2.68 -        req.setResponseCode(http.BAD_REQUEST, "Error restoring domain: "+ str(err))
    2.69 -        return str(err)
    2.70 -        
    2.71      def render_POST(self, req):
    2.72          return self.perform(req)
    2.73