コード例 #1
0
class BackendPublicFunctions(object):
    """
  All public functions of this class are automatically exposed as part of the
  xmlrpc interface.
  """
    def _dispatch(self, method, args):
        """
    We provide a _dispatch function (which SimpleXMLRPCServer looks for and
    uses) so that we can log exceptions due to our programming errors within
    the backend as well to detect incorrect usage by clients.
    """

        try:
            # Get the requested function (making sure it exists).
            try:
                func = getattr(self, method)
            except AttributeError:
                raise InvalidRequestError("The requested method '" + method +
                                          "' doesn't exist.")

            # Call the requested function.
            return func(*args)

        except NodemanagerCommunicationError, e:
            raise xmlrpclib.Fault(100, "Node communication failure: " + str(e))

        except (DoesNotExistError, InvalidRequestError, AssertionError):
            log.error("The backend was used incorrectly: " +
                      traceback.format_exc())
            raise
コード例 #2
0
    def _dispatch(self, method, args):
        """
    We provide a _dispatch function (which SimpleXMLRPCServer looks for and
    uses) so that we can log exceptions due to our programming errors within
    thelockserver as well to detect incorrect usage by clients. When an
    internal lockserver error is detected, this method will signal to the main
    server thread to shutdown.
    """
        global lockserver_had_error

        try:
            # Get the requested function (making sure it exists).
            try:
                func = getattr(self, method)
            except AttributeError:
                raise LockserverInvalidRequestError("The requested method '" +
                                                    method +
                                                    "' doesn't exist.")

            # Call the requested function.
            return func(*args)

        except LockserverInvalidRequestError:
            log.error("The lockserver was used incorrectly: " +
                      traceback.format_exc())
            raise

        except:
            # We assume all other exceptions are bugs in the lockserver.
            # If there is a bug in the lockserver, that's really bad. We terminate the
            # lockserver in this case rather than risk incorrect locking behavior.

            # This will tell the server thread to exit.
            lockserver_had_error = True

            message = "The lockserver had an internal error and is exiting." + traceback.format_exc(
            )
            log.critical(message)

            # Send an email to the addresses listed in settings.ADMINS
            if not settings.DEBUG:
                subject = "Critical SeattleGeni lockserver error"
                django.core.mail.mail_admins(subject, message)

            # This request will likely end up seeing an xmlrpclib.ProtocolError due to the
            # shutdown, regardless of this exception.
            raise
コード例 #3
0
    def _dispatch(self, method, args):
        """
    We provide a _dispatch function (which SimpleXMLRPCServer looks for and
    uses) so that we can log exceptions due to our programming errors within
    thelockserver as well to detect incorrect usage by clients. When an
    internal lockserver error is detected, this method will signal to the main
    server thread to shutdown.
    """
        global lockserver_had_error

        try:
            # Get the requested function (making sure it exists).
            try:
                func = getattr(self, method)
            except AttributeError:
                raise LockserverInvalidRequestError("The requested method '" + method + "' doesn't exist.")

            # Call the requested function.
            return func(*args)

        except LockserverInvalidRequestError:
            log.error("The lockserver was used incorrectly: " + traceback.format_exc())
            raise

        except:
            # We assume all other exceptions are bugs in the lockserver.
            # If there is a bug in the lockserver, that's really bad. We terminate the
            # lockserver in this case rather than risk incorrect locking behavior.

            # This will tell the server thread to exit.
            lockserver_had_error = True

            message = "The lockserver had an internal error and is exiting." + traceback.format_exc()
            log.critical(message)

            # Send an email to the addresses listed in settings.ADMINS
            if not settings.DEBUG:
                subject = "Critical SeattleGeni lockserver error"
                django.core.mail.mail_admins(subject, message)

            # This request will likely end up seeing an xmlrpclib.ProtocolError due to the
            # shutdown, regardless of this exception.
            raise
コード例 #4
0
ファイル: views.py プロジェクト: SeattleTestbed/clearinghouse
  def _dispatch(self, method, args):
    """
    We provide a _dispatch function (which SimpleXMLRPCServer looks for and
    uses) so that we can log exceptions due to our programming errors within
    clearinghouse as well to detect incorrect usage by clients.
    """
      
    try:
      # Get the requested function (making sure it exists).
      try:
        func = getattr(self, method)
      except AttributeError:
        raise InvalidRequestError("The requested method '" + method + "' doesn't exist.")
      
      # Call the requested function.
      return func(*args)
    
    except InvalidRequestError:
      log.error("The xmlrpc server was used incorrectly: " + traceback.format_exc())
      raise
    
    except xmlrpclib.Fault:
      # A xmlrpc Fault was intentionally raised by the code in this module.
      raise
    
    except Exception, e:
      # We assume all other exceptions are bugs in our code.

      # We use the log message as the basis for the email message, as well.
      logmessage = "Internal error while handling an xmlrpc request: " + traceback.format_exc()
      log.critical(logmessage)

      # Normally django will send an email to the ADMINS defined in settings.py
      # when an exception occurs. However, our xmlrpc dispatcher will turn this
      # into a Fault that is returned to the client. So, django won't see it as
      # an uncaught exception. Therefore, we have to send it ourselves.
      if not settings.DEBUG:
        subject = "Error handling xmlrpc request '" + method + "': " + str(type(e)) + " " + str(e)
        
        emailmessage = logmessage + "\n\n"
        emailmessage += "XMLRPC method called: " + method + "\n"
        
        # If the first argument looks like auth info, don't include the
        # api_key in the email we send. Otherwise, include all the args.
        # We wrap this in a try block just in case we screw this up we want to
        # be sure we get an email still.
        try:
          if len(args) > 0 and isinstance(args[0], dict) and "username" in args[0]:
            emailmessage += "Username: "******"username"]) + "\n"
            if len(args) > 1:
              emailmessage += "Non-auth arguments: " + str(args[1:]) + "\n"
            else:
              emailmessage += "There were no non-auth arguments." + "\n"
          else:
            emailmessage += "Arguments: " + str(args) + "\n"
        except:
          pass
          
        # Send an email to the addresses listed in settings.ADMINS
        django.core.mail.mail_admins(subject, emailmessage)
      
      # It's not unlikely that the user ends up seeing this message, so we
      # are careful about what the content of the message is. We don't
      # include the exception trace.
      raise xmlrpclib.Fault(FAULTCODE_INTERNALERROR, "Internal error while handling the xmlrpc request.")
コード例 #5
0
ファイル: views.py プロジェクト: ericvelazquez/clearinghouse
    def _dispatch(self, method, args):
        """
    We provide a _dispatch function (which SimpleXMLRPCServer looks for and
    uses) so that we can log exceptions due to our programming errors within
    clearinghouse as well to detect incorrect usage by clients.
    """

        try:
            # Get the requested function (making sure it exists).
            try:
                func = getattr(self, method)
            except AttributeError:
                raise InvalidRequestError("The requested method '" + method +
                                          "' doesn't exist.")

            # Call the requested function.
            return func(*args)

        except InvalidRequestError:
            log.error("The xmlrpc server was used incorrectly: " +
                      traceback.format_exc())
            raise

        except xmlrpclib.Fault:
            # A xmlrpc Fault was intentionally raised by the code in this module.
            raise

        except Exception, e:
            # We assume all other exceptions are bugs in our code.

            # We use the log message as the basis for the email message, as well.
            logmessage = "Internal error while handling an xmlrpc request: " + traceback.format_exc(
            )
            log.critical(logmessage)

            # Normally django will send an email to the ADMINS defined in settings.py
            # when an exception occurs. However, our xmlrpc dispatcher will turn this
            # into a Fault that is returned to the client. So, django won't see it as
            # an uncaught exception. Therefore, we have to send it ourselves.
            if not settings.DEBUG:
                subject = "Error handling xmlrpc request '" + method + "': " + str(
                    type(e)) + " " + str(e)

                emailmessage = logmessage + "\n\n"
                emailmessage += "XMLRPC method called: " + method + "\n"

                # If the first argument looks like auth info, don't include the
                # api_key in the email we send. Otherwise, include all the args.
                # We wrap this in a try block just in case we screw this up we want to
                # be sure we get an email still.
                try:
                    if len(args) > 0 and isinstance(
                            args[0], dict) and "username" in args[0]:
                        emailmessage += "Username: "******"username"]) + "\n"
                        if len(args) > 1:
                            emailmessage += "Non-auth arguments: " + str(
                                args[1:]) + "\n"
                        else:
                            emailmessage += "There were no non-auth arguments." + "\n"
                    else:
                        emailmessage += "Arguments: " + str(args) + "\n"
                except:
                    pass

                # Send an email to the addresses listed in settings.ADMINS
                django.core.mail.mail_admins(subject, emailmessage)

            # It's not unlikely that the user ends up seeing this message, so we
            # are careful about what the content of the message is. We don't
            # include the exception trace.
            raise xmlrpclib.Fault(
                FAULTCODE_INTERNALERROR,
                "Internal error while handling the xmlrpc request.")
コード例 #6
0
ファイル: models.py プロジェクト: asm582/clearinghouse
# Called when new database connections are created (see below).
def _prepare_newly_created_db_connection(sender, **kwargs):
  from clearinghouse.common.api import maindb
  maindb.init_maindb()

# If this is a modern-enough version of django to support specifying a function
# to be called on database connection creation, then have it call init_maindb()
# at that time. This is to help prevent init_maindb() from accidentally not
# being called when it should be.
if django.VERSION >= (1,1):
  # connection_created only exists with django >= 1.1
  import django.db.backends.signals
  django.db.backends.signals.connection_created.connect(_prepare_newly_created_db_connection)
else:
  log.error("You must use django >= 1.1 in order to support automatically " +
            "perform custom database connection initialization. (See settings.py)")






class GeniUser(DjangoUser):
  """
  Defines the GeniUser model. A GeniUser record represents a SeattleGeni user.
  
  By extending the DjangoUser model, django will still create a separate table
  in the database for the GeniUser model but will take care of making it look
  the same to us.
  """