Skip to content

Commit c6b4383

Browse files
author
Ravi Sankar Penta
committed
Added internal bundle() method to ovsExec interface
- bundle() enables execution of given add and/or delete ovs flows in a single atomic transaction
1 parent bb38a8d commit c6b4383

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

pkg/util/ovs/ovs.go

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ovs
22

33
import (
4+
"bytes"
45
"fmt"
56
"strconv"
67
"strings"
@@ -138,16 +139,26 @@ func New(execer exec.Interface, bridge string, minVersion string) (Interface, er
138139
return ovsif, nil
139140
}
140141

141-
func (ovsif *ovsExec) exec(cmd string, args ...string) (string, error) {
142+
func (ovsif *ovsExec) execWithStdin(cmd string, stdinArgs []string, args ...string) (string, error) {
142143
switch cmd {
143144
case OVS_OFCTL:
144145
args = append([]string{"-O", "OpenFlow13"}, args...)
145146
case OVS_VSCTL:
146147
args = append([]string{"--timeout=30"}, args...)
147148
}
148-
glog.V(4).Infof("Executing: %s %s", cmd, strings.Join(args, " "))
149149

150-
output, err := ovsif.execer.Command(cmd, args...).CombinedOutput()
150+
kcmd := ovsif.execer.Command(cmd, args...)
151+
if stdinArgs != nil {
152+
stdinString := strings.Join(stdinArgs, "\n")
153+
stdin := bytes.NewBufferString(stdinString)
154+
kcmd.SetStdin(stdin)
155+
156+
glog.V(4).Infof("Executing: %s %s <<\n%s", cmd, strings.Join(args, " "), stdinString)
157+
} else {
158+
glog.V(4).Infof("Executing: %s %s", cmd, strings.Join(args, " "))
159+
}
160+
161+
output, err := kcmd.CombinedOutput()
151162
if err != nil {
152163
glog.V(2).Infof("Error executing %s: %s", cmd, string(output))
153164
return "", err
@@ -164,6 +175,10 @@ func (ovsif *ovsExec) exec(cmd string, args ...string) (string, error) {
164175
return outStr, nil
165176
}
166177

178+
func (ovsif *ovsExec) exec(cmd string, args ...string) (string, error) {
179+
return ovsif.execWithStdin(cmd, nil, args...)
180+
}
181+
167182
func (ovsif *ovsExec) AddBridge(properties ...string) error {
168183
args := []string{"add-br", ovsif.bridge}
169184
if len(properties) > 0 {
@@ -337,3 +352,13 @@ func (ovsif *ovsExec) DumpFlows(flow string, args ...interface{}) ([]string, err
337352
}
338353
return flows, nil
339354
}
355+
356+
// bundle executes all given flows as a single atomic transaction
357+
func (ovsif *ovsExec) bundle(flows []string) error {
358+
if len(flows) == 0 {
359+
return nil
360+
}
361+
362+
_, err := ovsif.execWithStdin(OVS_OFCTL, flows, "bundle", ovsif.bridge, "-")
363+
return err
364+
}

0 commit comments

Comments
 (0)