本文整理匯總了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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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
示例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"))
示例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'])
示例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)
示例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}
示例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}
示例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}
示例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}