def index(self, title='', text='', state='draft', labels='', limit=10, page=0, **kw): if request.method == 'POST': require_access(c.app, 'write') post = BM.BlogPost.new(title=title, state=state, text=text, labels=labels.split(','), **kw) return exc.HTTPCreated(headers=dict(Location=h.absurl('/rest' + post.url()))) else: result = RootController().index(limit=limit, page=page) posts = result['posts'] post_titles = [] for post in posts: if has_access(post, 'read')(): post_titles.append({ 'title': post.title, 'url': h.absurl('/rest' + post.url()) }) return dict(posts=post_titles, count=result['count'], limit=result['limit'], page=result['page'])
def update(self, req, server_id, id, body): context = req.environ["nova.context"] authorize(context, action='update') self._check_instance_in_valid_state(context, server_id, 'update tag') try: jsonschema.validate(id, schema.tag) except jsonschema.ValidationError as e: msg = (_("Tag '%(tag)s' is invalid. It must be a string without " "characters '/' and ','. Validation error message: " "%(err)s") % { 'tag': id, 'err': e.message }) raise exc.HTTPBadRequest(explanation=msg) try: tags = objects.TagList.get_by_resource_id(context, server_id) except exception.InstanceNotFound as e: raise exc.HTTPNotFound(explanation=e.format_message()) if len(tags) >= objects.instance.MAX_TAG_COUNT: msg = (_("The number of tags exceeded the per-server limit %d") % objects.instance.MAX_TAG_COUNT) raise exc.HTTPBadRequest(explanation=msg) if len(id) > objects.tag.MAX_TAG_LENGTH: msg = (_("Tag '%(tag)s' is too long. Maximum length of a tag " "is %(length)d") % { 'tag': id, 'length': objects.tag.MAX_TAG_LENGTH }) raise exc.HTTPBadRequest(explanation=msg) if id in _get_tags_names(tags): # NOTE(snikitin): server already has specified tag return exc.HTTPNoContent() tag = objects.Tag(context=context, resource_id=server_id, tag=id) try: tag.create() except exception.InstanceNotFound as e: raise exc.HTTPNotFound(explanation=e.format_message()) response = exc.HTTPCreated() response.headers['Location'] = self._view_builder.get_location( req, server_id, id) return response
def create(self, req, body): """ Create a new stack """ data = InstantiationData(body) try: result = self.engine.create_stack(req.context, data.stack_name(), data.template(), data.user_params(), data.args()) except rpc_common.RemoteError as ex: return util.remote_error(ex) raise exc.HTTPCreated(location=util.make_url(req, result))
def create(self, req, body): """ Create a new stack """ data = InstantiationData(body) try: result = self.engine_rpcapi.create_stack(req.context, data.stack_name(), data.template(), data.user_params(), data.args()) except rpc_common.RemoteError as ex: return util.remote_error(ex, True) if 'Description' in result: raise exc.HTTPBadRequest(explanation=result['Description']) raise exc.HTTPCreated(location=util.make_url(req, result))
def create(self, req): """ Create a new stack """ if PARAM_STACK_NAME not in req.params: raise exc.HTTPBadRequest(explanation=_("No stack name specified")) stack_name = req.params[PARAMS_STACK_NAME] stack_params = get_user_params(req) template = get_template(req) args = get_args(req) try: identity = self.engine_rpcapi.create_stack(req.context, stack_name, template, stack_params, args) except rpc_common.RemoteError as ex: return self._remote_error(ex) raise exc.HTTPCreated(location=stack_url(req, identity))
def index(self, title='', text='', state='draft', labels='', limit=10, page=0, **kw): if request.method == 'POST': require_access(c.app, 'write') if BM.BlogPost.is_limit_exceeded(c.app.config, user=c.user): log.warn('Create/edit rate limit exceeded. %s', c.app.config.url()) raise forge_exc.HTTPTooManyRequests() post = BM.BlogPost.new( title=title, state=state, text=text, labels=labels.split(','), **kw) return exc.HTTPCreated(headers=dict(Location=str(h.absurl('/rest' + post.url()).encode('utf-8')))) else: result = RootController().index(limit=limit, page=page) posts = result['posts'] post_titles = [] for post in posts: if has_access(post, 'read')(): post_titles.append( {'title': post.title, 'url': h.absurl('/rest' + post.url())}) return dict(posts=post_titles, count=result['count'], limit=result['limit'], page=result['page'])