From 3de2404d92c1d4afb65d1db872c50e942ad0537a Mon Sep 17 00:00:00 2001 From: Taku Fukushima Date: Wed, 22 Jul 2015 17:10:43 +0900 Subject: [PATCH] Add constants This patch adds constants.py and separate the shared response data from controllers. Change-Id: Ia64eca2591e6617265debfa664e647f81edba416 Signed-off-by: Taku Fukushima --- kuryr/constants.py | 51 ++++++++++++++++++++++++++++++++++++++++++++ kuryr/controllers.py | 49 +++++++++--------------------------------- 2 files changed, 61 insertions(+), 39 deletions(-) create mode 100644 kuryr/constants.py diff --git a/kuryr/constants.py b/kuryr/constants.py new file mode 100644 index 00000000..a81d216b --- /dev/null +++ b/kuryr/constants.py @@ -0,0 +1,51 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +TYPES = { + # NEXTHOP indicates a StaticRoute with an IP next hop. + "NEXTHOP": 0, + # CONNECTED indicates a StaticRoute with a interface for directly connected + # peers. + "CONNECTED": 1 +} + +SCHEMA = { + "PLUGIN_ACTIVATE": {"Implements": ["NetworkDriver"]}, + # TODO(tfukushima): This is mocked and should be replaced with real data. + "CREATE_ENDPOINT": { + "Interfaces": [{ + "ID": 1, + "Address": "192.168.1.42/24", + "AddressIPv6": "fe80::f816:3eff:fe20:57c3/64", + "MacAddress": "fa:16:3e:20:57:c3", + }] + }, + # TODO(tfukushima): This is mocked and should be replaced with real data. + "ENDPOINT_OPER_INFO": {"Value": {}}, + # TODO(tfukushima): This is mocked and should be replaced with real data. + "JOIN": { + "InterfaceNames": [{ + "SrcName": "foobar", + "DstPrefix": "" + }], + "Gateway": "192.168.1.1/24", + "GatewayIPv6": "fe80::f816:3eff:fe20:57c1/64", + "StaticRoutes": [{ + "Destination": "192.168.1.42", + "RouteType": TYPES['CONNECTED'], + "NextHop": "", + "InterfaceID": 0 + }] + }, + "SUCCESS": {} +} diff --git a/kuryr/controllers.py b/kuryr/controllers.py index 26cba3ab..01f17514 100644 --- a/kuryr/controllers.py +++ b/kuryr/controllers.py @@ -13,73 +13,44 @@ from flask import jsonify from kuryr import app - - -# NEXTHOP indicates a StaticRoute with an IP next hop. -NEXTHOP = 0 -# CONNECTED indicates a StaticRoute with a interface for directly connected -# peers. -CONNECTED = 1 +from kuryr.constants import SCHEMA @app.route('/Plugin.Activate', methods=['POST']) -def plubin_activate(): - return jsonify({"Implements": ["NetworkDriver"]}) +def plugin_activate(): + return jsonify(SCHEMA['PLUGIN_ACTIVATE']) @app.route('/NetworkDriver.CreateNetwork', methods=['POST']) def network_driver_create_network(): - return jsonify({}) + return jsonify(SCHEMA['SUCCESS']) @app.route('/NetworkDriver.DeleteNetwork', methods=['POST']) def network_driver_delete_network(): - return jsonify({}) + return jsonify(SCHEMA['SUCCESS']) @app.route('/NetworkDriver.CreateEndpoint', methods=['POST']) def network_driver_create_endpoint(): - # TODO(tfukushima): This is mocked and should be replaced with real data. - return jsonify({ - "Interfaces": [{ - "ID": 1, - "Address": "192.168.1.42/24", - "AddressIPv6": "fe80::f816:3eff:fe20:57c3/64", - "MacAddress": "fa:16:3e:20:57:c3", - }] - }) + return jsonify(SCHEMA['CREATE_ENDPOINT']) @app.route('/NetworkDriver.EndpointOperInfo', methods=['POST']) def network_driver_endpoint_operational_info(): - # TODO(tfukushima): This is mocked and should be replaced with real data. - return jsonify({"Value": {}}) + return jsonify(SCHEMA['ENDPOINT_OPER_INFO']) @app.route('/NetworkDriver.DeleteEndpoint', methods=['POST']) def network_driver_delete_endpoint(): - return jsonify({}) + return jsonify(SCHEMA['SUCCESS']) @app.route('/NetworkDriver.Join', methods=['POST']) def network_driver_join(): - # TODO(tfukushima): This is mocked and should be replaced with real data. - return jsonify({ - "InterfaceNames": [{ - "SrcName": "foobar", - "DstPrefix": "" - }], - "Gateway": "192.168.1.1/24", - "GatewayIPv6": "fe80::f816:3eff:fe20:57c1/64", - "StaticRoutes": [{ - "Destination": "192.168.1.42", - "RouteType": CONNECTED, - "NextHop": "", - "InterfaceID": 0 - }] - }) + return jsonify(SCHEMA['JOIN']) @app.route('/NetworkDriver.Leave', methods=['POST']) def network_driver_leave(): - return jsonify({}) + return jsonify(SCHEMA['SUCCESS'])