本文整理汇总了Python中murano.common.i18n._LI函数的典型用法代码示例。如果您正苦于以下问题:Python _LI函数的具体用法?Python _LI怎么用?Python _LI使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_LI函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __inner
def __inner(self, request, *args, **kwargs):
if hasattr(request, 'context') and not request.context.session:
LOG.info(_LI('Session is required for this call'))
raise exc.HTTPForbidden()
session_id = request.context.session
unit = db_session.get_session()
session = unit.query(models.Session).get(session_id)
if session is None:
LOG.info(_LI('Session <SessionId {0}> '
'is not found').format(session_id))
raise exc.HTTPForbidden()
if not sessions.SessionServices.validate(session):
LOG.info(_LI('Session <SessionId {0}> '
'is invalid').format(session_id))
raise exc.HTTPForbidden()
if session.state == states.SessionState.DEPLOYING:
LOG.info(_LI('Session <SessionId {0}> is already in '
'deployment state').format(session_id))
raise exc.HTTPForbidden()
return func(self, request, *args, **kwargs)
示例2: update
def update(self, request, environment_id, body):
LOG.debug('Environments:Update <Id: {0}, '
'Body: {1}>'.format(environment_id, body))
target = {"environment_id": environment_id}
policy.check('update_environment', request.context, target)
session = db_session.get_session()
environment = session.query(models.Environment).get(environment_id)
if environment is None:
LOG.info(_LI('Environment <EnvId {0}> not '
'found').format(environment_id))
raise exc.HTTPNotFound
if environment.tenant_id != request.context.tenant:
LOG.info(_LI('User is not authorized to access '
'this tenant resources.'))
raise exc.HTTPUnauthorized
LOG.debug('ENV NAME: {0}>'.format(body['name']))
if VALID_NAME_REGEX.match(str(body['name'])):
environment.update(body)
environment.save(session)
else:
msg = _('Environment name must contain only alphanumeric '
'or "_-." characters, must start with alpha')
LOG.error(msg)
raise exc.HTTPClientError(explanation=msg)
return environment.to_dict()
示例3: show
def show(self, request, environment_id):
LOG.debug('Environments:Show <Id: {0}>'.format(environment_id))
target = {"environment_id": environment_id}
policy.check('show_environment', request.context, target)
session = db_session.get_session()
environment = session.query(models.Environment).get(environment_id)
if environment is None:
LOG.info(_LI('Environment <EnvId {0}> is not found').format(
environment_id))
raise exc.HTTPNotFound
if environment.tenant_id != request.context.tenant:
LOG.info(_LI('User is not authorized to access '
'this tenant resources.'))
raise exc.HTTPUnauthorized
env = environment.to_dict()
env['status'] = envs.EnvironmentServices.get_status(env['id'])
session_id = None
if hasattr(request, 'context') and request.context.session:
session_id = request.context.session
# add services to env
get_data = core_services.CoreServices.get_data
env['services'] = get_data(environment_id, '/services', session_id)
return env
示例4: validate
def validate(self, model, class_loader=None):
"""Validate model using Congress rule engine.
@type model: dict
@param model: Dictionary representation of model starting on
environment level (['Objects'])
@type class_loader: murano.dsl.class_loader.MuranoClassLoader
@param class_loader: Optional. Used for evaluating parent class types
@raises ValidationError in case validation was not successful
"""
if model is None:
return
client = self._client_manager.get_congress_client(self._environment)
if not client:
raise ValueError(_('Congress client is not configured!'))
LOG.info(_LI('Validating model'))
LOG.debug(model)
rules = congress_rules.CongressRulesManager().convert(
model, class_loader, self._environment.tenant_id)
rules_str = map(str, rules)
env_id = model['?']['id']
# cleanup of data populated by murano driver
rules_str.insert(0, 'deleteEnv("{0}")'.format(env_id))
rules_line = " ".join(rules_str)
LOG.debug('Congress rules: \n ' +
'\n '.join(rules_str))
validation_result = client.execute_policy_action(
"murano_system",
"simulate",
False,
False,
{'query': 'predeploy_errors(eid, oid, msg)',
'action_policy': 'murano_action',
'sequence': rules_line})
if validation_result["result"]:
messages = self._parse_messages(env_id,
validation_result["result"])
if messages:
result_str = "\n ".join(map(str, messages))
msg = _("Murano object model validation failed: {0}").format(
"\n " + result_str)
LOG.error(msg)
raise ValidationError(msg)
else:
LOG.info(_LI('Model valid'))
示例5: _execute
def _execute(self, pkg_loader):
class_loader = package_class_loader.PackageClassLoader(pkg_loader)
system_objects.register(class_loader, pkg_loader)
get_plugin_loader().register_in_loader(class_loader)
exc = executor.MuranoDslExecutor(class_loader, self.environment)
obj = exc.load(self.model)
self._validate_model(obj, self.action, class_loader)
action_result = None
exception = None
exception_traceback = None
try:
LOG.info(_LI('Invoking pre-cleanup hooks'))
self.environment.start()
exc.cleanup(self._model)
except Exception as e:
exception = e
exception_traceback = TaskExecutor._log_exception(e, obj, '<GC>')
finally:
LOG.info(_LI('Invoking post-cleanup hooks'))
self.environment.finish()
if exception is None and self.action:
try:
LOG.info(_LI('Invoking pre-execution hooks'))
self.environment.start()
action_result = self._invoke(exc)
except Exception as e:
exception = e
exception_traceback = TaskExecutor._log_exception(
e, obj, self.action['method'])
finally:
LOG.info(_LI('Invoking post-execution hooks'))
self.environment.finish()
model = serializer.serialize_model(obj, exc)
model['SystemData'] = self._environment.system_attributes
result = {
'model': model,
'action': {
'result': None,
'isException': False
}
}
if exception is not None:
result['action'] = TaskExecutor.exception_result(
exception, exception_traceback)
else:
result['action']['result'] = serializer.serialize_object(
action_result)
return result
示例6: _execute
def _execute(self, pkg_loader):
class_loader = package_class_loader.PackageClassLoader(pkg_loader)
system_objects.register(class_loader, pkg_loader)
get_plugin_loader().register_in_loader(class_loader)
exc = executor.MuranoDslExecutor(class_loader, self.environment)
obj = exc.load(self.model)
self._validate_model(obj, self.action, class_loader)
action_result = None
exception = None
exception_traceback = None
try:
LOG.info(_LI('Invoking pre-execution hooks'))
self.environment.start()
# Skip execution of action in case no action is provided.
# Model will be just loaded, cleaned-up and unloaded.
# Most of the time this is used for deletion of environments.
if self.action:
action_result = self._invoke(exc)
except Exception as e:
exception = e
if isinstance(e, dsl_exception.MuranoPlException):
LOG.error('\n' + e.format(prefix=' '))
else:
exception_traceback = traceback.format_exc()
LOG.exception(
_LE("Exception %(exc)s occured"
" during invocation of %(method)s"),
{'exc': e, 'method': self.action['method']})
reporter = status_reporter.StatusReporter()
reporter.initialize(obj)
reporter.report_error(obj, str(e))
finally:
LOG.info(_LI('Invoking post-execution hooks'))
self.environment.finish()
model = serializer.serialize_model(obj, exc)
model['SystemData'] = self._environment.system_attributes
result = {
'model': model,
'action': {
'result': None,
'isException': False
}
}
if exception is not None:
result['action'] = TaskExecutor.exception_result(
exception, exception_traceback)
else:
result['action']['result'] = serializer.serialize_object(
action_result)
return result
示例7: verify_and_get_env
def verify_and_get_env(db_session, environment_id, request):
environment = db_session.query(models.Environment).get(environment_id)
if not environment:
LOG.info(_LI(
'Environment with id {0} not found').format(environment_id))
raise exc.HTTPNotFound
if environment.tenant_id != request.context.tenant:
LOG.info(_LI(
'User is not authorized to access this tenant resources.'))
raise exc.HTTPUnauthorized
return environment
示例8: _validate_environment
def _validate_environment(self, unit, request, environment_id):
environment = unit.query(models.Environment).get(environment_id)
if environment is None:
LOG.info(_LI('Environment <EnvId {0}> '
'is not found').format(environment_id))
raise exc.HTTPNotFound
if environment.tenant_id != request.context.tenant:
LOG.info(_LI('User is not authorized to access '
'this tenant resources.'))
raise exc.HTTPUnauthorized
示例9: verify_and_get_deployment
def verify_and_get_deployment(db_session, environment_id, deployment_id):
deployment = db_session.query(models.Task).get(deployment_id)
if not deployment:
LOG.info(_LI('Deployment with id {0} not found').format(deployment_id))
raise exc.HTTPNotFound
if deployment.environment_id != environment_id:
LOG.info(_LI('Deployment with id {0} not found'
' in environment {1}').format(deployment_id,
environment_id))
raise exc.HTTPBadRequest
deployment.description = _patch_description(deployment.description)
return deployment
示例10: call_static_action
def call_static_action(cls, context, task):
s_task = token_sanitizer.TokenSanitizer().sanitize(task)
LOG.info(_LI('Starting execution of static action: '
'{task_desc}').format(task_desc=jsonutils.dumps(s_task)))
result = None
reporter = status_reporter.StatusReporter(task['id'])
try:
task_executor = StaticActionExecutor(task, reporter)
result = task_executor.execute()
return result
finally:
LOG.info(_LI('Finished execution of static action: '
'{task_desc}').format(task_desc=jsonutils.dumps(result)))
示例11: execute
def execute(task):
s_task = token_sanitizer.TokenSanitizer().sanitize(task)
LOG.info(_LI('Starting processing task: {task_desc}').format(
task_desc=jsonutils.dumps(s_task)))
result = None
reporter = status_reporter.StatusReporter(task['id'])
try:
task_executor = TaskExecutor(task, reporter)
result = task_executor.execute()
return result
finally:
LOG.info(_LI('Finished processing task: {task_desc}').format(
task_desc=jsonutils.dumps(result)))
示例12: execute
def execute(self, request, environment_id, action_id, body):
policy.check("execute_action", request.context, {})
LOG.debug("Action:Execute <ActionId: {0}>".format(action_id))
unit = db_session.get_session()
# no new session can be opened if environment has deploying status
env_status = envs.EnvironmentServices.get_status(environment_id)
if env_status in (states.EnvironmentStatus.DEPLOYING, states.EnvironmentStatus.DELETING):
LOG.info(
_LI(
"Could not open session for environment <EnvId: {0}>," "environment has deploying " "status."
).format(environment_id)
)
raise exc.HTTPForbidden()
user_id = request.context.user
session = sessions.SessionServices.create(environment_id, user_id)
if not sessions.SessionServices.validate(session):
LOG.error(_LE("Session <SessionId {0}> " "is invalid").format(session.id))
raise exc.HTTPForbidden()
task_id = actions.ActionServices.execute(action_id, session, unit, request.context.auth_token, body or {})
return {"task_id": task_id}
示例13: get_default_router
def get_default_router(self):
router_name = self._settings.router_name
routers = self._client.list_routers(tenant_id=self._project_id, name=router_name).get("routers")
if len(routers) == 0:
LOG.debug("Router {name} not found".format(name=router_name))
if self._settings.create_router:
LOG.debug("Attempting to create Router {router}".format(router=router_name))
external_network = self._settings.external_network
kwargs = (
{"id": external_network} if uuidutils.is_uuid_like(external_network) else {"name": external_network}
)
networks = self._client.list_networks(**kwargs).get("networks")
ext_nets = filter(lambda n: n["router:external"], networks)
if len(ext_nets) == 0:
raise KeyError("Router %s could not be created, " "no external network found" % router_name)
nid = ext_nets[0]["id"]
body_data = {
"router": {
"name": router_name,
"external_gateway_info": {"network_id": nid},
"admin_state_up": True,
}
}
router = self._client.create_router(body=body_data).get("router")
LOG.info(_LI("Created router: {id}").format(id=router["id"]))
return router["id"]
else:
raise KeyError("Router %s was not found" % router_name)
else:
if routers[0]["external_gateway_info"] is None:
raise exc.RouterInfoException("Please set external gateway for" " the router %s " % router_name)
router_id = routers[0]["id"]
return router_id
示例14: _build_index
def _build_index(self):
for folder in self.search_package_folders(self._base_path):
try:
package = load_utils.load_from_dir(folder)
dsl_package = murano_package.MuranoPackage(self._root_loader, package)
for class_name in package.classes:
dsl_package.register_class(
(lambda pkg, cls: lambda: get_class(pkg, cls))(package, class_name), class_name
)
if dsl_package.name == constants.CORE_LIBRARY:
system_objects.register(dsl_package)
self.register_package(dsl_package)
except pkg_exc.PackageLoadError:
LOG.info(_LI("Unable to load package from path: {0}").format(folder))
continue
LOG.info(_LI("Loaded package from path {0}").format(folder))
示例15: validate
def validate(self, model, package_loader=None):
"""Validate model using Congress rule engine.
@type model: dict
@param model: Dictionary representation of model starting on
environment level (['Objects'])
@type package_loader: murano.dsl.package_loader.MuranoPackageLoader
@param package_loader: Optional. Used for evaluating parent class types
@raises ValidationError in case validation was not successful
"""
if model is None:
return
env_id = model['?']['id']
validation_result = self._execute_simulation(
package_loader, env_id, model,
'predeploy_errors(eid, oid, msg)')
if validation_result["result"]:
messages = self._parse_simulation_result(
'predeploy_errors', env_id,
validation_result["result"])
if messages:
result_str = "\n ".join(map(str, messages))
msg = _("Murano object model validation failed: {0}").format(
"\n " + result_str)
LOG.error(msg)
raise ValidationError(msg)
else:
LOG.info(_LI('Model valid'))