Please ignore previous patch, because I forgot to check coding style with
pep8, here is the new patch


Signed-off-by: Takeshi <[email protected]>
---
 ryu/app/rest_topology.py | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/ryu/app/rest_topology.py b/ryu/app/rest_topology.py
index 5eed243..77cfc37 100644
--- a/ryu/app/rest_topology.py
+++ b/ryu/app/rest_topology.py
@@ -19,7 +19,7 @@ from webob import Response
 from ryu.app.wsgi import ControllerBase, WSGIApplication, route
 from ryu.base import app_manager
 from ryu.lib import dpid as dpid_lib
-from ryu.topology.api import get_switch, get_link
+from ryu.topology.api import get_switch, get_link, get_host

 # REST API for switch configuration
 #
@@ -76,6 +76,16 @@ class TopologyController(ControllerBase):
     def get_links(self, req, **kwargs):
         return self._links(req, **kwargs)

+    @route('topology', '/v1.0/topology/hosts',
+           methods=['GET'])
+    def list_hosts(self, req, **kwargs):
+        return self._hosts(req, **kwargs)
+
+    @route('topology', '/v1.0/topology/hosts/{dpid}',
+           methods=['GET'], requirements={'dpid': dpid_lib.DPID_PATTERN})
+    def get_hosts(self, req, **kwargs):
+        return self._hosts(req, **kwargs)
+
     def _switches(self, req, **kwargs):
         dpid = None
         if 'dpid' in kwargs:
@@ -91,3 +101,11 @@ class TopologyController(ControllerBase):
         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)
+
+    def _hosts(self, req, **kwargs):
+        dpid = None
+        if 'dpid' in kwargs:
+            dpid = dpid_lib.str_to_dpid(kwargs['dpid'])
+        hosts = get_host(self.topology_api_app, dpid)
+        body = json.dumps([host.to_dict() for host in hosts])
+        return Response(content_type='application/json', body=body)
-- 
2.3.2 (Apple Git-55)



2015-06-11 2:30 GMT+08:00 Yi Tseng <[email protected]>:

> Signed-off-by: Takeshi <[email protected]>
> ---
>  ryu/app/rest_topology.py | 22 +++++++++++++++++++++-
>  1 file changed, 21 insertions(+), 1 deletion(-)
>
> diff --git a/ryu/app/rest_topology.py b/ryu/app/rest_topology.py
> index 5eed243..9cc2485 100644
> --- a/ryu/app/rest_topology.py
> +++ b/ryu/app/rest_topology.py
> @@ -19,7 +19,7 @@ from webob import Response
>  from ryu.app.wsgi import ControllerBase, WSGIApplication, route
>  from ryu.base import app_manager
>  from ryu.lib import dpid as dpid_lib
> -from ryu.topology.api import get_switch, get_link
> +from ryu.topology.api import get_switch, get_link, get_host
>
>  # REST API for switch configuration
>  #
> @@ -76,6 +76,16 @@ class TopologyController(ControllerBase):
>      def get_links(self, req, **kwargs):
>          return self._links(req, **kwargs)
>
> +    @route('topology', '/v1.0/topology/hosts',
> +           methods=['GET'])
> +    def list_hosts(self, req, **kwargs):
> +        return self._hosts(req, **kwargs)
> +
> +    @route('topology', '/v1.0/topology/hosts/{dpid}',
> +           methods=['GET'], requirements={'dpid': dpid_lib.DPID_PATTERN})
> +    def get_hosts(self, req, **kwargs):
> +        return self._hosts(req, **kwargs)
> +
>      def _switches(self, req, **kwargs):
>          dpid = None
>          if 'dpid' in kwargs:
> @@ -91,3 +101,13 @@ class TopologyController(ControllerBase):
>          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)
> +
> +    def _hosts(self, req, **kwargs):
> +        dpid = None
> +        if 'dpid' in kwargs:
> +            dpid = dpid_lib.str_to_dpid(kwargs['dpid'])
> +        hosts = get_host(self.topology_api_app, dpid)
> +        body = json.dumps([host.to_dict() for host in hosts])
> +        return Response(content_type='application/json', body=body)
> +
> +
> --
> 2.3.2 (Apple Git-55)
>
>
> --
> Yi Tseng (a.k.a Takeshi)
> Taiwan National Chiao Tung University
> Department of Computer Science
> W2CNLab
>



-- 
Yi Tseng (a.k.a Takeshi)
Taiwan National Chiao Tung University
Department of Computer Science
W2CNLab
------------------------------------------------------------------------------
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to