1
1
package ovs
2
2
3
3
import (
4
+ "bytes"
4
5
"fmt"
5
6
"strconv"
6
7
"strings"
@@ -138,16 +139,26 @@ func New(execer exec.Interface, bridge string, minVersion string) (Interface, er
138
139
return ovsif , nil
139
140
}
140
141
141
- func (ovsif * ovsExec ) exec (cmd string , args ... string ) (string , error ) {
142
+ func (ovsif * ovsExec ) execWithStdin (cmd string , stdinArgs [] string , args ... string ) (string , error ) {
142
143
switch cmd {
143
144
case OVS_OFCTL :
144
145
args = append ([]string {"-O" , "OpenFlow13" }, args ... )
145
146
case OVS_VSCTL :
146
147
args = append ([]string {"--timeout=30" }, args ... )
147
148
}
148
- glog .V (4 ).Infof ("Executing: %s %s" , cmd , strings .Join (args , " " ))
149
149
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 ()
151
162
if err != nil {
152
163
glog .V (2 ).Infof ("Error executing %s: %s" , cmd , string (output ))
153
164
return "" , err
@@ -164,6 +175,10 @@ func (ovsif *ovsExec) exec(cmd string, args ...string) (string, error) {
164
175
return outStr , nil
165
176
}
166
177
178
+ func (ovsif * ovsExec ) exec (cmd string , args ... string ) (string , error ) {
179
+ return ovsif .execWithStdin (cmd , nil , args ... )
180
+ }
181
+
167
182
func (ovsif * ovsExec ) AddBridge (properties ... string ) error {
168
183
args := []string {"add-br" , ovsif .bridge }
169
184
if len (properties ) > 0 {
@@ -337,3 +352,13 @@ func (ovsif *ovsExec) DumpFlows(flow string, args ...interface{}) ([]string, err
337
352
}
338
353
return flows , nil
339
354
}
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