From 249279cd7c70a7306ed28a62939477ef94ecbc91 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Thu, 9 Jun 2011 15:31:10 -0400 Subject: further changes --- nova/api/openstack/notes.txt | 3 --- 1 file changed, 3 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/notes.txt b/nova/api/openstack/notes.txt index 2330f1002..4e95bffc8 100644 --- a/nova/api/openstack/notes.txt +++ b/nova/api/openstack/notes.txt @@ -7,9 +7,6 @@ image ids. GlanceImageService(ImageService): image ids are URIs. -LocalImageService(ImageService): -image ids are random strings. - OpenstackAPITranslationStore: translates RS server/images/flavor/etc ids into formats required by a given ImageService strategy. -- cgit From febb7130192afcc77408643b5bba595c784671d3 Mon Sep 17 00:00:00 2001 From: Thierry Carrez Date: Fri, 10 Jun 2011 16:53:06 +0200 Subject: Only update updateable fields --- nova/api/ec2/cloud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 316298c39..4a2387a0a 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -967,7 +967,7 @@ class CloudController(object): changes[field] = kwargs[field] if changes: instance_id = ec2utils.ec2_id_to_id(instance_id) - self.compute_api.update(context, instance_id=instance_id, **kwargs) + self.compute_api.update(context, instance_id=instance_id, **changes) return True @staticmethod -- cgit From 98fb2c9388ea4f4221d7557653a3bd732dbd3f32 Mon Sep 17 00:00:00 2001 From: Naveed Massjouni Date: Mon, 13 Jun 2011 19:57:35 -0400 Subject: Alias of volumes extension should be OS-VOLUMES --- nova/api/openstack/contrib/volumes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/volumes.py b/nova/api/openstack/contrib/volumes.py index feabdce89..1563dd8c0 100644 --- a/nova/api/openstack/contrib/volumes.py +++ b/nova/api/openstack/contrib/volumes.py @@ -301,7 +301,7 @@ class Volumes(extensions.ExtensionDescriptor): return "Volumes" def get_alias(self): - return "VOLUMES" + return "OS-VOLUMES" def get_description(self): return "Volumes support" -- cgit From da5e5106565f4999c1856be9c3230ba1a1505b82 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Wed, 15 Jun 2011 17:52:44 +0000 Subject: Adding UUID test --- nova/api/openstack/views/servers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/views/servers.py b/nova/api/openstack/views/servers.py index 245d0e3fa..cbfa5aae7 100644 --- a/nova/api/openstack/views/servers.py +++ b/nova/api/openstack/views/servers.py @@ -75,7 +75,7 @@ class ViewBuilder(object): } inst_dict = { - 'id': int(inst['id']), + 'id': inst['id'], 'name': inst['display_name'], 'addresses': self.addresses_builder.build(inst), 'status': power_mapping[inst.get('state')]} @@ -99,6 +99,7 @@ class ViewBuilder(object): self._build_image(inst_dict, inst) self._build_flavor(inst_dict, inst) + inst_dict['uuid'] = inst['uuid'] return dict(server=inst_dict) def _build_image(self, response, inst): -- cgit From e35878070ce594d3c9db2f433dcf3f3f1441a497 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Wed, 15 Jun 2011 15:28:39 -0400 Subject: adding server existence check to server metadata resource --- nova/api/openstack/server_metadata.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/server_metadata.py b/nova/api/openstack/server_metadata.py index 57666f6b7..ec9e10496 100644 --- a/nova/api/openstack/server_metadata.py +++ b/nova/api/openstack/server_metadata.py @@ -18,9 +18,10 @@ from webob import exc from nova import compute -from nova import quota from nova.api.openstack import faults from nova.api.openstack import wsgi +from nova import exception +from nova import quota class Controller(object): @@ -42,14 +43,23 @@ class Controller(object): expl = _('No Request Body') raise exc.HTTPBadRequest(explanation=expl) + def _check_server_exists(self, context, server_id): + try: + self.compute_api.routing_get(context, server_id) + except exception.InstanceNotFound: + msg = _('Server does not exist') + raise exc.HTTPNotFound(explanation=msg) + def index(self, req, server_id): """ Returns the list of metadata for a given instance """ context = req.environ['nova.context'] + self._check_server_exists(context, server_id) return self._get_metadata(context, server_id) def create(self, req, server_id, body): self._check_body(body) context = req.environ['nova.context'] + self._check_server_exists(context, server_id) metadata = body.get('metadata') try: self.compute_api.update_or_create_instance_metadata(context, @@ -62,6 +72,7 @@ class Controller(object): def update(self, req, server_id, id, body): self._check_body(body) context = req.environ['nova.context'] + self._check_server_exists(context, server_id) if not id in body: expl = _('Request body and URI mismatch') raise exc.HTTPBadRequest(explanation=expl) @@ -80,6 +91,7 @@ class Controller(object): def show(self, req, server_id, id): """ Return a single metadata item """ context = req.environ['nova.context'] + self._check_server_exists(context, server_id) data = self._get_metadata(context, server_id) if id in data['metadata']: return {id: data['metadata'][id]} @@ -89,6 +101,7 @@ class Controller(object): def delete(self, req, server_id, id): """ Deletes an existing metadata """ context = req.environ['nova.context'] + self._check_server_exists(context, server_id) self.compute_api.delete_instance_metadata(context, server_id, id) def _handle_quota_error(self, error): -- cgit From aa726953eb3818b7282044314599bfa3bc22793b Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Wed, 15 Jun 2011 19:30:48 +0000 Subject: Fixing private-ips test --- nova/api/openstack/ips.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/ips.py b/nova/api/openstack/ips.py index abea71830..71646b6d3 100644 --- a/nova/api/openstack/ips.py +++ b/nova/api/openstack/ips.py @@ -32,25 +32,24 @@ class Controller(object): self.compute_api = nova.compute.API() self.builder = nova.api.openstack.views.addresses.ViewBuilderV10() - def index(self, req, server_id): + def _get_instance(self, req, server_id): try: - instance = self.compute_api.get(req.environ['nova.context'], id) + instance = self.compute_api.get( + req.environ['nova.context'], server_id) except nova.exception.NotFound: return faults.Fault(exc.HTTPNotFound()) + return instance + + def index(self, req, server_id): + instance = self._get_instance(req, server_id) return {'addresses': self.builder.build(instance)} def public(self, req, server_id): - try: - instance = self.compute_api.get(req.environ['nova.context'], id) - except nova.exception.NotFound: - return faults.Fault(exc.HTTPNotFound()) + instance = self._get_instance(req, server_id) return {'public': self.builder.build_public_parts(instance)} def private(self, req, server_id): - try: - instance = self.compute_api.get(req.environ['nova.context'], id) - except nova.exception.NotFound: - return faults.Fault(exc.HTTPNotFound()) + instance = self._get_instance(req, server_id) return {'private': self.builder.build_private_parts(instance)} def show(self, req, server_id, id): -- cgit From 98ad65c2bf20632c33f2cb99eb613e07575ecd4a Mon Sep 17 00:00:00 2001 From: Naveed Massjouni Date: Wed, 15 Jun 2011 16:15:40 -0400 Subject: The volumes resource extension should be prefixed by its alias - os-volumes --- nova/api/openstack/contrib/volumes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/volumes.py b/nova/api/openstack/contrib/volumes.py index 1563dd8c0..2a35e4e3e 100644 --- a/nova/api/openstack/contrib/volumes.py +++ b/nova/api/openstack/contrib/volumes.py @@ -317,12 +317,12 @@ class Volumes(extensions.ExtensionDescriptor): # NOTE(justinsb): No way to provide singular name ('volume') # Does this matter? - res = extensions.ResourceExtension('volumes', + res = extensions.ResourceExtension('os-volumes', VolumeController(), collection_actions={'detail': 'GET'}) resources.append(res) - res = extensions.ResourceExtension('volume_attachments', + res = extensions.ResourceExtension('os-volume_attachments', VolumeAttachmentController(), parent=dict( member_name='server', -- cgit From f4d9da4cd6b9fef162d1a69e6b3f50d51744b3de Mon Sep 17 00:00:00 2001 From: Naveed Massjouni Date: Wed, 15 Jun 2011 16:33:05 -0400 Subject: Fixing case of volumes alias --- nova/api/openstack/contrib/volumes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/volumes.py b/nova/api/openstack/contrib/volumes.py index 2a35e4e3e..e5e2c5b50 100644 --- a/nova/api/openstack/contrib/volumes.py +++ b/nova/api/openstack/contrib/volumes.py @@ -301,7 +301,7 @@ class Volumes(extensions.ExtensionDescriptor): return "Volumes" def get_alias(self): - return "OS-VOLUMES" + return "os-volumes" def get_description(self): return "Volumes support" -- cgit From 2a20e38d9f39732dd2f47cedeb9b1e48de767770 Mon Sep 17 00:00:00 2001 From: Brian Lamar Date: Wed, 15 Jun 2011 16:58:55 -0400 Subject: Passed in explanation to 400 messages. --- nova/api/openstack/create_instance_helper.py | 12 ++++++------ nova/api/openstack/servers.py | 8 ++++---- nova/api/openstack/wsgi.py | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/create_instance_helper.py b/nova/api/openstack/create_instance_helper.py index fbc6318ef..63485eb53 100644 --- a/nova/api/openstack/create_instance_helper.py +++ b/nova/api/openstack/create_instance_helper.py @@ -94,7 +94,7 @@ class CreateInstanceHelper(object): except Exception, e: msg = _("Cannot find requested image %(image_href)s: %(e)s" % locals()) - raise faults.Fault(exc.HTTPBadRequest(msg)) + raise faults.Fault(exc.HTTPBadRequest(explanation=msg)) personality = body['server'].get('personality') @@ -106,7 +106,7 @@ class CreateInstanceHelper(object): if not 'name' in body['server']: msg = _("Server name is not defined") - raise exc.HTTPBadRequest(msg) + raise exc.HTTPBadRequest(explanation=msg) zone_blob = body['server'].get('blob') name = body['server']['name'] @@ -145,7 +145,7 @@ class CreateInstanceHelper(object): self._handle_quota_error(error) except exception.ImageNotFound as error: msg = _("Can not find requested image") - raise faults.Fault(exc.HTTPBadRequest(msg)) + raise faults.Fault(exc.HTTPBadRequest(explanation=msg)) # Let the caller deal with unhandled exceptions. @@ -180,11 +180,11 @@ class CreateInstanceHelper(object): def _validate_server_name(self, value): if not isinstance(value, basestring): msg = _("Server name is not a string or unicode") - raise exc.HTTPBadRequest(msg) + raise exc.HTTPBadRequest(explanation=msg) if value.strip() == '': msg = _("Server name is an empty string") - raise exc.HTTPBadRequest(msg) + raise exc.HTTPBadRequest(explanation=msg) def _get_kernel_ramdisk_from_image(self, req, image_id): """Fetch an image from the ImageService, then if present, return the @@ -265,7 +265,7 @@ class CreateInstanceHelper(object): return utils.generate_password(16) if not isinstance(password, basestring) or password == '': msg = _("Invalid adminPass") - raise exc.HTTPBadRequest(msg) + raise exc.HTTPBadRequest(explanation=msg) return password diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index 798fdd7f7..b82a6de19 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -51,7 +51,7 @@ class Controller(object): try: servers = self._items(req, is_detail=False) except exception.Invalid as err: - return exc.HTTPBadRequest(str(err)) + return exc.HTTPBadRequest(explanation=str(err)) return servers def detail(self, req): @@ -59,7 +59,7 @@ class Controller(object): try: servers = self._items(req, is_detail=True) except exception.Invalid as err: - return exc.HTTPBadRequest(str(err)) + return exc.HTTPBadRequest(explanation=str(err)) return servers def _get_view_builder(self, req): @@ -488,11 +488,11 @@ class ControllerV11(Controller): if (not 'changePassword' in input_dict or not 'adminPass' in input_dict['changePassword']): msg = _("No adminPass was specified") - return exc.HTTPBadRequest(msg) + return exc.HTTPBadRequest(explanation=msg) password = input_dict['changePassword']['adminPass'] if not isinstance(password, basestring) or password == '': msg = _("Invalid adminPass") - return exc.HTTPBadRequest(msg) + return exc.HTTPBadRequest(explanation=msg) self.compute_api.set_admin_password(context, id, password) return exc.HTTPAccepted() diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index 3f8acf339..a57b7f72b 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -363,11 +363,11 @@ class Resource(wsgi.Application): action, action_args, accept = self.deserializer.deserialize( request) except exception.InvalidContentType: - return webob.exc.HTTPBadRequest(_("Unsupported Content-Type")) + msg = _("Unsupported Content-Type") + return webob.exc.HTTPBadRequest(explanation=msg) except exception.MalformedRequestBody: - explanation = _("Malformed request body") - return faults.Fault(webob.exc.HTTPBadRequest( - explanation=explanation)) + msg = _("Malformed request body") + return faults.Fault(webob.exc.HTTPBadRequest(explanation=msg)) action_result = self.dispatch(request, action, action_args) -- cgit From da09c8fca687d0756cda38c5bd038d677dacd1f3 Mon Sep 17 00:00:00 2001 From: "Kevin L. Mitchell" Date: Thu, 16 Jun 2011 21:27:17 +0000 Subject: Fix lp795123 and lp795126 by making _check_extension() return True or False and checking the result only from the top of _add_extension() --- nova/api/openstack/extensions.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/extensions.py b/nova/api/openstack/extensions.py index 54e17e23d..28d9d9192 100644 --- a/nova/api/openstack/extensions.py +++ b/nova/api/openstack/extensions.py @@ -374,6 +374,8 @@ class ExtensionManager(object): LOG.debug(_('Ext updated: %s'), extension.get_updated()) except AttributeError as ex: LOG.exception(_("Exception loading extension: %s"), unicode(ex)) + return False + return True def _load_all_extensions(self): """Load extensions from the configured path. @@ -412,15 +414,16 @@ class ExtensionManager(object): 'file': ext_path}) continue new_ext = new_ext_class() - self._check_extension(new_ext) self._add_extension(new_ext) def _add_extension(self, ext): + # Do nothing if the extension doesn't check out + if not self._check_extension(ext): + return + alias = ext.get_alias() LOG.audit(_('Loaded extension: %s'), alias) - self._check_extension(ext) - if alias in self.extensions: raise exception.Error("Found duplicate extension: %s" % alias) self.extensions[alias] = ext -- cgit From 6ce8a156ea4a40190dd2a71eeba67a101ae7370d Mon Sep 17 00:00:00 2001 From: Kevin Bringard Date: Fri, 17 Jun 2011 10:07:25 -0600 Subject: Cleaned up some pep8 issues in nova/api/openstack/create_instance_helper.py and nova/api/openstack/__init__.py --- nova/api/openstack/__init__.py | 3 +-- nova/api/openstack/create_instance_helper.py | 7 ++----- 2 files changed, 3 insertions(+), 7 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/__init__.py b/nova/api/openstack/__init__.py index ddd9580d7..f24017df0 100644 --- a/nova/api/openstack/__init__.py +++ b/nova/api/openstack/__init__.py @@ -113,8 +113,7 @@ class APIRouter(base_wsgi.Router): collection={'detail': 'GET', 'info': 'GET', 'select': 'POST', - 'boot': 'POST' - }) + 'boot': 'POST'}) mapper.resource("console", "consoles", controller=consoles.create_resource(), diff --git a/nova/api/openstack/create_instance_helper.py b/nova/api/openstack/create_instance_helper.py index fbc6318ef..2501ed9fe 100644 --- a/nova/api/openstack/create_instance_helper.py +++ b/nova/api/openstack/create_instance_helper.py @@ -121,8 +121,7 @@ class CreateInstanceHelper(object): extra_values = { 'instance_type': inst_type, 'image_ref': image_href, - 'password': password - } + 'password': password} return (extra_values, create_method(context, @@ -138,9 +137,7 @@ class CreateInstanceHelper(object): injected_files=injected_files, admin_password=password, zone_blob=zone_blob, - reservation_id=reservation_id - ) - ) + reservation_id=reservation_id)) except quota.QuotaError as error: self._handle_quota_error(error) except exception.ImageNotFound as error: -- cgit From f0b0f4ad4c6f90b1b3b23e6a048ebda8e62cb254 Mon Sep 17 00:00:00 2001 From: "Kevin L. Mitchell" Date: Fri, 17 Jun 2011 17:33:00 +0000 Subject: Remove thirdwheel.py and do the test with a now-public ExtensionManager.add_extension() --- nova/api/openstack/extensions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/extensions.py b/nova/api/openstack/extensions.py index 28d9d9192..da06ecd15 100644 --- a/nova/api/openstack/extensions.py +++ b/nova/api/openstack/extensions.py @@ -414,9 +414,9 @@ class ExtensionManager(object): 'file': ext_path}) continue new_ext = new_ext_class() - self._add_extension(new_ext) + self.add_extension(new_ext) - def _add_extension(self, ext): + def add_extension(self, ext): # Do nothing if the extension doesn't check out if not self._check_extension(ext): return -- cgit From a0ab4e7f141ccf14caca23f15eed5408079a58d0 Mon Sep 17 00:00:00 2001 From: Thierry Carrez Date: Fri, 17 Jun 2011 22:32:17 +0200 Subject: Fix PEP8 --- nova/api/ec2/cloud.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 4a2387a0a..eb7ec2b80 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -967,7 +967,8 @@ class CloudController(object): changes[field] = kwargs[field] if changes: instance_id = ec2utils.ec2_id_to_id(instance_id) - self.compute_api.update(context, instance_id=instance_id, **changes) + self.compute_api.update(context, instance_id=instance_id, + **changes) return True @staticmethod -- cgit From e2fa70fb9d2b6684823328a491e18c0f98184665 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Fri, 17 Jun 2011 17:40:48 -0400 Subject: moving instance existance logic down to api layer --- nova/api/openstack/server_metadata.py | 47 +++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 18 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/server_metadata.py b/nova/api/openstack/server_metadata.py index ec9e10496..8a314de22 100644 --- a/nova/api/openstack/server_metadata.py +++ b/nova/api/openstack/server_metadata.py @@ -43,36 +43,35 @@ class Controller(object): expl = _('No Request Body') raise exc.HTTPBadRequest(explanation=expl) - def _check_server_exists(self, context, server_id): - try: - self.compute_api.routing_get(context, server_id) - except exception.InstanceNotFound: - msg = _('Server does not exist') - raise exc.HTTPNotFound(explanation=msg) - def index(self, req, server_id): """ Returns the list of metadata for a given instance """ context = req.environ['nova.context'] - self._check_server_exists(context, server_id) - return self._get_metadata(context, server_id) + try: + return self._get_metadata(context, server_id) + except exception.InstanceNotFound: + msg = _('Server %(server_id)s does not exist') % locals() + raise exc.HTTPNotFound(explanation=msg) def create(self, req, server_id, body): self._check_body(body) context = req.environ['nova.context'] - self._check_server_exists(context, server_id) metadata = body.get('metadata') try: self.compute_api.update_or_create_instance_metadata(context, server_id, metadata) + except exception.InstanceNotFound: + msg = _('Server %(server_id)s does not exist') % locals() + raise exc.HTTPNotFound(explanation=msg) + except quota.QuotaError as error: self._handle_quota_error(error) + return body def update(self, req, server_id, id, body): self._check_body(body) context = req.environ['nova.context'] - self._check_server_exists(context, server_id) if not id in body: expl = _('Request body and URI mismatch') raise exc.HTTPBadRequest(explanation=expl) @@ -83,6 +82,10 @@ class Controller(object): self.compute_api.update_or_create_instance_metadata(context, server_id, body) + except exception.InstanceNotFound: + msg = _('Server %(server_id)s does not exist') % locals() + raise exc.HTTPNotFound(explanation=msg) + except quota.QuotaError as error: self._handle_quota_error(error) @@ -91,18 +94,26 @@ class Controller(object): def show(self, req, server_id, id): """ Return a single metadata item """ context = req.environ['nova.context'] - self._check_server_exists(context, server_id) - data = self._get_metadata(context, server_id) - if id in data['metadata']: + try: + data = self._get_metadata(context, server_id) + except exception.InstanceNotFound: + msg = _('Server %(server_id)s does not exist') % locals() + raise exc.HTTPNotFound(explanation=msg) + + try: return {id: data['metadata'][id]} - else: - return faults.Fault(exc.HTTPNotFound()) + except KeyError: + msg = _("metadata item %s was not found" % (id)) + raise exc.HTTPNotFound(explanation=msg) def delete(self, req, server_id, id): """ Deletes an existing metadata """ context = req.environ['nova.context'] - self._check_server_exists(context, server_id) - self.compute_api.delete_instance_metadata(context, server_id, id) + try: + self.compute_api.delete_instance_metadata(context, server_id, id) + except exception.InstanceNotFound: + msg = _('Server %(server_id)s does not exist') % locals() + raise exc.HTTPNotFound(explanation=msg) def _handle_quota_error(self, error): """Reraise quota errors as api-specific http exceptions.""" -- cgit