def delete_kind_documents(self, descriptions, db_categories): """ Delete kind documents that is related to the scheme + term contained in the description provided Args: @param descriptions: OCCI description of the kind document to delete @param db_categories: Category data already contained in the database """ kind_ref = list() res_code = return_code["OK"] # Step[1]: Verify the existence of such kind document for desc in descriptions: occi_id = joker.get_description_id(desc) kind_id_rev = joker.verify_exist_occi_id(occi_id, db_categories) if kind_id_rev is not None: # Step[2]: if Yes, return kind doc ref for delete kind_ref.append(kind_id_rev) event = "Kind document " + occi_id + " is sent for delete " logger.debug("===== Delete_kind_documents : " + event + " =====") else: event = "Could not find this kind document " + occi_id logger.error("===== Delete kind : " + event + " ===== ") return list(), return_code["Bad Request"] return kind_ref, res_code
def delete_action_documents(self, descriptions, db_categories): """ Delete action documents that is related to the scheme + term contained in the description provided Args: @param descriptions: OCCI description of the action document to delete @param db_categories: Category data already contained in the database """ message = list() res_code = return_code['OK'] #Verify the existence of such action document for desc in descriptions: occi_id = joker.get_description_id(desc) action_id_rev = joker.verify_exist_occi_id(occi_id, db_categories) if action_id_rev is not None: message.append(action_id_rev) event = "Action document " + occi_id + " is sent for delete " logger.debug("===== Delete_action_documents: " + event + " =====") else: event = "Could not find this action document " + occi_id logger.error("===== Delete_action_documents : " + event + " =====") return list(), return_code['Bad Request'] return message, res_code
def delete_action_documents(self, descriptions, db_categories): """ Delete action documents that is related to the scheme + term contained in the description provided Args: @param descriptions: OCCI description of the action document to delete @param db_categories: Category data already contained in the database """ message = list() res_code = return_code['OK'] #Step[1]: Verify the existence of such action document for desc in descriptions: occi_id = joker.get_description_id(desc) action_id_rev = joker.verify_exist_occi_id(occi_id, db_categories) if action_id_rev is not None: #Step[2]: Store the ref of the action document to send it for delete message.append(action_id_rev) event = "Action document " + occi_id + " is sent for delete " logger.debug("===== Delete_action_documents: " + event + " =====") else: event = "Could not find this action document " + occi_id logger.error("===== Delete_action_documents : " + event + " =====") return list(), return_code['Bad Request'] #Send doc ref collection for delete return message, res_code
def register_actions(self, descriptions, db_actions): """ Add new actions to the database Args: @param descriptions: OCCI action descriptions @param db_actions: Existing actions in database """ loc_res = list() resp_code = return_code['OK'] for desc in descriptions: occi_id = joker.get_description_id(desc) ok_k = joker.verify_occi_uniqueness(occi_id, db_actions) if ok_k is True: jData = dict() jData['_id'] = uuid_Generator.get_UUID() jData['OCCI_Description'] = desc jData['OCCI_ID'] = occi_id jData['Type'] = "Action" loc_res.append(jData) else: message = "This Action description already exists in document. " logger.error("===== Register_actions : " + message + " ===== ") resp_code = return_code['Conflict'] return list(), resp_code return loc_res, resp_code
def delete_mixin_documents(self, descriptions, db_categories, db_entities): """ Delete mixin documents that is related to the scheme + term contained in the description provided Args: @param descriptions: OCCI description of the mixin document to delete @param db_categories: Category data already contained in the database @param db_entities: Entity data already contained in the database """ mix_ref = list() res_code = return_code['OK'] #Verify the existence of such kind document for desc in descriptions: occi_id = joker.get_description_id(desc) mixin_id_rev = joker.verify_exist_occi_id(occi_id, db_categories) if mixin_id_rev is not None: db_entities, dissociated = self.dissociate_entities_belonging_to_mixin(occi_id, db_entities) if dissociated is True: mix_ref.append(mixin_id_rev) event = "Mixin document " + occi_id + " is sent for delete " logger.debug("===== Delete_mixin_documents : " + event + " =====") else: event = "Unable to delete because this mixin document " + occi_id + \ " still has resources depending on it. " logger.error(" ===== Delete_mixin_documents : " + event + " =====") return list(), list(), return_code['Bad Request'] else: event = "Could not find this mixin document " + occi_id logger.error("===== Delete_mixin_documents : " + event + " =====") return list(), list(), return_code['Bad Request'] return mix_ref, db_entities, res_code
def delete_kind_documents(self, descriptions, db_categories): """ Delete kind documents that is related to the scheme + term contained in the description provided Args: @param descriptions: OCCI description of the kind document to delete @param db_categories: Category data already contained in the database """ kind_ref = list() res_code = return_code['OK'] #Step[1]: Verify the existence of such kind document for desc in descriptions: occi_id = joker.get_description_id(desc) kind_id_rev = joker.verify_exist_occi_id(occi_id, db_categories) if kind_id_rev is not None: #Step[2]: if Yes, return kind doc ref for delete kind_ref.append(kind_id_rev) event = "Kind document " + occi_id + " is sent for delete " logger.debug("===== Delete_kind_documents : " + event + " =====") else: event = "Could not find this kind document " + occi_id logger.error("===== Delete kind : " + event + " ===== ") return list(), return_code['Bad Request'] return kind_ref, res_code
def register_actions(self, descriptions, db_actions): """ Add new actions to the database Args: @param descriptions: OCCI action descriptions @param db_actions: Existing actions in database """ loc_res = list() resp_code = return_code['OK'] for desc in descriptions: #Step[1]: Verify action uniqueness occi_id = joker.get_description_id(desc) ok_k = joker.verify_occi_uniqueness(occi_id, db_actions) #Step[2]: Create action if ok_k is True: jData = dict() jData['_id'] = uuid_Generator.get_UUID() jData['OCCI_Description'] = desc jData['OCCI_ID'] = occi_id jData['Type'] = "Action" loc_res.append(jData) else: message = "This Action description already exists in document. " logger.error("===== Register_actions : " + message + " ===== ") resp_code = return_code['Conflict'] return list(), resp_code #Step[3]: return the newly created actions return loc_res, resp_code
def bake_to_delete_categories_mixins(self, mixins): db_mixin_entities = list() for mix in mixins: occi_id = joker.get_description_id(mix) query = self.category_sup.get_entities_of_mixin(occi_id) if query is None: return None else: if query.count() is not 0: db_mixin_entities.append(query.first()['value']) return db_mixin_entities
def delete_kind_documents(self, descriptions, db_categories): """ Delete kind documents that is related to the scheme + term contained in the description provided Args: @param descriptions: OCCI description of the kind document to delete @param db_categories: Category data already contained in the database """ kind_ref = list() res_code = return_code['OK'] #Verify the existence of such kind document for desc in descriptions: occi_id = joker.get_description_id(desc) kind_id_rev = joker.verify_exist_occi_id(occi_id, db_categories) if kind_id_rev is not None: kind_ref.append(kind_id_rev) event = "Kind document " + occi_id + " is sent for delete " logger.debug("===== Delete_kind_documents : " + event + " =====") else: event = "Could not find this kind document " + occi_id logger.error("===== Delete kind : " + event + " ===== ") return list(), return_code['Bad Request'] return kind_ref, res_code #======================================================================================================================== # Independant Functions #======================================================================================================================== # # def get_entities_belonging_to_kind(self, occi_id,db_data): # """ # Verifies if there are entities of this kind # Args: # @param occi_id: OCCI_ID of the kind # @param db_data: OCCI_IDs of the kind that has entities running # """ # try: # db_data.index(occi_id) # except ValueError as e: # logger.debug("Entities belong kind : " + e.message) # return False # return True
def register_kinds(self, descriptions, db_occi_ids, db_occi_locs): """ Create new kinds Args: @param descriptions: OCCI kind descriptions @param db_occi_ids: Kind IDs already existing in the database @param db_occi_locs: Kind locations already existing in the database """ loc_res = list() resp_code = return_code['OK'] for desc in descriptions: occi_id = joker.get_description_id(desc) #Step[1]: verify uniqueness of the new kind ok_k = joker.verify_occi_uniqueness(occi_id, db_occi_ids) if ok_k is True: occi_loc = joker.make_category_location(desc) ok_loc = joker.verify_occi_uniqueness(occi_loc, db_occi_locs) if ok_loc is True: jData = dict() jData['_id'] = uuid_Generator.get_UUID() jData['OCCI_Location'] = occi_loc jData['OCCI_Description'] = desc jData['OCCI_ID'] = occi_id jData['Type'] = "Kind" #Default backend is dummy jData['Provider'] = {"local": [config.DEFAULT_BACKEND], "remote": []} loc_res.append(jData) else: message = "Location conflict, kind will not be created." logger.error("===== Register kind : " + message + " =====") resp_code = return_code['Conflict'] return list(), resp_code else: message = "This kind description already exists in document " logger.error("===== Register kind : " + message + " =====") resp_code = return_code['Conflict'] return list(), resp_code return loc_res, resp_code
def register_kinds(self, descriptions, db_occi_ids, db_occi_locs): """ Create new kinds Args: @param descriptions: OCCI kind descriptions @param db_occi_ids: Kind IDs already existing in the database @param db_occi_locs: Kind locations already existing in the database """ loc_res = list() resp_code = return_code["OK"] for desc in descriptions: occi_id = joker.get_description_id(desc) # Step[1]: verify uniqueness of the new kind ok_k = joker.verify_occi_uniqueness(occi_id, db_occi_ids) if ok_k is True: occi_loc = joker.make_category_location(desc) ok_loc = joker.verify_occi_uniqueness(occi_loc, db_occi_locs) if ok_loc is True: jData = dict() jData["_id"] = uuid_Generator.get_UUID() jData["OCCI_Location"] = occi_loc jData["OCCI_Description"] = desc jData["OCCI_ID"] = occi_id jData["Type"] = "Kind" # Default backend is dummy jData["Provider"] = {"local": [config.DEFAULT_BACKEND], "remote": []} loc_res.append(jData) else: message = "Location conflict, kind will not be created." logger.error("===== Register kind : " + message + " =====") resp_code = return_code["Conflict"] return list(), resp_code else: message = "This kind description already exists in document " logger.error("===== Register kind : " + message + " =====") resp_code = return_code["Conflict"] return list(), resp_code return loc_res, resp_code
def update_OCCI_kind_descriptions(self, new_data, db_data): """ Updates the OCCI kind description which OCCI_ID is equal to OCCI_ID contained in new_data Args: @param new_data: Data containing the OCCI ID of the kind and the new OCCI kind description @param db_data: Categories already contained in the database """ to_update = list() resp_code = return_code['OK'] for desc in new_data: occi_id = joker.get_description_id(desc) #Step[1]: Extract the old document old_doc = joker.extract_doc(occi_id, db_data) if old_doc is not None: #Step[2]: Update kind OCCI description problems, occi_description = joker.update_occi_category_description(old_doc['OCCI_Description'], desc) #Step[3]: Detect if there is problems if problems is True: message = "Kind OCCI description " + occi_id + " has not been totally updated." logger.error("===== Kind OCCI description update:" + message + " =====") return list(), return_code['Bad Request'] else: message = "Kind OCCI description " + occi_id + " has been updated successfully" old_doc['OCCI_Description'] = occi_description #Step[4]: If no problem, just append the doc to the to_update list to_update.append(old_doc) logger.debug("===== Update kind OCCI description : " + message + " =====") else: message = "Kind document " + occi_id + " couldn\'t be found " logger.error("===== Update kind OCCI description : " + message + " =====") return list(), return_code['Not Found'] return to_update, resp_code
def update_OCCI_kind_descriptions(self, new_data, db_data): """ Updates the OCCI kind description which OCCI_ID is equal to OCCI_ID contained in new_data Args: @param new_data: Data containing the OCCI ID of the kind and the new OCCI kind description @param db_data: Categories already contained in the database """ to_update = list() resp_code = return_code["OK"] for desc in new_data: occi_id = joker.get_description_id(desc) # Step[1]: Extract the old document old_doc = joker.extract_doc(occi_id, db_data) if old_doc is not None: # Step[2]: Update kind OCCI description problems, occi_description = joker.update_occi_category_description(old_doc["OCCI_Description"], desc) # Step[3]: Detect if there is problems if problems is True: message = "Kind OCCI description " + occi_id + " has not been totally updated." logger.error("===== Kind OCCI description update:" + message + " =====") return list(), return_code["Bad Request"] else: message = "Kind OCCI description " + occi_id + " has been updated successfully" old_doc["OCCI_Description"] = occi_description # Step[4]: If no problem, just append the doc to the to_update list to_update.append(old_doc) logger.debug("===== Update kind OCCI description : " + message + " =====") else: message = "Kind document " + occi_id + " couldn't be found " logger.error("===== Update kind OCCI description : " + message + " =====") return list(), return_code["Not Found"] return to_update, resp_code
def register_mixins(self, descriptions, db_occi_ids, db_occi_locs): """ Add new mixins to the database Args: @param descriptions: OCCI mixin descriptions @param db_occi_ids: Existing Mixin IDs in database @param db_occi_locs: Existing Mixin locations in database """ loc_res = list() resp_code = return_code['OK'] for desc in descriptions: #Step[1]: Verify mixin uniqueness occi_id = joker.get_description_id(desc) ok_k = joker.verify_occi_uniqueness(occi_id, db_occi_ids) if ok_k is True: #Step[2]: Start creation the mixin occi_loc = joker.make_category_location(desc) ok_loc = joker.verify_occi_uniqueness(occi_loc, db_occi_locs) if ok_loc is True: jData = dict() jData['_id'] = uuid_Generator.get_UUID() jData['OCCI_Location'] = occi_loc jData['OCCI_Description'] = desc jData['OCCI_ID'] = occi_id jData['Type'] = "Mixin" loc_res.append(jData) else: message = "Location conflict, Mixin will not be created." logger.error("===== Register Mixin : " + message + " =====") resp_code = return_code['Conflict'] return list(), resp_code else: message = "This Mixin description already exists in document." logger.error(" ====== Register Mixin : " + message + " =====") resp_code = return_code['Conflict'] return list(), resp_code #Step[3]: return the newly created mixins return loc_res, resp_code
def update_OCCI_action_descriptions(self, new_data, db_data): """ Updates the OCCI description field of the action which document OCCI_ID is equal to OCCI_ID contained in data Args: @param new_data: Data containing the OCCI ID of the action and the new OCCI action description @param db_data: Data already contained in the database """ to_update = list() resp_code = return_code['OK'] for desc in new_data: #Step[1]: Extract the action document occi_id = joker.get_description_id(desc) old_doc = joker.extract_doc(occi_id, db_data) if old_doc is not None: #Step[2]: Update the Action OCCI description problems, occi_description = joker.update_occi_category_description( old_doc['OCCI_Description'], desc) if problems is True: message = "Action OCCI description " + occi_id + " has not been totally updated." logger.error("===== Update_OCCI_action_description: " + message + " =====") return list(), return_code['Bad Request'] else: message = "Action OCCI description " + occi_id + " has been updated successfully" old_doc['OCCI_Description'] = occi_description to_update.append(old_doc) logger.debug("===== Update_OCCI_action_description: " + message + " =====") else: message = "Action document " + occi_id + " couldn\'t be found " logger.error("===== Update_OCCI_action_description: " + message + " =====") return list(), return_code['Not Found'] #Step[3]: Return the collection of documents to update return to_update, resp_code
def register_kinds(self, descriptions, db_occi_ids, db_occi_locs): """ Add new kinds to the database Args: @param descriptions: OCCI kind descriptions @param db_occi_ids: Kind IDs already existing in the database @param db_occi_locs: Kind locations already existing in the database """ loc_res = list() resp_code = return_code['OK'] for desc in descriptions: occi_id = joker.get_description_id(desc) ok_k = joker.verify_occi_uniqueness(occi_id, db_occi_ids) if ok_k is True: occi_loc = joker.make_category_location(desc) ok_loc = joker.verify_occi_uniqueness(occi_loc, db_occi_locs) if ok_loc is True: jData = dict() jData['_id'] = uuid_Generator.get_UUID() jData['OCCI_Location'] = occi_loc jData['OCCI_Description'] = desc jData['OCCI_ID'] = occi_id jData['Type'] = "Kind" jData['Provider'] = {"local": ["dummy"], "remote": []} loc_res.append(jData) else: message = "Location conflict, kind will not be created." logger.error("===== Register kind ERROR: " + message + " =====") resp_code = return_code['Conflict'] return list(), resp_code else: message = "This kind description already exists in document " logger.error("===== Register kind ERROR: " + message + " =====") resp_code = return_code['Conflict'] return list(), resp_code return loc_res, resp_code
def delete_mixin_documents(self, descriptions, db_categories, db_entities): """ Delete mixin documents that is related to the OCCI_ID(scheme + term) contained in the description provided Args: @param descriptions: OCCI description of the mixin document to delete @param db_categories: Category data already contained in the database @param db_entities: Entity data already contained in the database """ mix_ref = list() res_code = return_code['OK'] for desc in descriptions: #Step[1]: Verify the existence of such mixin document occi_id = joker.get_description_id(desc) mixin_id_rev = joker.verify_exist_occi_id(occi_id, db_categories) if mixin_id_rev is not None: #Step[2]: dissociate entities from mixins db_entities, dissociated = self.dissociate_entities_belonging_to_mixin(occi_id, db_entities) if dissociated is True: #Step[3]: If OK, add mixin doc ref to the delete list mix_ref.append(mixin_id_rev) event = "Mixin document " + occi_id + " is sent for delete " logger.debug("===== Delete_mixin_documents : " + event + " =====") else: event = "Unable to delete because this mixin document " + occi_id + \ " still has resources depending on it. " logger.error(" ===== Delete_mixin_documents : " + event + " =====") return list(), list(), return_code['Bad Request'] else: event = "Could not find this mixin document " + occi_id logger.error("===== Delete_mixin_documents : " + event + " =====") return list(), list(), return_code['Bad Request'] return mix_ref, db_entities, res_code
def update_OCCI_mixin_descriptions(self, new_data, db_data): """ Updates the OCCI description field of the mixin which document OCCI_ID is equal to OCCI_ID contained in data Args: @param new_data: Data containing the OCCI ID of the mixin and the new OCCI mixin description @param db_data: Data already contained in the database """ to_update = list() resp_code = return_code['OK'] for desc in new_data: #Step[1]: Extract the old document occi_id = joker.get_description_id(desc) old_doc = joker.extract_doc(occi_id, db_data) if old_doc is not None: #Step[2]: Update OCCI mixin description problems, occi_description = joker.update_occi_category_description(old_doc['OCCI_Description'], desc) if problems is True: message = "Mixin OCCI description " + occi_id + " has not been totally updated." logger.error("===== update_OCCI_mixin_descriptions: " + message + " ===== ") return list(), return_code['Bad Request'] else: #Step[3]: If OK, append the mixin doc to the to_update list message = "Mixin OCCI description " + occi_id + " has been updated successfully" old_doc['OCCI_Description'] = occi_description to_update.append(old_doc) logger.debug("===== update_OCCI_mixin_descriptions: " + message + " ===== ") else: message = "Mixin document " + occi_id + " couldn\'t be found " logger.error("===== update_OCCI_mixin_descriptions: " + message + " ===== ") return list(), return_code['Not Found'] return to_update, resp_code
def update_OCCI_kind_descriptions(self, new_data, db_data): """ Updates the OCCI description field of the kind which document OCCI_ID is equal to OCCI_ID contained in data (Should only be done by the creator of the kind document) Args: @param new_data: Data containing the OCCI ID of the kind and the new OCCI kind description @param db_data: Categories already contained in the database """ to_update = list() resp_code = return_code['OK'] for desc in new_data: occi_id = joker.get_description_id(desc) old_doc = joker.extract_doc(occi_id, db_data) if old_doc is not None: problems, occi_description = joker.update_occi_category_description(old_doc['OCCI_Description'], desc) if problems is True: message = "Kind OCCI description " + occi_id + " has not been totally updated." logger.error("===== Kind OCCI description update:" + message + " =====") return list(), return_code['Bad Request'] else: message = "Kind OCCI description " + occi_id + " has been updated successfully" old_doc['OCCI_Description'] = occi_description to_update.append(old_doc) logger.debug("===== Update kind OCCI description : " + message + " =====") else: message = "Kind document " + occi_id + " couldn\'t be found " logger.error("===== Update kind OCCI description : " + message + " =====") return list(), return_code['Not Found'] return to_update, resp_code
def bake_to_delete_categories_mixins(self, mixins): """ Get entities related to the mixin for the delete categories method @param mixins: mixin OCCI ID """ #Step[1]: Get data from the supplier db_mixin_entities = list() for mix in mixins: occi_id = joker.get_description_id(mix) query = self.category_sup.get_entities_of_mixin(occi_id) if query is None: return None #Step[2]: prepare data else: if query.count() is not 0: db_mixin_entities.append(query.first()['value']) #Step[3]: Return data return db_mixin_entities