Skip to content

Commit 7070551

Browse files
committed
ovsdb: initial example
1 parent b101c8d commit 7070551

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

ovsdb/example_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2017 DigitalOcean.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package ovsdb_test
16+
17+
import (
18+
"context"
19+
"fmt"
20+
"log"
21+
"time"
22+
23+
"github.com/digitalocean/go-openvswitch/ovsdb"
24+
)
25+
26+
// This example demonstrates basic usage of a Client. The Client connects to
27+
// ovsdb-server and requests a list of all databases known to the server.
28+
func ExampleClient_listDatabases() {
29+
// Dial an OVSDB connection and create a *ovsdb.Client.
30+
c, err := ovsdb.Dial("unix", "/var/run/openvswitch/db.sock")
31+
if err != nil {
32+
log.Fatalf("failed to dial: %v", err)
33+
}
34+
// Be sure to close the connection!
35+
defer c.Close()
36+
37+
// Ask ovsdb-server for all of its databases, but only allow the RPC
38+
// a limited amount of time to complete before timing out.
39+
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
40+
defer cancel()
41+
42+
dbs, err := c.ListDatabases(ctx)
43+
if err != nil {
44+
log.Fatalf("failed to list databases: %v", err)
45+
}
46+
47+
for _, d := range dbs {
48+
fmt.Println(d)
49+
}
50+
}

0 commit comments

Comments
 (0)