First round of i18n-ifying strings in Nova
This commit is contained in:
@@ -37,7 +37,6 @@ class DbDriver(object):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Imports the LDAP module"""
|
"""Imports the LDAP module"""
|
||||||
pass
|
pass
|
||||||
db
|
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self
|
return self
|
||||||
@@ -83,7 +82,7 @@ class DbDriver(object):
|
|||||||
user_ref = db.user_create(context.get_admin_context(), values)
|
user_ref = db.user_create(context.get_admin_context(), values)
|
||||||
return self._db_user_to_auth_user(user_ref)
|
return self._db_user_to_auth_user(user_ref)
|
||||||
except exception.Duplicate, e:
|
except exception.Duplicate, e:
|
||||||
raise exception.Duplicate('User %s already exists' % name)
|
raise exception.Duplicate(_('User %s already exists') % name)
|
||||||
|
|
||||||
def _db_user_to_auth_user(self, user_ref):
|
def _db_user_to_auth_user(self, user_ref):
|
||||||
return {'id': user_ref['id'],
|
return {'id': user_ref['id'],
|
||||||
@@ -105,8 +104,9 @@ class DbDriver(object):
|
|||||||
"""Create a project"""
|
"""Create a project"""
|
||||||
manager = db.user_get(context.get_admin_context(), manager_uid)
|
manager = db.user_get(context.get_admin_context(), manager_uid)
|
||||||
if not manager:
|
if not manager:
|
||||||
raise exception.NotFound("Project can't be created because "
|
raise exception.NotFound(_("Project can't be created because "
|
||||||
"manager %s doesn't exist" % manager_uid)
|
"manager %s doesn't exist")
|
||||||
|
% manager_uid)
|
||||||
|
|
||||||
# description is a required attribute
|
# description is a required attribute
|
||||||
if description is None:
|
if description is None:
|
||||||
@@ -133,8 +133,8 @@ class DbDriver(object):
|
|||||||
try:
|
try:
|
||||||
project = db.project_create(context.get_admin_context(), values)
|
project = db.project_create(context.get_admin_context(), values)
|
||||||
except exception.Duplicate:
|
except exception.Duplicate:
|
||||||
raise exception.Duplicate("Project can't be created because "
|
raise exception.Duplicate(_("Project can't be created because "
|
||||||
"project %s already exists" % name)
|
"project %s already exists") % name)
|
||||||
|
|
||||||
for member in members:
|
for member in members:
|
||||||
db.project_add_member(context.get_admin_context(),
|
db.project_add_member(context.get_admin_context(),
|
||||||
@@ -155,8 +155,8 @@ class DbDriver(object):
|
|||||||
if manager_uid:
|
if manager_uid:
|
||||||
manager = db.user_get(context.get_admin_context(), manager_uid)
|
manager = db.user_get(context.get_admin_context(), manager_uid)
|
||||||
if not manager:
|
if not manager:
|
||||||
raise exception.NotFound("Project can't be modified because "
|
raise exception.NotFound(_("Project can't be modified because "
|
||||||
"manager %s doesn't exist" %
|
"manager %s doesn't exist") %
|
||||||
manager_uid)
|
manager_uid)
|
||||||
values['project_manager'] = manager['id']
|
values['project_manager'] = manager['id']
|
||||||
if description:
|
if description:
|
||||||
@@ -243,8 +243,8 @@ class DbDriver(object):
|
|||||||
def _validate_user_and_project(self, user_id, project_id):
|
def _validate_user_and_project(self, user_id, project_id):
|
||||||
user = db.user_get(context.get_admin_context(), user_id)
|
user = db.user_get(context.get_admin_context(), user_id)
|
||||||
if not user:
|
if not user:
|
||||||
raise exception.NotFound('User "%s" not found' % user_id)
|
raise exception.NotFound(_('User "%s" not found') % user_id)
|
||||||
project = db.project_get(context.get_admin_context(), project_id)
|
project = db.project_get(context.get_admin_context(), project_id)
|
||||||
if not project:
|
if not project:
|
||||||
raise exception.NotFound('Project "%s" not found' % project_id)
|
raise exception.NotFound(_('Project "%s" not found') % project_id)
|
||||||
return user, project
|
return user, project
|
||||||
|
@@ -39,7 +39,7 @@ flags.DEFINE_integer('redis_db', 0, 'Multiple DB keeps tests away')
|
|||||||
class Redis(object):
|
class Redis(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
if hasattr(self.__class__, '_instance'):
|
if hasattr(self.__class__, '_instance'):
|
||||||
raise Exception('Attempted to instantiate singleton')
|
raise Exception(_('Attempted to instantiate singleton'))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def instance(cls):
|
def instance(cls):
|
||||||
|
@@ -159,7 +159,7 @@ class LdapDriver(object):
|
|||||||
self.conn.modify_s(self.__uid_to_dn(name), attr)
|
self.conn.modify_s(self.__uid_to_dn(name), attr)
|
||||||
return self.get_user(name)
|
return self.get_user(name)
|
||||||
else:
|
else:
|
||||||
raise exception.NotFound("LDAP object for %s doesn't exist"
|
raise exception.NotFound(_("LDAP object for %s doesn't exist")
|
||||||
% name)
|
% name)
|
||||||
else:
|
else:
|
||||||
attr = [
|
attr = [
|
||||||
@@ -182,11 +182,12 @@ class LdapDriver(object):
|
|||||||
description=None, member_uids=None):
|
description=None, member_uids=None):
|
||||||
"""Create a project"""
|
"""Create a project"""
|
||||||
if self.__project_exists(name):
|
if self.__project_exists(name):
|
||||||
raise exception.Duplicate("Project can't be created because "
|
raise exception.Duplicate(_("Project can't be created because "
|
||||||
"project %s already exists" % name)
|
"project %s already exists") % name)
|
||||||
if not self.__user_exists(manager_uid):
|
if not self.__user_exists(manager_uid):
|
||||||
raise exception.NotFound("Project can't be created because "
|
raise exception.NotFound(_("Project can't be created because "
|
||||||
"manager %s doesn't exist" % manager_uid)
|
"manager %s doesn't exist")
|
||||||
|
% manager_uid)
|
||||||
manager_dn = self.__uid_to_dn(manager_uid)
|
manager_dn = self.__uid_to_dn(manager_uid)
|
||||||
# description is a required attribute
|
# description is a required attribute
|
||||||
if description is None:
|
if description is None:
|
||||||
@@ -195,8 +196,8 @@ class LdapDriver(object):
|
|||||||
if member_uids is not None:
|
if member_uids is not None:
|
||||||
for member_uid in member_uids:
|
for member_uid in member_uids:
|
||||||
if not self.__user_exists(member_uid):
|
if not self.__user_exists(member_uid):
|
||||||
raise exception.NotFound("Project can't be created "
|
raise exception.NotFound(_("Project can't be created "
|
||||||
"because user %s doesn't exist"
|
"because user %s doesn't exist")
|
||||||
% member_uid)
|
% member_uid)
|
||||||
members.append(self.__uid_to_dn(member_uid))
|
members.append(self.__uid_to_dn(member_uid))
|
||||||
# always add the manager as a member because members is required
|
# always add the manager as a member because members is required
|
||||||
@@ -218,9 +219,9 @@ class LdapDriver(object):
|
|||||||
attr = []
|
attr = []
|
||||||
if manager_uid:
|
if manager_uid:
|
||||||
if not self.__user_exists(manager_uid):
|
if not self.__user_exists(manager_uid):
|
||||||
raise exception.NotFound("Project can't be modified because "
|
raise exception.NotFound(_("Project can't be modified because "
|
||||||
"manager %s doesn't exist" %
|
"manager %s doesn't exist")
|
||||||
manager_uid)
|
% manager_uid)
|
||||||
manager_dn = self.__uid_to_dn(manager_uid)
|
manager_dn = self.__uid_to_dn(manager_uid)
|
||||||
attr.append((self.ldap.MOD_REPLACE, 'projectManager', manager_dn))
|
attr.append((self.ldap.MOD_REPLACE, 'projectManager', manager_dn))
|
||||||
if description:
|
if description:
|
||||||
@@ -416,8 +417,9 @@ class LdapDriver(object):
|
|||||||
if member_uids is not None:
|
if member_uids is not None:
|
||||||
for member_uid in member_uids:
|
for member_uid in member_uids:
|
||||||
if not self.__user_exists(member_uid):
|
if not self.__user_exists(member_uid):
|
||||||
raise exception.NotFound("Group can't be created "
|
raise exception.NotFound(_("Group can't be created "
|
||||||
"because user %s doesn't exist" % member_uid)
|
"because user %s doesn't exist")
|
||||||
|
% member_uid)
|
||||||
members.append(self.__uid_to_dn(member_uid))
|
members.append(self.__uid_to_dn(member_uid))
|
||||||
dn = self.__uid_to_dn(uid)
|
dn = self.__uid_to_dn(uid)
|
||||||
if not dn in members:
|
if not dn in members:
|
||||||
@@ -432,8 +434,9 @@ class LdapDriver(object):
|
|||||||
def __is_in_group(self, uid, group_dn):
|
def __is_in_group(self, uid, group_dn):
|
||||||
"""Check if user is in group"""
|
"""Check if user is in group"""
|
||||||
if not self.__user_exists(uid):
|
if not self.__user_exists(uid):
|
||||||
raise exception.NotFound("User %s can't be searched in group "
|
raise exception.NotFound(_("User %s can't be searched in group "
|
||||||
"becuase the user doesn't exist" % (uid,))
|
"because the user doesn't exist")
|
||||||
|
% uid)
|
||||||
if not self.__group_exists(group_dn):
|
if not self.__group_exists(group_dn):
|
||||||
return False
|
return False
|
||||||
res = self.__find_object(group_dn,
|
res = self.__find_object(group_dn,
|
||||||
@@ -444,28 +447,30 @@ class LdapDriver(object):
|
|||||||
def __add_to_group(self, uid, group_dn):
|
def __add_to_group(self, uid, group_dn):
|
||||||
"""Add user to group"""
|
"""Add user to group"""
|
||||||
if not self.__user_exists(uid):
|
if not self.__user_exists(uid):
|
||||||
raise exception.NotFound("User %s can't be added to the group "
|
raise exception.NotFound(_("User %s can't be added to the group "
|
||||||
"becuase the user doesn't exist" % (uid,))
|
"because the user doesn't exist")
|
||||||
|
% uid)
|
||||||
if not self.__group_exists(group_dn):
|
if not self.__group_exists(group_dn):
|
||||||
raise exception.NotFound("The group at dn %s doesn't exist" %
|
raise exception.NotFound(_("The group at dn %s doesn't exist")
|
||||||
(group_dn,))
|
% group_dn)
|
||||||
if self.__is_in_group(uid, group_dn):
|
if self.__is_in_group(uid, group_dn):
|
||||||
raise exception.Duplicate("User %s is already a member of "
|
raise exception.Duplicate(_("User %s is already a member of "
|
||||||
"the group %s" % (uid, group_dn))
|
"the group %s") % (uid, group_dn))
|
||||||
attr = [(self.ldap.MOD_ADD, 'member', self.__uid_to_dn(uid))]
|
attr = [(self.ldap.MOD_ADD, 'member', self.__uid_to_dn(uid))]
|
||||||
self.conn.modify_s(group_dn, attr)
|
self.conn.modify_s(group_dn, attr)
|
||||||
|
|
||||||
def __remove_from_group(self, uid, group_dn):
|
def __remove_from_group(self, uid, group_dn):
|
||||||
"""Remove user from group"""
|
"""Remove user from group"""
|
||||||
if not self.__group_exists(group_dn):
|
if not self.__group_exists(group_dn):
|
||||||
raise exception.NotFound("The group at dn %s doesn't exist" %
|
raise exception.NotFound(_("The group at dn %s doesn't exist")
|
||||||
(group_dn,))
|
% group_dn)
|
||||||
if not self.__user_exists(uid):
|
if not self.__user_exists(uid):
|
||||||
raise exception.NotFound("User %s can't be removed from the "
|
raise exception.NotFound(_("User %s can't be removed from the "
|
||||||
"group because the user doesn't exist" % (uid,))
|
"group because the user doesn't exist")
|
||||||
|
% uid)
|
||||||
if not self.__is_in_group(uid, group_dn):
|
if not self.__is_in_group(uid, group_dn):
|
||||||
raise exception.NotFound("User %s is not a member of the group" %
|
raise exception.NotFound(_("User %s is not a member of the group")
|
||||||
(uid,))
|
% uid)
|
||||||
# NOTE(vish): remove user from group and any sub_groups
|
# NOTE(vish): remove user from group and any sub_groups
|
||||||
sub_dns = self.__find_group_dns_with_member(
|
sub_dns = self.__find_group_dns_with_member(
|
||||||
group_dn, uid)
|
group_dn, uid)
|
||||||
@@ -479,15 +484,16 @@ class LdapDriver(object):
|
|||||||
try:
|
try:
|
||||||
self.conn.modify_s(group_dn, attr)
|
self.conn.modify_s(group_dn, attr)
|
||||||
except self.ldap.OBJECT_CLASS_VIOLATION:
|
except self.ldap.OBJECT_CLASS_VIOLATION:
|
||||||
logging.debug("Attempted to remove the last member of a group. "
|
logging.debug(_("Attempted to remove the last member of a group. "
|
||||||
"Deleting the group at %s instead.", group_dn)
|
"Deleting the group at %s instead."), group_dn)
|
||||||
self.__delete_group(group_dn)
|
self.__delete_group(group_dn)
|
||||||
|
|
||||||
def __remove_from_all(self, uid):
|
def __remove_from_all(self, uid):
|
||||||
"""Remove user from all roles and projects"""
|
"""Remove user from all roles and projects"""
|
||||||
if not self.__user_exists(uid):
|
if not self.__user_exists(uid):
|
||||||
raise exception.NotFound("User %s can't be removed from all "
|
raise exception.NotFound(_("User %s can't be removed from all "
|
||||||
"because the user doesn't exist" % (uid,))
|
"because the user doesn't exist")
|
||||||
|
% uid)
|
||||||
role_dns = self.__find_group_dns_with_member(
|
role_dns = self.__find_group_dns_with_member(
|
||||||
FLAGS.role_project_subtree, uid)
|
FLAGS.role_project_subtree, uid)
|
||||||
for role_dn in role_dns:
|
for role_dn in role_dns:
|
||||||
@@ -500,7 +506,8 @@ class LdapDriver(object):
|
|||||||
def __delete_group(self, group_dn):
|
def __delete_group(self, group_dn):
|
||||||
"""Delete Group"""
|
"""Delete Group"""
|
||||||
if not self.__group_exists(group_dn):
|
if not self.__group_exists(group_dn):
|
||||||
raise exception.NotFound("Group at dn %s doesn't exist" % group_dn)
|
raise exception.NotFound(_("Group at dn %s doesn't exist")
|
||||||
|
% group_dn)
|
||||||
self.conn.delete_s(group_dn)
|
self.conn.delete_s(group_dn)
|
||||||
|
|
||||||
def __delete_roles(self, project_dn):
|
def __delete_roles(self, project_dn):
|
||||||
|
@@ -257,12 +257,12 @@ class AuthManager(object):
|
|||||||
# TODO(vish): check for valid timestamp
|
# TODO(vish): check for valid timestamp
|
||||||
(access_key, _sep, project_id) = access.partition(':')
|
(access_key, _sep, project_id) = access.partition(':')
|
||||||
|
|
||||||
logging.info('Looking up user: %r', access_key)
|
logging.info(_('Looking up user: %r'), access_key)
|
||||||
user = self.get_user_from_access_key(access_key)
|
user = self.get_user_from_access_key(access_key)
|
||||||
logging.info('user: %r', user)
|
logging.info('user: %r', user)
|
||||||
if user == None:
|
if user == None:
|
||||||
raise exception.NotFound('No user found for access key %s' %
|
raise exception.NotFound(_('No user found for access key %s')
|
||||||
access_key)
|
% access_key)
|
||||||
|
|
||||||
# NOTE(vish): if we stop using project name as id we need better
|
# NOTE(vish): if we stop using project name as id we need better
|
||||||
# logic to find a default project for user
|
# logic to find a default project for user
|
||||||
@@ -271,12 +271,12 @@ class AuthManager(object):
|
|||||||
|
|
||||||
project = self.get_project(project_id)
|
project = self.get_project(project_id)
|
||||||
if project == None:
|
if project == None:
|
||||||
raise exception.NotFound('No project called %s could be found' %
|
raise exception.NotFound(_('No project called %s could be found')
|
||||||
project_id)
|
% project_id)
|
||||||
if not self.is_admin(user) and not self.is_project_member(user,
|
if not self.is_admin(user) and not self.is_project_member(user,
|
||||||
project):
|
project):
|
||||||
raise exception.NotFound('User %s is not a member of project %s' %
|
raise exception.NotFound(_('User %s is not a member of project %s')
|
||||||
(user.id, project.id))
|
% (user.id, project.id))
|
||||||
if check_type == 's3':
|
if check_type == 's3':
|
||||||
sign = signer.Signer(user.secret.encode())
|
sign = signer.Signer(user.secret.encode())
|
||||||
expected_signature = sign.s3_authorization(headers, verb, path)
|
expected_signature = sign.s3_authorization(headers, verb, path)
|
||||||
@@ -284,7 +284,7 @@ class AuthManager(object):
|
|||||||
logging.debug('expected_signature: %s', expected_signature)
|
logging.debug('expected_signature: %s', expected_signature)
|
||||||
logging.debug('signature: %s', signature)
|
logging.debug('signature: %s', signature)
|
||||||
if signature != expected_signature:
|
if signature != expected_signature:
|
||||||
raise exception.NotAuthorized('Signature does not match')
|
raise exception.NotAuthorized(_('Signature does not match'))
|
||||||
elif check_type == 'ec2':
|
elif check_type == 'ec2':
|
||||||
# NOTE(vish): hmac can't handle unicode, so encode ensures that
|
# NOTE(vish): hmac can't handle unicode, so encode ensures that
|
||||||
# secret isn't unicode
|
# secret isn't unicode
|
||||||
@@ -294,7 +294,7 @@ class AuthManager(object):
|
|||||||
logging.debug('expected_signature: %s', expected_signature)
|
logging.debug('expected_signature: %s', expected_signature)
|
||||||
logging.debug('signature: %s', signature)
|
logging.debug('signature: %s', signature)
|
||||||
if signature != expected_signature:
|
if signature != expected_signature:
|
||||||
raise exception.NotAuthorized('Signature does not match')
|
raise exception.NotAuthorized(_('Signature does not match'))
|
||||||
return (user, project)
|
return (user, project)
|
||||||
|
|
||||||
def get_access_key(self, user, project):
|
def get_access_key(self, user, project):
|
||||||
@@ -364,7 +364,7 @@ class AuthManager(object):
|
|||||||
with self.driver() as drv:
|
with self.driver() as drv:
|
||||||
if role == 'projectmanager':
|
if role == 'projectmanager':
|
||||||
if not project:
|
if not project:
|
||||||
raise exception.Error("Must specify project")
|
raise exception.Error(_("Must specify project"))
|
||||||
return self.is_project_manager(user, project)
|
return self.is_project_manager(user, project)
|
||||||
|
|
||||||
global_role = drv.has_role(User.safe_id(user),
|
global_role = drv.has_role(User.safe_id(user),
|
||||||
@@ -398,9 +398,9 @@ class AuthManager(object):
|
|||||||
@param project: Project in which to add local role.
|
@param project: Project in which to add local role.
|
||||||
"""
|
"""
|
||||||
if role not in FLAGS.allowed_roles:
|
if role not in FLAGS.allowed_roles:
|
||||||
raise exception.NotFound("The %s role can not be found" % role)
|
raise exception.NotFound(_("The %s role can not be found") % role)
|
||||||
if project is not None and role in FLAGS.global_roles:
|
if project is not None and role in FLAGS.global_roles:
|
||||||
raise exception.NotFound("The %s role is global only" % role)
|
raise exception.NotFound(_("The %s role is global only") % role)
|
||||||
with self.driver() as drv:
|
with self.driver() as drv:
|
||||||
drv.add_role(User.safe_id(user), role, Project.safe_id(project))
|
drv.add_role(User.safe_id(user), role, Project.safe_id(project))
|
||||||
|
|
||||||
@@ -546,7 +546,8 @@ class AuthManager(object):
|
|||||||
Project.safe_id(project))
|
Project.safe_id(project))
|
||||||
|
|
||||||
if not network_ref['vpn_public_port']:
|
if not network_ref['vpn_public_port']:
|
||||||
raise exception.NotFound('project network data has not been set')
|
raise exception.NotFound(_('project network data has not '
|
||||||
|
'been set'))
|
||||||
return (network_ref['vpn_public_address'],
|
return (network_ref['vpn_public_address'],
|
||||||
network_ref['vpn_public_port'])
|
network_ref['vpn_public_port'])
|
||||||
|
|
||||||
@@ -659,8 +660,7 @@ class AuthManager(object):
|
|||||||
port=vpn_port)
|
port=vpn_port)
|
||||||
zippy.writestr(FLAGS.credential_vpn_file, config)
|
zippy.writestr(FLAGS.credential_vpn_file, config)
|
||||||
else:
|
else:
|
||||||
logging.warn("No vpn data for project %s" %
|
logging.warn(_("No vpn data for project %s"), pid)
|
||||||
pid)
|
|
||||||
|
|
||||||
zippy.writestr(FLAGS.ca_file, crypto.fetch_ca(user.id))
|
zippy.writestr(FLAGS.ca_file, crypto.fetch_ca(user.id))
|
||||||
zippy.close()
|
zippy.close()
|
||||||
|
@@ -37,12 +37,12 @@ class Exchange(object):
|
|||||||
self._routes = {}
|
self._routes = {}
|
||||||
|
|
||||||
def publish(self, message, routing_key=None):
|
def publish(self, message, routing_key=None):
|
||||||
logging.debug('(%s) publish (key: %s) %s',
|
logging.debug(_('(%s) publish (key: %s) %s'),
|
||||||
self.name, routing_key, message)
|
self.name, routing_key, message)
|
||||||
routing_key = routing_key.split('.')[0]
|
routing_key = routing_key.split('.')[0]
|
||||||
if routing_key in self._routes:
|
if routing_key in self._routes:
|
||||||
for f in self._routes[routing_key]:
|
for f in self._routes[routing_key]:
|
||||||
logging.debug('Publishing to route %s', f)
|
logging.debug(_('Publishing to route %s'), f)
|
||||||
f(message, routing_key=routing_key)
|
f(message, routing_key=routing_key)
|
||||||
|
|
||||||
def bind(self, callback, routing_key):
|
def bind(self, callback, routing_key):
|
||||||
@@ -82,16 +82,16 @@ class Backend(object):
|
|||||||
|
|
||||||
def queue_declare(self, queue, **kwargs):
|
def queue_declare(self, queue, **kwargs):
|
||||||
if queue not in self._queues:
|
if queue not in self._queues:
|
||||||
logging.debug('Declaring queue %s', queue)
|
logging.debug(_('Declaring queue %s'), queue)
|
||||||
self._queues[queue] = Queue(queue)
|
self._queues[queue] = Queue(queue)
|
||||||
|
|
||||||
def exchange_declare(self, exchange, type, *args, **kwargs):
|
def exchange_declare(self, exchange, type, *args, **kwargs):
|
||||||
if exchange not in self._exchanges:
|
if exchange not in self._exchanges:
|
||||||
logging.debug('Declaring exchange %s', exchange)
|
logging.debug(_('Declaring exchange %s'), exchange)
|
||||||
self._exchanges[exchange] = Exchange(exchange, type)
|
self._exchanges[exchange] = Exchange(exchange, type)
|
||||||
|
|
||||||
def queue_bind(self, queue, exchange, routing_key, **kwargs):
|
def queue_bind(self, queue, exchange, routing_key, **kwargs):
|
||||||
logging.debug('Binding %s to %s with key %s',
|
logging.debug(_('Binding %s to %s with key %s'),
|
||||||
queue, exchange, routing_key)
|
queue, exchange, routing_key)
|
||||||
self._exchanges[exchange].bind(self._queues[queue].push,
|
self._exchanges[exchange].bind(self._queues[queue].push,
|
||||||
routing_key)
|
routing_key)
|
||||||
@@ -117,7 +117,7 @@ class Backend(object):
|
|||||||
content_type=content_type,
|
content_type=content_type,
|
||||||
content_encoding=content_encoding)
|
content_encoding=content_encoding)
|
||||||
message.result = True
|
message.result = True
|
||||||
logging.debug('Getting from %s: %s', queue, message)
|
logging.debug(_('Getting from %s: %s'), queue, message)
|
||||||
return message
|
return message
|
||||||
|
|
||||||
def prepare_message(self, message_data, delivery_mode,
|
def prepare_message(self, message_data, delivery_mode,
|
||||||
|
@@ -131,7 +131,7 @@ def get_process_output(executable, args=None, env=None, path=None,
|
|||||||
cmd = executable
|
cmd = executable
|
||||||
if args:
|
if args:
|
||||||
cmd = " ".join([cmd] + args)
|
cmd = " ".join([cmd] + args)
|
||||||
logging.debug("Running cmd: %s", cmd)
|
logging.debug(_("Running cmd: %s"), cmd)
|
||||||
process_handler = BackRelayWithInput(
|
process_handler = BackRelayWithInput(
|
||||||
deferred,
|
deferred,
|
||||||
cmd,
|
cmd,
|
||||||
|
36
nova/rpc.py
36
nova/rpc.py
@@ -91,15 +91,15 @@ class Consumer(messaging.Consumer):
|
|||||||
self.failed_connection = False
|
self.failed_connection = False
|
||||||
break
|
break
|
||||||
except: # Catching all because carrot sucks
|
except: # Catching all because carrot sucks
|
||||||
logging.exception("AMQP server on %s:%d is unreachable." \
|
logging.exception(_("AMQP server on %s:%d is unreachable."
|
||||||
" Trying again in %d seconds." % (
|
" Trying again in %d seconds.") % (
|
||||||
FLAGS.rabbit_host,
|
FLAGS.rabbit_host,
|
||||||
FLAGS.rabbit_port,
|
FLAGS.rabbit_port,
|
||||||
FLAGS.rabbit_retry_interval))
|
FLAGS.rabbit_retry_interval))
|
||||||
self.failed_connection = True
|
self.failed_connection = True
|
||||||
if self.failed_connection:
|
if self.failed_connection:
|
||||||
logging.exception("Unable to connect to AMQP server" \
|
logging.exception(_("Unable to connect to AMQP server"
|
||||||
" after %d tries. Shutting down." % FLAGS.rabbit_max_retries)
|
" after %d tries. Shutting down.") % FLAGS.rabbit_max_retries)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def fetch(self, no_ack=None, auto_ack=None, enable_callbacks=False):
|
def fetch(self, no_ack=None, auto_ack=None, enable_callbacks=False):
|
||||||
@@ -116,14 +116,14 @@ class Consumer(messaging.Consumer):
|
|||||||
self.declare()
|
self.declare()
|
||||||
super(Consumer, self).fetch(no_ack, auto_ack, enable_callbacks)
|
super(Consumer, self).fetch(no_ack, auto_ack, enable_callbacks)
|
||||||
if self.failed_connection:
|
if self.failed_connection:
|
||||||
logging.error("Reconnected to queue")
|
logging.error(_("Reconnected to queue"))
|
||||||
self.failed_connection = False
|
self.failed_connection = False
|
||||||
# NOTE(vish): This is catching all errors because we really don't
|
# NOTE(vish): This is catching all errors because we really don't
|
||||||
# exceptions to be logged 10 times a second if some
|
# exceptions to be logged 10 times a second if some
|
||||||
# persistent failure occurs.
|
# persistent failure occurs.
|
||||||
except Exception: # pylint: disable-msg=W0703
|
except Exception: # pylint: disable-msg=W0703
|
||||||
if not self.failed_connection:
|
if not self.failed_connection:
|
||||||
logging.exception("Failed to fetch message from queue")
|
logging.exception(_("Failed to fetch message from queue"))
|
||||||
self.failed_connection = True
|
self.failed_connection = True
|
||||||
|
|
||||||
def attach_to_eventlet(self):
|
def attach_to_eventlet(self):
|
||||||
@@ -161,7 +161,7 @@ class TopicConsumer(Consumer):
|
|||||||
class AdapterConsumer(TopicConsumer):
|
class AdapterConsumer(TopicConsumer):
|
||||||
"""Calls methods on a proxy object based on method and args"""
|
"""Calls methods on a proxy object based on method and args"""
|
||||||
def __init__(self, connection=None, topic="broadcast", proxy=None):
|
def __init__(self, connection=None, topic="broadcast", proxy=None):
|
||||||
LOG.debug('Initing the Adapter Consumer for %s' % (topic))
|
LOG.debug(_('Initing the Adapter Consumer for %s') % (topic))
|
||||||
self.proxy = proxy
|
self.proxy = proxy
|
||||||
super(AdapterConsumer, self).__init__(connection=connection,
|
super(AdapterConsumer, self).__init__(connection=connection,
|
||||||
topic=topic)
|
topic=topic)
|
||||||
@@ -176,7 +176,7 @@ class AdapterConsumer(TopicConsumer):
|
|||||||
|
|
||||||
Example: {'method': 'echo', 'args': {'value': 42}}
|
Example: {'method': 'echo', 'args': {'value': 42}}
|
||||||
"""
|
"""
|
||||||
LOG.debug('received %s' % (message_data))
|
LOG.debug(_('received %s') % (message_data))
|
||||||
msg_id = message_data.pop('_msg_id', None)
|
msg_id = message_data.pop('_msg_id', None)
|
||||||
|
|
||||||
ctxt = _unpack_context(message_data)
|
ctxt = _unpack_context(message_data)
|
||||||
@@ -189,8 +189,8 @@ class AdapterConsumer(TopicConsumer):
|
|||||||
# messages stay in the queue indefinitely, so for now
|
# messages stay in the queue indefinitely, so for now
|
||||||
# we just log the message and send an error string
|
# we just log the message and send an error string
|
||||||
# back to the caller
|
# back to the caller
|
||||||
LOG.warn('no method for message: %s' % (message_data))
|
LOG.warn(_('no method for message: %s') % (message_data))
|
||||||
msg_reply(msg_id, 'No method for message: %s' % message_data)
|
msg_reply(msg_id, _('No method for message: %s') % message_data)
|
||||||
return
|
return
|
||||||
|
|
||||||
node_func = getattr(self.proxy, str(method))
|
node_func = getattr(self.proxy, str(method))
|
||||||
@@ -246,7 +246,7 @@ def msg_reply(msg_id, reply=None, failure=None):
|
|||||||
if failure:
|
if failure:
|
||||||
message = failure.getErrorMessage()
|
message = failure.getErrorMessage()
|
||||||
traceback = failure.getTraceback()
|
traceback = failure.getTraceback()
|
||||||
logging.error("Returning exception %s to caller", message)
|
logging.error(_("Returning exception %s to caller"), message)
|
||||||
logging.error(traceback)
|
logging.error(traceback)
|
||||||
failure = (failure.type.__name__, str(failure.value), traceback)
|
failure = (failure.type.__name__, str(failure.value), traceback)
|
||||||
conn = Connection.instance()
|
conn = Connection.instance()
|
||||||
@@ -287,7 +287,7 @@ def _unpack_context(msg):
|
|||||||
if key.startswith('_context_'):
|
if key.startswith('_context_'):
|
||||||
value = msg.pop(key)
|
value = msg.pop(key)
|
||||||
context_dict[key[9:]] = value
|
context_dict[key[9:]] = value
|
||||||
LOG.debug('unpacked context: %s', context_dict)
|
LOG.debug(_('unpacked context: %s'), context_dict)
|
||||||
return context.RequestContext.from_dict(context_dict)
|
return context.RequestContext.from_dict(context_dict)
|
||||||
|
|
||||||
|
|
||||||
@@ -306,10 +306,10 @@ def _pack_context(msg, context):
|
|||||||
|
|
||||||
def call(context, topic, msg):
|
def call(context, topic, msg):
|
||||||
"""Sends a message on a topic and wait for a response"""
|
"""Sends a message on a topic and wait for a response"""
|
||||||
LOG.debug("Making asynchronous call...")
|
LOG.debug(_("Making asynchronous call..."))
|
||||||
msg_id = uuid.uuid4().hex
|
msg_id = uuid.uuid4().hex
|
||||||
msg.update({'_msg_id': msg_id})
|
msg.update({'_msg_id': msg_id})
|
||||||
LOG.debug("MSG_ID is %s" % (msg_id))
|
LOG.debug(_("MSG_ID is %s") % (msg_id))
|
||||||
_pack_context(msg, context)
|
_pack_context(msg, context)
|
||||||
|
|
||||||
class WaitMessage(object):
|
class WaitMessage(object):
|
||||||
@@ -345,7 +345,7 @@ def call_twisted(context, topic, msg):
|
|||||||
LOG.debug("Making asynchronous call...")
|
LOG.debug("Making asynchronous call...")
|
||||||
msg_id = uuid.uuid4().hex
|
msg_id = uuid.uuid4().hex
|
||||||
msg.update({'_msg_id': msg_id})
|
msg.update({'_msg_id': msg_id})
|
||||||
LOG.debug("MSG_ID is %s" % (msg_id))
|
LOG.debug(_("MSG_ID is %s") % (msg_id))
|
||||||
_pack_context(msg, context)
|
_pack_context(msg, context)
|
||||||
|
|
||||||
conn = Connection.instance()
|
conn = Connection.instance()
|
||||||
@@ -384,7 +384,7 @@ def cast(context, topic, msg):
|
|||||||
|
|
||||||
def generic_response(message_data, message):
|
def generic_response(message_data, message):
|
||||||
"""Logs a result and exits"""
|
"""Logs a result and exits"""
|
||||||
LOG.debug('response %s', message_data)
|
LOG.debug(_('response %s'), message_data)
|
||||||
message.ack()
|
message.ack()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
@@ -393,8 +393,8 @@ def send_message(topic, message, wait=True):
|
|||||||
"""Sends a message for testing"""
|
"""Sends a message for testing"""
|
||||||
msg_id = uuid.uuid4().hex
|
msg_id = uuid.uuid4().hex
|
||||||
message.update({'_msg_id': msg_id})
|
message.update({'_msg_id': msg_id})
|
||||||
LOG.debug('topic is %s', topic)
|
LOG.debug(_('topic is %s'), topic)
|
||||||
LOG.debug('message %s', message)
|
LOG.debug(_('message %s'), message)
|
||||||
|
|
||||||
if wait:
|
if wait:
|
||||||
consumer = messaging.Consumer(connection=Connection.instance(),
|
consumer = messaging.Consumer(connection=Connection.instance(),
|
||||||
|
@@ -47,7 +47,7 @@ class SimpleScheduler(chance.ChanceScheduler):
|
|||||||
for result in results:
|
for result in results:
|
||||||
(service, instance_cores) = result
|
(service, instance_cores) = result
|
||||||
if instance_cores + instance_ref['vcpus'] > FLAGS.max_cores:
|
if instance_cores + instance_ref['vcpus'] > FLAGS.max_cores:
|
||||||
raise driver.NoValidHost("All hosts have too many cores")
|
raise driver.NoValidHost(_("All hosts have too many cores"))
|
||||||
if self.service_is_up(service):
|
if self.service_is_up(service):
|
||||||
# NOTE(vish): this probably belongs in the manager, if we
|
# NOTE(vish): this probably belongs in the manager, if we
|
||||||
# can generalize this somehow
|
# can generalize this somehow
|
||||||
@@ -57,7 +57,7 @@ class SimpleScheduler(chance.ChanceScheduler):
|
|||||||
{'host': service['host'],
|
{'host': service['host'],
|
||||||
'scheduled_at': now})
|
'scheduled_at': now})
|
||||||
return service['host']
|
return service['host']
|
||||||
raise driver.NoValidHost("No hosts found")
|
raise driver.NoValidHost(_("No hosts found"))
|
||||||
|
|
||||||
def schedule_create_volume(self, context, volume_id, *_args, **_kwargs):
|
def schedule_create_volume(self, context, volume_id, *_args, **_kwargs):
|
||||||
"""Picks a host that is up and has the fewest volumes."""
|
"""Picks a host that is up and has the fewest volumes."""
|
||||||
@@ -66,7 +66,8 @@ class SimpleScheduler(chance.ChanceScheduler):
|
|||||||
for result in results:
|
for result in results:
|
||||||
(service, volume_gigabytes) = result
|
(service, volume_gigabytes) = result
|
||||||
if volume_gigabytes + volume_ref['size'] > FLAGS.max_gigabytes:
|
if volume_gigabytes + volume_ref['size'] > FLAGS.max_gigabytes:
|
||||||
raise driver.NoValidHost("All hosts have too many gigabytes")
|
raise driver.NoValidHost(_("All hosts have too many "
|
||||||
|
"gigabytes"))
|
||||||
if self.service_is_up(service):
|
if self.service_is_up(service):
|
||||||
# NOTE(vish): this probably belongs in the manager, if we
|
# NOTE(vish): this probably belongs in the manager, if we
|
||||||
# can generalize this somehow
|
# can generalize this somehow
|
||||||
@@ -76,7 +77,7 @@ class SimpleScheduler(chance.ChanceScheduler):
|
|||||||
{'host': service['host'],
|
{'host': service['host'],
|
||||||
'scheduled_at': now})
|
'scheduled_at': now})
|
||||||
return service['host']
|
return service['host']
|
||||||
raise driver.NoValidHost("No hosts found")
|
raise driver.NoValidHost(_("No hosts found"))
|
||||||
|
|
||||||
def schedule_set_network_host(self, context, *_args, **_kwargs):
|
def schedule_set_network_host(self, context, *_args, **_kwargs):
|
||||||
"""Picks a host that is up and has the fewest networks."""
|
"""Picks a host that is up and has the fewest networks."""
|
||||||
@@ -85,7 +86,7 @@ class SimpleScheduler(chance.ChanceScheduler):
|
|||||||
for result in results:
|
for result in results:
|
||||||
(service, instance_count) = result
|
(service, instance_count) = result
|
||||||
if instance_count >= FLAGS.max_networks:
|
if instance_count >= FLAGS.max_networks:
|
||||||
raise driver.NoValidHost("All hosts have too many networks")
|
raise driver.NoValidHost(_("All hosts have too many networks"))
|
||||||
if self.service_is_up(service):
|
if self.service_is_up(service):
|
||||||
return service['host']
|
return service['host']
|
||||||
raise driver.NoValidHost("No hosts found")
|
raise driver.NoValidHost(_("No hosts found"))
|
||||||
|
@@ -58,7 +58,7 @@ def stop(pidfile):
|
|||||||
try:
|
try:
|
||||||
pid = int(open(pidfile, 'r').read().strip())
|
pid = int(open(pidfile, 'r').read().strip())
|
||||||
except IOError:
|
except IOError:
|
||||||
message = "pidfile %s does not exist. Daemon not running?\n"
|
message = _("pidfile %s does not exist. Daemon not running?\n")
|
||||||
sys.stderr.write(message % pidfile)
|
sys.stderr.write(message % pidfile)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ def serve(name, main):
|
|||||||
if not FLAGS.pidfile:
|
if not FLAGS.pidfile:
|
||||||
FLAGS.pidfile = '%s.pid' % name
|
FLAGS.pidfile = '%s.pid' % name
|
||||||
|
|
||||||
logging.debug("Full set of FLAGS: \n\n\n")
|
logging.debug(_("Full set of FLAGS: \n\n\n"))
|
||||||
for flag in FLAGS:
|
for flag in FLAGS:
|
||||||
logging.debug("%s : %s", flag, FLAGS.get(flag, None))
|
logging.debug("%s : %s", flag, FLAGS.get(flag, None))
|
||||||
|
|
||||||
|
@@ -208,7 +208,7 @@ def stop(pidfile):
|
|||||||
pid = None
|
pid = None
|
||||||
|
|
||||||
if not pid:
|
if not pid:
|
||||||
message = "pidfile %s does not exist. Daemon not running?\n"
|
message = _("pidfile %s does not exist. Daemon not running?\n")
|
||||||
sys.stderr.write(message % pidfile)
|
sys.stderr.write(message % pidfile)
|
||||||
# Not an error in a restart
|
# Not an error in a restart
|
||||||
return
|
return
|
||||||
@@ -229,7 +229,7 @@ def stop(pidfile):
|
|||||||
|
|
||||||
|
|
||||||
def serve(filename):
|
def serve(filename):
|
||||||
logging.debug("Serving %s" % filename)
|
logging.debug(_("Serving %s") % filename)
|
||||||
name = os.path.basename(filename)
|
name = os.path.basename(filename)
|
||||||
OptionsClass = WrapTwistedOptions(TwistdServerOptions)
|
OptionsClass = WrapTwistedOptions(TwistdServerOptions)
|
||||||
options = OptionsClass()
|
options = OptionsClass()
|
||||||
@@ -281,7 +281,7 @@ def serve(filename):
|
|||||||
else:
|
else:
|
||||||
logging.getLogger().setLevel(logging.WARNING)
|
logging.getLogger().setLevel(logging.WARNING)
|
||||||
|
|
||||||
logging.debug("Full set of FLAGS:")
|
logging.debug(_("Full set of FLAGS:"))
|
||||||
for flag in FLAGS:
|
for flag in FLAGS:
|
||||||
logging.debug("%s : %s" % (flag, FLAGS.get(flag, None)))
|
logging.debug("%s : %s" % (flag, FLAGS.get(flag, None)))
|
||||||
|
|
||||||
|
@@ -42,7 +42,7 @@ def rangetest(**argchecks):
|
|||||||
# was passed by name
|
# was passed by name
|
||||||
if float(kargs[argname]) < low or \
|
if float(kargs[argname]) < low or \
|
||||||
float(kargs[argname]) > high:
|
float(kargs[argname]) > high:
|
||||||
errmsg = '{0} argument "{1}" not in {2}..{3}'
|
errmsg = _('{0} argument "{1}" not in {2}..{3}')
|
||||||
errmsg = errmsg.format(funcname, argname, low, high)
|
errmsg = errmsg.format(funcname, argname, low, high)
|
||||||
raise TypeError(errmsg)
|
raise TypeError(errmsg)
|
||||||
|
|
||||||
@@ -51,8 +51,8 @@ def rangetest(**argchecks):
|
|||||||
position = positionals.index(argname)
|
position = positionals.index(argname)
|
||||||
if float(pargs[position]) < low or \
|
if float(pargs[position]) < low or \
|
||||||
float(pargs[position]) > high:
|
float(pargs[position]) > high:
|
||||||
errmsg = '{0} argument "{1}" with value of {4} ' \
|
errmsg = _('{0} argument "{1}" with value of {4} '
|
||||||
'not in {2}..{3}'
|
'not in {2}..{3}')
|
||||||
errmsg = errmsg.format(funcname, argname, low, high,
|
errmsg = errmsg.format(funcname, argname, low, high,
|
||||||
pargs[position])
|
pargs[position])
|
||||||
raise TypeError(errmsg)
|
raise TypeError(errmsg)
|
||||||
@@ -76,14 +76,14 @@ def typetest(**argchecks):
|
|||||||
for (argname, typeof) in argchecks.items():
|
for (argname, typeof) in argchecks.items():
|
||||||
if argname in kargs:
|
if argname in kargs:
|
||||||
if not isinstance(kargs[argname], typeof):
|
if not isinstance(kargs[argname], typeof):
|
||||||
errmsg = '{0} argument "{1}" not of type {2}'
|
errmsg = _('{0} argument "{1}" not of type {2}')
|
||||||
errmsg = errmsg.format(funcname, argname, typeof)
|
errmsg = errmsg.format(funcname, argname, typeof)
|
||||||
raise TypeError(errmsg)
|
raise TypeError(errmsg)
|
||||||
elif argname in positionals:
|
elif argname in positionals:
|
||||||
position = positionals.index(argname)
|
position = positionals.index(argname)
|
||||||
if not isinstance(pargs[position], typeof):
|
if not isinstance(pargs[position], typeof):
|
||||||
errmsg = '{0} argument "{1}" with value of {2} ' \
|
errmsg = _('{0} argument "{1}" with value of {2} '
|
||||||
'not of type {3}'
|
'not of type {3}')
|
||||||
errmsg = errmsg.format(funcname, argname,
|
errmsg = errmsg.format(funcname, argname,
|
||||||
pargs[position], typeof)
|
pargs[position], typeof)
|
||||||
raise TypeError(errmsg)
|
raise TypeError(errmsg)
|
||||||
|
Reference in New Issue
Block a user