Commit 80578d96 authored by John Giannelos's avatar John Giannelos
Browse files

Merge branch 'master' of bitbucket.org:nemo32/snf-occi

Conflicts:
	snf-occi-server.py
parents d0ea08cc 592e8117
...@@ -3,7 +3,11 @@ ...@@ -3,7 +3,11 @@
from kamaki.clients.compute import ComputeClient from kamaki.clients.compute import ComputeClient
from kamaki.config import Config from kamaki.config import Config
<<<<<<< HEAD
from occi.core_model import Mixin from occi.core_model import Mixin
=======
from occi.core_model import Mixin, Resource, Link, Entity
>>>>>>> 592e811729d5f061377c854f645311e560ec4faa
from occi.backend import ActionBackend, KindBackend, MixinBackend from occi.backend import ActionBackend, KindBackend, MixinBackend
from occi.extensions.infrastructure import COMPUTE, START, STOP, SUSPEND, RESTART, RESOURCE_TEMPLATE, OS_TEMPLATE from occi.extensions.infrastructure import COMPUTE, START, STOP, SUSPEND, RESTART, RESOURCE_TEMPLATE, OS_TEMPLATE
...@@ -38,12 +42,17 @@ class MyBackend(KindBackend, ActionBackend): ...@@ -38,12 +42,17 @@ class MyBackend(KindBackend, ActionBackend):
class ComputeBackend(MyBackend): class ComputeBackend(MyBackend):
''' '''
<<<<<<< HEAD
A Backend for compute instances. A Backend for compute instances.
=======
Backend for Cyclades/Openstack compute instances
>>>>>>> 592e811729d5f061377c854f645311e560ec4faa
''' '''
def create(self, entity, extras): def create(self, entity, extras):
for mixin in entity.mixins: for mixin in entity.mixins:
<<<<<<< HEAD
print mixin.term print mixin.term
print mixin.attributes print mixin.attributes
if mixin.related[0].term == 'os_tpl': if mixin.related[0].term == 'os_tpl':
...@@ -58,15 +67,54 @@ class ComputeBackend(MyBackend): ...@@ -58,15 +67,54 @@ class ComputeBackend(MyBackend):
entity.actions = [STOP, SUSPEND, RESTART] entity.actions = [STOP, SUSPEND, RESTART]
#TODO VM identifier #TODO VM identifier
=======
if mixin.related[0].term == 'os_tpl':
image = mixin
image_id = mixin.attributes['occi.core.id']
if mixin.related[0].term == 'resource_tpl':
flavor = mixin
flavor_id = mixin.attributes['occi.core.id']
entity.attributes['occi.compute.state'] = 'active'
entity.actions = [STOP, SUSPEND, RESTART]
#Registry identifier is the uuid key occi.handler assigns
#attribute 'occi.core.id' will be the snf-server id
>>>>>>> 592e811729d5f061377c854f645311e560ec4faa
snf = ComputeClient(Config()) snf = ComputeClient(Config())
vm_name = entity.attributes['occi.compute.hostname'] vm_name = entity.attributes['occi.compute.hostname']
info = snf.create_server(vm_name, flavor_id, image_id) info = snf.create_server(vm_name, flavor_id, image_id)
entity.attributes['occi.core.id'] = str(info['id']) entity.attributes['occi.core.id'] = str(info['id'])
<<<<<<< HEAD
def retrieve(self, entity, extras): def retrieve(self, entity, extras):
# triggering cyclades to retrieve up to date information # triggering cyclades to retrieve up to date information
=======
entity.attributes['occi.compute.cores'] = flavor.attributes['occi.compute.cores']
entity.attributes['occi.compute.memory'] = flavor.attributes['occi.compute.memory']
def retrieve(self, entity, extras):
# triggering cyclades to retrieve up to date information
snf = ComputeClient(Config())
vm_id = int(entity.attributes['occi.core.id'])
vm_info = snf.get_server_details(vm_id)
vm_state = vm_info['status']
status_dict = {'ACTIVE' : 'active',
'STOPPED' : 'inactive',
'ERROR' : 'inactive',
'BUILD' : 'inactive',
'DELETED' : 'inactive',
}
entity.attributes['occi.compute.state'] = status_dict[vm_state]
>>>>>>> 592e811729d5f061377c854f645311e560ec4faa
if entity.attributes['occi.compute.state'] == 'inactive': if entity.attributes['occi.compute.state'] == 'inactive':
entity.actions = [START] entity.actions = [START]
if entity.attributes['occi.compute.state'] == 'active': if entity.attributes['occi.compute.state'] == 'active':
...@@ -74,10 +122,22 @@ class ComputeBackend(MyBackend): ...@@ -74,10 +122,22 @@ class ComputeBackend(MyBackend):
if entity.attributes['occi.compute.state'] == 'suspended': if entity.attributes['occi.compute.state'] == 'suspended':
entity.actions = [START] entity.actions = [START]
<<<<<<< HEAD
def delete(self, entity, extras): def delete(self, entity, extras):
# call the management framework to delete this compute instance... # call the management framework to delete this compute instance...
print('Removing representation of virtual machine with id: ' print('Removing representation of virtual machine with id: '
+ entity.identifier) + entity.identifier)
=======
def delete(self, entity, extras):
# delete vm with vm_id = entity.attributes['occi.core.id']
snf = ComputeClient(Config())
vm_id = int(entity.attributes['occi.core.id'])
snf.delete_server(vm_id)
>>>>>>> 592e811729d5f061377c854f645311e560ec4faa
def action(self, entity, action, extras): def action(self, entity, action, extras):
if action not in entity.actions: if action not in entity.actions:
...@@ -112,10 +172,18 @@ class MyAPP(Application): ...@@ -112,10 +172,18 @@ class MyAPP(Application):
def __call__(self, environ, response): def __call__(self, environ, response):
sec_obj = {'username': 'password'} sec_obj = {'username': 'password'}
<<<<<<< HEAD
#Refresh registry entries with current Cyclades state #Refresh registry entries with current Cyclades state
snf = ComputeClient(Config()) snf = ComputeClient(Config())
=======
#Refresh registry entries with current Cyclades state
snf = ComputeClient(Config())
'''
>>>>>>> 592e811729d5f061377c854f645311e560ec4faa
images = snf.list_images() images = snf.list_images()
for image in images: for image in images:
IMAGE_ATTRIBUTES = {'occi.core.id': str(image['id'])} IMAGE_ATTRIBUTES = {'occi.core.id': str(image['id'])}
...@@ -131,9 +199,15 @@ class MyAPP(Application): ...@@ -131,9 +199,15 @@ class MyAPP(Application):
} }
FLAVOR = Mixin("http://schemas.ogf.org/occi/infrastructure#", str(flavor['name']), [RESOURCE_TEMPLATE], attributes = FLAVOR_ATTRIBUTES) FLAVOR = Mixin("http://schemas.ogf.org/occi/infrastructure#", str(flavor['name']), [RESOURCE_TEMPLATE], attributes = FLAVOR_ATTRIBUTES)
self.register_backend(FLAVOR, MixinBackend()) self.register_backend(FLAVOR, MixinBackend())
<<<<<<< HEAD
#TODO show only current VM instances #TODO show only current VM instances
=======
'''
#TODO show only current VM instances
>>>>>>> 592e811729d5f061377c854f645311e560ec4faa
return self._call_occi(environ, response, security=sec_obj, foo=None) return self._call_occi(environ, response, security=sec_obj, foo=None)
...@@ -151,6 +225,27 @@ if __name__ == '__main__': ...@@ -151,6 +225,27 @@ if __name__ == '__main__':
APP.register_backend(RESOURCE_TEMPLATE, MixinBackend()) APP.register_backend(RESOURCE_TEMPLATE, MixinBackend())
APP.register_backend(OS_TEMPLATE, MixinBackend()) APP.register_backend(OS_TEMPLATE, MixinBackend())
<<<<<<< HEAD
=======
snf = ComputeClient(Config())
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())
flavors = snf.list_flavors()
for flavor in flavors:
FLAVOR_ATTRIBUTES = {'occi.core.id': flavor['id'],
'occi.compute.cores': snf.get_flavor_details(flavor['id'])['cpu'],
'occi.compute.memory': snf.get_flavor_details(flavor['id'])['ram'],
'occi.storage.size': snf.get_flavor_details(flavor['id'])['disk'],
}
FLAVOR = Mixin("http://schemas.ogf.org/occi/infrastructure#", str(flavor['name']), [RESOURCE_TEMPLATE], attributes = FLAVOR_ATTRIBUTES)
APP.register_backend(FLAVOR, MixinBackend())
>>>>>>> 592e811729d5f061377c854f645311e560ec4faa
VALIDATOR_APP = validator(APP) VALIDATOR_APP = validator(APP)
HTTPD = make_server('', 8888, VALIDATOR_APP) HTTPD = make_server('', 8888, VALIDATOR_APP)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment