Esempio n. 1
0
 def __generateResponse(self,request,response,code=200):
     """
     Takes care of automatically rendering the response and converting it to appropriate format (text,XML,JSON,YAML)
     depending on what the caller can accept. Returns Response
     """
     if isinstance(response, str):
         return Response(code,response,{HttpHeader.CONTENT_TYPE:MediaType.TEXT_PLAIN})
     elif isinstance(response, Response):
         return response
     else:
         (content,contentType) = self.__convertObjectToContentType(request, response)
         return Response(code,content,{HttpHeader.CONTENT_TYPE:contentType})
Esempio n. 2
0
 def put(self, request, customerId, addressId, streetNumber, streetName,
         stateCode, countryCode):
     address = DB.getCustomerAddress(customerId, addressId)
     (address.streetNumber, address.streetName, address.stateCode,
      address.countryCode) = (streetNumber, streetName, stateCode,
                              countryCode)
     return Response(200)
Esempio n. 3
0
 def post(self, request, customerId, addressId, streetNumber, streetName,
          stateCode, countryCode):
     c = DB.getCustomer(customerId)
     address = CustomerAddress(streetNumber, streetName, stateCode,
                               countryCode)
     c.addresses[addressId] = address
     return Response(201)
Esempio n. 4
0
 def __finishDeferred(self, val, request):
     """Finishes any Defered/inlineCallback methods. Returns Response"""
     if isinstance(val, Response):
         return val
     elif val != None:
         try:
             return self.__generateResponse(request, val)
         except Exception as ex:
             msg = "Unexpected server error: %s\n%s" % (type(ex), ex)
             return self.__createErrorResponse(request, 500, msg)
     else:
         return Response(209, None)
Esempio n. 5
0
    def get_node_list(self, request, **kwargs):
        nodes_list = []
        for node_svc in service.IServiceCollection(self.cc_svc):
            node_dict = {
                'name': node_svc.name,
                'uri': node_svc.nagios_uri,
                'hosts': node_svc.for_json(),
            }

            node_dict['path'] = "/%s/" % slugify(node_svc.name)
            node_dict[
                'hosts_lastupdate_utc'] = node_svc.hosts_lastupdate_utc.strftime(
                    "%d-%m-%Y %H:%M:%S")
            node_dict['hosts_error'] = node_svc.hosts_error
            node_dict[
                'services_lastupdate_utc'] = node_svc.services_lastupdate_utc.strftime(
                    "%d-%m-%Y %H:%M:%S")
            node_dict['services_error'] = node_svc.services_error

            nodes_list.append(node_dict)
        data = json.dumps(nodes_list)
        return Response(200, data, {'Content-Type': 'application/json'})
Esempio n. 6
0
 def put(self, request, customerId, firstName, lastName):
     c = DB.getCustomer(customerId)
     (c.firstName, c.lastName) = (firstName, lastName)
     return Response(200)
Esempio n. 7
0
 def post(self, request, customerId, firstName, lastName):
     customer = Customer(customerId, firstName, lastName)
     DB.saveCustomer(customer)
     return Response(201)
Esempio n. 8
0
 def deleteAll(self, request, customerId):
     c = DB.getCustomer(customerId)
     c.addresses = {}
     return Response(200)
Esempio n. 9
0
 def delete(self, request, customerId, addressId):
     DB.getCustomerAddress(customerId, addressId)  #validate address exists
     del (DB.getCustomer(customerId).addresses[addressId])
     return Response(200)
Esempio n. 10
0
 def deleteAll(self, request):
     DB.deleteAllCustomers()
     return Response(200)
Esempio n. 11
0
 def delete(self, request, customerId):
     DB.deleteCustomer(customerId)
     return Response(200)
Esempio n. 12
0
 def __createErrorResponse(self, request, code, message):
     """Common method for rendering errors"""
     return Response(code=code,
                     entity=message,
                     headers={"content-type": MediaType.TEXT_PLAIN})