def on_put(self, req, resp, address):
"""
Handles the creation of a new Host.
:param req: Request instance that will be passed through.
:type req: falcon.Request
:param resp: Response instance that will be passed through.
:type resp: falcon.Response
:param address: The address of the Host being requested.
:type address: str
"""
try:
# Extract what we need from the input data.
# Don't treat it as a skeletal host record.
req_data = req.stream.read()
req_body = json.loads(req_data.decode())
ssh_priv_key = req_body['ssh_priv_key']
# Remote user is optional.
remote_user = req_body.get('remote_user', 'root')
# Cluster member is optional.
cluster_name = req_body.get('cluster', None)
except (KeyError, ValueError):
self.logger.info(
'Bad client PUT request for host {0}: {1}'.
format(address, req_data))
resp.status = falcon.HTTP_400
return
resp.status, host_model = util.etcd_host_create(
address, ssh_priv_key, remote_user, cluster_name)
req.context['model'] = host_model
评论列表
文章目录