Log in
+Need an account? Sign up now!
+Switch to OpenID sign-in
+Switch to standard sign-in
+ +X-Git-Url: https://code.grnet.gr/git/snf-occi/blobdiff_plain/80578d96574d2467b41e592937ae901ac892c4b6..fddcb6884675e66027d83a02e6ae4fc39098b4c6:/snf-occi-server.py diff --git a/snf-occi-server.py b/snf-occi-server.py old mode 100755 new mode 100644 index 5949353..a17ad11 --- a/snf-occi-server.py +++ b/snf-occi-server.py @@ -1,253 +1,293 @@ -#!/usr/bin/env python - -from kamaki.clients.compute import ComputeClient -from kamaki.config import Config - -<<<<<<< HEAD -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.extensions.infrastructure import COMPUTE, START, STOP, SUSPEND, RESTART, RESOURCE_TEMPLATE, OS_TEMPLATE - -from occi.wsgi import Application - -from wsgiref.simple_server import make_server -from wsgiref.validate import validator - - -class MyBackend(KindBackend, ActionBackend): - ''' - An very simple abstract backend which handles update and replace for - attributes. Support for links and mixins would need to added. - ''' - - def update(self, old, new, extras): - # here you can check what information from new_entity you wanna bring - # into old_entity - - # trigger your hypervisor and push most recent information - print('Updating a resource with id: ' + old.identifier) - for item in new.attributes.keys(): - old.attributes[item] = new.attributes[item] - - def replace(self, old, new, extras): - print('Replacing a resource with id: ' + old.identifier) - old.attributes = {} - for item in new.attributes.keys(): - old.attributes[item] = new.attributes[item] - old.attributes['occi.compute.state'] = 'inactive' - - -class ComputeBackend(MyBackend): - ''' -<<<<<<< HEAD - A Backend for compute instances. -======= - Backend for Cyclades/Openstack compute instances ->>>>>>> 592e811729d5f061377c854f645311e560ec4faa - ''' - - def create(self, entity, extras): - - for mixin in entity.mixins: -<<<<<<< HEAD - print mixin.term - print mixin.attributes - if mixin.related[0].term == 'os_tpl': - image = mixin.related[0] - image_id = mixin.attributes['occi.core.id'] - if mixin.related[0].term == 'resource_tpl': - flavor = mixin.related[0] - flavor_id = mixin.attributes['occi.core.id'] - - - entity.attributes['occi.compute.state'] = 'active' - entity.actions = [STOP, SUSPEND, RESTART] - - #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()) - vm_name = entity.attributes['occi.compute.hostname'] - info = snf.create_server(vm_name, flavor_id, image_id) - entity.attributes['occi.core.id'] = str(info['id']) -<<<<<<< HEAD - - def retrieve(self, entity, extras): - # 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': - entity.actions = [START] - if entity.attributes['occi.compute.state'] == 'active': - entity.actions = [STOP, SUSPEND, RESTART] - if entity.attributes['occi.compute.state'] == 'suspended': - entity.actions = [START] - -<<<<<<< HEAD - def delete(self, entity, extras): - # call the management framework to delete this compute instance... - print('Removing representation of virtual machine with id: ' - + entity.identifier) -======= + + +
+Need an account? Sign up now!
+Switch to OpenID sign-in
+Switch to standard sign-in
+ +