Skip to content

Commit b4cac9e

Browse files
committed
Add ovsdb-manipulating methods to pkg/ovs
1 parent 3febe97 commit b4cac9e

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

pkg/util/ovs/ovs.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,45 @@ func (ovsif *Interface) SetFrags(mode string) error {
149149
return err
150150
}
151151

152+
// Create creates a record in the OVS database, as with "ovs-vsctl create" and
153+
// returns the UUID of the newly-created item.
154+
// NOTE: This only works for QoS; for all other tables the created object will
155+
// immediately be garbage-collected; we'd need an API that calls "create" and "set"
156+
// in the same "ovs-vsctl" call.
157+
func (ovsif *Interface) Create(table string, values ...string) (string, error) {
158+
args := append([]string{"create", table}, values...)
159+
return ovsif.exec(OVS_VSCTL, args...)
160+
}
161+
162+
// Destroy deletes the indicated record in the OVS database. It is not an error if
163+
// the record does not exist
164+
func (ovsif *Interface) Destroy(table, record string) error {
165+
_, err := ovsif.exec(OVS_VSCTL, "--if-exists", "destroy", table, record)
166+
return err
167+
}
168+
169+
// Get gets the indicated value from the OVS database. For multi-valued or
170+
// map-valued columns, the data is returned in the same format as "ovs-vsctl get".
171+
func (ovsif *Interface) Get(table, record, column string) (string, error) {
172+
return ovsif.exec(OVS_VSCTL, "get", table, record, column)
173+
}
174+
175+
// Set sets one or more columns on a record in the OVS database, as with
176+
// "ovs-vsctl set"
177+
func (ovsif *Interface) Set(table, record string, values ...string) error {
178+
args := append([]string{"set", table, record}, values...)
179+
_, err := ovsif.exec(OVS_VSCTL, args...)
180+
return err
181+
}
182+
183+
// Clear unsets the indicated columns in the OVS database. It is not an error if
184+
// the value is already unset
185+
func (ovsif *Interface) Clear(table, record string, columns ...string) error {
186+
args := append([]string{"--if-exists", "clear", table, record}, columns...)
187+
_, err := ovsif.exec(OVS_VSCTL, args...)
188+
return err
189+
}
190+
152191
type Transaction struct {
153192
ovsif *Interface
154193
err error

0 commit comments

Comments
 (0)