luci-base: switch luci.model.network to common ubus api
Replaces the ubus calls in luci.model.network with the common api from luci.util. Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
This commit is contained in:
parent
199c8cbc4c
commit
c159d28091
1 changed files with 11 additions and 13 deletions
|
@ -1,7 +1,7 @@
|
||||||
--[[
|
--[[
|
||||||
LuCI - Network model
|
LuCI - Network model
|
||||||
|
|
||||||
Copyright 2009-2010 Jo-Philipp Wich <xm@subsignal.org>
|
Copyright 2009-2015 Jo-Philipp Wich <jow@openwrt.org>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -24,7 +24,6 @@ local tonumber, tostring, math = tonumber, tostring, math
|
||||||
|
|
||||||
local require = require
|
local require = require
|
||||||
|
|
||||||
local bus = require "ubus"
|
|
||||||
local nxo = require "nixio"
|
local nxo = require "nixio"
|
||||||
local nfs = require "nixio.fs"
|
local nfs = require "nixio.fs"
|
||||||
local ipc = require "luci.ip"
|
local ipc = require "luci.ip"
|
||||||
|
@ -47,7 +46,7 @@ protocol = utl.class()
|
||||||
local _protocols = { }
|
local _protocols = { }
|
||||||
|
|
||||||
local _interfaces, _bridge, _switch, _tunnel
|
local _interfaces, _bridge, _switch, _tunnel
|
||||||
local _ubus, _ubusnetcache, _ubusdevcache, _ubuswificache
|
local _ubusnetcache, _ubusdevcache, _ubuswificache
|
||||||
local _uci_real, _uci_state
|
local _uci_real, _uci_state
|
||||||
|
|
||||||
function _filter(c, s, o, r)
|
function _filter(c, s, o, r)
|
||||||
|
@ -138,7 +137,7 @@ function _wifi_state(key, val, field)
|
||||||
local radio, radiostate, ifc, ifcstate
|
local radio, radiostate, ifc, ifcstate
|
||||||
|
|
||||||
if not next(_ubuswificache) then
|
if not next(_ubuswificache) then
|
||||||
_ubuswificache = _ubus:call("network.wireless", "status", {}) or {}
|
_ubuswificache = utl.ubus("network.wireless", "status", {}) or {}
|
||||||
|
|
||||||
-- workaround extended section format
|
-- workaround extended section format
|
||||||
for radio, radiostate in pairs(_ubuswificache) do
|
for radio, radiostate in pairs(_ubuswificache) do
|
||||||
|
@ -230,7 +229,6 @@ function init(cursor)
|
||||||
_switch = { }
|
_switch = { }
|
||||||
_tunnel = { }
|
_tunnel = { }
|
||||||
|
|
||||||
_ubus = bus.connect()
|
|
||||||
_ubusnetcache = { }
|
_ubusnetcache = { }
|
||||||
_ubusdevcache = { }
|
_ubusdevcache = { }
|
||||||
_ubuswificache = { }
|
_ubuswificache = { }
|
||||||
|
@ -637,10 +635,10 @@ end
|
||||||
|
|
||||||
function get_status_by_route(self, addr, mask)
|
function get_status_by_route(self, addr, mask)
|
||||||
local _, object
|
local _, object
|
||||||
for _, object in ipairs(_ubus:objects()) do
|
for _, object in ipairs(utl.ubus()) do
|
||||||
local net = object:match("^network%.interface%.(.+)")
|
local net = object:match("^network%.interface%.(.+)")
|
||||||
if net then
|
if net then
|
||||||
local s = _ubus:call(object, "status", {})
|
local s = utl.ubus(object, "status", {})
|
||||||
if s and s.route then
|
if s and s.route then
|
||||||
local rt
|
local rt
|
||||||
for _, rt in ipairs(s.route) do
|
for _, rt in ipairs(s.route) do
|
||||||
|
@ -655,10 +653,10 @@ end
|
||||||
|
|
||||||
function get_status_by_address(self, addr)
|
function get_status_by_address(self, addr)
|
||||||
local _, object
|
local _, object
|
||||||
for _, object in ipairs(_ubus:objects()) do
|
for _, object in ipairs(utl.ubus()) do
|
||||||
local net = object:match("^network%.interface%.(.+)")
|
local net = object:match("^network%.interface%.(.+)")
|
||||||
if net then
|
if net then
|
||||||
local s = _ubus:call(object, "status", {})
|
local s = utl.ubus(object, "status", {})
|
||||||
if s and s['ipv4-address'] then
|
if s and s['ipv4-address'] then
|
||||||
local a
|
local a
|
||||||
for _, a in ipairs(s['ipv4-address']) do
|
for _, a in ipairs(s['ipv4-address']) do
|
||||||
|
@ -722,8 +720,8 @@ end
|
||||||
|
|
||||||
function protocol._ubus(self, field)
|
function protocol._ubus(self, field)
|
||||||
if not _ubusnetcache[self.sid] then
|
if not _ubusnetcache[self.sid] then
|
||||||
_ubusnetcache[self.sid] = _ubus:call("network.interface.%s" % self.sid,
|
_ubusnetcache[self.sid] = utl.ubus("network.interface.%s" % self.sid,
|
||||||
"status", { })
|
"status", { })
|
||||||
end
|
end
|
||||||
if _ubusnetcache[self.sid] and field then
|
if _ubusnetcache[self.sid] and field then
|
||||||
return _ubusnetcache[self.sid][field]
|
return _ubusnetcache[self.sid][field]
|
||||||
|
@ -1070,8 +1068,8 @@ end
|
||||||
|
|
||||||
function interface._ubus(self, field)
|
function interface._ubus(self, field)
|
||||||
if not _ubusdevcache[self.ifname] then
|
if not _ubusdevcache[self.ifname] then
|
||||||
_ubusdevcache[self.ifname] = _ubus:call("network.device", "status",
|
_ubusdevcache[self.ifname] = utl.ubus("network.device", "status",
|
||||||
{ name = self.ifname })
|
{ name = self.ifname })
|
||||||
end
|
end
|
||||||
if _ubusdevcache[self.ifname] and field then
|
if _ubusdevcache[self.ifname] and field then
|
||||||
return _ubusdevcache[self.ifname][field]
|
return _ubusdevcache[self.ifname][field]
|
||||||
|
|
Loading…
Reference in a new issue