Permalink
Browse files

Changed in backend Manager

  • Loading branch information...
Msekni Bilel
Msekni Bilel committed Nov 13, 2012
1 parent 66719e1 commit 874e6bb6322a99662dc14f6caef02a6bf9534cbc
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -2,12 +2,8 @@
"backends":
[
{
- "name": "dummy_backend",
- "path": "/home/houssem/MyPycharmProjects/pyOCNI/pyocni/backends/dummy_backend.py"
- },
- {
- "name": "backend1",
- "path": "/home/houssem//MyPycharmProjects/pyOCNI/pyocni/backends/backend1.py"
+ "name": "dummy",
+ "path": "/home/skible/PycharmProjects/PyOCNI/pyocni/backends/dummy_backend.py"
}
]
}
@@ -64,9 +64,9 @@ def test_register_entities(self):
storage = StringIO.StringIO()
c = pycurl.Curl()
c.setopt(c.URL, 'http://127.0.0.1:8090/compute/')
- c.setopt(c.HTTPHEADER, ['Accept:application/occi+json', 'Content-Type: text/plain'])
+ c.setopt(c.HTTPHEADER, ['Accept:application/occi+json', 'Content-Type: application/occi+json'])
c.setopt(c.VERBOSE, True)
- c.setopt(pycurl.POSTFIELDS, f_entities.entity_http)
+ c.setopt(pycurl.POSTFIELDS, f_entities.resource)
c.setopt(c.CUSTOMREQUEST, 'POST')
c.setopt(c.WRITEFUNCTION, storage.write)
c.perform()
@@ -116,11 +116,11 @@ def test_get_entities(self):
c = pycurl.Curl()
c.setopt(c.URL, "http://127.0.0.1:8090/compute/")
- c.setopt(c.HTTPHEADER, ['Content-type: text/plain', 'Accept: text/occi', f_entities.x_occi_att])
+ c.setopt(c.HTTPHEADER, ['Content-type: application/occi+json', 'Accept: application/occi+json'])
c.setopt(c.VERBOSE, True)
c.setopt(c.CUSTOMREQUEST, 'GET')
c.setopt(c.WRITEFUNCTION, storage.write)
- #c.setopt(c.POSTFIELDS,f_entities.x_occi_att)
+ c.setopt(c.POSTFIELDS,f_entities.j_occi_att)
c.perform()
content = storage.getvalue()
@@ -225,4 +225,5 @@ def test_dissociate_mixins(self):
#Run tests
- runner.run(get_suite)
+ #runner.run(get_suite)
+ runner.run(post_suite)
@@ -66,11 +66,11 @@ def test_post_entities(self):
"""
storage = StringIO.StringIO()
c = pycurl.Curl()
- c.setopt(c.URL,'http://127.0.0.1:8090/compute/258af9df-dcba-4ff5-89f6-2c5f17c46e6f?action=stop')
- c.setopt(c.HTTPHEADER, ['Accept: application/occi+json','Content-Type: text/plain'])
+ c.setopt(c.URL,'http://127.0.0.1:8090/compute/258af9df-dcba-4ff5-89f6-2c5f17c46e6f')
+ c.setopt(c.HTTPHEADER, ['Accept: application/occi+json','Content-Type: application/occi+json'])
c.setopt(c.CUSTOMREQUEST, 'POST')
c.setopt(c.VERBOSE, True)
- c.setopt(c.POSTFIELDS,categories.action_att_http)
+ c.setopt(c.POSTFIELDS,entities.j_occi_att)
c.setopt(c.WRITEFUNCTION, storage.write)
c.perform()
content = storage.getvalue()
@@ -39,16 +39,7 @@
"compute": {
"speed": 2,
"memory": 4,
- "cores": 2
- }
- },
- "org": {
- "other": {
- "occi": {
- "my_mixin": {
- "my_attribute": "my_value"
- }
- }
+ "cores": 12
}
}
},
@@ -99,7 +90,23 @@
"""
#=======================================================================================================================
-
+j_occi_att = """
+{
+ "resources": [
+ {
+ "attributes": {
+ "occi": {
+ "compute": {
+ "speed": 2,
+ "memory": 4,
+ "cores": 12
+ }
+ }
+ }
+ }
+ ]
+}
+"""
#=======================================================================================================================
@@ -61,18 +61,17 @@ def trigger_action_on_multi_resource(data):
def choose_appropriate_provider(provider):
- backend = None
+ backend = None
backends_json_data = open(config.BACKENDS_FILE)
backends_list = json.load(backends_json_data)
backends_json_data.close()
-
+ print provider
for i in backends_list["backends"]:
if i["name"] == provider:
- #print i["path"]
+ print " I am here !!!!!"
backend_instance = imp.load_source('', i["path"])
backend = backend_instance.backend()
- backend.create('a')
# if provider == "dummy":
# backend = dummy_backend.dummy_backend()
@@ -33,8 +33,11 @@ def __init__(self):
def save_registered_docs_in_db(self, docs):
self.database.save_docs(docs, use_uuids=True, all_or_nothing=True)
- def save_updated_docs_in_db(self, categories):
- self.database.save_docs(categories, force_update=True, all_or_nothing=True)
+ def save_updated_doc_in_db(self, categories):
+ self.database.save_doc(categories, force_update=True, all_or_nothing=True)
+
+ def save_partial_updated_doc_in_db(self, categories):
+ self.database.save_doc(categories, force_update=True, all_or_nothing=True)
def save_deleted_categories_in_db(self, categories, to_update):
self.database.delete_docs(categories)
@@ -105,6 +105,7 @@ def channel_put_single_resource(self, jBody, path_url):
#Step[2b]: This is an 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:
@@ -123,14 +124,15 @@ def channel_put_single_resource(self, jBody, path_url):
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_desc = olddoc['OCCI_Description']
olddoc['OCCI_Description'] = entity
- self.PostMan.save_updated_docs_in_db(olddoc)
+ self.PostMan.save_updated_doc_in_db(olddoc)
logger.debug("===== Channel_post_single_resource ==== : Finished (2b) with success")
#return the locations of the resources
- backend_m.update_entity(entity,entity)
+ backend_m.update_entity(old_desc,entity)
return olddoc['OCCI_Location'],return_code['OK, and location returned']
@@ -200,7 +202,8 @@ def channel_post_single_resource(self, jBody, path_url):
return "An error has occurred, please check log for more details",return_code['Bad Request']
old_doc['OCCI_Description'] = entity
- self.PostMan.save_updated_docs_in_db(old_doc)
+
+ 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)
View
@@ -5,4 +5,4 @@
OCNI_IP = 127.0.0.1
OCNI_PORT = 8090
OCNI_PURGE_DB = 0
-backends_file = /home/houssem/MyPycharmProjects/pyOCNI/backends.json
+backends_file = /home/skible/PycharmProjects/PyOCNI/backends.json
@@ -200,14 +200,3 @@ def check_db():
else:
logger.warning("===== The DB is OFF: ")
return 0
-
- #=======================================================================================================================
- #
- # "my_occi_locations":{
- # "map": "(function(doc) {emit (doc.OCCI_Location,) });"
- # }
-
- #"for_delete_entities" :{
- # "map": "(function(doc) {if ((doc.Type == \"Resource\")||(doc.Type == \"Link\"))"
- # "emit (,[doc.OCCI_Location,doc._id,doc._rev]) });"
- # },
@@ -93,6 +93,41 @@ def update_occi_entity_description(oldData, newData):
return False, oldData
+def update_occi_entity_description(oldData, newData):
+ """
+ Update only a part of the occi entity description
+ Args:
+ @param newData: The new OCCI entity description
+ @param oldData: The old OCCI entity description
+ @return : Updated data and a boolean (false if all fields are updated, true if there were some un-updated fields)
+ """
+
+ #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)
+ if key == 'attributes':
+ oldData['attributes'] = complete_occi_description_with_default_attributes(newData['attributes'],
+ oldData['attributes'])
+
+ else:
+ oldData[key] = newData[key]
+ except ValueError:
+ #Keep the record of the keys(=parts) that couldn't be updated
+ logger.debug("update entity description : " + key + " could not be found")
+ return True, None
+
+ return False, oldData
def get_description_id(occi_description):
"""

0 comments on commit 874e6bb

Please sign in to comment.