From 5ff189808d45582f0799c14eaaec687a3cf8ad5e Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Mon, 17 Jan 2011 16:47:19 -0800 Subject: openstack api fixes for glance --- nova/api/openstack/common.py | 7 ++++++- nova/api/openstack/servers.py | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 037ed47a0..3b93d961e 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -38,6 +38,11 @@ def limited(items, req): return items[offset:range_end] +def get_image_id_or_id(image): + """Some image services return image_id, others id""" + return image.get('imageId', image.get('id', None)) + + def get_image_id_from_image_hash(image_service, context, image_hash): """Given an Image ID Hash, return an objectstore Image ID. @@ -54,7 +59,7 @@ def get_image_id_from_image_hash(image_service, context, image_hash): except NotImplementedError: items = image_service.index(context) for image in items: - image_id = image['imageId'] + image_id = get_image_id_or_id(image) if abs(hash(image_id)) == int(image_hash): return image_id raise exception.NotFound(image_hash) diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index 8cbcebed2..54af09a5d 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -127,6 +127,7 @@ class Controller(wsgi.Controller): def _get_kernel_ramdisk_from_image(self, image_id): mapping_filename = FLAGS.os_krm_mapping_file + image_id = str(image_id) with open(mapping_filename) as f: mapping = json.load(f) if image_id in mapping: -- cgit From edceeb76885a246191315c6a6c76a7e4e89511e5 Mon Sep 17 00:00:00 2001 From: Tushar Patil Date: Thu, 20 Jan 2011 16:47:46 -0800 Subject: Fix for LP Bug #699654 --- nova/api/ec2/__init__.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'nova/api') diff --git a/nova/api/ec2/__init__.py b/nova/api/ec2/__init__.py index 238cb0f38..f251c8d41 100644 --- a/nova/api/ec2/__init__.py +++ b/nova/api/ec2/__init__.py @@ -168,7 +168,7 @@ class Authenticate(wsgi.Middleware): req.path) # Be explicit for what exceptions are 403, the rest bubble as 500 except (exception.NotFound, exception.NotAuthorized) as ex: - LOG.audit(_("Authentication Failure: %s"), str(ex)) + LOG.error(_("Authentication Failure: %s"), ex.args[0]) raise webob.exc.HTTPForbidden() # Authenticated! @@ -310,17 +310,17 @@ class Executor(wsgi.Application): try: result = api_request.invoke(context) except exception.NotFound as ex: - LOG.info(_('NotFound raised: %s'), str(ex), context=context) - return self._error(req, context, type(ex).__name__, str(ex)) + LOG.info(_('NotFound raised: %s'), ex.args[0], context=context) + return self._error(req, context, type(ex).__name__, ex.args[0]) except exception.ApiError as ex: - LOG.exception(_('ApiError raised: %s'), str(ex), context=context) + LOG.exception(_('ApiError raised: %s'), ex.args[0], context=context) if ex.code: - return self._error(req, context, ex.code, str(ex)) + return self._error(req, context, ex.code, ex.args[0]) else: - return self._error(req, context, type(ex).__name__, str(ex)) + return self._error(req, context, type(ex).__name__, ex.args[0]) except Exception as ex: extra = {'environment': req.environ} - LOG.exception(_('Unexpected error raised: %s'), str(ex), + LOG.exception(_('Unexpected error raised: %s'), ex.args[0], extra=extra, context=context) return self._error(req, context, @@ -343,7 +343,8 @@ class Executor(wsgi.Application): '%s' '%s' '%s' % - (code, message, context.request_id)) + (utils.utf8(code), utils.utf8(message), + utils.utf8(context.request_id))) return resp -- cgit From 14f01f5daeca8cac9d669c584348712c2e893bc1 Mon Sep 17 00:00:00 2001 From: Tushar Patil Date: Thu, 20 Jan 2011 17:29:17 -0800 Subject: Reverted log type from error to audit --- nova/api/ec2/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/ec2/__init__.py b/nova/api/ec2/__init__.py index f251c8d41..3656bb44b 100644 --- a/nova/api/ec2/__init__.py +++ b/nova/api/ec2/__init__.py @@ -168,7 +168,7 @@ class Authenticate(wsgi.Middleware): req.path) # Be explicit for what exceptions are 403, the rest bubble as 500 except (exception.NotFound, exception.NotAuthorized) as ex: - LOG.error(_("Authentication Failure: %s"), ex.args[0]) + LOG.audit(_("Authentication Failure: %s"), ex.args[0]) raise webob.exc.HTTPForbidden() # Authenticated! -- cgit From 842bd9646ad0e9008af86da9153fdf592788b3c3 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Fri, 21 Jan 2011 14:51:24 -0800 Subject: Wrap instance at api layer to print the proper error. Use same logic for volumes. --- nova/api/ec2/cloud.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'nova/api') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index c94540793..766727b56 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -529,11 +529,18 @@ class CloudController(object): def describe_volumes(self, context, volume_id=None, **kwargs): if volume_id: - volume_id = [ec2_id_to_id(x) for x in volume_id] - volumes = self.volume_api.get_all(context) - # NOTE(vish): volume_id is an optional list of volume ids to filter by. - volumes = [self._format_volume(context, v) for v in volumes - if volume_id is None or v['id'] in volume_id] + volumes = [] + for ec2_id in volume_id: + internal_id = ec2_id_to_id(ec2_id) + try: + volume = self.volume_api.get(context, internal_id) + volumes.append(volume) + except exception.NotFound: + raise exception.NotFound("Volume %s could not be found" + % ec2_id) + else: + volumes = self.volume_api.get_all(context) + volumes = [self._format_volume(context, v) for v in volumes] return {'volumeSet': volumes} def _format_volume(self, context, volume): @@ -657,8 +664,15 @@ class CloudController(object): reservations = {} # NOTE(vish): instance_id is an optional list of ids to filter by if instance_id: - instance_id = [ec2_id_to_id(x) for x in instance_id] - instances = [self.compute_api.get(context, x) for x in instance_id] + instances = [] + for ec2_id in instance_id: + internal_id = ec2_id_to_id(ec2_id) + try: + instance = self.compute_api.get(context, internal_id) + instances.append(instance) + except exception.NotFound: + raise exception.NotFound("Instance %s could not be found" + % ec2_id) else: instances = self.compute_api.get_all(context, **kwargs) for instance in instances: -- cgit From 60f992b7fa1d1abf494cc210f7f199414a0538bb Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Fri, 21 Jan 2011 16:03:51 -0800 Subject: i18n! --- nova/api/ec2/cloud.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nova/api') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 766727b56..60e47fb87 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -536,7 +536,7 @@ class CloudController(object): volume = self.volume_api.get(context, internal_id) volumes.append(volume) except exception.NotFound: - raise exception.NotFound("Volume %s could not be found" + raise exception.NotFound(_("Volume %s not found") % ec2_id) else: volumes = self.volume_api.get_all(context) @@ -671,7 +671,7 @@ class CloudController(object): instance = self.compute_api.get(context, internal_id) instances.append(instance) except exception.NotFound: - raise exception.NotFound("Instance %s could not be found" + raise exception.NotFound(_("Instance %s not found") % ec2_id) else: instances = self.compute_api.get_all(context, **kwargs) -- cgit From a9ab2d0f0618f855686cb8713b28c3737faabdcc Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Sat, 22 Jan 2011 21:20:09 +0000 Subject: Use Glance to relate machine image with kernel and ramdisk --- nova/api/openstack/__init__.py | 3 --- nova/api/openstack/servers.py | 28 +++++++++++++++++----------- 2 files changed, 17 insertions(+), 14 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/__init__.py b/nova/api/openstack/__init__.py index f2caac483..c70bb39ed 100644 --- a/nova/api/openstack/__init__.py +++ b/nova/api/openstack/__init__.py @@ -38,9 +38,6 @@ from nova.api.openstack import shared_ip_groups LOG = logging.getLogger('nova.api.openstack') FLAGS = flags.FLAGS -flags.DEFINE_string('os_krm_mapping_file', - 'krm_mapping.json', - 'Location of OpenStack Flavor/OS:EC2 Kernel/Ramdisk/Machine JSON file.') flags.DEFINE_bool('allow_admin_api', False, 'When True, this API service will accept admin operations.') diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index 8cbcebed2..9d308ea24 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -124,17 +124,22 @@ class Controller(wsgi.Controller): return faults.Fault(exc.HTTPNotFound()) return exc.HTTPAccepted() - def _get_kernel_ramdisk_from_image(self, image_id): - mapping_filename = FLAGS.os_krm_mapping_file - - with open(mapping_filename) as f: - mapping = json.load(f) - if image_id in mapping: - return mapping[image_id] + def _get_kernel_ramdisk_from_image(self, req, image_id): + """ + Machine images are associated with Kernels and Ramdisk images via + metadata stored in Glance as 'image_properties' + """ + def lookup(param): + _image_id = image_id + try: + return image['properties'][param] + except KeyError: + raise exception.NotFound( + _("%(param)s property not found for image %(_image_id)s") % + locals()) - raise exception.NotFound( - _("No entry for image '%s' in mapping file '%s'") % - (image_id, mapping_filename)) + image = self._image_service.show(req.environ['nova.context'], image_id) + return lookup('kernel_id'), lookup('ramdisk_id') def create(self, req): """ Creates a new server for a given user """ @@ -146,7 +151,8 @@ class Controller(wsgi.Controller): req.environ['nova.context'])[0] image_id = common.get_image_id_from_image_hash(self._image_service, req.environ['nova.context'], env['server']['imageId']) - kernel_id, ramdisk_id = self._get_kernel_ramdisk_from_image(image_id) + kernel_id, ramdisk_id = self._get_kernel_ramdisk_from_image( + req, image_id) instances = self.compute_api.create( req.environ['nova.context'], instance_types.get_by_flavor_id(env['server']['flavorId']), -- cgit From 50d845e717b3e9ceb650fb5058d44ed4fc1507ca Mon Sep 17 00:00:00 2001 From: Tushar Patil Date: Tue, 25 Jan 2011 12:50:54 -0800 Subject: Fixed pep8 errors --- nova/api/ec2/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/ec2/__init__.py b/nova/api/ec2/__init__.py index 3656bb44b..bb060ec8b 100644 --- a/nova/api/ec2/__init__.py +++ b/nova/api/ec2/__init__.py @@ -344,7 +344,7 @@ class Executor(wsgi.Application): '%s' '%s' % (utils.utf8(code), utils.utf8(message), - utils.utf8(context.request_id))) + utils.utf8(context.request_id))) return resp -- cgit From 0167151518dcfa714ecd8dab55f2378de5edf51f Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Tue, 25 Jan 2011 15:06:05 -0600 Subject: moved imageId change to s3 client --- nova/api/openstack/common.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 3b93d961e..01d620aed 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -38,11 +38,6 @@ def limited(items, req): return items[offset:range_end] -def get_image_id_or_id(image): - """Some image services return image_id, others id""" - return image.get('imageId', image.get('id', None)) - - def get_image_id_from_image_hash(image_service, context, image_hash): """Given an Image ID Hash, return an objectstore Image ID. @@ -59,7 +54,6 @@ def get_image_id_from_image_hash(image_service, context, image_hash): except NotImplementedError: items = image_service.index(context) for image in items: - image_id = get_image_id_or_id(image) - if abs(hash(image_id)) == int(image_hash): + if abs(hash(image['id'])) == int(image_hash): return image_id raise exception.NotFound(image_hash) -- cgit From 078914a7b6b517cb2929b5f3e27e5a327447e801 Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Tue, 25 Jan 2011 16:38:29 -0600 Subject: Fixed up a little image_id return --- nova/api/openstack/common.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 01d620aed..6d2fa16e8 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -54,6 +54,7 @@ def get_image_id_from_image_hash(image_service, context, image_hash): except NotImplementedError: items = image_service.index(context) for image in items: - if abs(hash(image['id'])) == int(image_hash): + image_id = image['id'] + if abs(hash(image_id)) == int(image_hash): return image_id raise exception.NotFound(image_hash) -- cgit From 7f04601100c06140445705ee74418907d9b27c0f Mon Sep 17 00:00:00 2001 From: Tushar Patil Date: Tue, 25 Jan 2011 14:50:04 -0800 Subject: Limit all lines to a maximum of 79 characters --- nova/api/ec2/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/ec2/__init__.py b/nova/api/ec2/__init__.py index bb060ec8b..f661493b1 100644 --- a/nova/api/ec2/__init__.py +++ b/nova/api/ec2/__init__.py @@ -313,7 +313,8 @@ class Executor(wsgi.Application): LOG.info(_('NotFound raised: %s'), ex.args[0], context=context) return self._error(req, context, type(ex).__name__, ex.args[0]) except exception.ApiError as ex: - LOG.exception(_('ApiError raised: %s'), ex.args[0], context=context) + LOG.exception(_('ApiError raised: %s'), ex.args[0], + context=context) if ex.code: return self._error(req, context, ex.code, ex.args[0]) else: -- cgit From ccb5e573f7a3f85a2b591d3a1fb968003e321b28 Mon Sep 17 00:00:00 2001 From: Tushar Patil Date: Tue, 25 Jan 2011 15:53:43 -0800 Subject: Fixed pep8 errors --- nova/api/ec2/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/ec2/__init__.py b/nova/api/ec2/__init__.py index f661493b1..79f5af897 100644 --- a/nova/api/ec2/__init__.py +++ b/nova/api/ec2/__init__.py @@ -313,7 +313,7 @@ class Executor(wsgi.Application): LOG.info(_('NotFound raised: %s'), ex.args[0], context=context) return self._error(req, context, type(ex).__name__, ex.args[0]) except exception.ApiError as ex: - LOG.exception(_('ApiError raised: %s'), ex.args[0], + LOG.exception(_('ApiError raised: %s'), ex.args[0], context=context) if ex.code: return self._error(req, context, ex.code, ex.args[0]) -- cgit From 687886beeb7519e79b792ff6c42eaab75e664336 Mon Sep 17 00:00:00 2001 From: Todd Willey Date: Tue, 25 Jan 2011 16:40:23 -0800 Subject: Add DescribeInstanceTypes to admin api (dashboard uses it). --- nova/api/ec2/admin.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'nova/api') diff --git a/nova/api/ec2/admin.py b/nova/api/ec2/admin.py index 78ff1b3e0..d7e899d12 100644 --- a/nova/api/ec2/admin.py +++ b/nova/api/ec2/admin.py @@ -26,6 +26,7 @@ from nova import db from nova import exception from nova import log as logging from nova.auth import manager +from nova.compute import instance_types LOG = logging.getLogger('nova.api.ec2.admin') @@ -62,6 +63,14 @@ def host_dict(host): return {} +def instance_dict(name, inst): + return {'name': name, + 'memory_mb': inst['memory_mb'], + 'vcpus': inst['vcpus'], + 'disk_gb': inst['local_gb'], + 'flavor_id': inst['flavorid']} + + class AdminController(object): """ API Controller for users, hosts, nodes, and workers. @@ -70,6 +79,10 @@ class AdminController(object): def __str__(self): return 'AdminController' + def describe_instance_types(self, _context, **_kwargs): + return {'instanceTypeSet': [instance_dict(n, v) for n, v in + instance_types.INSTANCE_TYPES.iteritems()]} + def describe_user(self, _context, name, **_kwargs): """Returns user data, including access and secret keys.""" return user_dict(manager.AuthManager().get_user(name)) -- cgit From 8dceebdf9ebce6aa94124504564b395b11c55682 Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Wed, 26 Jan 2011 10:16:16 -0600 Subject: Added missing int to string conversion --- nova/api/openstack/servers.py | 1 + 1 file changed, 1 insertion(+) (limited to 'nova/api') diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index 9d308ea24..17c5519a1 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -138,6 +138,7 @@ class Controller(wsgi.Controller): _("%(param)s property not found for image %(_image_id)s") % locals()) + image_id = str(image_id) image = self._image_service.show(req.environ['nova.context'], image_id) return lookup('kernel_id'), lookup('ramdisk_id') -- cgit From f43e1182a77b68ebb3401f3b7316de4e242eb746 Mon Sep 17 00:00:00 2001 From: Soren Hansen Date: Wed, 26 Jan 2011 23:44:21 +0100 Subject: Make xml namespace match the API version requested. --- nova/api/ec2/__init__.py | 3 ++- nova/api/ec2/apirequest.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'nova/api') diff --git a/nova/api/ec2/__init__.py b/nova/api/ec2/__init__.py index fc9a37908..be9751256 100644 --- a/nova/api/ec2/__init__.py +++ b/nova/api/ec2/__init__.py @@ -213,7 +213,8 @@ class Requestify(wsgi.Middleware): LOG.debug(_('arg: %(key)s\t\tval: %(value)s') % locals()) # Success! - api_request = apirequest.APIRequest(self.controller, action, args) + api_request = apirequest.APIRequest(self.controller, action, + req.params['Version'], args) req.environ['ec2.request'] = api_request req.environ['ec2.action_args'] = args return self.application diff --git a/nova/api/ec2/apirequest.py b/nova/api/ec2/apirequest.py index d8a2b5f53..7e72d67fb 100644 --- a/nova/api/ec2/apirequest.py +++ b/nova/api/ec2/apirequest.py @@ -83,9 +83,10 @@ def _try_convert(value): class APIRequest(object): - def __init__(self, controller, action, args): + def __init__(self, controller, action, version, args): self.controller = controller self.action = action + self.version = version self.args = args def invoke(self, context): @@ -132,7 +133,7 @@ class APIRequest(object): response_el = xml.createElement(self.action + 'Response') response_el.setAttribute('xmlns', - 'http://ec2.amazonaws.com/doc/2009-11-30/') + 'http://ec2.amazonaws.com/doc/%s/' % self.version) request_id_el = xml.createElement('requestId') request_id_el.appendChild(xml.createTextNode(request_id)) response_el.appendChild(request_id_el) -- cgit From 9c35a9a32dc58cb56685292a7ba056f95e715474 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Thu, 27 Jan 2011 10:48:00 -0800 Subject: Fixes NotFound messages in api to show the ec2_id. Added InstanceNotFound and VolumeNotFound errors to store internal id. Removed redundant method instance_get_by_id. Caught exceptions in api layer and fixed messages to use ec2_id. --- nova/api/ec2/__init__.py | 15 ++++++++++++++- nova/api/ec2/cloud.py | 16 ++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) (limited to 'nova/api') diff --git a/nova/api/ec2/__init__.py b/nova/api/ec2/__init__.py index fc9a37908..3329beed9 100644 --- a/nova/api/ec2/__init__.py +++ b/nova/api/ec2/__init__.py @@ -33,6 +33,7 @@ from nova import log as logging from nova import utils from nova import wsgi from nova.api.ec2 import apirequest +from nova.api.ec2 import cloud from nova.auth import manager @@ -313,8 +314,20 @@ class Executor(wsgi.Application): result = None try: result = api_request.invoke(context) + except exception.InstanceNotFound as ex: + LOG.info(_('InstanceNotFound raised: %s'), ex.args[0], + context=context) + ec2_id = cloud.id_to_ec2_id(ex.instance_id) + message = _('Instance %s not found') % ec2_id + return self._error(req, context, type(ex).__name__, message) + except exception.VolumeNotFound as ex: + LOG.info(_('VolumeNotFound raised: %s'), ex.args[0], + context=context) + ec2_id = cloud.id_to_ec2_id(ex.volume_id, 'vol-%08x') + message = _('Volume %s not found') % ec2_id + return self._error(req, context, type(ex).__name__, message) except exception.NotFound as ex: - LOG.info(_('NotFound raised: %s'), ex.args[0], context=context) + LOG.info(_('NotFound raised: %s'), ex.args[0], context=context) return self._error(req, context, type(ex).__name__, ex.args[0]) except exception.ApiError as ex: LOG.exception(_('ApiError raised: %s'), ex.args[0], diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 22b8c19cb..9683e2ebd 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -532,12 +532,8 @@ class CloudController(object): volumes = [] for ec2_id in volume_id: internal_id = ec2_id_to_id(ec2_id) - try: - volume = self.volume_api.get(context, internal_id) - volumes.append(volume) - except exception.NotFound: - raise exception.NotFound(_("Volume %s not found") - % ec2_id) + volume = self.volume_api.get(context, internal_id) + volumes.append(volume) else: volumes = self.volume_api.get_all(context) volumes = [self._format_volume(context, v) for v in volumes] @@ -668,12 +664,8 @@ class CloudController(object): instances = [] for ec2_id in instance_id: internal_id = ec2_id_to_id(ec2_id) - try: - instance = self.compute_api.get(context, internal_id) - instances.append(instance) - except exception.NotFound: - raise exception.NotFound(_("Instance %s not found") - % ec2_id) + instance = self.compute_api.get(context, internal_id) + instances.append(instance) else: instances = self.compute_api.get_all(context, **kwargs) for instance in instances: -- cgit