Commit b7ca7496 authored by nasia's avatar nasia
Browse files

Minor changes

parent 7d1d34a2
......@@ -170,7 +170,7 @@ Moreover, a valid certificate issued by a valid CA is required for the server ho
::
$ ls /etc/ssl/certs/server.crt
$ ls /e tc/ssl/private/server.key
$ ls /etc/ssl/private/server.key
Apache Installation and Configuration
......@@ -263,8 +263,8 @@ Assuming that the snf-occi server has the FQDM nodeX.example.com, then the follo
$ ln /usr/lib/cgi-bin/snf_voms/snf_voms.py /usr/lib/cgi-bin/snf_voms/main
$ cp snf-occi/snfOCCI/httpd/snf_voms_auth.py /usr/lib/cgi-bin/snf_voms/snf_voms_auth.py
$ ln /usr/lib/cgi-bin/snf_voms/snf_voms_auth.py /usr/lib/cgi-bin/snf_voms/main_auth
$ cp snf-occi/snfOCCI/snf_voms_auth-paste.ini /home/synneo/snf_voms_auth-paste.ini
$ cp snf-occi/snfOCCI/snf_voms-paste.ini /home/synnefo/snf_voms-paste.ini
$ cp snf-occi/snfOCCI/httpd/snf_voms_auth-paste.ini /home/synneo/snf_voms_auth-paste.ini
$ cp snf-occi/snfOCCI/httpd/snf_voms-paste.ini /home/synnefo/snf_voms-paste.ini
......@@ -354,6 +354,14 @@ The user must have a valid authentication token in order to interact with the sn
$ curl --capath /etc/grid-security/certificates -X GET https://<snf-occi_host>:8888/compute/$ID -H 'X-Auth-Token: $AUTH'
* Perform a STOP action upon a VM::
$ curl -X POST https://<snf-occi_host>:8888/compute/$ID?action=stop -H 'Content-type: text/occi' -H 'X-Auth-Token: $AUTH' -H 'Category: stop; scheme="http://schemas.ogf.org/occi/infrastructure/compute/action#"; class="action"'
* Perform a START action upon a VM::
$ curl -X POST https://<snf-occi_host>:8888/compute/$ID?action=start -H 'Content-type: text/occi' -H 'X-Auth-Token:$AUTH' -H 'Category: start; scheme="http://schemas.ogf.org/occi/infrastructure/compute/action#"; class="action"'
* Delete the VM with identifier $ID::
......
......@@ -56,6 +56,7 @@ from kamaki.clients.cyclades import CycladesClient
from kamaki.clients import astakos
from kamaki.clients import ClientError
from kamaki.cli import config as kamaki_config
from kamaki.clients.cyclades import CycladesNetworkClient
from occi.core_model import Mixin, Resource
from occi.backend import MixinBackend
......
......@@ -35,7 +35,7 @@
from snfOCCI.config import SERVER_CONFIG
from occi.backend import ActionBackend, KindBackend
from occi.extensions.infrastructure import START, STOP, SUSPEND, RESTART
from occi.extensions import infrastructure
from occi.exceptions import HTTPError
......@@ -75,13 +75,16 @@ class ComputeBackend(MyBackend):
vm_name = entity.attributes['occi.core.title']
info = snf.create_server(vm_name, flavor_id, image_id)
entity.actions = [START]
entity.attributes['occi.compute.state'] = 'inactive'
entity.attributes['occi.core.id'] = str(info['id'])
entity.attributes['occi.compute.architecture'] = SERVER_CONFIG['compute_arch']
entity.attributes['occi.compute.cores'] = flavor.attributes['occi.compute.cores']
entity.attributes['occi.compute.memory'] = flavor.attributes['occi.compute.memory']
entity.actions = [infrastructure.STOP,
infrastructure.SUSPEND,
infrastructure.RESTART]
# entity.attributes['occi.compute.hostname'] = SERVER_CONFIG['hostname'] % {'id':info['id']}
info['adminPass']= ""
print info
......@@ -108,9 +111,11 @@ class ComputeBackend(MyBackend):
status_dict = {'ACTIVE' : 'active',
'STOPPED' : 'inactive',
'REBOOT' : 'inactive',
'ERROR' : 'inactive',
'BUILD' : 'inactive',
'DELETED' : 'inactive',
'UNKNOWN' : 'inactive'
}
entity.attributes['occi.compute.state'] = status_dict[vm_state]
......@@ -120,21 +125,47 @@ class ComputeBackend(MyBackend):
else:
if entity.attributes['occi.compute.state'] == 'inactive':
entity.actions = [START]
entity.actions = [infrastructure.START]
if entity.attributes['occi.compute.state'] == 'active':
entity.actions = [STOP, SUSPEND, RESTART]
entity.actions = [infrastructure.STOP, infrastructure.SUSPEND, infrastructure.RESTART]
def delete(self, entity, extras):
#Deleting compute instance
print "Deleting VM" + str(vm_id)
snf = extras['snf']
vm_id = int(entity.attributes['occi.core.id'])
snf.delete_server(vm_id)
def action(self, entity, action, extras):
def get_vm_actions(self, entity ,vm_state):
actions = []
status_dict = {'ACTIVE' : 'active',
'STOPPED' : 'inactive',
'REBOOT' : 'inactive',
'ERROR' : 'inactive',
'BUILD' : 'inactive',
'DELETED' : 'inactive',
'UNKNOWN' : 'inactive'
}
if vm_state in status_dict:
entity.attributes['occi.compute.state'] = status_dict[vm_state]
if vm_state == 'ACTIVE':
actions.append(infrastructure.STOP)
actions.append(infrastructure.RESTART)
elif vm_state in ('STOPPED'):
actions.append(infrastructure.START)
return actions
else:
raise HTTPError(500, 'Undefined status of the VM')
def action(self, entity, action, attributes, extras):
#Triggering action to compute instances
......@@ -144,26 +175,32 @@ class ComputeBackend(MyBackend):
vm_id = int(entity.attributes['occi.core.id'])
vm_info = snf.get_server_details(vm_id)
vm_state = vm_info['status']
# Define the allowed actions depending on the state of the VM
entity.actions = self.get_vm_actions(entity,vm_state)
if vm_state == 'ERROR':
raise HTTPError(500, 'ERROR building the compute instance')
else:
if action not in entity.actions:
raise AttributeError("This action is currently no applicable.")
raise AttributeError("This action is currently no applicable in the current status of the VM (CURRENT_STATE = " + str(vm_state)+ ").")
elif action == START:
print "Starting VM"
elif action == infrastructure.START:
print "Starting VM" + str(vm_id)
client.start_server(vm_id)
elif action == STOP:
print "Stopping VM"
elif action == infrastructure.STOP:
print "Stopping VM" + str(vm_id)
client.shutdown_server(vm_id)
elif action == RESTART:
print "Restarting VM"
elif action == infrastructure.RESTART:
print "Restarting VM" + str(vm_id)
snf.reboot_server(vm_id)
elif action == SUSPEND:
elif action == infrastructure.SUSPEND:
raise HTTPError(501, "This actions is currently no applicable")
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