当前位置: 首页>>代码示例>>Python>>正文


Python falcon.HTTP_201属性代码示例

本文整理汇总了Python中falcon.HTTP_201属性的典型用法代码示例。如果您正苦于以下问题:Python falcon.HTTP_201属性的具体用法?Python falcon.HTTP_201怎么用?Python falcon.HTTP_201使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在falcon的用法示例。


在下文中一共展示了falcon.HTTP_201属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: task_validate_design

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_201 [as 别名]
def task_validate_design(self, req, resp, json_data):
        """Create async task for validate design."""
        action = json_data.get('action', None)

        if action != 'validate_design':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_validate_design"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
开发者ID:airshipit,项目名称:drydock,代码行数:24,代码来源:tasks.py

示例2: task_verify_site

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_201 [as 别名]
def task_verify_site(self, req, resp, json_data):
        """Create async task for verify site."""
        action = json_data.get('action', None)

        if action != 'verify_site':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_verify_site"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
开发者ID:airshipit,项目名称:drydock,代码行数:24,代码来源:tasks.py

示例3: task_prepare_site

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_201 [as 别名]
def task_prepare_site(self, req, resp, json_data):
        """Create async task for prepare site."""
        action = json_data.get('action', None)

        if action != 'prepare_site':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_prepare_site"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
开发者ID:airshipit,项目名称:drydock,代码行数:24,代码来源:tasks.py

示例4: task_prepare_nodes

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_201 [as 别名]
def task_prepare_nodes(self, req, resp, json_data):
        """Create async task for prepare node."""
        action = json_data.get('action', None)

        if action != 'prepare_nodes':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_prepare_nodes"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
开发者ID:airshipit,项目名称:drydock,代码行数:24,代码来源:tasks.py

示例5: task_deploy_nodes

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_201 [as 别名]
def task_deploy_nodes(self, req, resp, json_data):
        """Create async task for deploy node."""
        action = json_data.get('action', None)

        if action != 'deploy_nodes':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_deploy_nodes"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
开发者ID:airshipit,项目名称:drydock,代码行数:24,代码来源:tasks.py

示例6: task_destroy_nodes

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_201 [as 别名]
def task_destroy_nodes(self, req, resp, json_data):
        """Create async task for destroy node."""
        action = json_data.get('action', None)

        if action != 'destroy_nodes':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_destroy_nodes"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
开发者ID:airshipit,项目名称:drydock,代码行数:24,代码来源:tasks.py

示例7: task_relabel_nodes

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_201 [as 别名]
def task_relabel_nodes(self, req, resp, json_data):
        """Create async task for relabel nodes."""
        action = json_data.get('action', None)

        if action != 'relabel_nodes':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_relabel_nodes"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
开发者ID:airshipit,项目名称:drydock,代码行数:24,代码来源:tasks.py

示例8: test_create_task

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_201 [as 别名]
def test_create_task(self, falcontest, blank_state):
        url = '/api/v1.0/tasks'

        req_hdr = {
            'Content-Type': 'application/json',
            'X-IDENTITY-STATUS': 'Confirmed',
            'X-USER-NAME': 'Test',
            'X-ROLES': 'admin',
        }

        json_body = json.dumps({
            'action': 'verify_site',
            'design_ref': 'http://foo.com',
        })

        resp = falcontest.simulate_post(url, headers=req_hdr, body=json_body)

        assert resp.status == falcon.HTTP_201
        assert resp.headers.get('Location') is not None

    # TODO(sh8121att) Make this a general fixture in conftest.py 
开发者ID:airshipit,项目名称:drydock,代码行数:23,代码来源:test_api_tasks.py

示例9: on_post

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_201 [as 别名]
def on_post(self, req, resp, cn):
        """
        Sign a certificate signing request
        """
        try:
            cert, buf = self.authority.sign(cn,
                profile=config.PROFILES[req.get_param("profile", default="rw")],
                overwrite=True,
                signer=req.context.get("user").name)
            # Mailing and long poll publishing implemented in the function above
        except EnvironmentError: # no such CSR
            raise falcon.HTTPNotFound()

        resp.body = "Certificate successfully signed"
        resp.status = falcon.HTTP_201
        resp.location = os.path.join(req.relative_uri, "..", "..", "signed", cn)
        logger.info("Signing request %s signed by %s from %s", cn,
            req.context.get("user"), req.context.get("remote_addr")) 
开发者ID:laurivosandi,项目名称:certidude,代码行数:20,代码来源:request.py

示例10: on_post

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_201 [as 别名]
def on_post(self, req, resp, **kwargs):
        """
        Accept an action into shipyard
        """
        # The 'allow-intermediate-commits' query parameter is set to False
        # unless explicitly set to True
        allow_intermediate_commits = (
            req.get_param_as_bool(name='allow-intermediate-commits'))

        input_action = self.req_json(req, validate_json_schema=ACTION)
        action = self.create_action(
            action=input_action,
            context=req.context,
            allow_intermediate_commits=allow_intermediate_commits)

        LOG.info("Id %s generated for action %s", action['id'], action['name'])
        # respond with the action and location for checking status
        resp.status = falcon.HTTP_201
        resp.body = self.to_json(action)
        resp.location = '/api/v1.0/actions/{}'.format(action['id']) 
开发者ID:airshipit,项目名称:shipyard,代码行数:22,代码来源:actions_api.py

示例11: on_post

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_201 [as 别名]
def on_post(self, req, resp):
        """Method handler for POST requests.

        :param req: Falcon request object
        :param resp: Falcon response object
        """
        try:
            json_data = self.req_json(req)
            design = None
            if json_data is not None:
                base_design = json_data.get('base_design_id', None)

                if base_design is not None:
                    base_design = uuid.UUID(base_design)
                    design = hd_objects.SiteDesign(base_design_id=base_design)
            else:
                design = hd_objects.SiteDesign()
            design.assign_id()
            design.create(req.context, self.state_manager)

            resp.body = json.dumps(design.obj_to_simple())
            resp.status = falcon.HTTP_201
        except errors.StateError:
            self.error(req.context, "Error updating persistence")
            self.return_error(
                resp,
                falcon.HTTP_500,
                message="Error updating persistence",
                retry=True)
        except errors.InvalidFormat as fex:
            self.error(req.context, str(fex))
            self.return_error(
                resp, falcon.HTTP_400, message=str(fex), retry=False) 
开发者ID:airshipit,项目名称:drydock,代码行数:35,代码来源:designs.py

示例12: on_post

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_201 [as 别名]
def on_post(self, req, resp):
        # POST /v1/actions    Creates action entry
        doc = self.json_body(req)
        if not doc:
            raise freezer_api_exc.BadDataFormat(
                message='Missing request body')
        user_id = req.get_header('X-User-ID')
        action_id = self.db.add_action(user_id=user_id, doc=doc)
        resp.status = falcon.HTTP_201
        resp.body = {'action_id': action_id} 
开发者ID:openstack,项目名称:freezer-api,代码行数:12,代码来源:actions.py

示例13: on_post

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_201 [as 别名]
def on_post(self, req, resp):
        # POST /v1/sessions    Creates session entry
        doc = self.json_body(req)
        if not doc:
            raise freezer_api_exc.BadDataFormat(
                message='Missing request body')
        user_id = req.get_header('X-User-ID')
        session_id = self.db.add_session(user_id=user_id, doc=doc)
        resp.status = falcon.HTTP_201
        resp.body = {'session_id': session_id} 
开发者ID:openstack,项目名称:freezer-api,代码行数:12,代码来源:sessions.py

示例14: on_post

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_201 [as 别名]
def on_post(self, req, resp):
        # POST /v1/jobs    Creates job entry
        try:
            job = Job(self.json_body(req))
        except KeyError:
            raise freezer_api_exc.BadDataFormat(
                message='Missing request body')

        user_id = req.get_header('X-User-ID')
        self.update_actions_in_job(user_id, job.doc)
        job_id = self.db.add_job(user_id=user_id, doc=job.doc)
        resp.status = falcon.HTTP_201
        resp.body = {'job_id': job_id} 
开发者ID:openstack,项目名称:freezer-api,代码行数:15,代码来源:jobs.py

示例15: on_post

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_201 [as 别名]
def on_post(self, req, resp):
        # POST /v1/backups    Creates backup entry
        doc = self.json_body(req)
        if not doc:
            raise freezer_api_exc.BadDataFormat(
                message='Missing request body')
        user_name = req.get_header('X-User-Name')
        user_id = req.get_header('X-User-ID')
        backup_id = self.db.add_backup(
            user_id=user_id, user_name=user_name, doc=doc)
        resp.status = falcon.HTTP_201
        resp.body = {'backup_id': backup_id} 
开发者ID:openstack,项目名称:freezer-api,代码行数:14,代码来源:backups.py


注:本文中的falcon.HTTP_201属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。