summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorSandy Walsh <sandy.walsh@rackspace.com>2011-01-25 13:34:50 -0600
committerSandy Walsh <sandy.walsh@rackspace.com>2011-01-25 13:34:50 -0600
commita6052241ec7bce94b81e8d4fa1d43353e4eec51b (patch)
treead4a2dc6a1495bf546d2095ff9f975714ba81421 /nova/api
parent5ff189808d45582f0799c14eaaec687a3cf8ad5e (diff)
parentb2d0a77c53d1bd108d233e58f68655381cec4e16 (diff)
downloadnova-a6052241ec7bce94b81e8d4fa1d43353e4eec51b.tar.gz
nova-a6052241ec7bce94b81e8d4fa1d43353e4eec51b.tar.xz
nova-a6052241ec7bce94b81e8d4fa1d43353e4eec51b.zip
merge with trunk
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/direct.py12
-rw-r--r--nova/api/ec2/__init__.py20
-rw-r--r--nova/api/ec2/admin.py39
-rw-r--r--nova/api/ec2/apirequest.py6
-rw-r--r--nova/api/ec2/cloud.py26
-rw-r--r--nova/api/openstack/servers.py6
6 files changed, 66 insertions, 43 deletions
diff --git a/nova/api/direct.py b/nova/api/direct.py
index 81b3ae202..208b6d086 100644
--- a/nova/api/direct.py
+++ b/nova/api/direct.py
@@ -142,9 +142,15 @@ class Reflection(object):
if argspec[2]:
args_out.insert(0, ('**%s' % argspec[2],))
+ if f.__doc__:
+ short_doc = f.__doc__.split('\n')[0]
+ doc = f.__doc__
+ else:
+ short_doc = doc = _('not available')
+
methods['/%s/%s' % (route, k)] = {
- 'short_doc': f.__doc__.split('\n')[0],
- 'doc': f.__doc__,
+ 'short_doc': short_doc,
+ 'doc': doc,
'name': k,
'args': list(reversed(args_out))}
@@ -196,6 +202,8 @@ class ServiceWrapper(wsgi.Controller):
# TODO(termie): do some basic normalization on methods
method = getattr(self.service_handle, action)
+ # NOTE(vish): make sure we have no unicode keys for py2.6.
+ params = dict([(str(k), v) for (k, v) in params.iteritems()])
result = method(context, **params)
if type(result) is dict or type(result) is list:
return self._serialize(result, req)
diff --git a/nova/api/ec2/__init__.py b/nova/api/ec2/__init__.py
index 238cb0f38..9938b23f8 100644
--- a/nova/api/ec2/__init__.py
+++ b/nova/api/ec2/__init__.py
@@ -131,9 +131,11 @@ class Lockout(wsgi.Middleware):
# NOTE(vish): To use incr, failures has to be a string.
self.mc.set(failures_key, '1', time=FLAGS.lockout_window * 60)
elif failures >= FLAGS.lockout_attempts:
- LOG.warn(_('Access key %s has had %d failed authentications'
- ' and will be locked out for %d minutes.'),
- access_key, failures, FLAGS.lockout_minutes)
+ lock_mins = FLAGS.lockout_minutes
+ msg = _('Access key %(access_key)s has had %(failures)d'
+ ' failed authentications and will be locked out'
+ ' for %(lock_mins)d minutes.') % locals()
+ LOG.warn(msg)
self.mc.set(failures_key, str(failures),
time=FLAGS.lockout_minutes * 60)
return res
@@ -179,8 +181,10 @@ class Authenticate(wsgi.Middleware):
project=project,
remote_address=remote_address)
req.environ['ec2.context'] = ctxt
- LOG.audit(_('Authenticated Request For %s:%s)'), user.name,
- project.name, context=req.environ['ec2.context'])
+ uname = user.name
+ pname = project.name
+ msg = _('Authenticated Request For %(uname)s:%(pname)s)') % locals()
+ LOG.audit(msg, context=req.environ['ec2.context'])
return self.application
@@ -206,7 +210,7 @@ class Requestify(wsgi.Middleware):
LOG.debug(_('action: %s'), action)
for key, value in args.items():
- LOG.debug(_('arg: %s\t\tval: %s'), key, value)
+ LOG.debug(_('arg: %(key)s\t\tval: %(value)s') % locals())
# Success!
api_request = apirequest.APIRequest(self.controller, action, args)
@@ -277,8 +281,8 @@ class Authorizer(wsgi.Middleware):
if self._matches_any_role(context, allowed_roles):
return self.application
else:
- LOG.audit(_("Unauthorized request for controller=%s "
- "and action=%s"), controller, action, context=context)
+ LOG.audit(_('Unauthorized request for controller=%(controller)s '
+ 'and action=%(action)s') % locals(), context=context)
raise webob.exc.HTTPUnauthorized()
def _matches_any_role(self, context, roles):
diff --git a/nova/api/ec2/admin.py b/nova/api/ec2/admin.py
index 758b612e8..78ff1b3e0 100644
--- a/nova/api/ec2/admin.py
+++ b/nova/api/ec2/admin.py
@@ -111,19 +111,23 @@ class AdminController(object):
"""Add or remove a role for a user and project."""
if operation == 'add':
if project:
- LOG.audit(_("Adding role %s to user %s for project %s"), role,
- user, project, context=context)
+ msg = _("Adding role %(role)s to user %(user)s"
+ " for project %(project)s") % locals()
+ LOG.audit(msg, context=context)
else:
- LOG.audit(_("Adding sitewide role %s to user %s"), role, user,
- context=context)
+ msg = _("Adding sitewide role %(role)s to"
+ " user %(user)s") % locals()
+ LOG.audit(msg, context=context)
manager.AuthManager().add_role(user, role, project)
elif operation == 'remove':
if project:
- LOG.audit(_("Removing role %s from user %s for project %s"),
- role, user, project, context=context)
+ msg = _("Removing role %(role)s from user %(user)s"
+ " for project %(project)s") % locals()
+ LOG.audit(msg, context=context)
else:
- LOG.audit(_("Removing sitewide role %s from user %s"), role,
- user, context=context)
+ msg = _("Removing sitewide role %(role)s"
+ " from user %(user)s") % locals()
+ LOG.audit(msg, context=context)
manager.AuthManager().remove_role(user, role, project)
else:
raise exception.ApiError(_('operation must be add or remove'))
@@ -139,8 +143,9 @@ class AdminController(object):
project = name
project = manager.AuthManager().get_project(project)
user = manager.AuthManager().get_user(name)
- LOG.audit(_("Getting x509 for user: %s on project: %s"), name,
- project, context=context)
+ msg = _("Getting x509 for user: %(name)s"
+ " on project: %(project)s") % locals()
+ LOG.audit(msg, context=context)
return user_dict(user, base64.b64encode(project.get_credentials(user)))
def describe_project(self, context, name, **kwargs):
@@ -156,8 +161,9 @@ class AdminController(object):
def register_project(self, context, name, manager_user, description=None,
member_users=None, **kwargs):
"""Creates a new project"""
- LOG.audit(_("Create project %s managed by %s"), name, manager_user,
- context=context)
+ msg = _("Create project %(name)s managed by"
+ " %(manager_user)s") % locals()
+ LOG.audit(msg, context=context)
return project_dict(
manager.AuthManager().create_project(
name,
@@ -181,12 +187,13 @@ class AdminController(object):
**kwargs):
"""Add or remove a user from a project."""
if operation == 'add':
- LOG.audit(_("Adding user %s to project %s"), user, project,
- context=context)
+ msg = _("Adding user %(user)s to project %(project)s") % locals()
+ LOG.audit(msg, context=context)
manager.AuthManager().add_to_project(user, project)
elif operation == 'remove':
- LOG.audit(_("Removing user %s from project %s"), user, project,
- context=context)
+ msg = _("Removing user %(user)s from"
+ " project %(project)s") % locals()
+ LOG.audit(msg, context=context)
manager.AuthManager().remove_from_project(user, project)
else:
raise exception.ApiError(_('operation must be add or remove'))
diff --git a/nova/api/ec2/apirequest.py b/nova/api/ec2/apirequest.py
index 78576470a..d8a2b5f53 100644
--- a/nova/api/ec2/apirequest.py
+++ b/nova/api/ec2/apirequest.py
@@ -93,8 +93,10 @@ class APIRequest(object):
method = getattr(self.controller,
_camelcase_to_underscore(self.action))
except AttributeError:
- _error = _('Unsupported API request: controller = %s,'
- 'action = %s') % (self.controller, self.action)
+ controller = self.controller
+ action = self.action
+ _error = _('Unsupported API request: controller = %(controller)s,'
+ ' action = %(action)s') % locals()
LOG.exception(_error)
# TODO: Raise custom exception, trap in apiserver,
# and reraise as 400 error.
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py
index c94540793..3b228bf1a 100644
--- a/nova/api/ec2/cloud.py
+++ b/nova/api/ec2/cloud.py
@@ -59,7 +59,7 @@ def _gen_key(context, user_id, key_name):
# creation before creating key_pair
try:
db.key_pair_get(context, user_id, key_name)
- raise exception.Duplicate("The key_pair %s already exists"
+ raise exception.Duplicate(_("The key_pair %s already exists")
% key_name)
except exception.NotFound:
pass
@@ -133,7 +133,7 @@ class CloudController(object):
return result
def _get_availability_zone_by_host(self, context, host):
- services = db.service_get_all_by_host(context, host)
+ services = db.service_get_all_by_host(context.elevated(), host)
if len(services) > 0:
return services[0]['availability_zone']
return 'unknown zone'
@@ -252,18 +252,18 @@ class CloudController(object):
regions = []
for region in FLAGS.region_list:
name, _sep, host = region.partition('=')
- endpoint = '%s://%s:%s%s' % (FLAGS.ec2_prefix,
+ endpoint = '%s://%s:%s%s' % (FLAGS.ec2_scheme,
host,
FLAGS.ec2_port,
- FLAGS.ec2_suffix)
+ FLAGS.ec2_path)
regions.append({'regionName': name,
'regionEndpoint': endpoint})
else:
regions = [{'regionName': 'nova',
- 'regionEndpoint': '%s://%s:%s%s' % (FLAGS.ec2_prefix,
+ 'regionEndpoint': '%s://%s:%s%s' % (FLAGS.ec2_scheme,
FLAGS.ec2_host,
FLAGS.ec2_port,
- FLAGS.ec2_suffix)}]
+ FLAGS.ec2_path)}]
return {'regionInfo': regions}
def describe_snapshots(self,
@@ -601,8 +601,9 @@ class CloudController(object):
def attach_volume(self, context, volume_id, instance_id, device, **kwargs):
volume_id = ec2_id_to_id(volume_id)
instance_id = ec2_id_to_id(instance_id)
- LOG.audit(_("Attach volume %s to instance %s at %s"), volume_id,
- instance_id, device, context=context)
+ msg = _("Attach volume %(volume_id)s to instance %(instance_id)s"
+ " at %(device)s") % locals()
+ LOG.audit(msg, context=context)
self.compute_api.attach_volume(context,
instance_id=instance_id,
volume_id=volume_id,
@@ -751,8 +752,8 @@ class CloudController(object):
return {'releaseResponse': ["Address released."]}
def associate_address(self, context, instance_id, public_ip, **kwargs):
- LOG.audit(_("Associate address %s to instance %s"), public_ip,
- instance_id, context=context)
+ LOG.audit(_("Associate address %(public_ip)s to"
+ " instance %(instance_id)s") % locals(), context=context)
instance_id = ec2_id_to_id(instance_id)
self.compute_api.associate_floating_ip(context,
instance_id=instance_id,
@@ -840,8 +841,9 @@ class CloudController(object):
if image_location is None and 'name' in kwargs:
image_location = kwargs['name']
image_id = self.image_service.register(context, image_location)
- LOG.audit(_("Registered image %s with id %s"), image_location,
- image_id, context=context)
+ msg = _("Registered image %(image_location)s with"
+ " id %(image_id)s") % locals()
+ LOG.audit(msg, context=context)
return {'imageId': image_id}
def describe_image_attribute(self, context, image_id, attribute, **kwargs):
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py
index 54af09a5d..32249b80e 100644
--- a/nova/api/openstack/servers.py
+++ b/nova/api/openstack/servers.py
@@ -133,9 +133,9 @@ class Controller(wsgi.Controller):
if image_id in mapping:
return mapping[image_id]
- raise exception.NotFound(
- _("No entry for image '%s' in mapping file '%s'") %
- (image_id, mapping_filename))
+ msg = _("No entry for image '%(image_id)s'"
+ " in mapping file '%(mapping_filename)s'") % locals()
+ raise exception.NotFound(msg)
def create(self, req):
""" Creates a new server for a given user """