本文整理汇总了Python中murano.common.policy.check函数的典型用法代码示例。如果您正苦于以下问题:Python check函数的具体用法?Python check怎么用?Python check使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: create
def create(self, request, body):
LOG.debug("Environments:Create <Body {body}>".format(body=body))
policy.check("create_environment", request.context)
if not body.get("name"):
msg = _("Please, specify a name of the environment to create")
LOG.exception(msg)
raise exc.HTTPBadRequest(explanation=msg)
name = unicode(body["name"])
if len(name) > 255:
msg = _("Environment name should be 255 characters maximum")
LOG.exception(msg)
raise exc.HTTPBadRequest(explanation=msg)
if VALID_NAME_REGEX.match(name):
try:
environment = envs.EnvironmentServices.create(body.copy(), request.context)
except db_exc.DBDuplicateEntry:
msg = _("Environment with specified name already exists")
LOG.exception(msg)
raise exc.HTTPConflict(explanation=msg)
else:
msg = _('Environment name must contain only alphanumeric or "_-." ' "characters, must start with alpha")
LOG.exception(msg)
raise exc.HTTPClientError(explanation=msg)
return environment.to_dict()
开发者ID:NikolayStarodubtsev,项目名称:murano,代码行数:27,代码来源:environments.py
示例2: update
def update(self, request, env_template_id, body):
"""It updates the description template.
:param request: the operation request.
:param env_template_id: the env template ID.
:param body: the description to be updated
:return: the updated template description.
"""
LOG.debug('Templates:Update <Id: {templ_id}, '
'Body: {body}>'.format(templ_id=env_template_id, body=body))
target = {"env_template_id": env_template_id}
policy.check('update_env_template', request.context, target)
self._validate_request(request, env_template_id)
try:
LOG.debug('ENV TEMP NAME: {temp_name}>'.format(
temp_name=body['name']))
if not envs_api.VALID_NAME_REGEX.match(str(body['name'])):
msg = _('Env Template must contain only alphanumeric '
'or "_-." characters, must start with alpha')
LOG.exception(msg)
raise exc.HTTPBadRequest(msg)
except Exception:
msg = _('EnvTemplate body is incorrect')
LOG.exception(msg)
raise exc.HTTPBadRequest(msg)
template = env_temps.EnvTemplateServices.update(env_template_id, body)
return template.to_dict()
开发者ID:NikolayStarodubtsev,项目名称:murano,代码行数:28,代码来源:templates.py
示例3: create
def create(self, request, body):
"""It creates the env template from the payload obtaining.
This payload can contain just the template name, or include
also service information.
:param request: the operation request.
:param body: the env template description
:return: the description of the created template.
"""
LOG.debug('EnvTemplates:Create <Body {body}>'.format(body=body))
policy.check('create_env_template', request.context)
try:
LOG.debug('ENV TEMP NAME: {templ_name}>'.format(
templ_name=body['name']))
if not envs_api.VALID_NAME_REGEX.match(str(body['name'])):
msg = _('Environment Template must contain only alphanumeric '
'or "_-." characters, must start with alpha')
LOG.error(msg)
raise exc.HTTPBadRequest(msg)
except Exception:
msg = _('Env template body is incorrect')
LOG.exception(msg)
raise exc.HTTPClientError(msg)
if len(body['name']) > 255:
msg = _('Environment Template name should be 255 characters '
'maximum')
LOG.exception(msg)
raise exc.HTTPBadRequest(explanation=msg)
try:
template = env_temps.EnvTemplateServices.create(
body.copy(), request.context.tenant)
return template.to_dict()
except db_exc.DBDuplicateEntry:
msg = _('Env Template with specified name already exists')
LOG.exception(msg)
raise exc.HTTPConflict(msg)
开发者ID:NikolayStarodubtsev,项目名称:murano,代码行数:35,代码来源:templates.py
示例4: clone
def clone(self, request, env_template_id, body):
"""Clones env template from another tenant
It clones the env template from another env template
from other tenant.
:param request: the operation request.
:param env_template_id: the env template ID.
:param body: the request body.
:return: the description of the created template.
"""
LOG.debug('EnvTemplates:Clone <Env Template {0} for body {1}>'.
format(body, env_template_id))
policy.check('clone_env_template', request.context)
old_env_template = self._validate_exists(env_template_id)
if not old_env_template.get('is_public'):
msg = _LE('User has no access to these resources.')
LOG.error(msg)
raise exc.HTTPForbidden(explanation=msg)
self._validate_body_name(body)
LOG.debug('ENV TEMP NAME: {0}'.format(body['name']))
try:
is_public = body.get('is_public', False)
template = env_temps.EnvTemplateServices.clone(
env_template_id, request.context.tenant, body['name'],
is_public)
except db_exc.DBDuplicateEntry:
msg = _('Environment with specified name already exists')
LOG.error(msg)
raise exc.HTTPConflict(explanation=msg)
return template.to_dict()
开发者ID:AleptNamrata,项目名称:murano,代码行数:35,代码来源:templates.py
示例5: update
def update(self, request, env_template_id, body):
"""It updates the description template
:param request: the operation request.
:param env_template_id: the env template ID.
:param body: the description to be updated
:return: the updated template description.
"""
LOG.debug('Templates:Update <Id: {templ_id}, '
'Body: {body}>'.format(templ_id=env_template_id, body=body))
target = {"env_template_id": env_template_id}
policy.check('update_env_template', request.context, target)
self._validate_request(request, env_template_id)
try:
LOG.debug('ENV TEMP NAME: {temp_name}>'.format(
temp_name=body['name']))
if not str(body['name']).strip():
msg = _('Environment Template must contain at least one '
'non-white space symbol')
LOG.exception(msg)
raise exc.HTTPBadRequest(msg)
except Exception:
msg = _('EnvTemplate body is incorrect')
LOG.exception(msg)
raise exc.HTTPBadRequest(msg)
template = env_temps.EnvTemplateServices.update(env_template_id, body)
return template.to_dict()
开发者ID:AleptNamrata,项目名称:murano,代码行数:29,代码来源:templates.py
示例6: show
def show(self, request, environment_id):
LOG.debug('Environments:Show <Id: {id}>'.format(id=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)
env = environment.to_dict()
env['status'] = envs.EnvironmentServices.get_status(env['id'])
# if env is currently being deployed we can provide information about
# the session right away
env['acquired_by'] = None
if env['status'] == states.EnvironmentStatus.DEPLOYING:
session_list = session_services.SessionServices.get_sessions(
environment_id, state=states.SessionState.DEPLOYING)
if session_list:
env['acquired_by'] = session_list[0].id
session_id = None
if hasattr(request, 'context') and request.context.session:
session_id = request.context.session
if session_id:
env_session = session.query(models.Session).get(session_id)
check_session(request, environment_id, env_session, session_id)
# add services to env
get_data = core_services.CoreServices.get_data
env['services'] = get_data(environment_id, '/services', session_id)
return env
开发者ID:AleptNamrata,项目名称:murano,代码行数:31,代码来源:environments.py
示例7: search
def search(self, req):
def _validate_limit(value):
if value is None:
return
try:
value = int(value)
except ValueError:
msg = _("limit param must be an integer")
LOG.error(msg)
raise exc.HTTPBadRequest(explanation=msg)
if value <= 0:
msg = _("limit param must be positive")
LOG.error(msg)
raise exc.HTTPBadRequest(explanation=msg)
return value
policy.check("search_packages", req.context)
filters = _get_filters(req.GET.items())
limit = _validate_limit(filters.get('limit'))
if limit is None:
limit = CONF.packages_opts.limit_param_default
limit = min(CONF.packages_opts.api_limit_max, limit)
result = {}
packages = db_api.package_search(filters, req.context, limit)
if len(packages) == limit:
result['next_marker'] = packages[-1].id
result['packages'] = [package.to_dict() for package in packages]
return result
开发者ID:OndrejVojta,项目名称:murano,代码行数:32,代码来源:catalog.py
示例8: 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}
开发者ID:sajuptpm,项目名称:murano,代码行数:26,代码来源:actions.py
示例9: update
def update(self, request, environment_id, body):
LOG.debug('Environments:Update <Id: {id}, '
'Body: {body}>'.format(id=environment_id, body=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)
new_name = six.text_type(body['name'])
if new_name.strip():
if len(new_name) > 255:
msg = _('Environment name should be 255 characters maximum')
LOG.error(msg)
raise exc.HTTPBadRequest(explanation=msg)
try:
environment.update(body)
environment.save(session)
except db_exc.DBDuplicateEntry:
msg = _('Environment with specified name already exists')
LOG.error(msg)
raise exc.HTTPConflict(explanation=msg)
else:
msg = _('Environment name must contain at least one '
'non-white space symbol')
LOG.error(msg)
raise exc.HTTPClientError(explanation=msg)
return environment.to_dict()
开发者ID:AleptNamrata,项目名称:murano,代码行数:28,代码来源:environments.py
示例10: 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(_('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.'))
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
开发者ID:alex-docker,项目名称:murano,代码行数:30,代码来源:environments.py
示例11: index
def index(self, request):
"""Lists the env templates associated to an tenant-id
It lists the env templates associated to an tenant-id.
:param request: The operation request.
:return: the env template description list.
"""
LOG.debug('EnvTemplates:List')
policy.check('list_env_templates', request.context)
tenant_id = request.context.tenant
filters = {}
if request.GET.get('is_public'):
is_public = request.GET.get('is_public', 'false').lower() == 'true'
if not is_public:
filters['is_public'] = False
filters['tenant_id'] = tenant_id
elif is_public:
filters['is_public'] = True
list_templates = env_temps.EnvTemplateServices.\
get_env_templates_by(filters)
else:
filters = (EnvironmentTemplate.is_public,
EnvironmentTemplate.tenant_id == tenant_id)
list_templates = env_temps.EnvTemplateServices.\
get_env_templates_or_by(filters)
list_templates = [temp.to_dict() for temp in list_templates]
return {"templates": list_templates}
开发者ID:AleptNamrata,项目名称:murano,代码行数:31,代码来源:templates.py
示例12: statuses
def statuses(self, request, environment_id, deployment_id):
target = {"environment_id": environment_id,
"deployment_id": deployment_id}
policy.check("statuses_deployments", request.context, target)
unit = db_session.get_session()
query = unit.query(models.Status) \
.filter_by(task_id=deployment_id) \
.order_by(models.Status.created)
deployment = verify_and_get_deployment(unit, environment_id,
deployment_id)
if 'service_id' in request.GET:
service_id_set = set(request.GET.getall('service_id'))
environment = deployment.description
entity_ids = []
for service in environment.get('services', []):
if service['?']['id'] in service_id_set:
id_map = utils.build_entity_map(service)
entity_ids = entity_ids + id_map.keys()
if entity_ids:
query = query.filter(models.Status.entity_id.in_(entity_ids))
else:
return {'reports': []}
result = query.all()
return {'reports': [status.to_dict() for status in result]}
开发者ID:alex-docker,项目名称:murano,代码行数:27,代码来源:deployments.py
示例13: 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(_('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.'))
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.exception(msg)
raise exc.HTTPClientError(msg)
return environment.to_dict()
开发者ID:alex-docker,项目名称:murano,代码行数:30,代码来源:environments.py
示例14: upload
def upload(self, req, body=None):
"""Upload new file archive for the new package
together with package metadata.
"""
policy.check("upload_package", req.context)
_check_content_type(req, 'multipart/form-data')
file_obj, package_meta = _validate_body(body)
if package_meta:
try:
jsonschema.validate(package_meta, schemas.PKG_UPLOAD_SCHEMA)
except jsonschema.ValidationError as e:
msg = _("Package schema is not valid: {reason}").format(
reason=e)
LOG.exception(msg)
raise exc.HTTPBadRequest(explanation=msg)
else:
package_meta = {}
if package_meta.get('is_public'):
policy.check('publicize_package', req.context)
with tempfile.NamedTemporaryFile(delete=False) as tempf:
LOG.debug("Storing package archive in a temporary file")
content = file_obj.file.read()
if not content:
msg = _("Uploading file can't be empty")
LOG.error(msg)
raise exc.HTTPBadRequest(explanation=msg)
tempf.write(content)
package_meta['archive'] = content
try:
with load_utils.load_from_file(
tempf.name, target_dir=None,
drop_dir=True) as pkg_to_upload:
# extend dictionary for update db
for k, v in six.iteritems(PKG_PARAMS_MAP):
if hasattr(pkg_to_upload, k):
package_meta[v] = getattr(pkg_to_upload, k)
if len(package_meta['name']) > 80:
msg = _('Package name should be 80 characters maximum')
LOG.error(msg)
raise exc.HTTPBadRequest(explanation=msg)
try:
package = db_api.package_upload(
package_meta, req.context.tenant)
except db_exc.DBDuplicateEntry:
msg = _('Package with specified full '
'name is already registered')
LOG.exception(msg)
raise exc.HTTPConflict(msg)
return package.to_dict()
except pkg_exc.PackageLoadError as e:
msg = _("Couldn't load package from file: {reason}").format(
reason=e)
LOG.exception(msg)
raise exc.HTTPBadRequest(explanation=msg)
finally:
LOG.debug("Deleting package archive temporary file")
os.remove(tempf.name)
开发者ID:GovardhanSN,项目名称:murano,代码行数:60,代码来源:catalog.py
示例15: delete
def delete(self, req, package_id):
target = {'package_id': package_id}
policy.check("delete_package", req.context, target)
package = db_api.package_get(package_id, req.context)
if package.is_public:
policy.check("manage_public_package", req.context, target)
db_api.package_delete(package_id, req.context)
开发者ID:swevm,项目名称:murano,代码行数:8,代码来源:catalog.py
示例16: index
def index(self, request, environment_id):
target = {"environment_id": environment_id}
policy.check("list_deployments", request.context, target)
unit = db_session.get_session()
query = unit.query(models.Task).filter_by(environment_id=environment_id).order_by(desc(models.Task.created))
result = query.all()
deployments = [set_dep_state(deployment, unit).to_dict() for deployment in result]
return {"deployments": deployments}
开发者ID:NeCTAR-RC,项目名称:murano,代码行数:9,代码来源:deployments.py
示例17: delete_category
def delete_category(self, req, category_id):
target = {'category_id': category_id}
policy.check("delete_category", req.context, target)
category = db_api.category_get(category_id, packages=True)
if category.packages:
msg = _("It's impossible to delete categories assigned"
" to the package, uploaded to the catalog")
raise exc.HTTPForbidden(explanation=msg)
db_api.category_delete(category_id)
开发者ID:swevm,项目名称:murano,代码行数:9,代码来源:catalog.py
示例18: delete
def delete(self, request, environment_id):
LOG.debug('Environments:Delete <Id: {0}>'.format(environment_id))
target = {"environment_id": environment_id}
policy.check('delete_environment', request.context, target)
sessions_controller = sessions.Controller()
session = sessions_controller.configure(request, environment_id)
session_id = session['id']
envs.EnvironmentServices.delete(environment_id, session_id)
sessions_controller.deploy(request, environment_id, session_id)
开发者ID:alex-docker,项目名称:murano,代码行数:9,代码来源:environments.py
示例19: get_for_environment
def get_for_environment(self, request, environment_id):
LOG.debug('EnvironmentStatistics:GetForEnvironment')
target = {"environment_id": environment_id}
policy.check("get_statistics", request.context, target)
# TODO (stanlagun): Check that caller is authorized to access
# tenant's statistics
return instances.InstanceStatsServices.get_raw_environment_stats(
environment_id)
开发者ID:ativelkov,项目名称:murano-api,代码行数:10,代码来源:instance_statistics.py
示例20: index
def index(self, request):
LOG.debug('Environments:List')
policy.check('list_environments', request.context)
#Only environments from same tenant as user should be returned
filters = {'tenant_id': request.context.tenant}
environments = envs.EnvironmentServices.get_environments_by(filters)
environments = [env.to_dict() for env in environments]
return {"environments": environments}
开发者ID:alex-docker,项目名称:murano,代码行数:10,代码来源:environments.py
注:本文中的murano.common.policy.check函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论