Revision 4b86ec7c
b/snf-occi-server.py | ||
---|---|---|
3 | 3 |
from kamaki.clients.compute import ComputeClient |
4 | 4 |
from kamaki.config import Config |
5 | 5 |
|
6 |
from occi.core_model import Mixin |
|
6 |
from occi.core_model import Mixin, Resource, Link, Entity
|
|
7 | 7 |
from occi.backend import ActionBackend, KindBackend, MixinBackend |
8 | 8 |
from occi.extensions.infrastructure import COMPUTE, START, STOP, SUSPEND, RESTART, RESOURCE_TEMPLATE, OS_TEMPLATE |
9 | 9 |
|
... | ... | |
95 | 95 |
|
96 | 96 |
def __call__(self, environ, response): |
97 | 97 |
sec_obj = {'username': 'password'} |
98 |
|
|
99 |
snf = ComputeClient(Config()) |
|
100 |
images = snf.list_images() |
|
101 |
for image in images: |
|
102 |
IMAGE = Mixin("http://schemas.ogf.org/occi/infrastructure#", str(image['name']), [OS_TEMPLATE]) |
|
103 |
self.register_backend(IMAGE, MixinBackend()) |
|
104 |
|
|
105 |
flavors = snf.list_flavors() |
|
106 |
for flavor in flavors: |
|
107 |
FLAVOR_ATTRIBUTES = {'occi.compute.cores': snf.get_flavor_details(flavor['id'])['cpu'], |
|
108 |
'occi.compute.memory': snf.get_flavor_details(flavor['id'])['ram'], |
|
109 |
'occi.storage.size': snf.get_flavor_details(flavor['id'])['disk'], |
|
110 |
} |
|
111 |
FLAVOR = Mixin("http://schemas.ogf.org/occi/infrastructure#", str(flavor['name']), [RESOURCE_TEMPLATE], attributes = FLAVOR_ATTRIBUTES) |
|
112 |
self.register_backend(FLAVOR, MixinBackend()) |
|
113 |
|
|
114 |
|
|
115 |
|
|
98 | 116 |
return self._call_occi(environ, response, security=sec_obj, foo=None) |
99 | 117 |
|
100 | 118 |
if __name__ == '__main__': |
... | ... | |
111 | 129 |
APP.register_backend(RESOURCE_TEMPLATE, MixinBackend()) |
112 | 130 |
APP.register_backend(OS_TEMPLATE, MixinBackend()) |
113 | 131 |
|
114 |
|
|
115 |
snf = ComputeClient(Config()) |
|
116 |
images = snf.list_images() |
|
117 |
for image in images: |
|
118 |
IMAGE = Mixin("http://schemas.ogf.org/occi/infrastructure#", str(image['name']), [OS_TEMPLATE]) |
|
119 |
APP.register_backend(IMAGE, MixinBackend()) |
|
120 |
|
|
121 |
flavors = snf.list_flavors() |
|
122 |
for flavor in flavors: |
|
123 |
FLAVOR_ATTRIBUTES = {'occi.compute.cores': snf.get_flavor_details(flavor['id'])['cpu'], |
|
124 |
'occi.compute.memory': snf.get_flavor_details(flavor['id'])['ram'], |
|
125 |
'occi.storage.size': snf.get_flavor_details(flavor['id'])['disk'], |
|
126 |
} |
|
127 |
FLAVOR =Mixin("http://schemas.ogf.org/occi/infrastructure#", str(flavor['name']), [RESOURCE_TEMPLATE], attributes = FLAVOR_ATTRIBUTES) |
|
128 |
APP.register_backend(FLAVOR, MixinBackend()) |
|
129 |
|
|
132 |
|
|
130 | 133 |
VALIDATOR_APP = validator(APP) |
131 |
|
|
132 | 134 |
HTTPD = make_server('', 8888, VALIDATOR_APP) |
133 | 135 |
HTTPD.serve_forever() |
134 | 136 |
|
Also available in: Unified diff