Пример #1
0
		def handle_fail(fail):
			self.log.warning(fail.type)
			self.log.warning(fail.getErrorMessage())
			if fail.type != xmlrpclib.Fault:
				raise Fault (6000, "Internal ZAPI error: %s" % fail)
			else:
				raise fail
Пример #2
0
    def render_POST(self, request):
        # Find out the user agent. User agent 'applicationserver-client' gets
        # a special treatment (pickled Fault)
        userAgent = request.getHeader("user-agent")
        isApplicationserverClient = bool(
            userAgent == "applicationserver-client")

        request.content.seek(0, 0)
        request.setHeader("content-type", "text/xml")
        try:
            args, functionPath = xmlrpclib.loads(request.content.read())
        except Exception, e:
            f = Fault(self.FAILURE, "Can't deserialize input: %s" % (e, ))
            self._cbRender(f, request)
Пример #3
0
 def _auth_validate(self, request, func_name, args):
     cleartext_token = '%s:%s' % (self.config.username,
                                  self.config.password)
     token = '%s:%s' % (request.getUser(), request.getPassword())
     if token != cleartext_token:
         self.logger.error(
             "Invalid login / password for HTTP basic authentication")
         request.setResponseCode(http.UNAUTHORIZED)
         self._cbRender(
             Fault(
                 http.UNAUTHORIZED,
                 "Unauthorized: invalid credentials to connect to this Pulse 2 Scheduler Proxy, basic HTTP authentication is required"
             ), request, func_name, args)
         return False
     else:
         return True
Пример #4
0
		def check_target_image_id(results, info):
			if results[0] == 0:
				info['target_image_id'] = results[1]
				return info
			else:
				raise Fault(6004, "Internal ZAPI error: %s" % results[1])
Пример #5
0
			def handle_multi_result(result, id_list):
				if result[0] == 0:
					id_list.append(result[1])
					return id_list
				else:
					raise Fault(6005, "Internal ZAPI error: %s" % result[1])
Пример #6
0
		def check_contact(results, info):
			if results[0] == 0:
				info['is_contact'] = results[1]
				return info
			else:
				raise Fault(6001, "Internal ZAPI error: %s" % results[1])
Пример #7
0
        userAgent = request.getHeader("user-agent")
        isApplicationserverClient = bool(
            userAgent == "applicationserver-client")

        request.content.seek(0, 0)
        request.setHeader("content-type", "text/xml")
        try:
            args, functionPath = xmlrpclib.loads(request.content.read())
        except Exception, e:
            f = Fault(self.FAILURE, "Can't deserialize input: %s" % (e, ))
            self._cbRender(f, request)
        else:
            try:
                function = self._getFunction(functionPath, request)
            except (NoSuchService, NoSuchMethod), e:
                self._cbRender(Fault(e.ERRNO, e.MESSAGE), request)
            except Fault, f:
                self._cbRender(f, request)
            else:
                defer.maybeDeferred(function, *args).addErrback(
                    self._ebRender, isApplicationserverClient).addCallback(
                        self._cbRender, request)
        return server.NOT_DONE_YET

    #Hack to work on old Twisted versions
    if not hasattr(xmlrpc.XMLRPC, 'render_POST'):
        render = render_POST

    def _ebRender(self, failure, isApplicationserverClient=False):
        '''Custom error render method'''
        if isinstance(failure.value, xmlrpclib.Fault):