From: John Giannelos Date: Mon, 30 Apr 2012 14:00:07 +0000 (+0300) Subject: Fixed compute instance naming X-Git-Url: https://code.grnet.gr/git/snf-occi/commitdiff_plain/b7fca2d23658fcfde1faca6b73f6867a05a8e87b Fixed compute instance naming --- diff --git a/snfOCCI/compute.py b/snfOCCI/compute.py index 7d2dc97..e9da682 100644 --- a/snfOCCI/compute.py +++ b/snfOCCI/compute.py @@ -50,7 +50,7 @@ class ComputeBackend(MyBackend): conf.set('token',extras['token']) snf = ComputeClient(conf) - vm_name = entity.attributes['occi.compute.hostname'] + vm_name = entity.attributes['occi.core.title'] 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'] diff --git a/snfOCCI/registry.py b/snfOCCI/registry.py index 767be4b..d797851 100644 --- a/snfOCCI/registry.py +++ b/snfOCCI/registry.py @@ -1,4 +1,11 @@ +from kamaki.clients.compute import ComputeClient +from kamaki.clients.cyclades import CycladesClient +from kamaki.config import Config + from occi import registry +from occi.core_model import Mixin +from occi.backend import MixinBackend +from occi.extensions.infrastructure import RESOURCE_TEMPLATE, OS_TEMPLATE class snfRegistry(registry.NonePersistentRegistry): diff --git a/snfOCCI/snf-occi-server.py b/snfOCCI/snf-occi-server.py index 09753cc..b24f528 100755 --- a/snfOCCI/snf-occi-server.py +++ b/snfOCCI/snf-occi-server.py @@ -24,18 +24,18 @@ class MyAPP(Application): An OCCI WSGI application. ''' - def __call__(self, environ, response): + def refresh_images(self): 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()) + self.register_backend(IMAGE, MixinBackend()) + def refresh_flavors(self): + + snf = ComputeClient(Config()) flavors = snf.list_flavors() for flavor in flavors: details = snf.get_flavor_details(flavor['id']) @@ -45,9 +45,15 @@ class MyAPP(Application): '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()) + self.register_backend(FLAVOR, MixinBackend()) + + + def __call__(self, environ, response): + + #Up-to-date flavors and images - #TODO up-to-date compute instances + self.refresh_images() + self.refresh_flavors() # token will be represented in self.extras return self._call_occi(environ, response, security = None, token = environ['HTTP_AUTH_TOKEN'])