ovsdb

package
v0.0.0-...-1b8d500 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

README

ovsdb

Package ovsdb implements an OVSDB client, as described in RFC 7047.

Package ovsdb allows you to communicate with an instance of ovsdb-server using the OVSDB protocol.

// Dial an OVSDB connection and create a *ovsdb.Client.
c, err := ovsdb.Dial("unix", "/var/run/openvswitch/db.sock")
if err != nil {
	log.Fatalf("failed to dial: %v", err)
}
// Be sure to close the connection!
defer c.Close()

// Ask ovsdb-server for all of its databases, but only allow the RPC
// a limited amount of time to complete before timing out.
ctx, cancel := context.WithTimeout(context.Background(), 2 * time.Second)
defer cancel()

dbs, err := c.ListDatabases(ctx)
if err != nil {
	log.Fatalf("failed to list databases: %v", err)
}

for _, d := range dbs {
	log.Println(d)
}

Documentation

Overview

Package ovsdb implements an OVSDB client, as described in RFC 7047.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

A Client is an OVSDB client. Clients can be customized by using OptionFuncs in the Dial and New functions.

All methods on the Client that accept a context.Context can use the context to cancel or time out requests. Some methods may use the context for advanced use cases. If this is the case, the documentation for the method will explain these use cases.

Example (ListDatabases)

This example demonstrates basic usage of a Client. The Client connects to ovsdb-server and requests a list of all databases known to the server.

package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/digitalocean/go-openvswitch/ovsdb"
)

func main() {
	// Dial an OVSDB connection and create a *ovsdb.Client.
	c, err := ovsdb.Dial("unix", "/var/run/openvswitch/db.sock")
	if err != nil {
		log.Fatalf("failed to dial: %v", err)
	}
	// Be sure to close the connection!
	defer c.Close()

	// Ask ovsdb-server for all of its databases, but only allow the RPC
	// a limited amount of time to complete before timing out.
	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
	defer cancel()

	dbs, err := c.ListDatabases(ctx)
	if err != nil {
		log.Fatalf("failed to list databases: %v", err)
	}

	for _, d := range dbs {
		fmt.Println(d)
	}
}
Output:

func Dial

func Dial(network, addr string, options ...OptionFunc) (*Client, error)

Dial dials a connection to an OVSDB server and returns a Client.

func New

func New(conn net.Conn, options ...OptionFunc) (*Client, error)

New wraps an existing connection to an OVSDB server and returns a Client.

func (*Client) Close

func (c *Client) Close() error

Close closes a Client's connection and cleans up its resources.

func (*Client) Echo

func (c *Client) Echo(ctx context.Context) error

Echo verifies that the OVSDB connection is alive, and can be used to keep the connection alive.

func (*Client) ListDatabases

func (c *Client) ListDatabases(ctx context.Context) ([]string, error)

ListDatabases returns the name of all databases known to the OVSDB server.

func (*Client) Stats

func (c *Client) Stats() ClientStats

Stats returns a ClientStats with current statistics for the Client.

func (*Client) Transact

func (c *Client) Transact(ctx context.Context, db string, ops []TransactOp) ([]Row, error)

Transact creates and executes a transaction on the specified database. Each operation is applied in the order they appear in ops.

type ClientStats

type ClientStats struct {
	// Statistics about the Client's internal callbacks.
	Callbacks struct {
		// The number of callback hooks currently registered and waiting
		// for RPC responses.
		Current int
	}

	// Statistics about the Client's internal echo RPC loop.
	EchoLoop struct {
		// The number of successful and failed echo RPCs in the loop.
		Success, Failure int
	}
}

ClientStats contains statistics about a Client.

type Cond

type Cond struct {
	Column, Function, Value string
}

A Cond is a conditional expression which is evaluated by the OVSDB server in a transaction.

func Equal

func Equal(column, value string) Cond

Equal creates a Cond that ensures a column's value equals the specified value.

func (Cond) MarshalJSON

func (c Cond) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

type Error

type Error struct {
	Err     string `json:"error"`
	Details string `json:"details"`
	Syntax  string `json:"syntax"`
}

An Error is an error returned by an OVSDB server. Its fields can be used to determine the cause of an error.

func (*Error) Error

func (e *Error) Error() string

type OptionFunc

type OptionFunc func(c *Client) error

An OptionFunc is a function which can configure a Client.

func Debug

func Debug(ll *log.Logger) OptionFunc

Debug enables debug logging for a Client.

func EchoInterval

func EchoInterval(d time.Duration) OptionFunc

EchoInterval specifies an interval at which the Client will send echo RPCs to an OVSDB server to keep the connection alive. Note that the OVSDB server may also send its own echo RPCs to the Client, and the Client will always reply to those on behalf of the user.

If this option is not used, the Client will only send echo RPCs when the server sends an echo RPC to it.

Specify a duration of 0 to disable sending background echo RPCs at a fixed interval.

type Row

type Row map[string]interface{}

A Row is a database row. Its keys are database column names, and its values are database column values.

type Select

type Select struct {
	// The name of the table to select from.
	Table string

	// Zero or more Conds for conditional select.
	Where []Cond
}

Select is a TransactOp which fetches information from a database.

func (Select) MarshalJSON

func (s Select) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

type TransactOp

type TransactOp interface {
	json.Marshaler
}

A TransactOp is an operation that can be applied with Client.Transact.

Directories

Path Synopsis
internal
jsonrpc
Package jsonrpc is a minimal JSON-RPC 1.0 implementation.
Package jsonrpc is a minimal JSON-RPC 1.0 implementation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL