Minor fixes to config.py
[snf-occi] / snfOCCI / APIserver.py
index 9e89a23..9111312 100755 (executable)
@@ -2,7 +2,7 @@
 
 from snfOCCI.registry import snfRegistry
 from snfOCCI.compute import ComputeBackend
 
 from snfOCCI.registry import snfRegistry
 from snfOCCI.compute import ComputeBackend
-from snfOCCI.config import SERVER_CONFIG
+from snfOCCI.config import SERVER_CONFIG, KAMAKI_CONFIG
 
 from kamaki.clients.compute import ComputeClient
 from kamaki.clients.cyclades import CycladesClient
 
 from kamaki.clients.compute import ComputeClient
 from kamaki.clients.cyclades import CycladesClient
@@ -57,13 +57,21 @@ class MyAPP(Application):
         resources = self.registry.resources
         occi_keys = resources.keys()
         
         resources = self.registry.resources
         occi_keys = resources.keys()
         
+        #Compute instances in synnefo not available in registry
         diff = [x for x in snf_keys if '/compute/'+x not in occi_keys]
         for key in diff:
 
             details = snf.get_server_details(int(key))
             flavor = snf.get_flavor_details(details['flavorRef'])
         diff = [x for x in snf_keys if '/compute/'+x not in occi_keys]
         for key in diff:
 
             details = snf.get_server_details(int(key))
             flavor = snf.get_flavor_details(details['flavorRef'])
+            image = snf.get_image_details(details['imageRef'])
 
 
-            resource = Resource(key, COMPUTE, [])
+            for i in self.registry.backends:
+                if i.term == str(image['name']):
+                    rel_image = i
+                if i.term == str(flavor['name']):
+                    rel_flavor = i
+
+            resource = Resource(key, COMPUTE, [rel_flavor, rel_image])
             resource.actions = [START]
             resource.attributes['occi.core.id'] = key
             resource.attributes['occi.compute.state'] = 'inactive'
             resource.actions = [START]
             resource.attributes['occi.core.id'] = key
             resource.attributes['occi.compute.state'] = 'inactive'
@@ -71,9 +79,10 @@ class MyAPP(Application):
             resource.attributes['occi.compute.cores'] = flavor['cpu']
             resource.attributes['occi.compute.memory'] = flavor['ram']
             resource.attributes['occi.compute.hostname'] = SERVER_CONFIG['hostname'] % {'id':int(key)}
             resource.attributes['occi.compute.cores'] = flavor['cpu']
             resource.attributes['occi.compute.memory'] = flavor['ram']
             resource.attributes['occi.compute.hostname'] = SERVER_CONFIG['hostname'] % {'id':int(key)}
-  
+
             self.registry.add_resource(key, resource, None)
 
             self.registry.add_resource(key, resource, None)
 
+        #Compute instances in registry not available in synnefo
         diff = [x for x in occi_keys if x[9:] not in snf_keys]
         for key in diff:
             self.registry.delete_resource(key, None)
         diff = [x for x in occi_keys if x[9:] not in snf_keys]
         for key in diff:
             self.registry.delete_resource(key, None)
@@ -81,15 +90,13 @@ class MyAPP(Application):
 
     def __call__(self, environ, response):
 
 
     def __call__(self, environ, response):
 
-        conf = Config()
-        conf.set('compute_token',environ['HTTP_AUTH_TOKEN'])
-        compClient = ComputeClient(conf)
-        cyclClient = CycladesClient(conf)
+        compClient = ComputeClient(KAMAKI_CONFIG['compute_url'], environ['HTTP_AUTH_TOKEN'])
+        cyclClient = CycladesClient(KAMAKI_CONFIG['compute_url'], environ['HTTP_AUTH_TOKEN'])
 
         #Up-to-date flavors and images
 
         #Up-to-date flavors and images
+        self.refresh_images(compClient,cyclClient)
+        self.refresh_flavors(compClient,cyclClient)
         self.refresh_compute_instances(compClient)
         self.refresh_compute_instances(compClient)
-        self.refresh_images(compClient, cyclClient)
-        self.refresh_flavors(compClient, cyclClient)
 
         # token will be represented in self.extras
         return self._call_occi(environ, response, security = None, token = environ['HTTP_AUTH_TOKEN'], snf = compClient, client = cyclClient)
 
         # token will be represented in self.extras
         return self._call_occi(environ, response, security = None, token = environ['HTTP_AUTH_TOKEN'], snf = compClient, client = cyclClient)