plugins/traffic-control: added clear setting control

This control remove any previous setting
This commit is contained in:
Alessandro Puccetti
2016-08-12 18:19:03 +02:00
parent 6eefb70628
commit 5d3e5b23ec
2 changed files with 24 additions and 3 deletions

View File

@@ -266,6 +266,17 @@ func getControls() []extControl {
return DoTrafficControl(pid, "1ms")
},
},
{
control: control{
ID: "clear",
Human: "Clear traffic control settings",
Icon: "fa-times-circle",
Rank: 23,
},
handler: func(pid int) error {
return DoTrafficControl(pid, "")
},
},
}
}

View File

@@ -29,9 +29,14 @@ func DoTrafficControl(pid int, latency string) error {
// bandwidth. See the TODO at the beginning of the
// file.
split(fmt.Sprintf("tc qdisc change dev eth0 root handle 1: netem delay %s", latency)),
}
netNS := fmt.Sprintf("/proc/%d/ns/net", pid)
if latency != "" {
cmds = append(cmds, split(fmt.Sprintf("tc qdisc change dev eth0 root handle 1: netem delay %s", latency)))
} else {
cmds = append(cmds, split("tc qdisc change dev eth0 root handle 1: netem"))
}
netNS := fmt.Sprintf("/proc/%d/ns/net", pid)
err := ns.WithNetNSPath(netNS, func(hostNS ns.NetNS) error {
for _, cmd := range cmds {
if output, err := exec.Command(cmd[0], cmd[1:]...).CombinedOutput(); err != nil {
@@ -50,7 +55,12 @@ func DoTrafficControl(pid int, latency string) error {
return fmt.Errorf("failed to get network namespace ID: %v", err)
} else {
trafficControlStatusCache[netNSID] = trafficControlStatus{
latency: latency,
latency: func(latency string) string {
if latency == "" {
return "-"
}
return latency
}(latency),
pktLoss: "-",
}
}