コード例 #1
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 = Node.get_one(session, name)
         if isinstance(element, Node):
             old_room = element.room
             element = Node.import_one(session, body, element=element)
             if isinstance(element, Node):
                 if old_room != element.room:
                     client_com.send_requests_process({"user": old_room}, "DELETE", "node", name, None, None, None)
                     client_com.send_requests_process({"user": element.room}, "PUT", "node", name, None, Node.export_one(element, export_attributes), "text/xml")
                     roles = {"backend": None, "monitor": None}
                 else:
                     roles = {"backend": None, "monitor": None, "user": element.room}
                 client_com.send_requests_process(roles, "POST", "node", name, None, body, "text/xml")
                 return "Node %s updated" % name
             elif element == Node.ERROR_VALUE_NOT_VALID:
                 raise cherrypy.HTTPError("403", "Value of attribute not valid")
             elif element == Node.ERROR_TAG_NOT_VALID:
                 raise cherrypy.HTTPError("400", "Tag not valid")
         elif element == Node.ERROR_ELEMENT_NOT_EXISTS:
             raise cherrypy.HTTPError("404", "Node %s not found" % name)
     else:
         raise cherrypy.HTTPError("400", "No body specified")
コード例 #2
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 = Node.import_one(session, body, name=name)
             if isinstance(element, Node):
                 element = Node.add_one(session, element)
                 if isinstance(element, Node):
                     client_com.send_requests_process({"backend": None, "monitor": None, "user": element.room}, "PUT", "node", name, attrib, body, "text/xml")
                     return "Node %s added" % name
                 elif element == Node.ERROR_ELEMENT_ALREADY_EXISTS:
                     raise cherrypy.HTTPError("403", "Node %s alread exists" % name)
             elif element == Node.ERROR_VALUE_NOT_VALID:
                 raise cherrypy.HTTPError("403", "Value of attribute not valid")
             elif element == Node.ERROR_TAG_NOT_VALID:
                 raise cherrypy.HTTPError("400", "Tag not valid")
         else:
             if not isinstance(cherrypy.request.role, str):
                 element = Node.get_one(session, name)
                 if isinstance(element, Node):
                     if not isinstance(cherrypy.request.role, Node) and attrib == "input":
                         response = client_com.send_request(element, "PUT", "node", name, attrib, value, "text/plain")
                         if response.status != 200:
                             raise cherrypy.HTTPError("403", "Node send error: %s %s %s" % (response.status, response.reason, response.read().decode()))
                     old_room = element.room
                     element = Node.edit_one(session, element, attrib, body)
                     if isinstance(element, Node):
                         if old_room != element.room:
                             client_com.send_requests_process({"user": old_room}, "DELETE", "node", name, None, None, None)
                             client_com.send_requests_process({"user": element.room}, "PUT", "node", name, None, Node.export_one(element, export_attributes), "text/xml")
                             roles = {"backend": None, "monitor": None}
                         else:
                             roles = {"backend": None, "monitor": None, "user": element.room}
                         client_com.send_requests_process(roles, "PUT", "node", name, attrib, body, "text/plain")
                         return "Node %s attribute %s value %s changed" % (name, attrib, body)
                     elif element == Node.ERROR_VALUE_NOT_VALID:
                         raise cherrypy.HTTPError("403", "Value %s of attribute %s not valid" % (body, attrib))
                     elif element == Node.ERROR_ATTRIB_NOT_VALID:
                         raise cherrypy.HTTPError("404", "Attribute %s not found" % attrib)
                 elif element == Node.ERROR_ELEMENT_NOT_EXISTS:
                     raise cherrypy.HTTPError("404", "Node %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")