networks.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:commissaire-mvp 作者: projectatomic 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号