An OVSDB client library written in Go.
OVSDB is the Open vSwitch Database Protocol, defined in RFC 7047. It is used primarily to manage the configuration of Open vSwitch and OVN.
Models are tagged Go structs that map to OVSDB tables:
type MyLogicalSwitch struct {
UUID string `ovsdb:"_uuid"` // required
Name string `ovsdb:"name"`
Ports []string `ovsdb:"ports"`
Config map[string]string `ovsdb:"other_config"`
}OVSDB types map to Go types as follows:
| OVSDB type | Go type |
|---|---|
| Set (min 0, max unlimited) | Slice |
| Set (min 0, max 1) | Pointer to scalar |
| Set (min 0, max N) | Array of N |
| Enum | Type-aliased string |
| Map | Map |
| Scalar | Equivalent Go scalar |
dbModel, err := model.NewClientDBModel("OVN_Northbound", map[string]model.Model{
"Logical_Switch": &MyLogicalSwitch{},
})ovs, err := client.NewOVSDBClient(dbModel, client.WithEndpoint("tcp:172.18.0.4:6641"))
if err != nil { ... }
err = ovs.Connect(context.Background())
err = ovs.MonitorAll(context.Background()) // required for cache-based operations// List all rows
var switches []MyLogicalSwitch
err = ovs.List(context.Background(), &switches)
// Create
ops, err := ovs.Create(&MyLogicalSwitch{Name: "foo"})
_, err = ovs.Transact(context.Background(), ops...)
// Get by index
ls := &MyLogicalSwitch{Name: "foo"}
err = ovs.Get(context.Background(), ls)
// Update
ls.Config["key"] = "value"
ops, err = ovs.Where(ls).Update(ls)
_, err = ovs.Transact(context.Background(), ops...)
// Delete
ops, err = ovs.Where(ls).Delete()
_, err = ovs.Transact(context.Background(), ops...)For the full API — conditional queries (Where, WhereAny, WhereAll, WhereCache),
client-defined indexes, Select, and cache event handlers — see the API guide.
modelgen generates Go model types from an OVSDB schema file, so you don't have to
write them by hand. See the modelgen guide.
API reference for each sub-package is available on pkg.go.dev:
make testIntegration tests require Docker with a running OVS container:
make integration-testTo test against a specific OVS version:
OVS_VERSION=v3.4.0 make integration-testSee CONTRIBUTING.md.
The libovsdb community is part of ovn-kubernetes. Find us in the #libovsdb channel on the CNCF Slack server.