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")
Example #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 = Room.import_one(session, body, name=name)
             if isinstance(element, Room):
                 element = Room.add_one(session, element)
                 if isinstance(element, Room):
                     client_com.send_requests_process({"backend": None, "monitor": None, "user": None}, "PUT", "room", name, attrib, body, "text/xml")
                     return "Room %s added" % name
                 elif element == Room.ERROR_ELEMENT_ALREADY_EXISTS:
                     raise cherrypy.HTTPError("403", "Room %s already exists" % name)
             elif element == Room.ERROR_TAG_NOT_VALID:
                 raise cherrypy.HTTPError("400", "Tag not valid")
         else:
             element = Room.get_one(session, name)
             if isinstance(element, Room):
                 element = Room.edit_one(session, element, attrib, body)
                 if isinstance(element, Room):
                     client_com.send_requests_process({"backend": None, "monitor": None, "user": None}, "PUT", "room", name, attrib, body, "text/plain")
                     return "Room %s attribute %s value %s changed" % (name, attrib, body)
                 elif element == Room.ERROR_ATTRIB_NOT_VALID:
                     raise cherrypy.HTTPError("404", "Attribute % not found" % attrib)
             elif element == Room.ERROR_ELEMENT_NOT_EXISTS:
                 raise cherrypy.HTTPError("404", "Room %s not found" % name)
     else:
         raise cherrypy.HTTPError("400", "No body specified")
Example #3
0
 def DELETE(self, name):
     session = cherrypy.request.db
     cherrypy.response.headers['content-type'] = 'text/plain'
     element = Room.get_one(session, name)
     if isinstance(element, Room):
         element = Room.del_one(session, element)
         if isinstance(element, Room):
             client_com.send_requests_process({"backend": None, "monitor": None, "user": None}, "DELETE", "room", name, None, None, None)
             return "Room %s deleted" % name
     elif element == Room.ERROR_ELEMENT_NOT_EXISTS:
         raise cherrypy.HTTPError("404", "User %s not found" % name)
 def DELETE(self, name):
     session = cherrypy.request.db
     cherrypy.response.headers["content-type"] = "text/plain"
     element = Monitor.get_one(session, name)
     if isinstance(element, Monitor):
         element = Monitor.del_one(session, element)
         if isinstance(element, Monitor):
             client_com.send_requests_process({"backend": None}, "DELETE", "monitor", name, None, None, None)
             return "Monitor %s deleted" % name
     elif element == Monitor.ERROR_ELEMENT_NOT_EXISTS:
         raise cherrypy.HTTPError("404", "Monitor %s not found" % name)
Example #5
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 = Room.get_one(session, name)
         if isinstance(element, Room):
             element = Room.import_one(session, body, element=element)
             if isinstance(element, Room):
                 client_com.send_requests_process({"backend": None, "monitor": None, "user": None}, "POST", "room", name, None, body, "text/xml")
                 return "Room %s updated" % name
             elif element == Room.ERROR_TAG_NOT_VALID:
                 raise cherrypy.HTTPError("400", "Tag not valid")
         elif element == Room.ERROR_ELEMENT_NOT_EXISTS:
             raise cherrypy.HTTPError("404", "Room %s not found" % name)
     else:
         raise cherrypy.HTTPError("400", "No body specified")
Example #6
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 = User.get_one(session, name)
         if isinstance(element, User):
             element = User.import_one(session, body, element=element)
             if isinstance(element, User):
                 client_com.send_requests_process(
                     {"backend": None, "monitor": None}, "POST", "user", name, None, body, "text/xml"
                 )
                 return "User %s updated" % name
             elif element == User.ERROR_VALUE_NOT_VALID:
                 raise cherrypy.HTTPError("403", "Value of attribute not valid")
             elif element == User.ERROR_TAG_NOT_VALID:
                 raise cherrypy.HTTPError("400", "Tag not valid")
         elif element == User.ERROR_ELEMENT_NOT_EXISTS:
             raise cherrypy.HTTPError("404", "User %s not found" % name)
     else:
         raise cherrypy.HTTPError("400", "No body specified")
Example #7
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")
Example #8
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")