Revision b7fca2d2 snfOCCI/snf-occi-server.py
b/snfOCCI/snf-occi-server.py | ||
---|---|---|
24 | 24 |
An OCCI WSGI application. |
25 | 25 |
''' |
26 | 26 |
|
27 |
def __call__(self, environ, response):
|
|
27 |
def refresh_images(self):
|
|
28 | 28 |
|
29 | 29 |
snf = ComputeClient(Config()) |
30 |
|
|
31 |
#Up-to-date flavors and images |
|
32 |
|
|
33 | 30 |
images = snf.list_images() |
34 | 31 |
for image in images: |
35 | 32 |
IMAGE_ATTRIBUTES = {'occi.core.id': str(image['id'])} |
36 | 33 |
IMAGE = Mixin("http://schemas.ogf.org/occi/infrastructure#", str(image['name']), [OS_TEMPLATE], attributes = IMAGE_ATTRIBUTES) |
37 |
APP.register_backend(IMAGE, MixinBackend())
|
|
34 |
self.register_backend(IMAGE, MixinBackend())
|
|
38 | 35 |
|
36 |
def refresh_flavors(self): |
|
37 |
|
|
38 |
snf = ComputeClient(Config()) |
|
39 | 39 |
flavors = snf.list_flavors() |
40 | 40 |
for flavor in flavors: |
41 | 41 |
details = snf.get_flavor_details(flavor['id']) |
... | ... | |
45 | 45 |
'occi.storage.size': details['disk'], |
46 | 46 |
} |
47 | 47 |
FLAVOR = Mixin("http://schemas.ogf.org/occi/infrastructure#", str(flavor['name']), [RESOURCE_TEMPLATE], attributes = FLAVOR_ATTRIBUTES) |
48 |
APP.register_backend(FLAVOR, MixinBackend()) |
|
48 |
self.register_backend(FLAVOR, MixinBackend()) |
|
49 |
|
|
50 |
|
|
51 |
def __call__(self, environ, response): |
|
52 |
|
|
53 |
#Up-to-date flavors and images |
|
49 | 54 |
|
50 |
#TODO up-to-date compute instances |
|
55 |
self.refresh_images() |
|
56 |
self.refresh_flavors() |
|
51 | 57 |
|
52 | 58 |
# token will be represented in self.extras |
53 | 59 |
return self._call_occi(environ, response, security = None, token = environ['HTTP_AUTH_TOKEN']) |
Also available in: Unified diff