Skip to content

Commit 2535fdc

Browse files
committed
Add ovsdb-manipulating methods to pkg/ovs
1 parent 9b81c8a commit 2535fdc

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
@@ -115,6 +115,45 @@ func (ovsif *Interface) DeletePort(port string) error {
115115
return err
116116
}
117117

118+
// Create creates a record in the OVS database, as with "ovs-vsctl create" and
119+
// returns the UUID of the newly-created item.
120+
// NOTE: This only works for QoS; for all other tables the created object will
121+
// immediately be garbage-collected; we'd need an API that calls "create" and "set"
122+
// in the same "ovs-vsctl" call.
123+
func (ovsif *Interface) Create(table string, values ...string) (string, error) {
124+
args := append([]string{"create", table}, values...)
125+
return ovsif.exec(OVS_VSCTL, args...)
126+
}
127+
128+
// Destroy deletes the indicated record in the OVS database. It is not an error if
129+
// the record does not exist
130+
func (ovsif *Interface) Destroy(table, record string) error {
131+
_, err := ovsif.exec(OVS_VSCTL, "--if-exists", "destroy", table, record)
132+
return err
133+
}
134+
135+
// Get gets the indicated value from the OVS database. For multi-valued or
136+
// map-valued columns, the data is returned in the same format as "ovs-vsctl get".
137+
func (ovsif *Interface) Get(table, record, column string) (string, error) {
138+
return ovsif.exec(OVS_VSCTL, "get", table, record, column)
139+
}
140+
141+
// Set sets one or more columns on a record in the OVS database, as with
142+
// "ovs-vsctl set"
143+
func (ovsif *Interface) Set(table, record string, values ...string) error {
144+
args := append([]string{"set", table, record}, values...)
145+
_, err := ovsif.exec(OVS_VSCTL, args...)
146+
return err
147+
}
148+
149+
// Clear unsets the indicated columns in the OVS database. It is not an error if
150+
// the value is already unset
151+
func (ovsif *Interface) Clear(table, record string, columns ...string) error {
152+
args := append([]string{"--if-exists", "clear", table, record}, columns...)
153+
_, err := ovsif.exec(OVS_VSCTL, args...)
154+
return err
155+
}
156+
118157
type Transaction struct {
119158
ovsif *Interface
120159
err error

0 commit comments

Comments
 (0)