mirror of
https://github.com/faucetsdn/ryu.git
synced 2026-05-12 00:03:24 +02:00
add host restful api
Signed-off-by: Takeshi <a86487817@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
parent
af63e5f519
commit
c7bf2707df
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user