summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSatoshi Kobayashi <satoshi-k@stratosphere.co.jp>2014-05-21 09:12:03 +0000
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-05-24 10:52:55 +0900
commitaecc7b0af53c3d8c0136373b254c1b674bcf28ef (patch)
treedaf34dfd728dc7ea407841da176cde5ae9890a3c
parentd91f5e08f7cd63645c4c5e48363add9b2645ccc7 (diff)
rest_topology: use decorator api
Signed-off-by: Satoshi Kobayashi <satoshi-k@stratosphere.co.jp> Reviewed-by: YAMADA Hideki <yamada.hideki@po.ntts.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/app/rest_topology.py74
1 files changed, 34 insertions, 40 deletions
diff --git a/ryu/app/rest_topology.py b/ryu/app/rest_topology.py
index 82a17557..5eed243d 100644
--- a/ryu/app/rest_topology.py
+++ b/ryu/app/rest_topology.py
@@ -16,10 +16,9 @@
import json
from webob import Response
-from ryu.app.wsgi import ControllerBase, WSGIApplication
+from ryu.app.wsgi import ControllerBase, WSGIApplication, route
from ryu.base import app_manager
from ryu.lib import dpid as dpid_lib
-from ryu.lib import port_no as port_no_lib
from ryu.topology.api import get_switch, get_link
# REST API for switch configuration
@@ -40,12 +39,44 @@ from ryu.topology.api import get_switch, get_link
# <dpid>: datapath id in 16 hex
+class TopologyAPI(app_manager.RyuApp):
+ _CONTEXTS = {
+ 'wsgi': WSGIApplication
+ }
+
+ def __init__(self, *args, **kwargs):
+ super(TopologyAPI, self).__init__(*args, **kwargs)
+
+ wsgi = kwargs['wsgi']
+ wsgi.register(TopologyController, {'topology_api_app': self})
+
+
class TopologyController(ControllerBase):
def __init__(self, req, link, data, **config):
super(TopologyController, self).__init__(req, link, data, **config)
self.topology_api_app = data['topology_api_app']
+ @route('topology', '/v1.0/topology/switches',
+ methods=['GET'])
def list_switches(self, req, **kwargs):
+ return self._switches(req, **kwargs)
+
+ @route('topology', '/v1.0/topology/switches/{dpid}',
+ methods=['GET'], requirements={'dpid': dpid_lib.DPID_PATTERN})
+ def get_switch(self, req, **kwargs):
+ return self._switches(req, **kwargs)
+
+ @route('topology', '/v1.0/topology/links',
+ methods=['GET'])
+ def list_links(self, req, **kwargs):
+ return self._links(req, **kwargs)
+
+ @route('topology', '/v1.0/topology/links/{dpid}',
+ methods=['GET'], requirements={'dpid': dpid_lib.DPID_PATTERN})
+ def get_links(self, req, **kwargs):
+ return self._links(req, **kwargs)
+
+ def _switches(self, req, **kwargs):
dpid = None
if 'dpid' in kwargs:
dpid = dpid_lib.str_to_dpid(kwargs['dpid'])
@@ -53,47 +84,10 @@ class TopologyController(ControllerBase):
body = json.dumps([switch.to_dict() for switch in switches])
return Response(content_type='application/json', body=body)
- def list_links(self, req, **kwargs):
+ def _links(self, req, **kwargs):
dpid = None
if 'dpid' in kwargs:
dpid = dpid_lib.str_to_dpid(kwargs['dpid'])
links = get_link(self.topology_api_app, dpid)
body = json.dumps([link.to_dict() for link in links])
return Response(content_type='application/json', body=body)
-
-
-class TopologyAPI(app_manager.RyuApp):
- _CONTEXTS = {
- 'wsgi': WSGIApplication
- }
-
- def __init__(self, *args, **kwargs):
- super(TopologyAPI, self).__init__(*args, **kwargs)
- wsgi = kwargs['wsgi']
- mapper = wsgi.mapper
-
- controller = TopologyController
- wsgi.registory[controller.__name__] = {'topology_api_app': self}
- route_name = 'topology'
-
- uri = '/v1.0/topology/switches'
- mapper.connect(route_name, uri, controller=controller,
- action='list_switches',
- conditions=dict(method=['GET']))
-
- uri = '/v1.0/topology/switches/{dpid}'
- requirements = {'dpid': dpid_lib.DPID_PATTERN}
- s = mapper.submapper(controller=controller, requirements=requirements)
- s.connect(route_name, uri, action='list_switches',
- conditions=dict(method=['GET']))
-
- uri = '/v1.0/topology/links'
- mapper.connect(route_name, uri, controller=controller,
- action='list_links',
- conditions=dict(method=['GET']))
-
- uri = '/v1.0/topology/links/{dpid}'
- requirements = {'dpid': dpid_lib.DPID_PATTERN}
- s = mapper.submapper(controller=controller, requirements=requirements)
- s.connect(route_name, uri, action='list_links',
- conditions=dict(method=['GET']))