From 711721d6806197744e7af712523042cbb9d898a9 Mon Sep 17 00:00:00 2001 From: John Giannelos Date: Mon, 30 Apr 2012 16:23:48 +0300 Subject: [PATCH] Minor fixes/comments --- snfOCCI/compute.py | 4 ++++ snfOCCI/registry.py | 2 -- snfOCCI/snf-occi-server.py | 41 ++++++++++++++++++++--------------------- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/snfOCCI/compute.py b/snfOCCI/compute.py index 883bac6..7d2dc97 100644 --- a/snfOCCI/compute.py +++ b/snfOCCI/compute.py @@ -93,6 +93,8 @@ class ComputeBackend(MyBackend): def delete(self, entity, extras): + #Deleting compute instance + conf = Config() conf.set('token',extras['token']) snf = ComputeClient(conf) @@ -103,6 +105,8 @@ class ComputeBackend(MyBackend): def action(self, entity, action, extras): + #Triggering action to compute instances + conf = Config() conf.set('token',extras['token']) client = CycladesClient(conf) diff --git a/snfOCCI/registry.py b/snfOCCI/registry.py index 0e86e84..767be4b 100644 --- a/snfOCCI/registry.py +++ b/snfOCCI/registry.py @@ -8,5 +8,3 @@ class snfRegistry(registry.NonePersistentRegistry): resource.identifier = key super(snfRegistry, self).add_resource(key, resource, extras) - - diff --git a/snfOCCI/snf-occi-server.py b/snfOCCI/snf-occi-server.py index 4db0247..09753cc 100755 --- a/snfOCCI/snf-occi-server.py +++ b/snfOCCI/snf-occi-server.py @@ -26,10 +26,29 @@ class MyAPP(Application): def __call__(self, environ, response): + snf = ComputeClient(Config()) + + #Up-to-date flavors and images + + images = snf.list_images() + for image in images: + IMAGE_ATTRIBUTES = {'occi.core.id': str(image['id'])} + IMAGE = Mixin("http://schemas.ogf.org/occi/infrastructure#", str(image['name']), [OS_TEMPLATE], attributes = IMAGE_ATTRIBUTES) + APP.register_backend(IMAGE, MixinBackend()) + + flavors = snf.list_flavors() + for flavor in flavors: + details = snf.get_flavor_details(flavor['id']) + FLAVOR_ATTRIBUTES = {'occi.core.id': flavor['id'], + 'occi.compute.cores': details['cpu'], + 'occi.compute.memory': details['ram'], + 'occi.storage.size': details['disk'], + } + FLAVOR = Mixin("http://schemas.ogf.org/occi/infrastructure#", str(flavor['name']), [RESOURCE_TEMPLATE], attributes = FLAVOR_ATTRIBUTES) + APP.register_backend(FLAVOR, MixinBackend()) #TODO up-to-date compute instances - # token will be represented in self.extras return self._call_occi(environ, response, security = None, token = environ['HTTP_AUTH_TOKEN']) @@ -46,26 +65,6 @@ if __name__ == '__main__': APP.register_backend(SUSPEND, COMPUTE_BACKEND) APP.register_backend(RESOURCE_TEMPLATE, MixinBackend()) APP.register_backend(OS_TEMPLATE, MixinBackend()) - - snf = ComputeClient(Config()) - - images = snf.list_images() - for image in images: - IMAGE_ATTRIBUTES = {'occi.core.id': str(image['id'])} - IMAGE = Mixin("http://schemas.ogf.org/occi/infrastructure#", str(image['name']), [OS_TEMPLATE], attributes = IMAGE_ATTRIBUTES) - APP.register_backend(IMAGE, MixinBackend()) - - flavors = snf.list_flavors() - for flavor in flavors: - details = snf.get_flavor_details(flavor['id']) - FLAVOR_ATTRIBUTES = {'occi.core.id': flavor['id'], - 'occi.compute.cores': details['cpu'], - 'occi.compute.memory': details['ram'], - 'occi.storage.size': details['disk'], - } - FLAVOR = Mixin("http://schemas.ogf.org/occi/infrastructure#", str(flavor['name']), [RESOURCE_TEMPLATE], attributes = FLAVOR_ATTRIBUTES) - APP.register_backend(FLAVOR, MixinBackend()) - VALIDATOR_APP = validator(APP) HTTPD = make_server('', SERVER_CONFIG['port'], VALIDATOR_APP) -- 1.7.10.4