def get_provider_of_a_kind(kind): """ Get the provider name @param kind: OCCI_ID of the kind """ database = config.prepare_PyOCNI_db() provider = None #Step[1]: Extract the kind description try: query = database.view('/db_views/my_providers', key=kind) except Exception as e: logger.error("===== Get_provider_of_a_kind : =====" + e.message) return provider if query.count() is 0: logger.error("===== Get_provider_of_a_kind : No such kind =====") return provider #Step[2]: return the provider name else: provider = query.first()['value'] return provider['local'][0]
def get_provider_of_a_kind(kind): database = config.prepare_PyOCNI_db() provider = None try: query = database.view('/db_views/my_providers', key=kind) except Exception as e: logger.error("get_provider_of_a_kind : " + e.message) print "----------------------------------------------" return provider if query.count() is 0: logger.error("get_provider_of_a_kind : No such provider") return provider else: provider = query.first()['value'] return provider['local'][0]
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']
def __init__(self): self.database = config.prepare_PyOCNI_db()