def channel_post_single_resource(self, jBody, path_url): """ Performs a partial description update of the resource Args: @param jBody: New OCCI values @param path_url: URL of the request """ #Step[1]: Get the necessary data from the database db_occi_ids_locs,old_doc = self.rd_baker.bake_to_post_single(path_url) if old_doc is 0: logger.error("===== Channel_post_single_resource ==== : Resource not found") return "An error has occurred, please check logs for more details",return_code['Internal Server Error'] else: old_data = old_doc['OCCI_Description'] entity = dict() #Step[2]: update only the part that exist in both the new values and the old resource description if jBody.has_key('resources'): logger.debug("===== Channel_post_single_resource ==== : Resource was found and channeled") entity, resp_code_r = self.manager_r.partial_resource_update(old_doc['OCCI_Description'],jBody['resources'][0]) else: logger.debug("===== Channel_post_single_resource ==== : No Resource was found") resp_code_r = return_code['OK, and location returned'] if jBody.has_key('links'): logger.debug("===== Channel_post_single_resource ==== : Link was found and channeled") entity, resp_code_l = self.manager_l.partial_link_update(old_doc['OCCI_Description'],jBody['links'][0]) else: logger.debug("===== Channel_post_single_resource ==== : No Link was found") 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'] old_doc['OCCI_Description'] = entity self.PostMan.save_partial_updated_doc_in_db(old_doc) logger.debug("===== Channel_post_single_resource ==== : Finished with success") backend_m.update_entity(old_data,entity) #Step[3]: Return the locations of the resource return old_doc['OCCI_Location'],return_code['OK, and location returned']
def channel_post_single_resource(self, jBody, path_url): """ Performs a partial description update of the resource Args: @param jBody: Data contained in the request body @param path_url: URL of the request """ db_occi_ids_locs,old_doc = self.rd_baker.bake_to_post_single(path_url) if old_doc is 0: logger.error("===== Channel_post_single_resource ==== : Resource not found") return "An error has occurred, please check logs for more details",return_code['Internal Server Error'] else: old_data = old_doc['OCCI_Description'] entity = dict() #This is an update of a resource if jBody.has_key('resources'): logger.debug("===== Channel_post_single_resource ==== : Resource was found and channeled") entity, resp_code_r = self.manager_r.partial_resource_update(old_doc['OCCI_Description'],jBody['resources'][0]) else: logger.debug("===== Channel_post_single_resource ==== : No Resource was found") resp_code_r = return_code['OK, and location returned'] if jBody.has_key('links'): logger.debug("===== Channel_post_single_resource ==== : Link was found and channeled") entity, resp_code_l = self.manager_l.partial_link_update(old_doc['OCCI_Description'],jBody['links'][0],db_occi_ids_locs) else: logger.debug("===== Channel_post_single_resource ==== : No Link was found") 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'] old_doc['OCCI_Description'] = entity self.PostMan.save_partial_updated_doc_in_db(old_doc) # self.PostMan.database.save_doc(old_doc,force_update=True, all_or_nothing=True) logger.debug("===== Channel_post_single_resource ==== : Finished with success") backend_m.update_entity(old_data,entity) #return the locations of the resources return old_doc['OCCI_Location'],return_code['OK, and location returned']
def channel_put_single_resource(self, jBody, path_url): """ Creates a new resource or performs a full update of the resource description Args: @param jBody: Data contained in the request body @param path_url: URL of the request """ #Step[1]: Get the data necessary from the database db_occi_ids_locs,db_resources_nb = self.rd_baker.bake_to_put_single(path_url) if db_occi_ids_locs is None or db_resources_nb is None: return "An error has occurred, please check log for more details",return_code['Internal Server Error'] else: if db_resources_nb is 0: #Step[2a]: This is a create a new resource request with a custom URL if jBody.has_key('resources'): logger.debug("===== Channel_put_single_resources ==== : Resource custom creation channeled") entity, resp_code_r = self.manager_r.register_custom_resource(jBody['resources'][0],path_url,db_occi_ids_locs) else: resp_code_r = return_code['OK, and location returned'] if jBody.has_key('links'): logger.debug("===== Channel_put_single_resources ==== : Link custom creation channeled") entity, resp_code_l = self.manager_l.register_custom_link(jBody['links'][0],path_url,db_occi_ids_locs) else: 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'] self.PostMan.save_custom_resource(entity) logger.debug("===== Channel_put_single_resource ==== : Finished (2a) with success") backend_m.create_entity(entity) #Step[3a]: Return the locations of the resources return entity['OCCI_Location'],return_code['OK, and location returned'] else: #Step[2b]: This is a full update resource request (More data is needed) olddoc = self.rd_baker.bake_to_put_single_updateCase(path_url) if olddoc is None: return "An error has occurred, please check log for more details",return_code['Bad Request'] else: if jBody.has_key('resources'): logger.debug("===== Channel_put_single_resources ==== : Resource full update channeled") entity, resp_code_r = self.manager_r.update_resource(olddoc,jBody['resources'][0]) else: resp_code_r = return_code['OK, and location returned'] if jBody.has_key('links'): logger.debug("===== Channel_put_single_resources ==== : Link full update channeled") entity, resp_code_l = self.manager_l.update_link(olddoc,jBody['links'][0]) else: 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'] self.PostMan.save_updated_doc_in_db(entity) logger.debug("===== Channel_put_single_resource ==== : Finished (2b) with success") #return the locations of the resources backend_m.update_entity(olddoc['OCCI_Description'],entity['OCCI_Description']) return olddoc['OCCI_Location'],return_code['OK, and location returned']
def channel_put_single_resource(self, jBody, path_url): """ Creates a new resource or performs a full update of the resource description Args: @param jBody: Data contained in the request body @param path_url: URL of the request """ #Step[1]: Get the data necessary from the database db_occi_ids_locs, db_resources_nb = self.rd_baker.bake_to_put_single( path_url) if db_occi_ids_locs is None or db_resources_nb is None: return "An error has occurred, please check log for more details", return_code[ 'Internal Server Error'] else: if db_resources_nb is 0: #Step[2a]: This is a create a new resource request with a custom URL if jBody.has_key('resources'): logger.debug( "===== Channel_put_single_resources ==== : Resource custom creation channeled" ) entity, resp_code_r = self.manager_r.register_custom_resource( jBody['resources'][0], path_url, db_occi_ids_locs) else: resp_code_r = return_code['OK, and location returned'] if jBody.has_key('links'): logger.debug( "===== Channel_put_single_resources ==== : Link custom creation channeled" ) entity, resp_code_l = self.manager_l.register_custom_link( jBody['links'][0], path_url, db_occi_ids_locs) else: 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'] self.PostMan.save_custom_resource(entity) logger.debug( "===== Channel_put_single_resource ==== : Finished (2a) with success" ) backend_m.create_entity(entity) #Step[3a]: Return the locations of the resources return entity['OCCI_Location'], return_code[ 'OK, and location returned'] else: #Step[2b]: This is a full update resource request (More data is needed) olddoc = self.rd_baker.bake_to_put_single_updateCase(path_url) if olddoc is None: return "An error has occurred, please check log for more details", return_code[ 'Bad Request'] else: if jBody.has_key('resources'): logger.debug( "===== Channel_put_single_resources ==== : Resource full update channeled" ) entity, resp_code_r = self.manager_r.update_resource( olddoc, jBody['resources'][0]) else: resp_code_r = return_code['OK, and location returned'] if jBody.has_key('links'): logger.debug( "===== Channel_put_single_resources ==== : Link full update channeled" ) entity, resp_code_l = self.manager_l.update_link( olddoc, jBody['links'][0]) else: 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'] self.PostMan.save_updated_doc_in_db(entity) logger.debug( "===== Channel_put_single_resource ==== : Finished (2b) with success" ) #return the locations of the resources backend_m.update_entity(olddoc['OCCI_Description'], entity['OCCI_Description']) return olddoc['OCCI_Location'], return_code[ 'OK, and location returned']
def channel_post_single_resource(self, jBody, path_url): """ Performs a partial description update of the resource Args: @param jBody: New OCCI values @param path_url: URL of the request """ #Step[1]: Get the necessary data from the database db_occi_ids_locs, old_doc = self.rd_baker.bake_to_post_single(path_url) if old_doc is 0: logger.error( "===== Channel_post_single_resource ==== : Resource not found") return "An error has occurred, please check logs for more details", return_code[ 'Internal Server Error'] else: old_data = old_doc['OCCI_Description'] entity = dict() #Step[2]: update only the part that exist in both the new values and the old resource description if jBody.has_key('resources'): logger.debug( "===== Channel_post_single_resource ==== : Resource was found and channeled" ) entity, resp_code_r = self.manager_r.partial_resource_update( old_doc['OCCI_Description'], jBody['resources'][0]) else: logger.debug( "===== Channel_post_single_resource ==== : No Resource was found" ) resp_code_r = return_code['OK, and location returned'] if jBody.has_key('links'): logger.debug( "===== Channel_post_single_resource ==== : Link was found and channeled" ) entity, resp_code_l = self.manager_l.partial_link_update( old_doc['OCCI_Description'], jBody['links'][0]) else: logger.debug( "===== Channel_post_single_resource ==== : No Link was found" ) 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'] old_doc['OCCI_Description'] = entity self.PostMan.save_partial_updated_doc_in_db(old_doc) logger.debug( "===== Channel_post_single_resource ==== : Finished with success" ) backend_m.update_entity(old_data, entity) #Step[3]: Return the locations of the resource return old_doc['OCCI_Location'], return_code[ 'OK, and location returned']