Added config.py / disabled OCCI's update,replace
authorJohn Giannelos <johngiannelos@gmail.com>
Mon, 30 Apr 2012 10:53:49 +0000 (13:53 +0300)
committerJohn Giannelos <johngiannelos@gmail.com>
Mon, 30 Apr 2012 10:53:49 +0000 (13:53 +0300)
snfOCCI/compute.py
snfOCCI/config.py [new file with mode: 0644]
snfOCCI/snf-occi-server.py

index 28621f7..79a7e1e 100644 (file)
@@ -1,3 +1,5 @@
+from snfOCCI.config import SERVER_CONFIG
+
 from kamaki.clients.compute import ComputeClient
 from kamaki.clients.cyclades import CycladesClient
 from kamaki.config  import Config
@@ -15,20 +17,10 @@ class MyBackend(KindBackend, ActionBackend):
     '''
 
     def update(self, old, new, extras):
-        # here you can check what information from new_entity you wanna bring
-        # into old_entity
-
-        # trigger your hypervisor and push most recent information
-        print('Updating a resource with id: ' + old.identifier)
-        for item in new.attributes.keys():
-            old.attributes[item] = new.attributes[item]
+        raise AttributeError("This action is currently no applicable.")
 
     def replace(self, old, new, extras):
-        print('Replacing a resource with id: ' + old.identifier)
-        old.attributes = {}
-        for item in new.attributes.keys():
-            old.attributes[item] = new.attributes[item]
-        old.attributes['occi.compute.state'] = 'inactive'
+        raise AttributeError("This action is currently no applicable.")
 
 
 class ComputeBackend(MyBackend):
@@ -46,8 +38,8 @@ class ComputeBackend(MyBackend):
                 flavor = mixin
                 flavor_id = mixin.attributes['occi.core.id']
                 
-        entity.attributes['occi.compute.state'] = 'active'
-        entity.actions = [STOP, SUSPEND, RESTART]
+        entity.attributes['occi.compute.state'] = 'inactive'
+        entity.actions = [START]
 
         #Registry identifier is the uuid key occi.handler assigns
         #attribute 'occi.core.id' will be the snf-server id
@@ -59,8 +51,10 @@ class ComputeBackend(MyBackend):
         vm_name = entity.attributes['occi.compute.hostname']
         info = snf.create_server(vm_name, flavor_id, image_id)
         entity.attributes['occi.core.id'] = str(info['id'])
+        entity.attributes['occi.compute.architecture'] = SERVER_CONFIG['compute_arch']
         entity.attributes['occi.compute.cores'] = flavor.attributes['occi.compute.cores']
         entity.attributes['occi.compute.memory'] = flavor.attributes['occi.compute.memory']
+        entity.attributes['occi.compute.hostname'] = SERVER_CONFIG['hostname'] % {'id':info['id']}
 
     def retrieve(self, entity, extras):
         
@@ -127,5 +121,4 @@ class ComputeBackend(MyBackend):
 
 
         elif action == SUSPEND:
-            #TODO VM suspending
-            print "Suspending VM"
+            raise AttributeError("This actions is currently no applicable")
diff --git a/snfOCCI/config.py b/snfOCCI/config.py
new file mode 100644 (file)
index 0000000..258481f
--- /dev/null
@@ -0,0 +1,9 @@
+SERVER_CONFIG = {
+    'port': 8888,
+    'hostname': 'snf-%(id)d.vm.okeanos.grnet.gr',
+    'compute_arch': 'x86'
+    }
+
+        
+
+    
index c995997..17ce9d1 100755 (executable)
@@ -2,6 +2,7 @@
 
 from snfOCCI.registry import snfRegistry
 from snfOCCI.compute import ComputeBackend
+from snfOCCI.config import SERVER_CONFIG
 
 from kamaki.clients.compute import ComputeClient
 from kamaki.clients.cyclades import CycladesClient
@@ -36,7 +37,6 @@ class MyAPP(Application):
 if __name__ == '__main__':
 
     APP = MyAPP(registry = snfRegistry())
-
     COMPUTE_BACKEND = ComputeBackend()
 
     APP.register_backend(COMPUTE, COMPUTE_BACKEND)
@@ -67,6 +67,6 @@ if __name__ == '__main__':
 
  
     VALIDATOR_APP = validator(APP)
-    HTTPD = make_server('', 8888, VALIDATOR_APP)
+    HTTPD = make_server('', SERVER_CONFIG['port'], VALIDATOR_APP)
     HTTPD.serve_forever()