minor fixes

This commit is contained in:
Thijs Metsch
2012-07-04 11:04:17 +02:00
parent a154a0c695
commit 18e93aff73
7 changed files with 35 additions and 22 deletions

View File

@@ -125,10 +125,10 @@ class ComputeBackend(KindBackend, ActionBackend):
LOG.debug('Updating an Virtual machine: ', uid) LOG.debug('Updating an Virtual machine: ', uid)
# update title, summary etc. # update title, summary etc.
if len(new.attributes['occi.core.title']) > 0: if 'occi.core.title' in new.attributes:
old.attributes['occi.core.title'] = \ old.attributes['occi.core.title'] = \
new.attributes['occi.core.title'] new.attributes['occi.core.title']
if len(new.attributes['occi.core.summary']) > 0: if 'occi.core.summary' in new.attributes:
old.attributes['occi.core.summary'] = \ old.attributes['occi.core.summary'] = \
new.attributes['occi.core.summary'] new.attributes['occi.core.summary']

View File

@@ -158,7 +158,7 @@ class SecurityGroupBackend(backend.UserDefinedMixinBackend):
context = extras['nova_ctx'] context = extras['nova_ctx']
security_group = security.retrieve_group(category.term, security_group = security.retrieve_group(category.term,
extras['nova_ctx'].project_id, extras['nova_ctx'].project_id,
extras) extras['nova_ctx'])
security.remove_group(security_group, context) security.remove_group(security_group, context)

View File

@@ -76,7 +76,6 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
if (hasattr(category, 'related') and if (hasattr(category, 'related') and
occi_future.SEC_GROUP in category.related): occi_future.SEC_GROUP in category.related):
backend = openstack.SecurityGroupBackend() backend = openstack.SecurityGroupBackend()
backend = backend
backend.init_sec_group(category, extras) backend.init_sec_group(category, extras)
super(OCCIRegistry, self).set_backend(category, backend, extras) super(OCCIRegistry, self).set_backend(category, backend, extras)

View File

@@ -34,6 +34,8 @@ class StorageLinkBackend(backend.KindBackend):
A backend for the storage links. A backend for the storage links.
""" """
# TODO: need to implement retrieve so states get updated!!!!
def create(self, link, extras): def create(self, link, extras):
""" """
Creates a link from a compute instance to a storage volume. Creates a link from a compute instance to a storage volume.

View File

@@ -111,7 +111,7 @@ class StorageBackend(backend.KindBackend, backend.ActionBackend):
Deletes the storage resource Deletes the storage resource
""" """
context = extras['nova_ctx'] context = extras['nova_ctx']
volume_id = int(entity.attributes['occi.core.id']) volume_id = entity.attributes['occi.core.id']
vol.delete_storage_instance(volume_id, context) vol.delete_storage_instance(volume_id, context)

View File

@@ -60,12 +60,17 @@ def remove_group(group_id, context):
context -- The os context. context -- The os context.
""" """
# TODO: check exception handling! # TODO: check exception handling!
if db.security_group_in_use(context, group_id):
raise AttributeError('Security group is still in use')
db.security_group_destroy(context, group_id)
SEC_HANDLER.trigger_security_group_destroy_refresh( try:
context, group_id) if db.security_group_in_use(context, group_id):
raise AttributeError('Security group is still in use')
db.security_group_destroy(context, group_id)
SEC_HANDLER.trigger_security_group_destroy_refresh(
context, group_id)
except Exception as error:
raise AttributeError(error)
def retrieve_group(mixin_term, project_id, context): def retrieve_group(mixin_term, project_id, context):
@@ -118,8 +123,9 @@ def remove_rule(rule, context):
db.security_group_rule_destroy(context, rule['id']) db.security_group_rule_destroy(context, rule['id'])
SEC_HANDLER.trigger_security_group_rule_destroy_refresh(context, SEC_HANDLER.trigger_security_group_rule_destroy_refresh(context,
[rule['id']]) [rule['id']])
COMPUTE_API.trigger_security_group_rules_refresh(context, # TODO: method is one!
security_group['id']) #SEC_HANDLER.trigger_security_group_rules_refresh(context,
# security_group['id'])
def get_rule(uid, context): def get_rule(uid, context):

View File

@@ -168,7 +168,7 @@ def rebuild_vm(uid, image_href, context):
COMPUTE_API.rebuild(context, instance, image_href, admin_password, COMPUTE_API.rebuild(context, instance, image_href, admin_password,
**kwargs) **kwargs)
except exception.InstanceInvalidState: except exception.InstanceInvalidState:
raise exceptions.HTTPError(409, 'VM is in an invalid state.') raise AttributeError('VM is in an invalid state.')
except exception.ImageNotFound: except exception.ImageNotFound:
raise AttributeError('Cannot find image for rebuild') raise AttributeError('Cannot find image for rebuild')
@@ -194,8 +194,9 @@ def resize_vm(uid, flavor_name, context):
raise AttributeError('Unable to locate requested flavor.') raise AttributeError('Unable to locate requested flavor.')
except exception.CannotResizeToSameSize: except exception.CannotResizeToSameSize:
raise AttributeError('Resize requires a change in size.') raise AttributeError('Resize requires a change in size.')
except exception.InstanceInvalidState: except exception.InstanceInvalidState as error:
raise exceptions.HTTPError(409, 'VM is in an invalid state.') raise error
#raise AttributeError('VM is in an invalid state.')
def delete_vm(uid, context): def delete_vm(uid, context):
@@ -309,7 +310,7 @@ def restart_vm(uid, method, context):
try: try:
COMPUTE_API.reboot(context, instance, reboot_type) COMPUTE_API.reboot(context, instance, reboot_type)
except exception.InstanceInvalidState: except exception.InstanceInvalidState:
raise exceptions.HTTPError(409, 'VM is in an invalid state.') raise exceptions.HTTPError(406, 'VM is in an invalid state.')
except Exception as error: except Exception as error:
msg = ("Error in reboot %s") % error msg = ("Error in reboot %s") % error
raise exceptions.HTTPError(500, msg) raise exceptions.HTTPError(500, msg)
@@ -330,7 +331,6 @@ 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!')
LOG.debug(str(vol_instance) + ',' + str(dir(vol_instance)))
volume_id = vol_instance['id'] volume_id = vol_instance['id']
try: try:
@@ -355,9 +355,14 @@ def detach_volume(volume_id, context):
instance = VOLUME_API.get(context, volume_id) 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!')
volume_id = instance[0] volume_id = instance['id']
COMPUTE_API.detach_volumne(context, volume_id) try:
#TODO(dizz): see issue #15
COMPUTE_API.detach_volume(context, volume_id)
except Exception as error:
LOG.error(str(error) + volume_id)
raise error
def set_password_for_vm(uid, password, context): def set_password_for_vm(uid, password, context):
@@ -403,7 +408,7 @@ def revert_resize_vm(uid, context):
except exception.MigrationNotFound: except exception.MigrationNotFound:
raise AttributeError('Instance has not been resized.') raise AttributeError('Instance has not been resized.')
except exception.InstanceInvalidState: except exception.InstanceInvalidState:
raise exceptions.HTTPError(409, 'VM is an invalid state.') raise exceptions.HTTPError(406, 'VM is an invalid state.')
except Exception: except Exception:
raise AttributeError('Error in revert-resize.') raise AttributeError('Error in revert-resize.')
@@ -420,8 +425,9 @@ def confirm_resize_vm(uid, context):
COMPUTE_API.confirm_resize(context, instance) COMPUTE_API.confirm_resize(context, instance)
except exception.MigrationNotFound: except exception.MigrationNotFound:
raise AttributeError('Instance has not been resized.') raise AttributeError('Instance has not been resized.')
except exception.InstanceInvalidState: except exception.InstanceInvalidState as error:
raise exceptions.HTTPError(409, 'VM is an invalid state.') raise error
# raise exceptions.HTTPError(406, 'VM is an invalid state.')
except Exception: except Exception:
raise AttributeError('Error in confirm-resize.') raise AttributeError('Error in confirm-resize.')