def on_put(self, req, resp, name):
"""
Handles the creation of a new Network.
: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 name: The friendly name of the network.
:type address: str
"""
try:
req_data = req.stream.read()
req_body = json.loads(req_data.decode())
network_type = req_body['type']
options = req_body.get('options', {})
except (KeyError, ValueError):
self.logger.info(
'Bad client PUT request for network {0}: {1}'.
format(name, req_data))
resp.status = falcon.HTTP_400
return
store_manager = cherrypy.engine.publish('get-store-manager')[0]
# If the type is flannel_etcd yet we have not etcd backend configured
# don't create and notify the caller
if network_type == C.NETWORK_TYPE_FLANNEL_ETCD:
backend_found = False
for handler_type, _, _ in store_manager.list_store_handlers():
if handler_type is EtcdStoreHandler:
backend_found = True
break
if not backend_found:
self.logger.info(
'Network {0} can not be created as type flannel_etcd '
'as no etcd backend is configured.'.format(name))
resp.status = falcon.HTTP_CONFLICT
return
network = Network.new(name=name, type=network_type, options=options)
self.logger.debug('Saving network: {0}'.format(network.to_json()))
store_manager.save(network)
resp.status = falcon.HTTP_CREATED
req.context['model'] = network
评论列表
文章目录