change states and little bug in storage backend

This commit is contained in:
Thijs Metsch
2012-07-02 13:11:45 +02:00
parent 22f39bdbdc
commit 273311d5fc
3 changed files with 43 additions and 66 deletions

View File

@@ -191,30 +191,16 @@ class ComputeBackend(KindBackend, ActionBackend):
if action not in entity.actions: if action not in entity.actions:
raise AttributeError("This action is currently not applicable.") raise AttributeError("This action is currently not applicable.")
elif action == infrastructure.START: elif action == infrastructure.START:
state = entity.attributes['occi.compute.state'] vm.start_vm(uid, context)
vm.start_vm(uid, state, context)
entity.attributes['occi.compute.state'] = 'active'
entity.actions = [infrastructure.STOP,
infrastructure.SUSPEND,
infrastructure.RESTART,
openstack.OS_REVERT_RESIZE,
openstack.OS_CONFIRM_RESIZE,
openstack.OS_CREATE_IMAGE]
elif action == infrastructure.STOP: elif action == infrastructure.STOP:
vm.stop_vm(uid, context) vm.stop_vm(uid, context)
entity.attributes['occi.compute.state'] = 'inactive'
entity.actions = [infrastructure.START]
elif action == infrastructure.RESTART: elif action == infrastructure.RESTART:
if not 'method' in attributes: if not 'method' in attributes:
raise AttributeError('Please provide a method!') raise AttributeError('Please provide a method!')
method = attributes['method'] method = attributes['method']
vm.restart_vm(uid, method, context) vm.restart_vm(uid, method, context)
entity.attributes['occi.compute.state'] = 'inactive'
entity.actions = []
elif action == infrastructure.SUSPEND: elif action == infrastructure.SUSPEND:
vm.suspend_vm(uid, context) vm.suspend_vm(uid, context)
entity.attributes['occi.compute.state'] = 'suspended'
entity.actions = [infrastructure.START]
# SOME HELPER FUNCTIONS # SOME HELPER FUNCTIONS

View File

@@ -75,12 +75,16 @@ class StorageBackend(backend.KindBackend, backend.ActionBackend):
entity.attributes['occi.storage.state'] = 'online' entity.attributes['occi.storage.state'] = 'online'
entity.actions = [infrastructure.OFFLINE, infrastructure.BACKUP, entity.actions = [infrastructure.OFFLINE, infrastructure.BACKUP,
infrastructure.SNAPSHOT, infrastructure.RESIZE] infrastructure.SNAPSHOT, infrastructure.RESIZE]
else:
entity.attributes['occi.storage.state'] = 'offline'
def update(self, old, new, extras): def update(self, old, new, extras):
""" """
Updates simple attributes of a storage resource: Updates simple attributes of a storage resource:
occi.core.title, occi.core.summary occi.core.title, occi.core.summary
""" """
# TODO: proper set the state of an storage instance!
# update attributes. # update attributes.
if len(new.attributes) > 0: if len(new.attributes) > 0:
# support only title and summary changes now. # support only title and summary changes now.

View File

@@ -43,7 +43,7 @@ import logging
COMPUTE_API = compute.API() COMPUTE_API = compute.API()
VOLUME_API = volume.API() VOLUME_API = volume.API()
LOG = logging.getLogger('openstackocci.nova_glue.vm') LOG = logging.getLogger('nova.api.occi.nova_glue')
def create_vm(entity, context): def create_vm(entity, context):
@@ -246,7 +246,7 @@ def snapshot_vm(uid, image_name, context):
raise AttributeError('VM is not in an valid state.') raise AttributeError('VM is not in an valid state.')
def start_vm(uid, state, context): def start_vm(uid, context):
""" """
Starts a vm that is in the stopped state. Note, currently we do not Starts a vm that is in the stopped state. Note, currently we do not
use the nova start and stop, rather the resume/suspend methods. The use the nova start and stop, rather the resume/suspend methods. The
@@ -257,11 +257,7 @@ def start_vm(uid, state, context):
context -- the os context context -- the os context
""" """
instance = get_vm(uid, context) instance = get_vm(uid, context)
try: try:
if state == 'suspended':
COMPUTE_API.unpause(context, instance)
else:
COMPUTE_API.resume(context, instance) COMPUTE_API.resume(context, instance)
except Exception as error: except Exception as error:
raise exceptions.HTTPError(500, 'Error while starting VM: ' + str raise exceptions.HTTPError(500, 'Error while starting VM: ' + str
@@ -334,14 +330,18 @@ def attach_volume(instance_id, volume_id, mount_point, context):
vol_instance = VOLUME_API.get(context, volume_id) vol_instance = VOLUME_API.get(context, volume_id)
except exception.NotFound: except exception.NotFound:
raise exceptions.HTTPError(404, 'Volume not found!') raise exceptions.HTTPError(404, 'Volume not found!')
print vol_instance, dir(vol_instance) LOG.debug(str(vol_instance) + ',' + str(dir(vol_instance)))
volume_id = vol_instance[0] volume_id = vol_instance['id']
try:
COMPUTE_API.attach_volume( COMPUTE_API.attach_volume(
context, context,
instance, instance,
volume_id, volume_id,
mount_point) mount_point)
except Exception as error:
LOG.error(str(error))
raise error
def detach_volume(volume_id, context): def detach_volume(volume_id, context):
@@ -454,43 +454,30 @@ def get_occi_state(uid, context):
context -- the os context. context -- the os context.
""" """
instance = get_vm(uid, context) instance = get_vm(uid, context)
state = 'inactive'
actions = []
if instance['vm_state'] in (vm_states.ACTIVE, if instance['vm_state'] in [vm_states.ACTIVE,
task_states.UPDATING_PASSWORD, vm_states.RESIZED]:
task_states.RESIZE_CONFIRMING): state = 'active'
return 'active', [infrastructure.STOP, actions.append(infrastructure.STOP)
infrastructure.SUSPEND, actions.append(infrastructure.SUSPEND)
infrastructure.RESTART, actions.append(infrastructure.RESTART)
openstack.OS_CONFIRM_RESIZE, elif instance['vm_state'] in [vm_states.BUILDING]:
openstack.OS_REVERT_RESIZE, state = 'inactive'
openstack.OS_CHG_PWD, elif instance['vm_state'] in [vm_states.PAUSED, vm_states.SUSPENDED,
openstack.OS_CREATE_IMAGE] vm_states.STOPPED]:
state = 'inactive'
actions.append(infrastructure.START)
elif instance['vm_state'] in [vm_states.RESCUED,
vm_states.ERROR, vm_states.SOFT_DELETED,
vm_states.DELETED]:
state = 'inactive'
# reboot server - OS, OCCI # Some task states require a state
# start server - OCCI # TODO: check for others!
elif instance['vm_state'] in (task_states.STARTING, if instance['vm_state'] in [task_states.IMAGE_SNAPSHOT]:
task_states.POWERING_ON, state = 'inactive'
task_states.REBOOTING, actions = []
task_states.REBOOTING_HARD):
return 'inactive', []
# pause server - OCCI, suspend server - OCCI, stop server - OCCI return state, actions
elif instance['vm_state'] in (task_states.STOPPING,
task_states.POWERING_OFF):
return 'inactive', [infrastructure.START]
# resume server - OCCI
elif instance['vm_state'] in (task_states.RESUMING,
task_states.PAUSING,
task_states.SUSPENDING):
if instance['vm_state'] in (vm_states.PAUSED,
vm_states.SUSPENDED):
return 'suspended', [infrastructure.START]
else:
return 'suspended', []
# rebuild server - OS
# resize server confirm rebuild
# revert resized server - OS (indirectly OCCI)
return 'inactive', []