mirror of
https://github.com/faucetsdn/ryu.git
synced 2026-05-08 22:06:10 +02:00
REST Apps: Adopt to Python 3
In Python 3, webob.Request.body is a byte type value and json.loads() cannot parse it, because json.loads() suppose a str type value. This patch fixes to use webob.Request.json to parse request body and avoids this problem. Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
parent
326b46bf6d
commit
c1047818d3
@ -111,7 +111,11 @@ class ConfSwitchController(ControllerBase):
|
||||
|
||||
def set_key(self, req, dpid, key, **_kwargs):
|
||||
def _set_val(dpid, key):
|
||||
val = json.loads(req.body)
|
||||
try:
|
||||
val = req.json if req.body else {}
|
||||
except ValueError:
|
||||
return Response(status=http_client.BAD_REQUEST,
|
||||
body='invalid syntax %s' % req.body)
|
||||
self.conf_switch.set_key(dpid, key, val)
|
||||
return None
|
||||
|
||||
|
||||
@ -492,8 +492,8 @@ class FirewallController(ControllerBase):
|
||||
|
||||
def _set_rule(self, req, switchid, vlan_id=VLANID_NONE):
|
||||
try:
|
||||
rule = json.loads(req.body)
|
||||
except SyntaxError:
|
||||
rule = req.json if req.body else {}
|
||||
except ValueError:
|
||||
FirewallController._LOGGER.debug('invalid syntax %s', req.body)
|
||||
return Response(status=400)
|
||||
|
||||
@ -516,8 +516,8 @@ class FirewallController(ControllerBase):
|
||||
|
||||
def _delete_rule(self, req, switchid, vlan_id=VLANID_NONE):
|
||||
try:
|
||||
ruleid = json.loads(req.body)
|
||||
except SyntaxError:
|
||||
ruleid = req.json if req.body else {}
|
||||
except ValueError:
|
||||
FirewallController._LOGGER.debug('invalid syntax %s', req.body)
|
||||
return Response(status=400)
|
||||
|
||||
|
||||
@ -506,8 +506,8 @@ class QoSController(ControllerBase):
|
||||
|
||||
def _access_switch(self, req, switchid, vlan_id, func, waiters):
|
||||
try:
|
||||
rest = json.loads(req.body) if req.body else {}
|
||||
except SyntaxError:
|
||||
rest = req.json if req.body else {}
|
||||
except ValueError:
|
||||
QoSController._LOGGER.debug('invalid syntax %s', req.body)
|
||||
return Response(status=400)
|
||||
|
||||
|
||||
@ -376,42 +376,45 @@ class RouterController(ControllerBase):
|
||||
@rest_command
|
||||
def get_data(self, req, switch_id, **_kwargs):
|
||||
return self._access_router(switch_id, VLANID_NONE,
|
||||
'get_data', req.body)
|
||||
'get_data', req)
|
||||
|
||||
# GET /router/{switch_id}/{vlan_id}
|
||||
@rest_command
|
||||
def get_vlan_data(self, req, switch_id, vlan_id, **_kwargs):
|
||||
return self._access_router(switch_id, vlan_id,
|
||||
'get_data', req.body)
|
||||
'get_data', req)
|
||||
|
||||
# POST /router/{switch_id}
|
||||
@rest_command
|
||||
def set_data(self, req, switch_id, **_kwargs):
|
||||
return self._access_router(switch_id, VLANID_NONE,
|
||||
'set_data', req.body)
|
||||
'set_data', req)
|
||||
|
||||
# POST /router/{switch_id}/{vlan_id}
|
||||
@rest_command
|
||||
def set_vlan_data(self, req, switch_id, vlan_id, **_kwargs):
|
||||
return self._access_router(switch_id, vlan_id,
|
||||
'set_data', req.body)
|
||||
'set_data', req)
|
||||
|
||||
# DELETE /router/{switch_id}
|
||||
@rest_command
|
||||
def delete_data(self, req, switch_id, **_kwargs):
|
||||
return self._access_router(switch_id, VLANID_NONE,
|
||||
'delete_data', req.body)
|
||||
'delete_data', req)
|
||||
|
||||
# DELETE /router/{switch_id}/{vlan_id}
|
||||
@rest_command
|
||||
def delete_vlan_data(self, req, switch_id, vlan_id, **_kwargs):
|
||||
return self._access_router(switch_id, vlan_id,
|
||||
'delete_data', req.body)
|
||||
'delete_data', req)
|
||||
|
||||
def _access_router(self, switch_id, vlan_id, func, rest_param):
|
||||
def _access_router(self, switch_id, vlan_id, func, req):
|
||||
rest_message = []
|
||||
routers = self._get_router(switch_id)
|
||||
param = json.loads(rest_param) if rest_param else {}
|
||||
try:
|
||||
param = req.json if req.body else {}
|
||||
except ValueError:
|
||||
raise SyntaxError('invalid syntax %s', req.body)
|
||||
for router in routers.values():
|
||||
function = getattr(router, func)
|
||||
data = function(vlan_id, param, self.waiters)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user