Simple RESTFul API for obtaining information from the Docker interface and for enforcing TBF-based (Token Bucket Filter) QoS policies.
pip install -r requeriments.txt
python run.py
Returns all containers with their respective IP and interfaces (veth)
/ifaces
GET
- Code: 200
- Content:
{"e943f949c929": [{"IP": "172.17.0.2", "veth": "veth0167b74"}]}
OR
- Code: 200
- Content:
{}
- Using
curl
$ curl -X GET http://localhost:5000:/ifaces
{
"e943f949c929": [
{
"IP": "172.17.0.2",
"veth": "veth0167b74"
}
]
}
- Using the library
requests
(python)
>> import requests
>> r = requests.get("http://localhost:5000/ifaces")
>> r.text
{
"e943f949c929": [
{
"IP": "172.17.0.2",
"veth": "veth0167b74"
}
]
}
Returns the RX and TX data of the Docker interface.
/stats
GET
None
{
"iface":"<target interface>"
}
- Code: 200
- Content:
{"veth0167b74": {"ID": "e943f949c929", "IP": "172.17.0.2", "rule": {"burst": "4Kb", "latency": "49.9ms", "minburst": "1519b", "peak": "91Kbit", "rate": "90Kbit"}}}
or{}
- Code: 404
- Content:
{"error":"Interface does not exist."}
- Using
curl
$ curl -X GET -d '{"iface":"docker0"}' http://localhost:5000:/stats
{
"RX": "0",
"TX": "8898"
}
- Using the library
requests
(python)
>> import requests
>> r = requests.get("http://localhost:5000/stats", data='{"iface":"docker0"}')
>> r.text
{
"RX": "0",
"TX": "8898"
}
Add, List, or Remove QoS rule from the interface of a given container.
/qos/rules
GET
,POST
and DELETE
None
- if the method is
DELETE
:
{
"veth":"<target interface>",
"user":"<host user (root privileges required)>",
"pass":"<user password>"
}
- if the method is
POST
:
{
"veth":"<target interface>",
"user":"<host user (root privileges required)>",
"pass":"<user password>",
"rate":"<average rate>",
"burst":"<bucket size>",
"latency":"<packet waiting time waiting for tokens>",
"peak":"<peak gust rate>",
"minburst":"<number of bytes counted per packet>"
}
- Method GET
- Code: 200
- Content:
{"veth0167b74": {"ID": "e943f949c929", "IP": "172.17.0.2", "rule": {"burst": "4Kb", "latency": "49.9ms", "minburst": "1519b", "peak": "91Kbit", "rate": "90Kbit"}}}
- Method POST or DELETE
- Code: 200
- Content:
'{"result":"success"}'
- Code: 404
- Content:
{"error":"Interface does not exist."}
OR
- Code: 404
- Content:
{"error":"Rule not applied."}
- Using
curl
$ curl -X GET http://localhost:5000:/qos/rules
{
"veth0167b74": {
"ID": "e943f949c929",
"IP": "172.17.0.2",
"rule": {
"burst": "4Kb",
"latency": "49.9ms",
"minburst": "1519b",
"peak": "91Kbit",
"rate": "90Kbit"
}
}
}
- Using the library
requests
(python)
>> import requests
>> r = requests.get("http://localhost:5000/qos/rules")
>> r.text
{
"veth0167b74": {
"ID": "e943f949c929",
"IP": "172.17.0.2",
"rule": {
"burst": "4Kb",
"latency": "49.9ms",
"minburst": "1519b",
"peak": "91Kbit",
"rate": "90Kbit"
}
}
}
- Using
curl
$ curl -X DELETE -d '{"veth":"veth0167b74","user":"root", "pass":"123"}' http://localhost:5000:/qos/rules
{
"result": "success"
}
- Using the library
requests
(python)
>> import requests
>> r = requests.delete("http://localhost:5000/qos/rules", data='{"veth":"veth0167b74","user":"root", "pass":"123"}')
>> r.text
{
"result": "success"
}
- Using
curl
$ curl -X POST -d '{"veth":"veth0167b74","user":"root", "pass":"123","rate":"90kbit", "burst":"32kbit", "latency":"50ms", "peak":"91kbit", "minburst":"1520"}' http://localhost:5000:/qos/rules
{
"result": "success"
}
- Using the library
requests
(python)
>> import requests
>> r = requests.post("http://localhost:5000/qos/rules", data='{"veth":"veth0167b74","user":"root", "pass":"123","rate":"90kbit", "burst":"32kbit", "latency":"50ms", "peak":"91kbit", "minburst":"1520"}')
>> r.text
{
"result": "success"
}