def __init__(self, lbservice, lbresource=None): if not lbresource: self.lbresource = self Utils.init(lbservice) else: self.lbresource = lbresource self.lbservice = lbservice self.logger = self.lbservice.logger
def get_listresponse(self, loadBalancers, req): payload = Utils.get_response_body("loadBalancers", loadBalancers, self) response = Response(body=payload, request=req) response.status = "200 OK" response.content_type = Utils.get_mimetype_from_format( self.response_format) response.charset = 'utf8' return response
def get_updateresponse(self, lbhealthmonitor, req): payload = Utils.get_response_body("healthMonitor", lbhealthmonitor, self) response = Response(body=payload, request=req) response.status = "202 Accepted" response.content_type = Utils.get_mimetype_from_format( self.response_format) response.charset = 'utf8' return response
def get_getresponse(self, loadBalancer, req): payload = Utils.get_response_body("loadBalancer", loadBalancer, self) self.logger.debug("response payload: %s" % payload) response = Response(body=payload, request=req) response.status = "200 OK" response.content_type = Utils.get_mimetype_from_format( self.response_format) response.charset = 'utf8' return response
def GetAlgorithms(self, req, env): self.init_request_environment(req, env) lbalgorithms = self.get_lbalgorithms() payload = Utils.get_response_body("algorithms", lbalgorithms, self) response = Response(body=payload, request=req) response.status = "200 OK" response.content_type = Utils.get_mimetype_from_format( self.response_format) response.charset = 'utf8' return response
def get_addresponse(self, lbnode, req): if isinstance(lbnode, list): payload = Utils.get_response_body("nodes", lbnode, self) else: payload = Utils.get_response_body("node", lbnode, self) response = Response(body=payload, request=req) response.status = "202 Accepted" response.content_type = Utils.get_mimetype_from_format( self.response_format) response.charset = 'utf8' return response
def get_loadbalancer_objects_from_request(self, req): dict_obj = Utils.get_dictionary_from_request(req, self.request_format) dict_keys = dict_obj.keys() if "loadBalancers" in dict_keys: state = dict_obj["loadBalancers"] loadbalancers = self.get_loadbalancer_objects_from_dictionary( state) return loadbalancers elif "loadBalancer" in dict_keys: state = dict_obj["loadBalancer"] loadbalancer = self.get_loadbalancer_object_from_dictionary(state) return loadbalancer else: self.logger.debug( "Bad Request: The root element in the request is neither \"loadBalancers\", nor \"loadBalancer\"" ) raise BadRequestException( "Validation fault", "the object is not valid", "malformed request body. object to add is not one loadBalancer or a list of loadBalancers" )
def get_lbhealthmonitor_object_from_request(self, req): dict_obj = Utils.get_dictionary_from_request(req, self.request_format) if not isinstance(dict_obj, dict): self.logger.debug( "Bad Request: The root element is not a dictionary") raise BadRequestException("Validation fault", "the object is not valid", "malformed request body.") dict_keys = dict_obj.keys() if "healthMonitor" in dict_keys: state = dict_obj["healthMonitor"] lbhealthmonitor = self.get_lbhealthmonitor_object_from_dictionary( state) return lbhealthmonitor else: self.logger.debug( "Bad Request: The root element in the request is not \"healthMonitor\"" ) raise BadRequestException( "Validation fault", "the object is not valid", "malformed request body. expecting a healthMonitor object")
def GetProtocols(self, req, env): self.init_request_environment(req, env) lbprotocols = self.get_lbprotocols() payload = Utils.get_response_body("protocols", lbprotocols, self) response = Response(body=payload, request=req) response.status = "200 OK" response.content_type = Utils.get_mimetype_from_format( self.response_format) response.charset = 'utf8' return response raise NotImplementedException( "GET Protocols functionality not implemented")
def get_updateresponse(self, loadBalancer, req): payload = Utils.get_response_body("loadBalancer", loadBalancer, self) """response = Response(body=payload, request=req)""" response = Response(request=req) response.status = "202 Accepted" """response.content_type = Utils.get_mimetype_from_format(self.response_format) response.charset = 'utf8' """ return response
def get_loadbalancer_object_from_dictionary(self, dict_obj): if not isinstance(dict_obj, dict): self.logger.debug( "Bad Request: We are expecting a dictionary to be passed as a parameter" ) raise BadRequestException( "Validation fault", "the object is not valid", "malformed request body. expecting a loadBalancer object") loadBalancer = Utils.get_object_from_dictionary( "loadBalancer", dict_obj, self) return loadBalancer
def get_lbnode_object_from_dictionary(self, dict_obj): if not isinstance(dict_obj, dict): self.logger.debug( "Bad Request: We are expecting a dictionary to be passed as a parameter" ) raise BadRequestException( "Validation fault", "the object is not valid", "malformed request body: expecting a node object") lbnode = Utils.get_object_from_dictionary("node", dict_obj, self) self.logger.debug("Exiting get_lbnode_object_from_dictionary()") return lbnode
def get_lbnode_objects_from_request(self, req): dict_obj = Utils.get_dictionary_from_request(req, self.request_format) dict_keys = dict_obj.keys() if "nodes" in dict_keys: state = dict_obj["nodes"] lbnodes = self.get_lbnode_objects_from_dictionary(state) return lbnodes elif "node" in dict_keys: state = dict_obj["node"] lbnode = self.get_lbnode_object_from_dictionary(state) return lbnode else: self.logger.debug( "Bad Request: The root element in the request is neither \"loadBalancers\", nor \"loadBalancer\"" ) raise BadRequestException("Validation fault", "the object is not valid", "malformed request body.")