From 77182fb8d57e5e80edc8683996b1a72cc1f3e235 Mon Sep 17 00:00:00 2001 From: John Giannelos Date: Tue, 22 May 2012 14:12:33 +0300 Subject: [PATCH] Implemented compute instance refreshing in registry --- snfOCCI/APIserver.py | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/snfOCCI/APIserver.py b/snfOCCI/APIserver.py index 66cfdd3..5325eed 100755 --- a/snfOCCI/APIserver.py +++ b/snfOCCI/APIserver.py @@ -8,7 +8,7 @@ from kamaki.clients.compute import ComputeClient from kamaki.clients.cyclades import CycladesClient from kamaki.config import Config -from occi.core_model import Mixin +from occi.core_model import Mixin, Resource from occi.backend import MixinBackend from occi.extensions.infrastructure import COMPUTE, START, STOP, SUSPEND, RESTART, RESOURCE_TEMPLATE, OS_TEMPLATE from occi.wsgi import Application @@ -46,6 +46,36 @@ class MyAPP(Application): self.register_backend(FLAVOR, MixinBackend()) + def refresh_compute_instances(self, snf): + + servers = snf.list_servers() + snf_keys = [] + for server in servers: + snf_keys.append(str(server['id'])) + + resources = self.registry.resources + occi_keys = resources.keys() + + 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']) + + resource = Resource(key, COMPUTE, []) + + resource.actions = [START] + resource.attribute = {} + resource.attributes['occi.core.id'] = key + resource.attributes['occi.compute.state'] = 'inactive' + resource.attributes['occi.compute.architecture'] = SERVER_CONFIG['compute_arch'] + 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) + def __call__(self, environ, response): conf = Config() @@ -54,6 +84,7 @@ class MyAPP(Application): cyclClient = CycladesClient(conf) #Up-to-date flavors and images + self.refresh_compute_instances(compClient) self.refresh_images(compClient, cyclClient) self.refresh_flavors(compClient, cyclClient) @@ -63,7 +94,6 @@ class MyAPP(Application): def main(): - APP = MyAPP(registry = snfRegistry()) COMPUTE_BACKEND = ComputeBackend() -- 1.7.10.4