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
Beispiel #2
0
    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 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_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
Beispiel #5
0
    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
Beispiel #6
0
    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
Beispiel #7
0
    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