Add translation support
Use openstack.common.gettextutils for translation Closes-Bug: #1267514 Change-Id: I4aaa9fae0b725bac724567a06387b6870c546ee5
This commit is contained in:
parent
c104c0c291
commit
a63ff0a82e
|
@ -12,8 +12,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import gettext
|
||||
gettext.install('muranoapi', './muranoapi/locale', unicode=1)
|
||||
from muranoapi.openstack.common.gettextutils import _ # noqa
|
||||
|
||||
from pbr import version
|
||||
__version_info = version.VersionInfo('murano-api')
|
||||
|
|
|
@ -64,11 +64,11 @@ class Controller(object):
|
|||
def verify_and_get_env(db_session, environment_id, request):
|
||||
environment = db_session.query(Environment).get(environment_id)
|
||||
if not environment:
|
||||
log.info('Environment with id {0} not found'.format(environment_id))
|
||||
log.info(_('Environment with id {0} not found'.format(environment_id)))
|
||||
raise exc.HTTPNotFound
|
||||
|
||||
if environment.tenant_id != request.context.tenant:
|
||||
log.info('User is not authorized to access this tenant resources.')
|
||||
log.info(_('User is not authorized to access this tenant resources.'))
|
||||
raise exc.HTTPUnauthorized
|
||||
return environment
|
||||
|
||||
|
@ -76,11 +76,12 @@ def verify_and_get_env(db_session, environment_id, request):
|
|||
def verify_and_get_deployment(db_session, environment_id, deployment_id):
|
||||
deployment = db_session.query(Deployment).get(deployment_id)
|
||||
if not deployment:
|
||||
log.info('Deployment with id {0} not found'.format(deployment_id))
|
||||
log.info(_('Deployment with id {0} not found'.format(deployment_id)))
|
||||
raise exc.HTTPNotFound
|
||||
if deployment.environment_id != environment_id:
|
||||
log.info('Deployment with id {0} not found'
|
||||
' in environment {1}'.format(deployment_id, environment_id))
|
||||
log.info(_('Deployment with id {0} not found'
|
||||
' in environment {1}'.format(deployment_id,
|
||||
environment_id)))
|
||||
raise exc.HTTPBadRequest
|
||||
return deployment
|
||||
|
||||
|
|
|
@ -59,7 +59,8 @@ class Controller(object):
|
|||
raise exc.HTTPNotFound
|
||||
|
||||
if environment.tenant_id != request.context.tenant:
|
||||
log.info('User is not authorized to access this tenant resources.')
|
||||
log.info(_('User is not authorized to access '
|
||||
'this tenant resources.'))
|
||||
raise exc.HTTPUnauthorized
|
||||
|
||||
env = environment.to_dict()
|
||||
|
@ -83,12 +84,13 @@ class Controller(object):
|
|||
environment = session.query(Environment).get(environment_id)
|
||||
|
||||
if environment is None:
|
||||
log.info('Environment <EnvId {0}> is not found'
|
||||
.format(environment_id))
|
||||
log.info(_('Environment <EnvId {0}> is not '
|
||||
'found'.format(environment_id)))
|
||||
raise exc.HTTPNotFound
|
||||
|
||||
if environment.tenant_id != request.context.tenant:
|
||||
log.info('User is not authorized to access this tenant resources.')
|
||||
log.info(_('User is not authorized to access '
|
||||
'this tenant resources.'))
|
||||
raise exc.HTTPUnauthorized
|
||||
|
||||
environment.update(body)
|
||||
|
@ -103,12 +105,13 @@ class Controller(object):
|
|||
environment = unit.query(Environment).get(environment_id)
|
||||
|
||||
if environment is None:
|
||||
log.info('Environment <EnvId {0}> is not found'
|
||||
.format(environment_id))
|
||||
log.info(_('Environment <EnvId {0}> '
|
||||
'is not found'.format(environment_id)))
|
||||
raise exc.HTTPNotFound
|
||||
|
||||
if environment.tenant_id != request.context.tenant:
|
||||
log.info('User is not authorized to access this tenant resources.')
|
||||
log.info(_('User is not authorized to access '
|
||||
'this tenant resources.'))
|
||||
raise exc.HTTPUnauthorized
|
||||
|
||||
EnvironmentServices.delete(environment_id, request.context.auth_token)
|
||||
|
|
|
@ -22,6 +22,7 @@ from muranoapi.db.services.environments import EnvironmentStatus
|
|||
from muranoapi.openstack.common import wsgi
|
||||
from muranoapi.openstack.common import log as logging
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -33,20 +34,21 @@ class Controller(object):
|
|||
environment = unit.query(Environment).get(environment_id)
|
||||
|
||||
if environment is None:
|
||||
log.info('Environment <EnvId {0}> is not found'
|
||||
.format(environment_id))
|
||||
log.info(_('Environment <EnvId {0}> '
|
||||
'is not found'.format(environment_id)))
|
||||
raise exc.HTTPNotFound
|
||||
|
||||
if environment.tenant_id != request.context.tenant:
|
||||
log.info('User is not authorized to access this tenant resources.')
|
||||
log.info(_('User is not authorized to access '
|
||||
'this tenant resources.'))
|
||||
raise exc.HTTPUnauthorized
|
||||
|
||||
# no new session can be opened if environment has deploying status
|
||||
env_status = EnvironmentServices.get_status(environment_id)
|
||||
if env_status == EnvironmentStatus.deploying:
|
||||
log.info('Could not open session for environment <EnvId: {0}>,'
|
||||
'environment has deploying '
|
||||
'status.'.format(environment_id))
|
||||
log.info(_('Could not open session for environment <EnvId: {0}>,'
|
||||
'environment has deploying '
|
||||
'status.'.format(environment_id)))
|
||||
raise exc.HTTPForbidden()
|
||||
|
||||
user_id = request.context.user
|
||||
|
@ -61,23 +63,24 @@ class Controller(object):
|
|||
session = unit.query(Session).get(session_id)
|
||||
|
||||
if session is None:
|
||||
log.error('Session <SessionId {0}> is not found'
|
||||
''.format(session_id))
|
||||
log.error(_('Session <SessionId {0}> '
|
||||
'is not found'.format(session_id)))
|
||||
raise exc.HTTPNotFound()
|
||||
|
||||
if session.environment_id != environment_id:
|
||||
log.error('Session <SessionId {0}> is not tied with Environment '
|
||||
'<EnvId {1}>'.format(session_id, environment_id))
|
||||
log.error(_('Session <SessionId {0}> is not tied with Environment '
|
||||
'<EnvId {1}>'.format(session_id, environment_id)))
|
||||
raise exc.HTTPNotFound()
|
||||
|
||||
user_id = request.context.user
|
||||
if session.user_id != user_id:
|
||||
log.error('User <UserId {0}> is not authorized to access '
|
||||
'session <SessionId {1}>.'.format(user_id, session_id))
|
||||
log.error(_('User <UserId {0}> is not authorized to access session'
|
||||
'<SessionId {1}>.'.format(user_id, session_id)))
|
||||
raise exc.HTTPUnauthorized()
|
||||
|
||||
if not SessionServices.validate(session):
|
||||
log.error('Session <SessionId {0}> is invalid'.format(session_id))
|
||||
log.error(_('Session <SessionId {0}> '
|
||||
'is invalid'.format(session_id)))
|
||||
raise exc.HTTPForbidden()
|
||||
|
||||
return session.to_dict()
|
||||
|
@ -89,24 +92,24 @@ class Controller(object):
|
|||
session = unit.query(Session).get(session_id)
|
||||
|
||||
if session is None:
|
||||
log.error('Session <SessionId {0}> is not found'
|
||||
''.format(session_id))
|
||||
log.error(_('Session <SessionId {0}> '
|
||||
'is not found'.format(session_id)))
|
||||
raise exc.HTTPNotFound()
|
||||
|
||||
if session.environment_id != environment_id:
|
||||
log.error('Session <SessionId {0}> is not tied with Environment '
|
||||
'<EnvId {1}>'.format(session_id, environment_id))
|
||||
log.error(_('Session <SessionId {0}> is not tied with Environment '
|
||||
'<EnvId {1}>'.format(session_id, environment_id)))
|
||||
raise exc.HTTPNotFound()
|
||||
|
||||
user_id = request.context.user
|
||||
if session.user_id != user_id:
|
||||
log.error('User <UserId {0}> is not authorized to access '
|
||||
'session <SessionId {1}>.'.format(user_id, session_id))
|
||||
log.error(_('User <UserId {0}> is not authorized to access session'
|
||||
'<SessionId {1}>.'.format(user_id, session_id)))
|
||||
raise exc.HTTPUnauthorized()
|
||||
|
||||
if session.state == SessionState.deploying:
|
||||
log.error('Session <SessionId: {0}> is in deploying state and '
|
||||
'could not be deleted'.format(session_id))
|
||||
log.error(_('Session <SessionId: {0}> is in deploying state and '
|
||||
'could not be deleted'.format(session_id)))
|
||||
raise exc.HTTPForbidden()
|
||||
|
||||
with unit.begin():
|
||||
|
@ -121,22 +124,23 @@ class Controller(object):
|
|||
session = unit.query(Session).get(session_id)
|
||||
|
||||
if session is None:
|
||||
log.error('Session <SessionId {0}> is not found'
|
||||
''.format(session_id))
|
||||
log.error(_('Session <SessionId {0}> '
|
||||
'is not found'.format(session_id)))
|
||||
raise exc.HTTPNotFound()
|
||||
|
||||
if session.environment_id != environment_id:
|
||||
log.error('Session <SessionId {0}> is not tied with Environment '
|
||||
'<EnvId {1}>'.format(session_id, environment_id))
|
||||
log.error(_('Session <SessionId {0}> is not tied with Environment '
|
||||
'<EnvId {1}>'.format(session_id, environment_id)))
|
||||
raise exc.HTTPNotFound()
|
||||
|
||||
if not SessionServices.validate(session):
|
||||
log.error('Session <SessionId {0}> is invalid'.format(session_id))
|
||||
log.error(_('Session <SessionId {0}> '
|
||||
'is invalid'.format(session_id)))
|
||||
raise exc.HTTPForbidden()
|
||||
|
||||
if session.state != SessionState.open:
|
||||
log.error('Session <SessionId {0}> is already deployed or '
|
||||
'deployment is in progress'.format(session_id))
|
||||
log.error(_('Session <SessionId {0}> is already deployed or '
|
||||
'deployment is in progress'.format(session_id)))
|
||||
raise exc.HTTPForbidden()
|
||||
|
||||
SessionServices.deploy(session, unit, request.context.auth_token)
|
||||
|
|
|
@ -31,6 +31,7 @@ from paste import deploy
|
|||
|
||||
from muranoapi.openstack.common import log
|
||||
from muranoapi import __version__ as version
|
||||
from muranoapi.openstack.common.gettextutils import _ # noqa
|
||||
|
||||
paste_deploy_opts = [
|
||||
cfg.StrOpt('flavor'),
|
||||
|
@ -110,8 +111,8 @@ def setup_logging():
|
|||
logging.config.fileConfig(CONF.log_config)
|
||||
return
|
||||
else:
|
||||
raise RuntimeError("Unable to locate specified logging "
|
||||
"config file: %s" % CONF.log_config)
|
||||
raise RuntimeError(_("Unable to locate specified logging "
|
||||
"config file: %s" % CONF.log_config))
|
||||
|
||||
root_logger = logging.root
|
||||
if CONF.debug:
|
||||
|
@ -174,7 +175,7 @@ def _get_deployment_config_file():
|
|||
if not path:
|
||||
path = _get_paste_config_path()
|
||||
if not path:
|
||||
msg = "Unable to locate paste config file for %s." % CONF.prog
|
||||
msg = _("Unable to locate paste config file for %s.") % CONF.prog
|
||||
raise RuntimeError(msg)
|
||||
return os.path.abspath(path)
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import eventlet
|
|||
from jsonschema import validate
|
||||
import types
|
||||
from muranoapi.openstack.common import log as logging
|
||||
from muranoapi.openstack.common.gettextutils import _ # noqa
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -69,7 +70,7 @@ class TraverseHelper(object):
|
|||
elif isinstance(source, TraverseHelper.value_type):
|
||||
break
|
||||
else:
|
||||
raise ValueError('Source object or path is malformed')
|
||||
raise ValueError(_('Source object or path is malformed'))
|
||||
|
||||
return source
|
||||
|
||||
|
@ -134,7 +135,7 @@ class TraverseHelper(object):
|
|||
elif isinstance(node, types.DictionaryType):
|
||||
del node[key]
|
||||
else:
|
||||
raise ValueError('Source object or path is malformed')
|
||||
raise ValueError(_('Source object or path is malformed'))
|
||||
|
||||
|
||||
def build_entity_map(value):
|
||||
|
@ -182,7 +183,7 @@ def retry(ExceptionToCheck, tries=4, delay=3, backoff=2):
|
|||
except ExceptionToCheck as e:
|
||||
|
||||
log.exception(e)
|
||||
log.info("Retrying in {0} seconds...".format(mdelay))
|
||||
log.info(_("Retrying in {0} seconds...".format(mdelay)))
|
||||
|
||||
eventlet.sleep(mdelay)
|
||||
|
||||
|
|
|
@ -28,14 +28,14 @@ def verify_env(func):
|
|||
unit = get_session()
|
||||
environment = unit.query(Environment).get(environment_id)
|
||||
if environment is None:
|
||||
log.info("Environment with id '{0}'"
|
||||
" not found".format(environment_id))
|
||||
log.info(_("Environment with id '{0}'"
|
||||
" not found".format(environment_id)))
|
||||
raise exc.HTTPNotFound()
|
||||
|
||||
if hasattr(request, 'context'):
|
||||
if environment.tenant_id != request.context.tenant:
|
||||
log.info('User is not authorized to access'
|
||||
' this tenant resources')
|
||||
log.info(_('User is not authorized to access'
|
||||
' this tenant resources'))
|
||||
raise exc.HTTPUnauthorized()
|
||||
|
||||
return func(self, request, environment_id, *args, **kwargs)
|
||||
|
@ -46,7 +46,7 @@ def verify_session(func):
|
|||
@functools.wraps(func)
|
||||
def __inner(self, request, *args, **kwargs):
|
||||
if hasattr(request, 'context') and not request.context.session:
|
||||
log.info('Session is required for this call')
|
||||
log.info(_('Session is required for this call'))
|
||||
raise exc.HTTPForbidden()
|
||||
|
||||
session_id = request.context.session
|
||||
|
@ -55,16 +55,18 @@ def verify_session(func):
|
|||
session = unit.query(Session).get(session_id)
|
||||
|
||||
if session is None:
|
||||
log.info('Session <SessionId {0}> is not found'.format(session_id))
|
||||
log.info(_('Session <SessionId {0}> '
|
||||
'is not found'.format(session_id)))
|
||||
raise exc.HTTPForbidden()
|
||||
|
||||
if not SessionServices.validate(session):
|
||||
log.info('Session <SessionId {0}> is invalid'.format(session_id))
|
||||
log.info(_('Session <SessionId {0}> '
|
||||
'is invalid'.format(session_id)))
|
||||
raise exc.HTTPForbidden()
|
||||
|
||||
if session.state == SessionState.deploying:
|
||||
log.info('Session <SessionId {0}> is already in '
|
||||
'deployment state'.format(session_id))
|
||||
log.info(_('Session <SessionId {0}> is already in '
|
||||
'deployment state'.format(session_id)))
|
||||
raise exc.HTTPForbidden()
|
||||
return func(self, request, *args, **kwargs)
|
||||
return __inner
|
||||
|
|
Loading…
Reference in New Issue