Example #1
0
    def channel_delete_multi(self, jreq, req_url):
        """
        Remove the mixin from the resources
        Args:
            @param jreq: OCCI_Locations of the resources
            @param req_url: URL of the request
        """

        #Step[1]: Get the necessary data from DB

        nb_res, mix_id = self.rd_baker.bake_to_post_multi_resources_2b(req_url)
        if nb_res is None:
            return "An error has occurred, please check log for more details", return_code[
                'Internal Server Error']

        elif nb_res is 0:
            return "An error has occurred, please check log for more details", return_code[
                'Not Found']

        else:
            to_search_for = jreq['X-OCCI-Location']
            db_docs = self.rd_baker.bake_to_post_multi_resources_2b2(
                to_search_for)

            if db_docs is 0:
                return "An error has occurred, please check log for more details", return_code[
                    'Not Found']

            elif db_docs is None:
                return "An error has occurred, please check log for more details", return_code[
                    'Internal Server Error']

            else:
                logger.debug(
                    " ===== Delete_multi_entities : Delete on mixin to Dissociate mixins channeled ====="
                )
                updated_entities, resp_code_e = dissociate_entities_from_a_mixin(
                    mix_id, db_docs)

            if resp_code_e is not return_code['OK']:
                return "An error has occurred, please check log for more details", return_code[
                    'Bad Request']

            self.PostMan.save_updated_docs_in_db(updated_entities)

            backend_m.update_entities(db_docs, updated_entities)

            return "", return_code['OK']
Example #2
0
    def channel_put_multi(self, jreq, req_url):
        """
        Update the mixin collection of resources
        Args:

            @param jreq: OCCI_Locations of the resources
            @param req_url: URL of the request
        """

        #Step[1]: Get the necessary data from DB

        nb_res, mix_id = self.rd_baker.bake_to_post_multi_resources_2b(req_url)
        if nb_res is None:
            return "An error has occurred, please check log for more details", return_code[
                'Internal Server Error']
        elif nb_res is 0:
            return "An error has occurred, please check log for more details", return_code[
                'Not Found']
        else:
            to_search_for = jreq['X-OCCI-Location']
            db_docs = self.rd_baker.bake_to_post_multi_resources_2b2(
                to_search_for)

            if db_docs is 0:
                return "An error has occurred, please check log for more details", return_code[
                    'Not Found']

            elif db_docs is None:
                return "An error has occurred, please check log for more details", return_code[
                    'Internal Server Error']

            else:
                #Step[2]: Ask the managers to associate mixins to resources
                logger.debug(
                    "===== Channel_put_multi_resources ==== : Put on mixin path to associate a mixin channeled"
                )
                updated_entities, resp_code_e = associate_entities_to_a_mixin(
                    mix_id, db_docs)

                self.PostMan.save_updated_docs_in_db(updated_entities)

                logger.debug(
                    "===== Channel_put_multi_resources ==== : Finished (2b) with success"
                )
                backend_m.update_entities(db_docs, updated_entities)
                return "", return_code['OK']
    def channel_delete_multi(self, jreq, req_url):
        """
        Remove the mixin from the resources
        Args:
            @param jreq: OCCI_Locations of the resources
            @param req_url: URL of the request
        """

        # Step[1]: Get the necessary data from DB

        nb_res, mix_id = self.rd_baker.bake_to_post_multi_resources_2b(req_url)
        if nb_res is None:
            return "An error has occurred, please check log for more details", return_code["Internal Server Error"]

        elif nb_res is 0:
            return "An error has occurred, please check log for more details", return_code["Not Found"]

        else:
            to_search_for = jreq["X-OCCI-Location"]
            db_docs = self.rd_baker.bake_to_post_multi_resources_2b2(to_search_for)

            if db_docs is 0:
                return "An error has occurred, please check log for more details", return_code["Not Found"]

            elif db_docs is None:
                return "An error has occurred, please check log for more details", return_code["Internal Server Error"]

            else:
                logger.debug(" ===== Delete_multi_entities : Delete on mixin to Dissociate mixins channeled =====")
                updated_entities, resp_code_e = dissociate_entities_from_a_mixin(mix_id, db_docs)

            if resp_code_e is not return_code["OK"]:
                return "An error has occurred, please check log for more details", return_code["Bad Request"]

            self.PostMan.save_updated_docs_in_db(updated_entities)

            backend_m.update_entities(db_docs, updated_entities)

            return "", return_code["OK"]
    def channel_put_multi(self, jreq, req_url):
        """
        Update the mixin collection of resources
        Args:

            @param jreq: OCCI_Locations of the resources
            @param req_url: URL of the request
        """

        # Step[1]: Get the necessary data from DB

        nb_res, mix_id = self.rd_baker.bake_to_post_multi_resources_2b(req_url)
        if nb_res is None:
            return "An error has occurred, please check log for more details", return_code["Internal Server Error"]
        elif nb_res is 0:
            return "An error has occurred, please check log for more details", return_code["Not Found"]
        else:
            to_search_for = jreq["X-OCCI-Location"]
            db_docs = self.rd_baker.bake_to_post_multi_resources_2b2(to_search_for)

            if db_docs is 0:
                return "An error has occurred, please check log for more details", return_code["Not Found"]

            elif db_docs is None:
                return "An error has occurred, please check log for more details", return_code["Internal Server Error"]

            else:
                # Step[2]: Ask the managers to associate mixins to resources
                logger.debug(
                    "===== Channel_put_multi_resources ==== : Put on mixin path to associate a mixin channeled"
                )
                updated_entities, resp_code_e = associate_entities_to_a_mixin(mix_id, db_docs)

                self.PostMan.save_updated_docs_in_db(updated_entities)

                logger.debug("===== Channel_put_multi_resources ==== : Finished (2b) with success")
                backend_m.update_entities(db_docs, updated_entities)
                return "", return_code["OK"]
    def channel_post_multi_resources(self, jreq, req_path):
        """
        Identifies the post path's goal : create a resource instance or update a mixin collection
        Args:
            @param jreq: Body content of the post request
            @param req_path: Address to which this post request was sent
        """
        # Step[1]: detect the goal of the request

        if jreq.has_key("resources") or jreq.has_key("links"):
            is_kind_loc = True
        else:
            is_kind_loc = False

        if is_kind_loc is True:

            # Step[2a]: This is a create new resources request

            db_occi_ids_locs = self.rd_baker.bake_to_post_multi_resources_2a()

            # Step[3a]: Look for the default attributes to complete the attribute description of the resource:
            default_attributes = self.rd_baker.bake_to_get_default_attributes(req_path)

            if db_occi_ids_locs is None or default_attributes is None:
                return "An error has occurred, please check log for more details", return_code["Internal Server Error"]
            else:

                # Step[4a]: Ask the managers to create the new resources

                if jreq.has_key("resources"):
                    logger.debug(
                        "===== Channel_post_multi_resources ==== : Post on kind path to create a new resource channeled"
                    )
                    new_resources, resp_code_r = self.manager_r.register_resources(
                        jreq["resources"], req_path, db_occi_ids_locs, default_attributes
                    )
                else:
                    new_resources = list()
                    resp_code_r = return_code["OK, and location returned"]

                if jreq.has_key("links"):
                    logger.debug(
                        "===== Channel_post_multi_resources ==== : Post on kind path to create a new link channeled"
                    )
                    new_links, resp_code_l = self.manager_l.register_links_explicit(
                        jreq["links"], req_path, db_occi_ids_locs, default_attributes
                    )
                else:
                    new_links = list()
                    resp_code_l = return_code["OK, and location returned"]

                if (
                    resp_code_r is not return_code["OK, and location returned"]
                    or resp_code_l is not return_code["OK, and location returned"]
                ):
                    return "An error has occurred, please check log for more details", return_code["Bad Request"]

                # Step[5a]: Save the new resources
                entities = new_resources + new_links

                self.PostMan.save_registered_docs_in_db(entities)
                logger.debug("===== Channel_post_multi_resources ==== : Finished (2a) with success")

                locations = list()

                for item in entities:
                    locations.append(item["OCCI_Location"])

                backend_m.create_entities(entities)

                return locations, return_code["OK, and location returned"]

                # Step[2b]: This is an associate mixins to resources request

        elif jreq.has_key("X-OCCI-Location"):

            # Step[3b]: Get the necessary data from DB
            nb_res, mix_id = self.rd_baker.bake_to_post_multi_resources_2b(req_path)

            if nb_res is None:
                return "An error has occurred, please check log for more details", return_code["Internal Server Error"]
            elif nb_res is 0:
                return "An error has occurred, please check log for more details", return_code["Not Found"]
            else:
                to_search_for = jreq["X-OCCI-Location"]

                db_docs = self.rd_baker.bake_to_post_multi_resources_2b2(to_search_for)

                if db_docs is 0:
                    return "An error has occurred, please check log for more details", return_code["Not Found"]

                elif db_docs is None:
                    return (
                        "An error has occurred, please check log for more details",
                        return_code["Internal Server Error"],
                    )

                else:
                    # Step[4b]: Ask the managers to associate mixins to resources
                    logger.debug(
                        "===== Channel_post_multi_resources ==== : Post on mixin path to associate a mixin channeled"
                    )
                    updated_entities, resp_code_e = associate_entities_to_a_mixin(mix_id, db_docs)

                    self.PostMan.save_updated_docs_in_db(updated_entities)
                    logger.debug("===== Channel_post_multi_resources ==== : Finished (2b) with success")
                    backend_m.update_entities(db_docs, updated_entities)
                    return "", return_code["OK"]
        else:
            return "An error has occurred, please check log for more details", return_code["Bad Request"]
Example #6
0
    def channel_post_multi_resources(self, jreq, req_path):
        """
        Identifies the post path's goal : create a resource instance or update a mixin collection
        Args:
            @param jreq: Body content of the post request
            @param req_path: Address to which this post request was sent
        """
        #Step[1]: detect the goal of the request

        if jreq.has_key('resources') or jreq.has_key('links'):
            is_kind_loc = True
        else:
            is_kind_loc = False

        if is_kind_loc is True:

            #Step[2a]: This is a create new resources request

            db_occi_ids_locs = self.rd_baker.bake_to_post_multi_resources_2a()

            #Step[3a]: Look for the default attributes to complete the attribute description of the resource:
            default_attributes = self.rd_baker.bake_to_get_default_attributes(
                req_path)

            if db_occi_ids_locs is None or default_attributes is None:
                return "An error has occurred, please check log for more details", return_code[
                    'Internal Server Error']
            else:

                #Step[4a]: Ask the managers to create the new resources

                if jreq.has_key('resources'):
                    logger.debug(
                        "===== Channel_post_multi_resources ==== : Post on kind path to create a new resource channeled"
                    )
                    new_resources, resp_code_r = self.manager_r.register_resources(
                        jreq['resources'], req_path, db_occi_ids_locs,
                        default_attributes)
                else:
                    new_resources = list()
                    resp_code_r = return_code['OK, and location returned']

                if jreq.has_key('links'):
                    logger.debug(
                        "===== Channel_post_multi_resources ==== : Post on kind path to create a new link channeled"
                    )
                    new_links, resp_code_l = self.manager_l.register_links_explicit(
                        jreq['links'], req_path, db_occi_ids_locs,
                        default_attributes)
                else:
                    new_links = list()
                    resp_code_l = return_code['OK, and location returned']

                if resp_code_r is not return_code['OK, and location returned']\
                or resp_code_l is not return_code['OK, and location returned']:
                    return "An error has occurred, please check log for more details", return_code[
                        'Bad Request']

                #Step[5a]: Save the new resources
                entities = new_resources + new_links

                self.PostMan.save_registered_docs_in_db(entities)
                logger.debug(
                    "===== Channel_post_multi_resources ==== : Finished (2a) with success"
                )

                locations = list()

                for item in entities:
                    locations.append(item['OCCI_Location'])

                backend_m.create_entities(entities)

                return locations, return_code['OK, and location returned']

                #Step[2b]: This is an associate mixins to resources request

        elif jreq.has_key('X-OCCI-Location'):

            #Step[3b]: Get the necessary data from DB
            nb_res, mix_id = self.rd_baker.bake_to_post_multi_resources_2b(
                req_path)

            if nb_res is None:
                return "An error has occurred, please check log for more details", return_code[
                    'Internal Server Error']
            elif nb_res is 0:
                return "An error has occurred, please check log for more details", return_code[
                    'Not Found']
            else:
                to_search_for = jreq['X-OCCI-Location']

                db_docs = self.rd_baker.bake_to_post_multi_resources_2b2(
                    to_search_for)

                if db_docs is 0:
                    return "An error has occurred, please check log for more details", return_code[
                        'Not Found']

                elif db_docs is None:
                    return "An error has occurred, please check log for more details", return_code[
                        'Internal Server Error']

                else:
                    #Step[4b]: Ask the managers to associate mixins to resources
                    logger.debug(
                        "===== Channel_post_multi_resources ==== : Post on mixin path to associate a mixin channeled"
                    )
                    updated_entities, resp_code_e = associate_entities_to_a_mixin(
                        mix_id, db_docs)

                    self.PostMan.save_updated_docs_in_db(updated_entities)
                    logger.debug(
                        "===== Channel_post_multi_resources ==== : Finished (2b) with success"
                    )
                    backend_m.update_entities(db_docs, updated_entities)
                    return "", return_code['OK']
        else:
            return "An error has occurred, please check log for more details", return_code[
                'Bad Request']