def register_resources(self, occi_descriptions, url_path, db_occi_ids_locs, default_attributes): """ Add new resources to the database Args: @param occi_descriptions: the OCCI description of the new resources @param db_occi_ids_locs: OCCI IDs and OCCI Location extracted from the database @param url_path: URL path of the request @param default_attributes: the default attributes extracted from kind """ loc_res = list() kind_occi_id = None #Step[1]: Get the kind on which the request was sent for elem in db_occi_ids_locs: if elem['OCCI_Location'] == url_path: kind_occi_id = elem['OCCI_ID'] break if kind_occi_id is not None: for desc in occi_descriptions: #Note: Verify if the kind to which this request is sent is the same as the one in the link description if desc['kind'] == kind_occi_id: ## added by Marouen Mechtri to generate automatically the category ID if 'id' not in desc: desc['id'] = uuid_Generator.get_UUID() #Note: create the url of the id based on the id provided in the request loc = joker.make_entity_location_from_url(url_path, desc['id']) exist_same = joker.verify_existences_teta([loc], db_occi_ids_locs) #Step[2]: Create the new resource if exist_same is False: jData = dict() jData['_id'] = uuid_Generator.get_UUID() jData['OCCI_Location'] = loc full_att = joker.complete_occi_description_with_default_attributes(desc['attributes'], default_attributes) desc['attributes'] = full_att jData['OCCI_Description'] = desc jData['Type'] = "Resource" loc_res.append(jData) else: logger.error(" ===== Register_resources : Bad Resource id ===== ") return list(), return_code['Conflict'] else: mesg = "Kind description and kind location don't match" logger.error("===== Register_resources: " + mesg + " ===== ") return list(), return_code['Conflict'] #Step[3]: return the list of resources for creation logger.debug("===== Register_resources: Resources sent for creation =====") return loc_res, return_code['OK, and location returned'] else: mesg = "No kind corresponding to this location was found" logger.error("===== Register_resources: " + mesg + " =====") return list(), return_code['Not Found']
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 register_custom_link(self, occi_description, path_url, db_occi_ids_locs): """ Add a new link with a custom URL to the database Args: @param occi_description: link description @param path_url: Custom URL of the link @param db_occi_ids_locs: Ids and locations from the database """ #Step[1]: Verify if the kind of the new link exists ok_k = joker.verify_existences_beta([occi_description['kind']], db_occi_ids_locs) #Step[2]: Create the link if ok_k is True: jData = dict() jData['_id'] = uuid_Generator.get_UUID() jData['OCCI_Location'] = path_url jData['OCCI_Description'] = occi_description jData['Type'] = "Link" else: mesg = "Kind description does not exist" logger.error(" ===== Register custom link : " + mesg + " ===== ") return list(), return_code['Not Found'] logger.debug( " ===== Register Custom link: Link sent for creation ===== ") return jData, return_code['OK, and location returned']
def format_text_plain_entity_to_json(self, body): kind, mixins, attributes, actions, links = extractor.get_entity_members_from_body( body) entity = dict() if kind is not None: entity['kind'] = kind if len(mixins) is not 0: entity['mixins'] = mixins if attributes is not None: entity['attributes'] = attributes if len(actions) is not 0: entity['actions'] = actions if len(links) is not 0: entity['links'] = links entity['id'] = generator.get_UUID() return {'resources': [entity]}
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 register_custom_resource(self, occi_description, path_url, db_occi_ids_locs): """ Add a new resource with a custom URL to the database Args: @param occi_description: Resource description @param path_url: Custom URL of the resource @param db_occi_ids_locs: Ids and locations from the database """ #Step[1]: Verify if the kind of the new resource exists ok_k = joker.verify_existences_beta([occi_description['kind']], db_occi_ids_locs) #Step[2]: create the resource if ok_k is True: jData = dict() jData['_id'] = uuid_Generator.get_UUID() jData['OCCI_Location'] = path_url jData['OCCI_Description'] = occi_description jData['Type'] = "Resource" else: mesg = "This kind does not exist" logger.error(" ===== Register_custom_resource : " + mesg + " =====") return list(), return_code['Not Found'] #Step[3]: send resource for creation logger.debug( "===== Register_custom_resource : Resources sent for creation") return jData, return_code['OK, and location returned']
def register_custom_resource(self, occi_description, path_url, db_occi_ids_locs): """ Add a new resource with a custom URL to the database Args: @param occi_description: Resource description @param path_url: Custom URL of the resource @param db_occi_ids_locs: Ids and locations from the database """ #Step[1]: Verify if the kind of the new resource exists ok_k = joker.verify_existences_beta([occi_description['kind']], db_occi_ids_locs) #Step[2]: create the resource if ok_k is True: jData = dict() jData['_id'] = uuid_Generator.get_UUID() jData['OCCI_Location'] = path_url jData['OCCI_Description'] = occi_description jData['Type'] = "Resource" else: mesg = "This kind does not exist" logger.error(" ===== Register_custom_resource : " + mesg + " =====") return list(), return_code['Not Found'] #Step[3]: send resource for creation logger.debug("===== Register_custom_resource : Resources sent for creation") return jData, return_code['OK, and location returned']
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 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 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 format_text_occi_entity_to_json(self, headers): kind, mixins, attributes, actions, links = extractor.get_entity_members_from_headers(headers) entity = dict() if kind is not None: entity['kind'] = kind if len(mixins) is not 0: entity['mixins'] = mixins if attributes is not None: entity['attributes'] = attributes if len(actions) is not 0: entity['actions'] = actions if len(links) is not 0: entity['links'] = links entity['id'] = generator.get_UUID() return {'resources': [entity]}
def register_links_explicit(self, occi_descriptions, url_path, db_occi_ids_locs, default_attributes): """ Add new links to database Args: @param occi_descriptions: The new Link OCCI descriptions @param db_occi_ids_locs: OCCI ID and locations extracted from the database @param url_path: URL path of the request @param default_attributes: The default attributes extracted from the kind """ loc_res = list() kind_occi_id = None #Step[1] Extract the kind of the sent request for elem in db_occi_ids_locs: if elem['OCCI_Location'] == url_path: kind_occi_id = elem['OCCI_ID'] break if kind_occi_id is not None: for desc in occi_descriptions: #Note: Verify if the kind to which this request is sent is the same as the one in the link description if desc['kind'] == kind_occi_id: #Note: Create the URL of the Link using the id provided in the OCCI description. loc = joker.make_entity_location_from_url( url_path, desc['id']) #Note: Verify the uniqueness of the Address. exist_same = joker.verify_existences_teta([loc], db_occi_ids_locs) if exist_same is False: jData = dict() jData['_id'] = uuid_Generator.get_UUID() jData['OCCI_Location'] = loc full_att = joker.complete_occi_description_with_default_attributes( desc['attributes'], default_attributes) desc['attributes'] = full_att jData['OCCI_Description'] = desc jData['Type'] = "Link" loc_res.append(jData) else: logger.error( " ===== Register links explicit : Bad Link id ===== " ) return list(), return_code['Conflict'] else: mesg = "Kind description and kind location don't match" logger.error(" ===== Register links explicit: " + mesg + " ===== ") return list(), return_code['Conflict'] #Step[3]: return the list of resources logger.debug( " ===== Register links explicit : links sent for creation ===== " ) return loc_res, return_code['OK, and location returned'] else: mesg = "No kind corresponding to this location was found" logger.error(" ===== Register links explicit: " + mesg + " =====") return list(), return_code['Not Found']