Add two restful api
/v1.0/topology/hosts
Sample result:
[
    {
        "port": {
            "hw_addr": "ca:a6:4a:60:a4:c7",
            "name": "s2-eth1",
            "port_no": "00000001",
            "dpid": "0000000000000002"
        },
        "mac": "00:00:00:00:00:02",
        "ipv4": [
            "10.0.0.2"
        ],
        "ipv6": [
            "fe80::200:ff:fe00:2"
        ]
    },
    {
        "port": {
            "hw_addr": "26:27:64:d8:ca:2a",
            "name": "s1-eth1",
            "port_no": "00000001",
            "dpid": "0000000000000001"
        },
        "mac": "00:00:00:00:00:01",
        "ipv4": [
            "10.0.0.1"
        ],
        "ipv6": [
            "fe80::200:ff:fe00:1"
        ]
    }
]

/v1.0/topology/hosts/{dpid}
Sample result(dpid = 0000000000000001):
[
    {
        "port": {
            "hw_addr": "26:27:64:d8:ca:2a",
            "name": "s1-eth1",
            "port_no": "00000001",
            "dpid": "0000000000000001"
        },
        "mac": "00:00:00:00:00:01",
        "ipv4": [
            "10.0.0.1"
        ],
        "ipv6": [
            "fe80::200:ff:fe00:1"
        ]
    }
]


-- 
Yi Tseng (a.k.a Takeshi)
Taiwan National Chiao Tung University
Department of Computer Science
W2CNLab
From 1a2d49a8c42c369306e8d97af7e8ba7d7608dfcc Mon Sep 17 00:00:00 2001
From: Takeshi <[email protected]>
Date: Thu, 16 Jul 2015 19:25:00 +0800
Subject: [PATCH 2/2] add host restful api

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)

------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to