Skip to content

Loading…

Feb version #35

Merged
merged 6 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 18, 2013
  1. Fixed the link Manager

    skible committed
  2. Finished the PyOCNI Reform

    skible committed
Commits on Feb 19, 2013
  1. Finished the PyOCNI Reform

    skible committed
Commits on Feb 26, 2013
  1. @mseknibilel

    Update README.rst

    mseknibilel committed
  2. @mseknibilel

    Update README.rst

    mseknibilel committed
  3. Merge pull request #34 from mseknibilel/master

    committed
    Reviewing PyOCNI is complete
This page is out of date. Refresh to see the latest.
View
11 README.rst
@@ -61,16 +61,10 @@ This software needs this packages to run:
* python-all-dev (for eventlet/greenlet install/make)
* python-setuptools (to execute the setup.py file)
* couchdb >= 1.2.0:
-Example of installing couchdb using build-couchdb on Ubuntu (more details on: https://github.com/iriscouch/build-couchdb)
+To install couchdb on Ubuntu
::
- sudo apt-get install help2man make gcc zlib1g-dev libssl-dev rake help2man
- git clone git://github.com/iriscouch/build-couchdb
- cd build-couchdb
- git submodule init
- git submodule update
- rake
- build/bin/couchdb
+ sudo apt-get install couchdb
To test CouchDB: http://127.0.0.1:5984
@@ -105,6 +99,7 @@ In order to use pyOCNI, you must respect certain rules :
#. Scheme + Term = OCCI_ID : unique identifier of the OCCI (Kind/Mixin/Action) description
#. PyOCNI_Server_Address + location = OCCI_Location of (Kind/Mixin/Action) description
#. location word refers to a kind or mixin location.
+#. Links will be treated the same way as resources and internal links are not taking into account for clarity reasons.
PyOCNI offers two OCCI rendering formats : **HTTP and JSON**. The following commands are JSON specific. If you want to see HTTP command please check `here <https://github.com/mseknibilel/PyOCNI/blob/milestone/HTTP_HowTo.rst>`_.
View
6 pyocni/TDD/Tests/multientityInterface_Tests.py
@@ -50,7 +50,7 @@ def setUp(self):
self.p = Process(target=start_server)
self.p.start()
time.sleep(0.5)
- init_fakeDB()
+ #init_fakeDB()
time.sleep(0.5)
def tearDown(self):
@@ -63,10 +63,10 @@ def test_register_entities(self):
"""
storage = StringIO.StringIO()
c = pycurl.Curl()
- c.setopt(c.URL, 'http://127.0.0.1:8090/compute/?action=start')
+ c.setopt(c.URL, 'http://127.0.0.1:8090/compute/')
c.setopt(c.HTTPHEADER, ['Accept:text/plain', 'Content-Type: application/occi+json'])
c.setopt(c.VERBOSE, True)
- c.setopt(pycurl.POSTFIELDS, f_entities.action_plus_attributes)
+ c.setopt(pycurl.POSTFIELDS, f_entities.link)
c.setopt(c.CUSTOMREQUEST, 'POST')
c.setopt(c.WRITEFUNCTION, storage.write)
c.perform()
View
1 pyocni/TDD/Tests/queryInterface_Tests.py
@@ -33,6 +33,7 @@
import pyocni.pyocni_tools.config as config
def start_server():
+
ocni_server_instance = ocni_server()
ocni_server_instance.run_server()
View
24 pyocni/dispachers/multi_entityDispatcher.py
@@ -79,7 +79,7 @@ def post(self):
jBody = self.req_adapter.convert_request_entity_content(self.req)
if jBody is None:
- self.res.status_code = return_code['Not Acceptable']
+ self.res.status_int = return_code['Not Acceptable']
self.res.body = self.req.content_type + " is an unknown request content type"
else:
@@ -92,11 +92,11 @@ def post(self):
if self.triggered_action is None:
- var, self.res.status_code = self.jungler.channel_post_multi_resources(jBody, self.path_url)
+ var, self.res.status_int = self.jungler.channel_post_multi_resources(jBody, self.path_url)
#Step[4a]: Adapt response to the required Accept-Type
- if self.res.status_code == return_code['OK, and location returned']:
+ if self.res.status_int == return_code['OK, and location returned']:
self.res_adapter.convert_response_entity_multi_location_content(var, self.res)
else:
@@ -105,7 +105,7 @@ def post(self):
#Step[3b]: Trigger an action on all resources belonging to a kind
else:
- self.res.body, self.res.status_code = self.jungler.channel_trigger_actions(jBody, self.path_url,
+ self.res.body, self.res.status_int = self.jungler.channel_trigger_actions(jBody, self.path_url,
self.triggered_action)
return self.res
@@ -124,20 +124,20 @@ def get(self):
jBody = self.req_adapter.convert_request_entity_content_v2(self.req)
if jBody is None:
- self.res.status_code = return_code['Not Acceptable']
+ self.res.status_int = return_code['Not Acceptable']
self.res.body = self.req.content_type + " is an unknown request content type"
else:
#Step[2a]: Retrieve entities matching the filter provided
- var, self.res.status_code = self.jungler.channel_get_filtered_entities(self.path_url, jBody)
+ var, self.res.status_int = self.jungler.channel_get_filtered_entities(self.path_url, jBody)
else:
#Step[2b]: Retrieve all the entities
- var, self.res.status_code = self.jungler.channel_get_all_entities(self.path_url, "")
+ var, self.res.status_int = self.jungler.channel_get_all_entities(self.path_url, "")
#Step[3]: Adapt the response to the format defined in the Accept-Type header
- if self.res.status_code == return_code['OK']:
+ if self.res.status_int == return_code['OK']:
self.res_adapter.convert_response_entity_multi_x_occi_location_content(var, self.res)
@@ -158,13 +158,13 @@ def put(self):
jBody = self.req_adapter.convert_request_category_content(self.req)
if jBody is None:
- self.res.status_code = return_code['Not Acceptable']
+ self.res.status_int = return_code['Not Acceptable']
self.res.body = self.req.content_type + " is an unknown request content type"
else:
#Step[2]: Fully update the mixin collection of entities
- self.res.body, self.res.status_code = self.jungler.channel_put_multi(jBody, self.path_url)
+ self.res.body, self.res.status_int = self.jungler.channel_put_multi(jBody, self.path_url)
return self.res
@@ -181,11 +181,11 @@ def delete(self):
jBody = self.req_adapter.convert_request_category_content(self.req)
if jBody is None:
- self.res.status_code = return_code['Not Acceptable']
+ self.res.status_int = return_code['Not Acceptable']
self.res.body = self.req.content_type + " is an unknown request content type"
#Step[2a]: This is a dissociate mixin request
- self.res.body, self.res.status_code = self.jungler.channel_delete_multi(jBody, self.path_url)
+ self.res.body, self.res.status_int = self.jungler.channel_delete_multi(jBody, self.path_url)
else:
#Step[2b]: This is a delete on path request:
self.jungler_p.channel_delete_on_path(self.path_url)
View
22 pyocni/dispachers/queryDispatcher.py
@@ -62,25 +62,25 @@ def get(self):
jreq = self.req_adapter.convert_request_category_content(self.req)
if jreq is None:
- self.res.status_code = return_code['Not Acceptable']
+ self.res.status_int = return_code['Not Acceptable']
self.res.body = self.req.content_type + " is an unknown request content type"
else:
#Step[2a]: Retrieve the categories matching with the filter provided in the request:
- var, self.res.status_code = self.jungler.channel_get_filtered_categories(jreq)
+ var, self.res.status_int = self.jungler.channel_get_filtered_categories(jreq)
else:
#Step[2b]: Retrieve all the categories:
- var, self.res.status_code = self.jungler.channel_get_all_categories()
+ var, self.res.status_int = self.jungler.channel_get_all_categories()
#Step[3]: Adapt the response to the required accept-type
- if self.res.status_code == return_code['OK']:
+ if self.res.status_int == return_code['OK']:
self.res = self.res_adapter.convert_response_category_content(self.res, var)
else:
self.res.content_type = "text/html"
- self.res.body = var
+ self.res.body = str(var)
return self.res
@@ -96,12 +96,12 @@ def post(self):
if jBody is None:
- self.res.status_code = return_code['Not Acceptable']
+ self.res.status_int = return_code['Not Acceptable']
self.res.body = self.req.content_type + " is an unknown request content type"
else:
#Step[2]: Create the categories
- self.res.body, self.res.status_code = self.jungler.channel_register_categories(jBody)
+ self.res.body, self.res.status_int = self.jungler.channel_register_categories(jBody)
return self.res
@@ -116,13 +116,13 @@ def put(self):
jBody = self.req_adapter.convert_request_category_content(self.req)
if jBody is None:
- self.res.status_code = return_code['Not Acceptable']
+ self.res.status_int = return_code['Not Acceptable']
self.res.body = self.req.content_type + " is an unknown request content type"
else:
#Step[2]: Update the new data:
- self.res.body, self.res.status_code = self.jungler.channel_update_categories(jBody)
+ self.res.body, self.res.status_int = self.jungler.channel_update_categories(jBody)
return self.res
@@ -136,12 +136,12 @@ def delete(self):
jBody = self.req_adapter.convert_request_category_content(self.req)
if jBody is None:
- self.res.status_code = return_code['Not Acceptable']
+ self.res.status_int = return_code['Not Acceptable']
self.res.body = self.req.content_type + " is an unknown request content type"
else:
#Step[2]: Delete the category
- self.res.body, self.res.status_code = self.jungler.channel_delete_categories(jBody)
+ self.res.body, self.res.status_int = self.jungler.channel_delete_categories(jBody)
return self.res
View
20 pyocni/dispachers/single_entityDispatcher.py
@@ -74,16 +74,16 @@ def put(self):
jBody = self.req_adapter.convert_request_entity_content(self.req)
if jBody is None:
- self.res.status_code = return_code['Not Acceptable']
+ self.res.status_int = return_code['Not Acceptable']
self.res.body = self.req.content_type + " is an unknown request content type"
else:
#Step[2]: create the resource with custom URL
- var, self.res.status_code = self.jungler.channel_put_single_resource(jBody, self.path_url)
+ var, self.res.status_int = self.jungler.channel_put_single_resource(jBody, self.path_url)
#Step[3]: Adapt the response to the required accept-type
- if self.res.status_code == return_code['OK, and location returned']:
+ if self.res.status_int == return_code['OK, and location returned']:
self.res = self.res_adapter.convert_response_entity_location_content(var, self.res)
else:
self.res.content_type = "text/html"
@@ -101,11 +101,11 @@ def get(self):
#Step[1]: get the resource description
- var, self.res.status_code = self.jungler.channel_get_single_resource(self.path_url)
+ var, self.res.status_int = self.jungler.channel_get_single_resource(self.path_url)
#Step[2]: Adapt the response to the required accept-type
- if self.res.status_code == return_code['OK']:
+ if self.res.status_int == return_code['OK']:
self.res = self.res_adapter.convert_response_entity_content(self.res, var)
else:
@@ -132,7 +132,7 @@ def post(self):
jBody = self.req_adapter.convert_request_entity_content_v2(self.req)
if jBody is None:
- self.res.status_code = return_code['Not Acceptable']
+ self.res.status_int = return_code['Not Acceptable']
self.res.body = self.req.content_type + " is an unknown request content type"
else:
@@ -140,9 +140,9 @@ def post(self):
if self.triggered_action is None:
- var, self.res.status_code = self.jungler.channel_post_single_resource(jBody, self.path_url)
+ var, self.res.status_int = self.jungler.channel_post_single_resource(jBody, self.path_url)
- if self.res.status_code == return_code['OK, and location returned']:
+ if self.res.status_int == return_code['OK, and location returned']:
#Step[4a]: Adapt the response to the required accept-type
self.res = self.res_adapter.convert_response_entity_location_content(var, self.res)
@@ -153,7 +153,7 @@ def post(self):
else:
# Step[3b]: Trigger an action on a resource
- self.res.body, self.res.status_code = self.jungler.channel_triggered_action_single(jBody, self.path_url,
+ self.res.body, self.res.status_int = self.jungler.channel_triggered_action_single(jBody, self.path_url,
self.triggered_action)
return self.res
@@ -167,7 +167,7 @@ def delete(self):
#Step[1]: Delete a single resource
- self.res.body, self.res.status_code = self.jungler.channel_delete_single_resource(self.path_url)
+ self.res.body, self.res.status_int = self.jungler.channel_delete_single_resource(self.path_url)
#Step[2]: return the response back to the caller
View
1 pyocni/junglers/categoryJungler.py
@@ -47,6 +47,7 @@ class CategoryJungler:
"""
def __init__(self):
+
self.manager_k = KindManager()
self.manager_m = MixinManager()
self.manager_a = ActionManager()
View
410 pyocni/junglers/managers/linkManager.py
@@ -27,252 +27,174 @@
##=======================================================================================================================
## LinkManager
##=======================================================================================================================
-#
+
+import pyocni.pyocni_tools.config as config
+import pyocni.pyocni_tools.occi_Joker as joker
+
+import pyocni.pyocni_tools.uuid_Generator as uuid_Generator
+
+try:
+ import simplejson as json
+except ImportError:
+ import json
+
+from pyocni.pyocni_tools.config import return_code
+
+# getting the Logger
+logger = config.logger
+
class LinkManager(object):
"""
- Manager of link documents in the couch database.
+ Manager of link documents.
"""
- pass
-
-# def register_links_explicit(self,creator,occi_descriptions,url_path,db_occi_ids_locs):
-# """
-# Add new links to database
-# Args:
-# @param creator: Issuer of the register request
-# @param occi_descriptions: Link OCCI descriptions
-# @param db_occi_ids_locs: OCCI ID and locations extracted from the database
-# @param url_path: URL path of the request
-# """
-#
-# loc_res = list()
-# kind_occi_id = None
-# 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:
-#
-# #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:
-#
-# ok_target_source = joker.verify_existences_teta([desc['target'],desc['source']],db_occi_ids_locs)
-# if ok_target_source is True:
-# ok_kappa = joker.verify_existences_kappa([desc['target'],desc['source']],db_occi_ids_locs)
-# if ok_kappa is True:
-# if desc.has_key('actions'):
-# ok_a = joker.verify_existences_delta(desc['actions'],db_occi_ids_locs)
-# else:
-# ok_a = True
-# if ok_a is True:
-# if desc.has_key('mixins'):
-# ok_m = joker.verify_existences_beta(desc['mixins'],db_occi_ids_locs)
-# else:
-# ok_m = True
-# if ok_m is True:
-# loc = joker.make_entity_location_from_url(creator,url_path,desc['id'])
-# 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['Creator'] = creator
-# jData['CreationDate'] = str(datetime.now())
-# jData['LastUpdate'] = ""
-# jData['OCCI_Location']= loc
-# jData['OCCI_Description']= desc
-# jData['Type']= "Link"
-# loc_res.append(jData)
-# else:
-# logger.error("Reg links exp : Bad Link id ")
-# return list(),return_code['Conflict']
-# else:
-# logger.error("Reg links exp : Bad Mixins description ")
-# return list(),return_code['Not Found']
-# else:
-# logger.error("Reg links exp : Bad Actions description ")
-# return list(),return_code['Not Found']
-# else:
-# logger.error("Reg links exp : Bad resources description ")
-# return list(),return_code['Bad Request']
-# else:
-# logger.error("Reg links exp : Bad resources description ")
-# return list(),return_code['Not Found']
-# else:
-# mesg = "Kind description and kind location don't match"
-# logger.error("Reg links exp: " + mesg)
-# return list(),return_code['Conflict']
-# logger.debug("Reg links exp: 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("Reg links exp: " + mesg)
-# return list(),return_code['Not Found']
-#
-# def get_filtered_links(self, filters, descriptions_link):
-# """
-# Retrieve the resources that match the filters provided
-# Args:
-# @param filters: Filters
-# @param descriptions_link: Link descriptions
-# """
-# var = list()
-# try:
-# for desc in descriptions_link:
-# for filter in filters:
-# checks =joker.filter_occi_description(desc['OCCI_Description'],filter)
-# if checks is True:
-# var.append(desc['OCCI_ID'])
-# logger.debug("Entity filtered : document found")
-# break
-# return var,return_code['OK']
-# except Exception as e:
-# logger.error("filtered link : " + e.message)
-# return list(),return_code['Internal Server Error']
-#
-# def register_custom_link(self, user_id, occi_description, path_url, db_occi_ids_locs):
-# """
-# Add a new link with a custom URL to the database
-# Args:
-# @param user_id: Issuer of the request
-# @param occi_description: link description
-# @param path_url: Custom URL of the link
-# @param db_occi_ids_locs: Ids and locations from the database
-# """
-# ok_k = joker.verify_existences_beta([occi_description['kind']],db_occi_ids_locs)
-#
-# #Verify if the kind to which this request is sent is the same as the one in the link description
-# if ok_k is True:
-# ok_target_source = joker.verify_existences_teta([occi_description['target'],occi_description['source']],db_occi_ids_locs)
-# if ok_target_source is True:
-# ok_kappa = joker.verify_existences_kappa([occi_description['target'],occi_description['source']],db_occi_ids_locs)
-# if ok_kappa is True:
-# if occi_description.has_key('actions'):
-# ok_a = joker.verify_existences_delta(occi_description['actions'],db_occi_ids_locs)
-# else:
-# ok_a = True
-# if ok_a is True:
-# if occi_description.has_key('mixins'):
-# ok_m = joker.verify_existences_beta(occi_description['mixins'],db_occi_ids_locs)
-# else:
-# ok_m = True
-# if ok_m is True:
-# jData = dict()
-# jData['_id'] = uuid_Generator.get_UUID()
-# jData['Creator'] = user_id
-# jData['CreationDate'] = str(datetime.now())
-# jData['LastUpdate'] = ""
-# jData['OCCI_Location']= path_url
-# jData['OCCI_Description']= occi_description
-# jData['Type']= "Link"
-#
-# else:
-# logger.error("Reg link cus : Bad Mixins description ")
-# return list(),return_code['Not Found']
-# else:
-# logger.error("Reg link cus : Bad Actions description ")
-# return list(),return_code['Not Found']
-# else:
-# logger.error("Reg link cus : Bad resources description ")
-# return list(),return_code['Bad Request']
-# else:
-# logger.error("Reg link cus : Bad resources description ")
-# return list(),return_code['Not Found']
-# else:
-# mesg = "Kind description does not exist"
-# logger.error("Reg link cus: " + mesg)
-# return list(),return_code['Not Found']
-#
-# logger.debug("Reg link cus: Link sent for creation")
-# return jData,return_code['OK, and location returned']
-#
-# def update_link(self, user_id, occi_description, db_occi_ids_locs):
-# """
-# Update the link description attached to the custom URL
-# Args:
-# @param user_id: Issuer of the request
-# @param occi_description: link description
-# @param db_occi_ids_locs: Ids and locations from the database
-# """
-# ok_k = joker.verify_existences_beta([occi_description['kind']],db_occi_ids_locs)
-#
-# #Verify if the kind to which this request is sent is the same as the one in the link description
-# if ok_k is True:
-# ok_target_source = joker.verify_existences_teta([occi_description['target'],occi_description['source']],db_occi_ids_locs)
-# if ok_target_source is True:
-# ok_kappa = joker.verify_existences_kappa([occi_description['target'],occi_description['source']],db_occi_ids_locs)
-# if ok_kappa is True:
-# if occi_description.has_key('actions'):
-# ok_a = joker.verify_existences_delta(occi_description['actions'],db_occi_ids_locs)
-# else:
-# ok_a = True
-# if ok_a is True:
-# if occi_description.has_key('mixins'):
-# ok_m = joker.verify_existences_beta(occi_description['mixins'],db_occi_ids_locs)
-# else:
-# ok_m = True
-# if ok_m is True:
-# logger.debug("UP link cus: Link sent for update")
-# return occi_description,return_code['OK']
-# else:
-# logger.error("UP link cus: Bad Mixins description ")
-# return list(),return_code['Not Found']
-# else:
-# logger.error("UP link cus: Bad Actions description ")
-# return list(),return_code['Not Found']
-# else:
-# logger.error("UP link cus: Bad resources description ")
-# return list(),return_code['Bad Request']
-# else:
-# logger.error("UP link cus: Bad resources description ")
-# return list(),return_code['Not Found']
-# else:
-# mesg = "Kind description does not exist"
-# logger.error("UP link cus: " + mesg)
-# return list(),return_code['Not Found']
-#
-#
-# def partial_link_update(self, user_id, old_data, occi_description, db_occi_ids_locs):
-# """
-# Update the link description attached to the custom URL
-# Args:
-# @param user_id: Issuer of the request
-# @param occi_description: link description
-# @param old_data: Old link description
-# @param db_occi_ids_locs: Ids and locations from the database
-# """
-# #Verify if the kind to which this request is sent is the same as the one in the link description
-# ok_target_source = joker.verify_existences_teta([occi_description['target'],occi_description['source']],db_occi_ids_locs)
-# if ok_target_source is True:
-# ok_kappa = joker.verify_existences_kappa([occi_description['target'],occi_description['source']],db_occi_ids_locs)
-# if ok_kappa is True:
-# if occi_description.has_key('actions'):
-# ok_a = joker.verify_existences_delta(occi_description['actions'],db_occi_ids_locs)
-# else:
-# ok_a = True
-# if ok_a is True:
-# if occi_description.has_key('mixins'):
-# ok_m = joker.verify_existences_beta(occi_description['mixins'],db_occi_ids_locs)
-# else:
-# ok_m = True
-# if ok_m is True:
-# problems,updated_data = joker.update_occi_entity_description(old_data,occi_description)
-# if problems is False:
-# logger.debug("Up part link: Link sent for update")
-# return updated_data,return_code['OK']
-# else:
-# logger.error("Up part link: Link couldn't have been fully updated")
-# return updated_data,return_code['Conflict']
-# else:
-# logger.error("UP partial link cus: Bad Mixins description ")
-# return list(),return_code['Not Found']
-# else:
-# logger.error("UP partial link cus: Bad Actions description ")
-# return list(),return_code['Not Found']
-# else:
-# logger.error("UP partial link cus: Bad resources description ")
-# return list(),return_code['Bad Request']
-# else:
-# logger.error("UP partial link cus: Bad resources description ")
-# return list(),return_code['Not Found']
+ 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']
+
+ def get_filtered_links(self, filters, descriptions_link):
+ """
+ Retrieve the resources that match the filters provided
+ Args:
+ @param filters: Filters
+ @param descriptions_link: Link descriptions
+ """
+ var = list()
+ try:
+ for desc in descriptions_link:
+ #Step[1]: Check if the descriptions match the filters
+ for filter in filters:
+ checks =joker.filter_occi_description(desc['OCCI_Description'],filter)
+ if checks is True:
+ #Step[2]: Keep the record of those descriptions matching the filter
+ var.append(desc['OCCI_ID'])
+ logger.debug(" ===== Get_filtered_links : A link document was found =====")
+ break
+ return var,return_code['OK']
+
+ except Exception as e:
+ logger.error(" ===== Get_filtered_links : " + e.message + " ===== ")
+ return list(),return_code['Internal Server Error']
+
+ 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 update_link(self, old_doc, occi_new_description):
+ """
+ Fully Update the link description attached to the custom URL
+ Args:
+ @param old_doc: old link document
+ @param occi_new_description: new link description
+ """
+ try:
+
+ logger.debug("===== Update_link: Link sent for update =====")
+ #Step[1]: Replace the old occi description with the new occi description
+ old_doc['OCCI_Description'] = occi_new_description
+ #Step[2]: Return the hole document for update
+ return old_doc, return_code['OK, and location returned']
+
+ except Exception as e:
+
+ logger.error("===== Update_link: Resource couldn't be updated =====")
+ return {}, return_code['Internal Server Error']
+
+
+ def partial_link_update(self, old_data, occi_description):
+ """
+ Partially update the link's old occi description
+ Args:
+
+ @param occi_description: link description
+ @param old_data: Old link description
+ """
+
+ #Step[1]: try a partial link update
+ problems, updated_data = joker.update_occi_entity_description(old_data, occi_description)
+ #Step[2]: if no problem then return the new data for update else return the old data with conflict status code
+ if problems is False:
+ logger.debug("===== Update_partial_resource: Resource sent for update =====")
+ return updated_data, return_code['OK, and location returned']
+ else:
+ logger.error("===== Update_partial_resource: Resource couldn't have been fully updated =====")
+ return old_data, return_code['Conflict']
View
2 pyocni/junglers/managers/mixinManager.py
@@ -159,7 +159,7 @@ def update_OCCI_mixin_descriptions(self, new_data, db_data):
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
- #Note: Dissociate entities from mixins before deleting them.
+
Args:
@param descriptions: OCCI description of the mixin document to delete
@param db_categories: Category data already contained in the database
View
2 pyocni/junglers/managers/resourceManager.py
@@ -173,7 +173,7 @@ def update_resource(self, old_doc, occi_new_description):
except Exception as e:
- logger.error("===== Update_partial_resource: Resource couldn't be updated =====")
+ logger.error("===== Update_resource: Resource couldn't be updated =====")
return {}, return_code['Internal Server Error']
def partial_resource_update(self, old_data, occi_description):
View
162 pyocni/junglers/multi_entityJungler.py
@@ -101,7 +101,7 @@ def channel_post_multi_resources(self, jreq, req_path):
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)
+ db_occi_ids_locs, default_attributes)
else:
new_links = list()
resp_code_l = return_code['OK, and location returned']
@@ -249,104 +249,78 @@ def channel_put_multi(self, jreq, req_url):
@param jreq: OCCI_Locations of the resources
@param req_url: URL of the request
"""
- return "This method is under reconstruction", return_code['Not Implemented']
-
- # database = config.prepare_PyOCNI_db()
- #
- # if jreq.has_key('Resource_Locations') and jreq.has_key('Mixin_Locations'):
- # url_path = joker.reformat_url_path(req_url)
- # db_docs = list()
- # to_validate = jreq['Mixin_Locations']
- # to_validate.append(url_path)
- # mix_ids = list()
- # for occi_loc in to_validate:
- # try:
- # query = database.view('/db_views/my_mixins',key = occi_loc)
- # except Exception as e:
- # logger.error("Associate mixins : " + e.message)
- # return "An error has occurred, please check log for more details",return_code['Internal Server Error']
- # if query.count() is 0:
- # logger.error("Associate mixins : " + occi_loc)
- # return "An error has occurred, please check log for more details",return_code['Internal Server Error']
- # else:
- # mix_ids.append(query.first()['value'])
- #
- # to_search_for = jreq['Resource_Locations']
- # for item in to_search_for:
- # try:
- # query = database.view('/db_views/for_associate_mixin',key=[item,user_id])
- # except Exception as e:
- # logger.error("Associate mixins : " + e.message)
- # return "An error has occurred, please check log for more details",return_code['Internal Server Error']
- # if query.count() is 0:
- # logger.error("Associate mixins : " + item)
- # return "An error has occurred, please check log for more details",return_code['Not Found']
- # else:
- # q = query.first()
- # db_docs.append(q['value'])
- #
- # logger.debug("Post path : Post on mixin path to associate mixins channeled")
- # updated_entities,resp_code_e = associate_entities_to_mixins(mix_ids,db_docs)
- # else:
- # updated_entities = list()
- # resp_code_e = return_code['Bad Request']
- #
- # if resp_code_e is not return_code['OK']:
- # return "An error has occurred, please check log for more details",return_code['Bad Request']
- #
- # database.save_docs(updated_entities,force_update=True,all_or_nothing=True)
- # backend_m.update_entities(db_docs,updated_entities)
- # return "",return_code['OK']
+
+ #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):
"""
- Update the mixin collection of resources
+ Remove the mixin from the resources
Args:
@param jreq: OCCI_Locations of the resources
@param req_url: URL of the request
"""
- return "This method is under reconstruction", return_code['Not Implemented']
-
- # if jreq.has_key('X-OCCI-Location'):
- #
- # url_path = joker.reformat_url_path(req_url)
- # db_docs = list()
- #
- # try:
- # query = database.view('/db_views/my_mixins',key = url_path)
- # except Exception as e:
- # logger.error("Dissociate mixins : " + e.message)
- # return "An error has occurred, please check log for more details",return_code['Internal Server Error']
- #
- #
- # mix_id = query.first()['value']
- #
- # to_search_for = jreq['X-OCCI-Location']
- # for item in to_search_for:
- # try:
- # query = database.view('/db_views/for_associate_mixin',key=item)
- # except Exception as e:
- # logger.error("Associate mixins : " + e.message)
- # return "An error has occurred, please check log for more details",return_code['Internal Server Error']
- # if query.count() is 0:
- # logger.error("Associate mixins : " + item)
- # return "An error has occurred, please check log for more details",return_code['Not Found']
- # else:
- # q = query.first()
- # db_docs.append(q['value'])
- #
- # logger.debug("Delete path: delete on mixin path to Dissociate mixins channeled")
- # updated_entities,resp_code_e = dissociate_entities_from_a_mixin(mix_id,db_docs)
- # else:
- # updated_entities = list()
- # resp_code_e = return_code['Bad Request']
- #
- # if resp_code_e is not return_code['OK']:
- # return "An error has occurred, please check log for more details",return_code['Bad Request']
- #
- # database.save_docs(updated_entities,force_update=True,all_or_nothing=True)
- # backend_m.update_entities(db_docs,updated_entities)
- # return "",return_code['OK']
+
+ #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_trigger_actions(self, jBody, req_url, triggered_action):
"""
@@ -388,7 +362,7 @@ def channel_trigger_actions(self, jBody, req_url, triggered_action):
# Independent Functions
#=======================================================================================================================
-def associate_entities_to_a_mixin( mix_id, db_docs):
+def associate_entities_to_a_mixin(mix_id, db_docs):
"""
Add a single mixin to entities
Args:
@@ -425,8 +399,6 @@ def dissociate_entities_from_a_mixin(mix_id, db_docs):
if doc['OCCI_Description'].has_key('mixins'):
var = doc['OCCI_Description']['mixins']
try:
- print mix_id
- print var
var.remove(mix_id)
doc['OCCI_Description']['mixins'] = var
View
2 pyocni/junglers/single_entityJungler.py
@@ -193,7 +193,7 @@ def channel_post_single_resource(self, jBody, path_url):
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)
+ 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']
View
14 pyocni/pyocni_tools/occi_Joker.py
@@ -105,14 +105,6 @@ def update_occi_entity_description(oldData, newData):
#Try to get the keys from occi entity description dictionary
oldData_keys = oldData.keys()
newData_keys = newData.keys()
- # forbidden_keys = ["id","kind"]
- # for key in newData_keys:
- # try:
- # forbidden_keys.index(key)
- # if oldData[key] != newData[key]:
- # logger.debug("update description : " + key + " is forbidden to change")
- # return True,None
- # except ValueError:
for key in newData_keys:
try:
oldData_keys.index(key)
@@ -308,8 +300,10 @@ def verify_occi_uniqueness(occi_term, db_categories):
@param occi_term: OCCI term to verify its uniqueness
@param db_categories: Collection of OCCI IDs
"""
+
try:
db_categories.index(occi_term)
+ print occi_term
return False
except ValueError as e:
logger.info("===== Verify_occi_uniqueness =====: " + e.message)
@@ -413,9 +407,11 @@ def look_for_update_key_values(new_attr):
def complete_occi_description_with_default_attributes(desc, default_attributes):
+
for key in desc.keys():
- if type(desc[key]) is dict:
+ if type(desc[key]) is dict and key in default_attributes.keys():
complete_occi_description_with_default_attributes(default_attributes[key], desc[key])
else:
default_attributes[key] = desc[key]
+
return default_attributes
Something went wrong with that request. Please try again.