Revision 77182fb8

b/snfOCCI/APIserver.py
8 8
from kamaki.clients.cyclades import CycladesClient
9 9
from kamaki.config  import Config
10 10

  
11
from occi.core_model import Mixin
11
from occi.core_model import Mixin, Resource
12 12
from occi.backend import MixinBackend
13 13
from occi.extensions.infrastructure import COMPUTE, START, STOP, SUSPEND, RESTART, RESOURCE_TEMPLATE, OS_TEMPLATE
14 14
from occi.wsgi import Application
......
46 46
            self.register_backend(FLAVOR, MixinBackend())
47 47

  
48 48

  
49
    def refresh_compute_instances(self, snf):
50
        
51
        servers = snf.list_servers()
52
        snf_keys = []
53
        for server in servers:
54
            snf_keys.append(str(server['id']))
55

  
56
        resources = self.registry.resources
57
        occi_keys = resources.keys()
58
        
59
        diff = [x for x in snf_keys if '/compute/'+x not in occi_keys]
60

  
61
        for key in diff:
62

  
63
            details = snf.get_server_details(int(key))
64
            flavor = snf.get_flavor_details(details['flavorRef'])
65

  
66
            resource = Resource(key, COMPUTE, [])
67

  
68
            resource.actions = [START]
69
            resource.attribute = {}
70
            resource.attributes['occi.core.id'] = key
71
            resource.attributes['occi.compute.state'] = 'inactive'
72
            resource.attributes['occi.compute.architecture'] = SERVER_CONFIG['compute_arch']
73
            resource.attributes['occi.compute.cores'] = flavor['cpu']
74
            resource.attributes['occi.compute.memory'] = flavor['ram']
75
            resource.attributes['occi.compute.hostname'] = SERVER_CONFIG['hostname'] % {'id':int(key)}
76
  
77
            self.registry.add_resource(key, resource, None)
78

  
49 79
    def __call__(self, environ, response):
50 80

  
51 81
        conf = Config()
......
54 84
        cyclClient = CycladesClient(conf)
55 85

  
56 86
        #Up-to-date flavors and images
87
        self.refresh_compute_instances(compClient)
57 88
        self.refresh_images(compClient, cyclClient)
58 89
        self.refresh_flavors(compClient, cyclClient)
59 90

  
......
63 94

  
64 95
def main():
65 96

  
66

  
67 97
    APP = MyAPP(registry = snfRegistry())
68 98
    COMPUTE_BACKEND = ComputeBackend()
69 99

  

Also available in: Unified diff