class PathManager(object): """ Handles operations concerning Paths """ def __init__(self): self.rd_baker = ResourceDataBaker() self.PostMan = PostMan() def channel_get_on_path(self, req_path, terms): """ Channel get on path request to the manager responsible Args: @param req_path: Address to which this post request was sent @param terms: Data provided for filtering """ locations = list() #Step[1]: get the necessary data from DB occi_loc = self.rd_baker.bake_to_get_on_path() if terms is "": #Step[2a]: Get on path without filtering if occi_loc is None: return "An error has occurred, please check log for more details", return_code['Internal Server Error'] else: for str_loc in occi_loc: if str_loc.find(req_path) is not -1: locations.append(str_loc) logger.debug("===== Channel_get_on_Path: Finished with success ===== ") return locations, return_code['OK'] else: #Step[2b]: Get on path with filtering for str_loc in occi_loc: if str_loc.endswith("/") is False and str_loc.find(req_path) is not -1: locations.append(str_loc) descriptions = self.rd_baker.bake_to_get_on_path_filtered(locations) if descriptions is None: return "An error has occurred, please check log for more details", return_code['Internal Server Error'] else: if terms.has_key('resources'): result_res, resp_code_r = get_filtered(terms['resources'], descriptions) else: result_res = list() resp_code_r = return_code['OK'] if terms.has_key('links'): result_link, resp_code_l = get_filtered(terms['links'], descriptions) else: result_link = list() resp_code_l = return_code['OK'] if resp_code_l is not return_code['OK'] or resp_code_r is not return_code['OK']: return "An error has occurred, please check logs for more details", return_code[ 'Internal Server Error'] result = result_res + result_link logger.debug("===== Channel_get_on_Path: Finished with success ===== ") return result, return_code['OK'] def channel_delete_on_path(self, req_path): """ Channel the delete resources request to the path manager Args: @param req_path: Address to which this post request was sent """ occi_loc,doc_loc = self.rd_baker.bake_to_delete_on_path() if occi_loc is None or doc_loc is None: return "An error has occurred, please check log for more details", return_code['Internal Server Error'] else: to_delete = list() for i in range(len(occi_loc)): str_loc = str(occi_loc[i]) if str_loc.find(req_path) is not -1: to_delete.append(doc_loc[i]) self.PostMan.delete_entities_in_db(to_delete) logger.debug("===== Channel Delete on Path: Finished with success =====") return "", return_code['OK']
class PathManager(object): """ dispachers operations on Path """ def __init__(self): self.rd_baker = ResourceDataBaker() self.PostMan = PostMan() def channel_get_on_path(self, req_path, terms): """ Channel the get request to the right method Args: @param req_path: Address to which this post request was sent @param terms: Data provided for filtering """ locations = list() query = self.rd_baker.bake_to_get_on_path() if terms is "": if query is None: return "An error has occurred, please check log for more details", return_code['Internal Server Error'] else: for q in query: str_loc = str(q['key']) if str_loc.endswith("/"): str_loc = joker.format_url_path(str_loc) if str_loc.find(req_path) is not -1: locations.append(str_loc) logger.debug("===== Channel_get_on_Path: Finished with success ===== ") return locations, return_code['OK'] else: for q in query: str_loc = str(q['key']) if str_loc.endswith("/") is False and str_loc.find(req_path) is not -1: locations.append(str_loc) descriptions = self.rd_baker.bake_to_get_on_path_filtered(locations) if descriptions is None: return "An error has occurred, please check log for more details", return_code['Internal Server Error'] else: if terms.has_key('resources'): result_res, resp_code_r = get_filtered(terms['resources'], descriptions) else: result_res = list() resp_code_r = return_code['OK'] if terms.has_key('links'): result_link, resp_code_l = get_filtered(terms['links'], descriptions) else: result_link = list() resp_code_l = return_code['OK'] if resp_code_l is not return_code['OK'] or resp_code_r is not return_code['OK']: return "An error has occurred, please check logs for more details", return_code[ 'Internal Server Error'] result = result_res + result_link logger.debug("===== Channel_get_on_Path: Finished with success ===== ") return result, return_code['OK'] def channel_delete_on_path(self, req_path, user_id): """ Channel the get request to the right method Args: @param user_id: ID of the issuer of the post request @param req_path: Address to which this post request was sent """ database = config.prepare_PyOCNI_db() locations = list() try: query = database.view('/db_views/for_delete_entities', key=user_id) except Exception as e: logger.error("Delete on Path: " + e.message) return "An error has occurred, please check log for more details", return_code['Internal Server Error'] for q in query: str_loc = str(q['value'][0]) if str_loc.find(req_path) is not -1: locations.append({'_id': q['value'][1], '_rev': q['value'][2]}) logger.debug("Delete on Path: done with success") database.delete_docs(locations) return "", return_code['OK']