|
This page is currently under construction. You can edit the article to help completing it. |
|
This page is currently under construction. You can edit the article to help completing it. |
The code can be found via git at git://nbd.name/luci2/libubox.git or via http at http://nbd.name/gitweb.cgi .
The ubus command line client allows to interact with the ubusd rpc server, below is an explanation of its commands.
By default, list all namespaces registered with the RPC server:
root@uplink:~# ubus list network network.device network.interface.lan network.interface.loopback network.interface.wan root@uplink:~#
If invoked with -v, additionally the procedures and their argument signatures are dumped in addition to the namespace path:
root@uplink:~# ubus -v list network.interface.lan
'network.interface.lan' @099f0c8b
"up": { }
"down": { }
"status": { }
"prepare": { }
"add_device": { "name": "String" }
"remove_device": { "name": "String" }
"notify_proto": { }
"remove": { }
"set_data": { }
root@uplink:~#
Calls a given procedure within a given namespace and passes given message to it:
root@uplink:~# ubus call network.interface.wan status
{
"up": true,
"pending": false,
"available": true,
"autostart": true,
"uptime": 86017,
"l3_device": "eth1",
"device": "eth1",
"address": [
{
"address": "178.25.65.236",
"mask": 21
}
],
"route": [
{
"target": "0.0.0.0",
"mask": 0,
"nexthop": "178.25.71.254"
}
],
"data": {
}
}
root@uplink:~#
The message argument must be a valid JSON string, with keys and values set according to the function signature:
root@uplink:~# ubus call network.device status '{ "name": "eth0" }'
{
"type": "Network device",
"up": true,
"link": true,
"mtu": 1500,
"macaddr": "c6:3d:c7:90:aa:da",
"txqueuelen": 1000,
"statistics": {
"collisions": 0,
"rx_frame_errors": 0,
"tx_compressed": 0,
"multicast": 0,
"rx_length_errors": 0,
"tx_dropped": 0,
"rx_bytes": 0,
"rx_missed_errors": 0,
"tx_errors": 0,
"rx_compressed": 0,
"rx_over_errors": 0,
"tx_fifo_errors": 0,
"rx_crc_errors": 0,
"rx_packets": 0,
"tx_heartbeat_errors": 0,
"rx_dropped": 0,
"tx_aborted_errors": 0,
"tx_packets": 184546,
"rx_errors": 0,
"tx_bytes": 17409452,
"tx_window_errors": 0,
"rx_fifo_errors": 0,
"tx_carrier_errors": 0
}
}
root@uplink:~#
Setup a listening socket and observe incoming events:
root@uplink:~# ubus listen &
root@uplink:~# ubus call network.interface.wan down
{ "network.interface": { "action": "ifdown", "interface": "wan" } }
root@uplink:~# ubus call network.interface.wan up
{ "network.interface": { "action": "ifup", "interface": "wan" } }
{ "network.interface": { "action": "ifdown", "interface": "he" } }
{ "network.interface": { "action": "ifdown", "interface": "v6" } }
{ "network.interface": { "action": "ifup", "interface": "he" } }
{ "network.interface": { "action": "ifup", "interface": "v6" } }
root@uplink:~#
Send an event notification:
root@uplink:~# ubus listen &
root@uplink:~# ubus send foo '{ "bar": "baz" }'
{ "foo": { "bar": "baz" } }
root@uplink:~#
The package libubus-lua implements a simple Lua binding to the libubus library to allow for easy client connections.
require "ubus"
local conn = ubus.connect()
if not conn then
error("Failed to connect to ubusd")
end
local namespaces = conn:objects()
for i, n in ipairs(namespaces) do
print("namespace=" .. n)
local signatures = conn:signatures(n)
for p, s in pairs(signatures) do
print("\tprocedure=" .. p)
for k, v in pairs(s) do
print("\t\tattribute=" .. k .. " type=" .. v)
end
end
end
local status = conn:call("network.device", "status", { name = "eth0" })
for k, v in pairs(status) do
print("key=" .. k .. " value=" .. tostring(v))
end
conn:close()
| Path | Procedure | Signature | Description |
|---|---|---|---|
network |
restart |
{ } |
Restart the network, reconfigures all interfaces |
network |
reload |
{ } |
Reload the network, reconfigure as needed |
network.device |
status |
{ "name": "ifname" } |
Dump status of given network device ifname |
network.device |
set_state |
{ "name": "ifname", "defer": deferred } |
Defer or ready the given network device ifname, depending on the boolean value deferred |
network.interface.name |
up |
{ } |
Bring interface name up |
network.interface.name |
down |
{ } |
Bring interface name down |
network.interface.name |
status |
{ } |
Dump status of interface name |
network.interface.name |
prepare |
{ } |
Prepare setup of interface name |
network.interface.name |
add_device |
{ "name": "ifname" } |
Add network device ifname to interface name (e.g. for bridges: brctl addif br-name ifname) |
network.interface.name |
remove_device |
{ "name": "ifname" } |
Remove network device ifname from interface name (e.g. for bridges: brctl delif br-name ifname) |
network.interface.name |
remove |
{ } |
Remove interface name (?) |
| Path | Procedure | Signature | Description |
|---|---|---|---|
session |
list |
{ "session": "sid" } |
Dump session specified by sid, if no ID is given, dump all sessions |
session |
create |
{ "timeout": timeout } |
Create a new session and return its ID, set the session timeout to timeout |
session |
grant |
{ "session": "sid",
"objects": [ [ "path", "func" ], … ] } |
Within the session identified by sid grant access to all specified procedures func in the namespace path listed in the objects array |
session |
revoke |
{ "session": "sid",
"objects": [ [ "path", "func" ], … ] } |
Within the session identified by sid revoke access to all specified procedures func in the namespace path listed in the objects array. If objects is unset, revoke all access |
session |
set |
{ "session": "sid",
"values": { "key": value, … } } |
Within the session identified by sid store the given arbitrary values under their corresponding keys specified in the values object |
session |
get |
{ "session": "sid",
"keys": [ "key", … ] } |
Within the session identified by sid retrieve all values associated with the given keys listed in the keys array. If the key array is unset, dump all key/value pairs |
session |
unset |
{ "session": "sid",
"keys": [ "key", … ] } |
Within the session identified by sid unset all keys listed in the keys array. If the key list is unset, clear all keys |
session |
extend |
{ "session": "sid" } |
Within the session identified by sid reset inactivity timeout counter |
session |
destroy |
{ "session": "sid" } |
Terminate the session identified by the given ID sid |
| Path | Procedure | Signature | Description |
|---|---|---|---|
uci |
get |
{ "package": "package",
"section": "sname",
"type": "type",
"option": "oname" } |
Return the requested uci value(s), all arguments are optional.
Return messages:
|
uci |
set |
{ "package": "package",
"section": "sname",
"option": "oname",
"value": "value" } |
Set the given value(s), the option argument is optional.
The call does not produce any data, instead it returns with the following status codes:
|
uci |
add |
{ "package": "package",
"type": "type" } |
Add new anonymous section of given type.
Return message:
|
uci |
delete |
{ "package": "package",
"section": "sname",
"type": "type",
"option": "oname" } |
Delete the given value(s) or section(s), the option and type arguments are optional.
The call does not result in any data, instead it returns the following status codes:
|
doc/techref/ubus.txt · Last modified: 2013/05/11 20:15 by jaseg