Skip to content
项目

关于

An OVSDB Client Library written in Golang

开发工具

这些数字如何统计

实测星标增长

24小时
0
7天
0
15天
0
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

libovsdb

libovsdb-ci Coverage Status Go Report Card

An OVSDB client library written in Go.

What is OVSDB?

OVSDB is the Open vSwitch Database Protocol, defined in RFC 7047. It is used primarily to manage the configuration of Open vSwitch and OVN.

Quick Start

1. Define a Model

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

2. Create a Database Model

dbModel, err := model.NewClientDBModel("OVN_Northbound", map[string]model.Model{
    "Logical_Switch": &MyLogicalSwitch{},
})

3. Connect

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

4. Interact with the Database

// 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.

Code Generation

modelgen generates Go model types from an OVSDB schema file, so you don't have to write them by hand. See the modelgen guide.

Container Images

See the container image guide for building the tools and OVS images, supported architectures, and CI/release publishing policies.

Package Documentation

API reference for each sub-package is available on pkg.go.dev:

Package Description
client OVSDB client and API
cache Model-based cache
model Model and database model
ovsdb Low-level OVSDB types
mapper Tagged struct ↔ OVSDB mapping
modelgen Code-generator library
server In-process test server
database Database types and interfaces
updates Model update helpers

Testing

Unit Tests

make test

Integration Tests

Integration tests require Docker with a running OVS container:

make integration-test

To test against a specific OVS version:

OVS_VERSION=v3.4.0 make integration-test

Contributing

See CONTRIBUTING.md.

Contact

The libovsdb community is part of ovn-kubernetes. Find us in the #libovsdb channel on the CNCF Slack server.

探索相关项目

加载中…