コード例 #1
0
 def PUT(self, name, attrib=None):
     session = cherrypy.request.db
     cherrypy.response.headers['content-type'] = 'text/plain'
     body = cherrypy.request.body.read().decode()
     if (cherrypy.request.process_request_body == True):
         if attrib == None:
             element = Backend.import_one(session, body, name=name)
             if isinstance(element, Backend):
                 element = Backend.add_one(session, element)
                 if isinstance(element, Backend):
                     client_com.send_requests_process({"backend": None}, "PUT", "backend", name, attrib, body, "text/xml")
                     return "Backend %s added" % name
                 elif element == Backend.ERROR_ELEMENT_ALREADY_EXISTS:
                     raise cherrypy.HTTPError("403", "Backend %s alread exists" % name)
             elif element == Backend.ERROR_TAG_NOT_VALID:
                 raise cherrypy.HTTPError("400", "Tag not valid")
         else:
             if not isinstance(cherrypy.request.role, str):
                 element = Backend.get_one(session, name)
                 if isinstance(element, Backend):
                     element = Backend.edit_one(session, element, attrib, body)
                     if isinstance(element, Backend):
                         client_com.send_requests_process({"backend": None}, "PUT", "backend", name, attrib, body, "text/plain")
                         return "Backend %s attribute %s value %s changed" % (name, attrib, body)
                     elif element == Backend.ERROR_ATTRIB_NOT_VALID:
                         raise cherrypy.HTTPError("404", "Attribute %s not found" % attrib)
                 elif element == Backend.ERROR_ELEMENT_NOT_EXISTS:
                     raise cherrypy.HTTPError("404", "Backend %s not found" % name)
             else:
                 raise cherrypy.HTTPError("401", "You are not allowed to access this resource.")
     else:
         raise cherrypy.HTTPError("400", "No body specified")
コード例 #2
0
 def DELETE(self, name):
     session = cherrypy.request.db
     cherrypy.response.headers['content-type'] = 'text/plain'
     element = Backend.get_one(session, name)
     if isinstance(element, Backend):
         element = Backend.del_one(session, element)
         if isinstance(element, Backend):
             client_com.send_requests_process({"backend": None}, "DELETE", "backend", name, None, None, None)
             return "Backend %s deleted" % name
     elif element == Backend.ERROR_ELEMENT_NOT_EXISTS:
         raise cherrypy.HTTPError("404", "Backend %s not found" % name)
コード例 #3
0
 def GET(self, name=None, master=None):
     session = cherrypy.request.db
     cherrypy.response.headers['content-type'] = 'text/xml'
     if name == None:
         elements = Backend.get_all(session, "master", master)
         if isinstance(elements, list):
             return Backend.export_all(elements, "all")
     else:
         element = Backend.get_one(session, name)
         if isinstance(element, Backend):
             return Backend.export_one(element, "all")
         elif elements == Backend.ERROR_ELEMENT_NOT_EXISTS:
             raise cherrypy.HTTPError("404", "Backend %s not found" % name)
コード例 #4
0
 def POST(self, name):
     session = cherrypy.request.db
     cherrypy.response.headers['content-type'] = 'text/plain'
     body = cherrypy.request.body.read().decode()
     if (cherrypy.request.process_request_body == True):
         element = Backend.get_one(session, name)
         if isinstance(element, Backend):
             element = Backend.import_one(session, body, element=element)
             if isinstance(element, Backend):
                 client_com.send_requests_process({"backend": None}, "POST", "backend", name, None, body, "text/xml")
                 return "Backend %s updated" % name
             elif element == Backend.ERROR_TAG_NOT_VALID:
                 raise cherrypy.HTTPError("400", "Tag not valid")
         elif element == Backend.ERROR_ELEMENT_NOT_EXISTS:
             raise cherrypy.HTTPError("404", "Backend %s not found" % name)
     else:
         raise cherrypy.HTTPError("400", "No body specified")