From 655eb8fbd21376e694f8134e42f10ddbc1aafb0e Mon Sep 17 00:00:00 2001 From: John Tran Date: Wed, 6 Apr 2011 18:22:03 -0700 Subject: ec2 api run_instances checks for image status must be 'available'. Overhauled test_run_instances for working set of test assertions --- nova/api/ec2/cloud.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 58effd134..0ea0e3603 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -814,10 +814,18 @@ class CloudController(object): if kwargs.get('ramdisk_id'): ramdisk = self._get_image(context, kwargs['ramdisk_id']) kwargs['ramdisk_id'] = ramdisk['id'] + image = self._get_image(context, kwargs['image_id']) + if not image: + raise exception.NotFound(_('Image %s not found') % + kwargs['image_id']) + if not 'properties' in image or \ + (not 'image_state' in image['properties']) or \ + (image['properties']['image_state'] is not 'available'): + raise exception.ApiError(_('Image must be available')) instances = self.compute_api.create(context, instance_type=instance_types.get_by_type( kwargs.get('instance_type', None)), - image_id=self._get_image(context, kwargs['image_id'])['id'], + image_id = image['id'], min_count=int(kwargs.get('min_count', max_count)), max_count=max_count, kernel_id=kwargs.get('kernel_id'), -- cgit From 10db492376a8bb8409e3fb3c33707865ac0f3ee7 Mon Sep 17 00:00:00 2001 From: John Tran Date: Mon, 2 May 2011 14:25:21 -0700 Subject: implemented review suggestion EAFP style, and fixed test stub fake_show needs to have image_state = available or other tests will fail --- nova/api/ec2/cloud.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'nova/api') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 0ea0e3603..5dc608139 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -815,17 +815,21 @@ class CloudController(object): ramdisk = self._get_image(context, kwargs['ramdisk_id']) kwargs['ramdisk_id'] = ramdisk['id'] image = self._get_image(context, kwargs['image_id']) - if not image: + if not image: raise exception.NotFound(_('Image %s not found') % kwargs['image_id']) - if not 'properties' in image or \ - (not 'image_state' in image['properties']) or \ - (image['properties']['image_state'] is not 'available'): + try: + available = (image['properties']['image_state'] == 'available') + except KeyError: + available = False + + if not available: raise exception.ApiError(_('Image must be available')) + instances = self.compute_api.create(context, instance_type=instance_types.get_by_type( kwargs.get('instance_type', None)), - image_id = image['id'], + image_id=image['id'], min_count=int(kwargs.get('min_count', max_count)), max_count=max_count, kernel_id=kwargs.get('kernel_id'), -- cgit From 0a3da155228228d3f0eeac1efdea1e29eef2f3a0 Mon Sep 17 00:00:00 2001 From: John Tran Date: Thu, 12 May 2011 12:04:39 -0700 Subject: changed NotFound exception to ImageNotFound --- nova/api/ec2/cloud.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'nova/api') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 8a54d23f2..ad8c3fe90 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -823,8 +823,7 @@ class CloudController(object): kwargs['ramdisk_id'] = ramdisk['id'] image = self._get_image(context, kwargs['image_id']) if not image: - raise exception.NotFound(_('Image %s not found') % - kwargs['image_id']) + raise exception.ImageNotFound(kwargs['image_id']) try: available = (image['properties']['image_state'] == 'available') except KeyError: -- cgit From a0cffc4de8ba4b15958e320308477d42287858e7 Mon Sep 17 00:00:00 2001 From: John Tran Date: Tue, 24 May 2011 09:43:52 -0700 Subject: specified image_id keyword in exception arg --- 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 59e00781e..80c61d62b 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -848,7 +848,7 @@ class CloudController(object): kwargs['ramdisk_id'] = ramdisk['id'] image = self._get_image(context, kwargs['image_id']) if not image: - raise exception.ImageNotFound(kwargs['image_id']) + raise exception.ImageNotFound(image_id=kwargs['image_id']) try: available = (image['properties']['image_state'] == 'available') except KeyError: -- cgit From f3d7ec3fd2b2b987ae1118a6ae96874e8bbfdac5 Mon Sep 17 00:00:00 2001 From: William Wolf Date: Tue, 24 May 2011 15:16:07 -0400 Subject: initial use of limited_by_marker --- nova/api/openstack/images.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'nova/api') diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 34d4c27fc..b06429943 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -153,3 +153,25 @@ class ControllerV11(Controller): def get_default_xmlns(self, req): return common.XML_NS_V11 + + def index(self, req): + """Return an index listing of images available to the request. + + :param req: `wsgi.Request` object + """ + context = req.environ['nova.context'] + images = self._image_service.index(context) + images = common.limited_by_marker(images, req) + builder = self.get_builder(req).build + return dict(images=[builder(image, detail=False) for image in images]) + + def detail(self, req): + """Return a detailed index listing of images available to the request. + + :param req: `wsgi.Request` object. + """ + context = req.environ['nova.context'] + images = self._image_service.detail(context) + images = common.limited_by_marker(images, req) + builder = self.get_builder(req).build + return dict(images=[builder(image, detail=True) for image in images]) -- cgit From 0b9ede226674b253f638b78cdce5fa40b2991701 Mon Sep 17 00:00:00 2001 From: William Wolf Date: Wed, 25 May 2011 11:21:46 -0400 Subject: simplified the limiting differences for different versions of the API --- nova/api/openstack/images.py | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index b06429943..c96b1c3e3 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -53,6 +53,9 @@ class Controller(common.OpenstackController): self._compute_service = compute_service or compute.API() self._image_service = image_service or _default_service + def _limit_items(self, items, req): + return common.limited(items, req) + def index(self, req): """Return an index listing of images available to the request. @@ -60,7 +63,7 @@ class Controller(common.OpenstackController): """ context = req.environ['nova.context'] images = self._image_service.index(context) - images = common.limited(images, req) + images = self._limit_items(images, req) builder = self.get_builder(req).build return dict(images=[builder(image, detail=False) for image in images]) @@ -71,7 +74,7 @@ class Controller(common.OpenstackController): """ context = req.environ['nova.context'] images = self._image_service.detail(context) - images = common.limited(images, req) + images = self._limited_items(images, req) builder = self.get_builder(req).build return dict(images=[builder(image, detail=True) for image in images]) @@ -154,24 +157,5 @@ class ControllerV11(Controller): def get_default_xmlns(self, req): return common.XML_NS_V11 - def index(self, req): - """Return an index listing of images available to the request. - - :param req: `wsgi.Request` object - """ - context = req.environ['nova.context'] - images = self._image_service.index(context) - images = common.limited_by_marker(images, req) - builder = self.get_builder(req).build - return dict(images=[builder(image, detail=False) for image in images]) - - def detail(self, req): - """Return a detailed index listing of images available to the request. - - :param req: `wsgi.Request` object. - """ - context = req.environ['nova.context'] - images = self._image_service.detail(context) - images = common.limited_by_marker(images, req) - builder = self.get_builder(req).build - return dict(images=[builder(image, detail=True) for image in images]) + def _limit_items(self, items, req): + return common.limited_by_marker(items, req) -- cgit From 1eee07811f9fb5fd29192b17610a6b2d2e6c3578 Mon Sep 17 00:00:00 2001 From: William Wolf Date: Tue, 31 May 2011 13:34:33 -0400 Subject: added get_pagination_params function in common with tests, allow fake and local image services to accept filters, markers, and limits (but ignore them for now) --- nova/api/openstack/common.py | 31 +++++++++++++++++++++++++++++++ nova/api/openstack/images.py | 25 ++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 3 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 32cd689ca..69877cbce 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -36,6 +36,37 @@ XML_NS_V10 = 'http://docs.rackspacecloud.com/servers/api/v1.0' XML_NS_V11 = 'http://docs.openstack.org/compute/api/v1.1' +def get_pagination_params(request): + """ + Return marker, limit tuple from request + + @param request: `wsgi.Request` possibly containing 'marker' and 'limit' + GET variables. 'marker' is the id of the last element + the client has seen, and 'limit' is the maximum number + of items to return. If 'limit' is not specified, 0, or + > max_limit, we default to max_limit. Negative values + for either marker or limit will cause + exc.HTTPBadRequest() exceptions to be raised. + """ + try: + marker = int(request.GET.get('marker', 0)) + except ValueError: + raise webob.exc.HTTPBadRequest(_('offset param must be an integer')) + + try: + limit = int(request.GET.get('limit', 0)) + except ValueError: + raise webob.exc.HTTPBadRequest(_('limit param must be an integer')) + + if limit < 0: + raise webob.exc.HTTPBadRequest(_('limit param must be positive')) + + if marker < 0: + raise webob.exc.HTTPBadRequest(_('marker param must be positive')) + + return(marker, limit) + + def limited(items, request, max_limit=FLAGS.osapi_max_limit): """ Return a slice of items according to requested offset and limit. diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index c96b1c3e3..afe0f79de 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -74,7 +74,7 @@ class Controller(common.OpenstackController): """ context = req.environ['nova.context'] images = self._image_service.detail(context) - images = self._limited_items(images, req) + images = self._limit_items(images, req) builder = self.get_builder(req).build return dict(images=[builder(image, detail=True) for image in images]) @@ -157,5 +157,24 @@ class ControllerV11(Controller): def get_default_xmlns(self, req): return common.XML_NS_V11 - def _limit_items(self, items, req): - return common.limited_by_marker(items, req) + def index(self, req): + """Return an index listing of images available to the request. + + :param req: `wsgi.Request` object + """ + context = req.environ['nova.context'] + (marker, limit) = common.get_pagination_params(req) + images = self._image_service.index(context, marker, limit) + builder = self.get_builder(req).build + return dict(images=[builder(image, detail=False) for image in images]) + + def detail(self, req): + """Return a detailed index listing of images available to the request. + + :param req: `wsgi.Request` object. + """ + context = req.environ['nova.context'] + (marker, limit) = common.get_pagination_params(req) + images = self._image_service.detail(context, marker, limit) + builder = self.get_builder(req).build + return dict(images=[builder(image, detail=True) for image in images]) -- cgit From b8f2f8d63608d76af41fd218dddb955bdc656354 Mon Sep 17 00:00:00 2001 From: William Wolf Date: Wed, 1 Jun 2011 10:00:15 -0400 Subject: fix filtering tests --- nova/api/openstack/images.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 20e6f38ce..8afd38a4f 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -181,8 +181,10 @@ class ControllerV11(Controller): :param req: `wsgi.Request` object """ context = req.environ['nova.context'] + filters = self._get_filters(req) (marker, limit) = common.get_pagination_params(req) - images = self._image_service.index(context, marker, limit) + images = self._image_service.index( + context, filters=filters, marker=marker, limit=limit) builder = self.get_builder(req).build return dict(images=[builder(image, detail=False) for image in images]) @@ -192,7 +194,9 @@ class ControllerV11(Controller): :param req: `wsgi.Request` object. """ context = req.environ['nova.context'] + filters = self._get_filters(req) (marker, limit) = common.get_pagination_params(req) - images = self._image_service.detail(context, marker, limit) + images = self._image_service.detail( + context, filters=filters, marker=marker, limit=limit) builder = self.get_builder(req).build return dict(images=[builder(image, detail=True) for image in images]) -- cgit From 3fa4ece45eea12f0923c55d87130c668bafd2751 Mon Sep 17 00:00:00 2001 From: William Wolf Date: Wed, 1 Jun 2011 10:31:53 -0400 Subject: fix pep8 issues --- nova/api/openstack/common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 69877cbce..b0d368dfa 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -39,13 +39,13 @@ XML_NS_V11 = 'http://docs.openstack.org/compute/api/v1.1' def get_pagination_params(request): """ Return marker, limit tuple from request - + @param request: `wsgi.Request` possibly containing 'marker' and 'limit' GET variables. 'marker' is the id of the last element the client has seen, and 'limit' is the maximum number of items to return. If 'limit' is not specified, 0, or > max_limit, we default to max_limit. Negative values - for either marker or limit will cause + for either marker or limit will cause exc.HTTPBadRequest() exceptions to be raised. """ try: -- cgit From 4fb46873ef4332c6570d3ac5559557745056dee6 Mon Sep 17 00:00:00 2001 From: William Wolf Date: Wed, 1 Jun 2011 23:09:37 -0400 Subject: cleanup based on waldon's comments, also caught a few other issues --- nova/api/openstack/common.py | 18 +++++------------- nova/api/openstack/images.py | 8 ++------ nova/api/openstack/servers.py | 1 + 3 files changed, 8 insertions(+), 19 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 342cc8b2e..c9e3dbb64 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -50,7 +50,7 @@ def get_pagination_params(request): try: marker = int(request.GET.get('marker', 0)) except ValueError: - raise webob.exc.HTTPBadRequest(_('offset param must be an integer')) + raise webob.exc.HTTPBadRequest(_('marker param must be an integer')) try: limit = int(request.GET.get('limit', 0)) @@ -102,19 +102,11 @@ def limited(items, request, max_limit=FLAGS.osapi_max_limit): def limited_by_marker(items, request, max_limit=FLAGS.osapi_max_limit): """Return a slice of items according to the requested marker and limit.""" + print "TEST LIMIT" + (marker, limit) = get_pagination_params(request) - try: - marker = int(request.GET.get('marker', 0)) - except ValueError: - raise webob.exc.HTTPBadRequest(_('marker param must be an integer')) - - try: - limit = int(request.GET.get('limit', max_limit)) - except ValueError: - raise webob.exc.HTTPBadRequest(_('limit param must be an integer')) - - if limit < 0: - raise webob.exc.HTTPBadRequest(_('limit param must be positive')) + if limit == 0: + limit = max_limit limit = min(max_limit, limit) start_index = 0 diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index dcedd3db2..4ef9a5974 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -46,9 +46,6 @@ class Controller(object): self._compute_service = compute_service or compute.API() self._image_service = image_service or _default_service - def _limit_items(self, items, req): - return common.limited(items, req) - def index(self, req): """Return an index listing of images available to the request. @@ -162,13 +159,11 @@ class ControllerV11(Controller): base_url = request.application_url return images_view.ViewBuilderV11(base_url) - def get_default_xmlns(self, req): - return common.XML_NS_V11 - def index(self, req): """Return an index listing of images available to the request. :param req: `wsgi.Request` object + """ context = req.environ['nova.context'] filters = self._get_filters(req) @@ -182,6 +177,7 @@ class ControllerV11(Controller): """Return a detailed index listing of images available to the request. :param req: `wsgi.Request` object. + """ context = req.environ['nova.context'] filters = self._get_filters(req) diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index f2ce64e78..ad556ca84 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -55,6 +55,7 @@ class Controller(object): def detail(self, req): """ Returns a list of server details for a given user """ + print "DETAIL" return self._items(req, is_detail=True) def _image_id_from_req_data(self, data): -- cgit From 5ded1f2c1d0d14b3c04df137f7cc6a0b65e53fda Mon Sep 17 00:00:00 2001 From: William Wolf Date: Wed, 1 Jun 2011 23:11:50 -0400 Subject: got rid of print debugs --- nova/api/openstack/common.py | 1 - nova/api/openstack/servers.py | 1 - 2 files changed, 2 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index c9e3dbb64..559b44ef5 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -102,7 +102,6 @@ def limited(items, request, max_limit=FLAGS.osapi_max_limit): def limited_by_marker(items, request, max_limit=FLAGS.osapi_max_limit): """Return a slice of items according to the requested marker and limit.""" - print "TEST LIMIT" (marker, limit) = get_pagination_params(request) if limit == 0: diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index ad556ca84..f2ce64e78 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -55,7 +55,6 @@ class Controller(object): def detail(self, req): """ Returns a list of server details for a given user """ - print "DETAIL" return self._items(req, is_detail=True) def _image_id_from_req_data(self, data): -- cgit From e28a6e96ec45439ed24a363f27d0421d720add0b Mon Sep 17 00:00:00 2001 From: William Wolf Date: Thu, 2 Jun 2011 09:34:01 -0400 Subject: move index and detail functions to v10 controller --- nova/api/openstack/images.py | 48 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 4ef9a5974..7f06c53df 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -46,30 +46,6 @@ class Controller(object): self._compute_service = compute_service or compute.API() self._image_service = image_service or _default_service - def index(self, req): - """Return an index listing of images available to the request. - - :param req: `wsgi.Request` object - """ - context = req.environ['nova.context'] - filters = self._get_filters(req) - images = self._image_service.index(context, filters) - images = common.limited(images, req) - builder = self.get_builder(req).build - return dict(images=[builder(image, detail=False) for image in images]) - - def detail(self, req): - """Return a detailed index listing of images available to the request. - - :param req: `wsgi.Request` object. - """ - context = req.environ['nova.context'] - filters = self._get_filters(req) - images = self._image_service.detail(context, filters) - images = common.limited(images, req) - builder = self.get_builder(req).build - return dict(images=[builder(image, detail=True) for image in images]) - def _get_filters(self, req): """ Return a dictionary of query param filters from the request @@ -150,6 +126,30 @@ class ControllerV10(Controller): base_url = request.application_url return images_view.ViewBuilderV10(base_url) + def index(self, req): + """Return an index listing of images available to the request. + + :param req: `wsgi.Request` object + """ + context = req.environ['nova.context'] + filters = self._get_filters(req) + images = self._image_service.index(context, filters) + images = common.limited(images, req) + builder = self.get_builder(req).build + return dict(images=[builder(image, detail=False) for image in images]) + + def detail(self, req): + """Return a detailed index listing of images available to the request. + + :param req: `wsgi.Request` object. + """ + context = req.environ['nova.context'] + filters = self._get_filters(req) + images = self._image_service.detail(context, filters) + images = common.limited(images, req) + builder = self.get_builder(req).build + return dict(images=[builder(image, detail=True) for image in images]) + class ControllerV11(Controller): """Version 1.1 specific controller logic.""" -- cgit From 7ca707c1cbfb3164d4b6f706a4e9720e54bcc35f Mon Sep 17 00:00:00 2001 From: Brian Lamar Date: Thu, 2 Jun 2011 12:02:16 -0400 Subject: Minor comment formatting changes. --- nova/api/openstack/common.py | 6 +++--- nova/api/openstack/images.py | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 559b44ef5..40fb59765 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -36,16 +36,16 @@ XML_NS_V11 = 'http://docs.openstack.org/compute/api/v1.1' def get_pagination_params(request): - """ - Return marker, limit tuple from request + """Return marker, limit tuple from request. - @param request: `wsgi.Request` possibly containing 'marker' and 'limit' + :param request: `wsgi.Request` possibly containing 'marker' and 'limit' GET variables. 'marker' is the id of the last element the client has seen, and 'limit' is the maximum number of items to return. If 'limit' is not specified, 0, or > max_limit, we default to max_limit. Negative values for either marker or limit will cause exc.HTTPBadRequest() exceptions to be raised. + """ try: marker = int(request.GET.get('marker', 0)) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 7f06c53df..73249b485 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -130,6 +130,7 @@ class ControllerV10(Controller): """Return an index listing of images available to the request. :param req: `wsgi.Request` object + """ context = req.environ['nova.context'] filters = self._get_filters(req) @@ -142,6 +143,7 @@ class ControllerV10(Controller): """Return a detailed index listing of images available to the request. :param req: `wsgi.Request` object. + """ context = req.environ['nova.context'] filters = self._get_filters(req) -- cgit From 8739529368cb755d33c3d8c532dd1c5d86f0bf85 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Fri, 3 Jun 2011 08:50:30 -0400 Subject: Implement OSAPI v1.1 style image create. --- nova/api/openstack/images.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 59d9e3082..48ea04248 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -123,7 +123,7 @@ class Controller(object): raise webob.exc.HTTPBadRequest() try: - server_id = body["image"]["serverId"] + server_id = self._server_id_from_req_data(body) image_name = body["image"]["name"] except KeyError: raise webob.exc.HTTPBadRequest() @@ -135,6 +135,9 @@ class Controller(object): """Indicates that you must use a Controller subclass.""" raise NotImplementedError + def _server_id_from_req_data(self, data): + raise NotImplementedError() + class ControllerV10(Controller): """Version 1.0 specific controller logic.""" @@ -144,6 +147,9 @@ class ControllerV10(Controller): base_url = request.application_url return images_view.ViewBuilderV10(base_url) + def _server_id_from_req_data(self, data): + return data['image']['serverId'] + class ControllerV11(Controller): """Version 1.1 specific controller logic.""" @@ -153,6 +159,9 @@ class ControllerV11(Controller): base_url = request.application_url return images_view.ViewBuilderV11(base_url) + def _server_id_from_req_data(self, data): + return data['image']['serverRef'] + def create_resource(version='1.0'): controller = { -- cgit From 0ef4a127e9539f90ac1d2f2846832ecc48b51e05 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Fri, 3 Jun 2011 09:31:43 -0400 Subject: Add serverRef to image metadata serialization list. --- nova/api/openstack/images.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 48ea04248..1fa3267dc 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -177,7 +177,7 @@ def create_resource(version='1.0'): metadata = { "attributes": { "image": ["id", "name", "updated", "created", "status", - "serverId", "progress"], + "serverId", "progress", "serverRef"], "link": ["rel", "type", "href"], }, } -- cgit From 24a90512f20310007f4ca8ab01da8e19a6b5bf6f Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Fri, 3 Jun 2011 11:28:49 -0400 Subject: Removed unused and erroneous (yes, it was both) function --- nova/api/ec2/admin.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'nova/api') diff --git a/nova/api/ec2/admin.py b/nova/api/ec2/admin.py index ea94d9c1f..4d981f70b 100644 --- a/nova/api/ec2/admin.py +++ b/nova/api/ec2/admin.py @@ -325,7 +325,3 @@ class AdminController(object): rv.append(host_dict(host, compute, instances, volume, volumes, now)) return {'hosts': rv} - - def describe_host(self, _context, name, **_kwargs): - """Returns status info for single node.""" - return host_dict(db.host_get(name)) -- cgit From ec5e5bcd3592dca44d1d71455ccd99e2c7f24d26 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Mon, 6 Jun 2011 10:49:29 -0400 Subject: Small pylint fixes --- nova/api/openstack/extensions.py | 6 ++++-- nova/api/openstack/views/limits.py | 9 --------- 2 files changed, 4 insertions(+), 11 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/extensions.py b/nova/api/openstack/extensions.py index 881b61733..9dad2f48d 100644 --- a/nova/api/openstack/extensions.py +++ b/nova/api/openstack/extensions.py @@ -137,7 +137,8 @@ class ActionExtensionResource(wsgi.Resource): def __init__(self, application): controller = ActionExtensionController(application) - super(ActionExtensionResource, self).__init__(controller) + #super(ActionExtensionResource, self).__init__(controller) + wsgi.Resource.__init__(self, controller) def add_action(self, action_name, handler): self.controller.add_action(action_name, handler) @@ -164,7 +165,8 @@ class RequestExtensionResource(wsgi.Resource): def __init__(self, application): controller = RequestExtensionController(application) - super(RequestExtensionResource, self).__init__(controller) + #super(RequestExtensionResource, self).__init__(controller) + wsgi.Resource.__init__(self, controller) def add_handler(self, handler): self.controller.add_handler(handler) diff --git a/nova/api/openstack/views/limits.py b/nova/api/openstack/views/limits.py index e21c9f2fd..934b4921a 100644 --- a/nova/api/openstack/views/limits.py +++ b/nova/api/openstack/views/limits.py @@ -29,9 +29,6 @@ class ViewBuilder(object): def _build_rate_limit(self, rate_limit): raise NotImplementedError() - def _build_absolute_limits(self, absolute_limit): - raise NotImplementedError() - def build(self, rate_limits, absolute_limits): rate_limits = self._build_rate_limits(rate_limits) absolute_limits = self._build_absolute_limits(absolute_limits) @@ -67,12 +64,6 @@ class ViewBuilder(object): limits[name] = value return limits - def _build_rate_limits(self, rate_limits): - raise NotImplementedError() - - def _build_rate_limit(self, rate_limit): - raise NotImplementedError() - class ViewBuilderV10(ViewBuilder): """Openstack API v1.0 limits view builder.""" -- cgit From 3d481e551ac81a35cafcd79c2b17d2bd9c8a050f Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Mon, 6 Jun 2011 11:39:34 -0400 Subject: Ignore complaining about dynamic definition --- nova/api/direct.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/direct.py b/nova/api/direct.py index ea20042a7..ea7425e19 100644 --- a/nova/api/direct.py +++ b/nova/api/direct.py @@ -324,7 +324,7 @@ class Limited(object): def __init__(self, proxy): self._proxy = proxy - if not self.__doc__: + if not self.__doc__: #pylint: disable=E0203 self.__doc__ = proxy.__doc__ if not self._allowed: self._allowed = [] -- cgit From 57df676a3302f8d754ef54e415d2fd82a4291f49 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Mon, 6 Jun 2011 15:59:39 -0400 Subject: Removed commented code --- nova/api/openstack/extensions.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/extensions.py b/nova/api/openstack/extensions.py index 9dad2f48d..54e17e23d 100644 --- a/nova/api/openstack/extensions.py +++ b/nova/api/openstack/extensions.py @@ -137,7 +137,6 @@ class ActionExtensionResource(wsgi.Resource): def __init__(self, application): controller = ActionExtensionController(application) - #super(ActionExtensionResource, self).__init__(controller) wsgi.Resource.__init__(self, controller) def add_action(self, action_name, handler): @@ -165,7 +164,6 @@ class RequestExtensionResource(wsgi.Resource): def __init__(self, application): controller = RequestExtensionController(application) - #super(RequestExtensionResource, self).__init__(controller) wsgi.Resource.__init__(self, controller) def add_handler(self, handler): -- cgit From e8d6740fefcac3734021edaf53a40ecb145ccaa3 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Tue, 7 Jun 2011 13:47:40 -0400 Subject: DRY up the image_state logic. Fix an issue where glance style images (which aren't required to have an 'image_state' property) couldn't be used to run instances on the EC2 controller. --- nova/api/ec2/cloud.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'nova/api') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index ac73cd595..316298c39 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -136,6 +136,13 @@ class CloudController(object): return services[0]['availability_zone'] return 'unknown zone' + def _get_image_state(self, image): + # NOTE(vish): fallback status if image_state isn't set + state = image.get('status') + if state == 'active': + state = 'available' + return image['properties'].get('image_state', state) + def get_metadata(self, address): ctxt = context.get_admin_context() instance_ref = self.compute_api.get_all(ctxt, fixed_ip=address) @@ -896,14 +903,13 @@ class CloudController(object): ramdisk = self._get_image(context, kwargs['ramdisk_id']) kwargs['ramdisk_id'] = ramdisk['id'] image = self._get_image(context, kwargs['image_id']) - if not image: + + if image: + image_state = self._get_image_state(image) + else: raise exception.ImageNotFound(image_id=kwargs['image_id']) - try: - available = (image['properties']['image_state'] == 'available') - except KeyError: - available = False - if not available: + if image_state != 'available': raise exception.ApiError(_('Image must be available')) instances = self.compute_api.create(context, @@ -1021,11 +1027,8 @@ class CloudController(object): get('image_location'), name) else: i['imageLocation'] = image['properties'].get('image_location') - # NOTE(vish): fallback status if image_state isn't set - state = image.get('status') - if state == 'active': - state = 'available' - i['imageState'] = image['properties'].get('image_state', state) + + i['imageState'] = self._get_image_state(image) i['displayName'] = name i['description'] = image.get('description') display_mapping = {'aki': 'kernel', -- cgit From 641f16a5343ca5d95ea10ec5031a27a7f131c337 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Tue, 7 Jun 2011 15:17:34 -0400 Subject: pep8 --- nova/api/direct.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/direct.py b/nova/api/direct.py index ea7425e19..ec79151b1 100644 --- a/nova/api/direct.py +++ b/nova/api/direct.py @@ -324,7 +324,7 @@ class Limited(object): def __init__(self, proxy): self._proxy = proxy - if not self.__doc__: #pylint: disable=E0203 + if not self.__doc__: # pylint: disable=E0203 self.__doc__ = proxy.__doc__ if not self._allowed: self._allowed = [] -- cgit