diff options
| author | Brian Lamar <brian.lamar@rackspace.com> | 2011-07-29 18:05:31 -0400 |
|---|---|---|
| committer | Brian Lamar <brian.lamar@rackspace.com> | 2011-07-29 18:05:31 -0400 |
| commit | 055a422643fc229ec0e7db3f6dcba9904c5a4f5d (patch) | |
| tree | 78323d01a529ef81049932e44cd11b0b83045726 | |
| parent | 7ac10c361af9bb52202abfacd75825496283774f (diff) | |
| download | nova-055a422643fc229ec0e7db3f6dcba9904c5a4f5d.tar.gz nova-055a422643fc229ec0e7db3f6dcba9904c5a4f5d.tar.xz nova-055a422643fc229ec0e7db3f6dcba9904c5a4f5d.zip | |
Created exceptions for accepting in OSAPI, and handled them appropriately.
| -rw-r--r-- | nova/api/openstack/servers.py | 40 | ||||
| -rw-r--r-- | nova/compute/api.py | 9 | ||||
| -rw-r--r-- | nova/exception.py | 12 |
3 files changed, 35 insertions, 26 deletions
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index 30169d450..e62e4e4f8 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -405,6 +405,24 @@ class Controller(object): error=item.error)) return dict(actions=actions) + def resize(self, req, instance_id, flavor_id): + """Begin the resize process with given instance/flavor.""" + context = req.environ["nova.context"] + + try: + self.compute_api.resize(context, instance_id, flavor_id) + except exception.FlavorDoesNotExist: + msg = _("Unable to locate requested flavor.") + raise exc.HTTPBadRequest(explanation=msg) + except exception.CannotResizeToSameSize: + msg = _("Resize requires a change in size.") + raise exc.HTTPBadRequest(explanation=msg) + except exception.CannotResizeToSmallerSize: + msg = _("Resizing to a smaller size is not supported.") + raise exc.HTTPBadRequest(explanation=msg) + + return webob.Response(status_int=202) + class ControllerV10(Controller): @@ -444,16 +462,7 @@ class ControllerV10(Controller): msg = _("Resize requests require 'flavorId' attribute.") raise exc.HTTPBadRequest(explanation=msg) - try: - i_type = instance_types.get_instance_type_by_flavor_id(flavor_id) - except exception.FlavorNotFound: - msg = _("Unable to locate requested flavor.") - raise exc.HTTPBadRequest(explanation=msg) - - context = req.environ["nova.context"] - self.compute_api.resize(context, id, i_type["id"]) - - return webob.Response(status_int=202) + return Controller.resize(self, req, id, flavor_id) def _action_rebuild(self, info, request, instance_id): context = request.environ['nova.context'] @@ -568,16 +577,7 @@ class ControllerV11(Controller): msg = _("Resize requests require 'flavorRef' attribute.") raise exc.HTTPBadRequest(explanation=msg) - try: - i_type = instance_types.get_instance_type_by_flavor_id(flavor_ref) - except exception.FlavorNotFound: - msg = _("Unable to locate requested flavor.") - raise exc.HTTPBadRequest(explanation=msg) - - context = req.environ["nova.context"] - self.compute_api.resize(context, id, i_type["id"]) - - return webob.Response(status_int=202) + return Controller.resize(self, req, id, flavor_ref) def _action_rebuild(self, info, request, instance_id): context = request.environ['nova.context'] diff --git a/nova/compute/api.py b/nova/compute/api.py index 8f7b3c3ef..9e4841e64 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -940,18 +940,15 @@ class API(base.Base): LOG.debug(_("Old instance type %(current_instance_type_name)s, " " new instance type %(new_instance_type_name)s") % locals()) if not new_instance_type: - raise exception.ApiError(_("Requested flavor %(flavor_id)d " - "does not exist") % locals()) + raise exception.FlavorDoesNotExist(flavor_id=flavor_id) current_memory_mb = current_instance_type['memory_mb'] new_memory_mb = new_instance_type['memory_mb'] if current_memory_mb > new_memory_mb: - raise exception.ApiError(_("Invalid flavor: cannot downsize" - "instances")) + raise exception.CannotResizeToSmallerSize() if (current_memory_mb == new_memory_mb) and flavor_id: - raise exception.ApiError(_("Invalid flavor: cannot use" - "the same flavor. ")) + raise exception.CannotResizeToSameSize() instance_ref = self._get_instance(context, instance_id, 'resize') self._cast_scheduler_message(context, diff --git a/nova/exception.py b/nova/exception.py index 8c9b45a80..b6455db9f 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -692,3 +692,15 @@ class PasteConfigNotFound(NotFound): class PasteAppNotFound(NotFound): message = _("Could not load paste app '%(name)s' from %(path)s") + + +class CannotResizeToSameSize(NovaException): + message = _("When resizing, instances must change size!") + + +class CannotResizeToSmallerSize(NovaException): + message = _("Resizing to a smaller size is not supported.") + + +class FlavorDoesNotExist(NovaException): + message = _("Requested flavor '%(flavor_id)s' does not exist.") |
