libovsdb

package module
v0.0.0-...-56bc700 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

README

libovsdb

Circle CI Coverage Status

An OVSDB Library written in Go

What is OVSDB?

OVSDB is the Open vSwitch Database Protocol. It's defined in RFC 7047 It's used mainly for managing the configuration of Open vSwitch, but it could also be used to manage your stamp collection. Philatelists Rejoice!

## Running the tests

To run integration tests, you'll need access to docker to run an Open vSwitch container. Mac users can use boot2docker

export DOCKER_IP=$(boot2docker ip)

docker-compose run test /bin/sh
# make test-local
...
# exit
docker-compose down

By invoking the command make, you will automatically get the same behaviour as what is shown above. In other words, it will start the two containers and execute make test-local from the test container.

Dependency Management

We use godep for dependency management with rewritten import paths. This allows the repo to be go getable.

To bump the version of a dependency, follow these instructions

Documentation

Index

Constants

View Source
const DefaultAddress = "127.0.0.1"

DefaultAddress is the default IPV4 address that is used for a connection

View Source
const DefaultPort = 6640

DefaultPort is the default port used for a connection

Variables

This section is empty.

Functions

func NewCancelArgs

func NewCancelArgs(id interface{}) []interface{}

NewCancelArgs creates a new set of arguments for a cancel RPC

func NewCondition

func NewCondition(column string, function string, value interface{}) []interface{}

NewCondition creates a new condition as specified in RFC7047

func NewGetSchemaArgs

func NewGetSchemaArgs(schema string) []interface{}

NewGetSchemaArgs creates a new set of arguments for a get_schemas RPC

func NewLockArgs

func NewLockArgs(id interface{}) []interface{}

NewLockArgs creates a new set of arguments for a lock, steal or unlock RPC

func NewMonitorArgs

func NewMonitorArgs(database string, value interface{}, requests map[string]MonitorRequest) []interface{}

NewMonitorArgs creates a new set of arguments for a monitor RPC

func NewMonitorCancelArgs

func NewMonitorCancelArgs(value interface{}) []interface{}

NewMonitorCancelArgs creates a new set of arguments for a monitor_cancel RPC

func NewMutation

func NewMutation(column string, mutator string, value interface{}) []interface{}

NewMutation creates a new mutation as specified in RFC7047

func NewTransactArgs

func NewTransactArgs(database string, operations ...Operation) []interface{}

NewTransactArgs creates a new set of arguments for a transact RPC

Types

type ColumnSchema

type ColumnSchema struct {
	Name      string      `json:"name"`
	Type      interface{} `json:"type"`
	Ephemeral bool        `json:"ephemeral,omitempty"`
	Mutable   bool        `json:"mutable,omitempty"`
}

ColumnSchema is a column schema according to RFC7047

type DatabaseSchema

type DatabaseSchema struct {
	Name    string                 `json:"name"`
	Version string                 `json:"version"`
	Tables  map[string]TableSchema `json:"tables"`
}

DatabaseSchema is a database schema according to RFC7047

func (DatabaseSchema) Print

func (schema DatabaseSchema) Print(w io.Writer)

Print will print the contents of the DatabaseSchema

type MonitorRequest

type MonitorRequest struct {
	Columns []string      `json:"columns,omitempty"`
	Select  MonitorSelect `json:"select,omitempty"`
}

MonitorRequest represents a monitor request according to RFC7047

type MonitorRequests

type MonitorRequests struct {
	Requests map[string]MonitorRequest `json:"requests,overflow"`
}

MonitorRequests represents a group of monitor requests according to RFC7047 We cannot use MonitorRequests by inlining the MonitorRequest Map structure till GoLang issue #6213 makes it. The only option is to go with raw map[string]interface{} option :-( that sucks ! Refer to client.go : MonitorAll() function for more details

type MonitorSelect

type MonitorSelect struct {
	Initial bool `json:"initial,omitempty"`
	Insert  bool `json:"insert,omitempty"`
	Delete  bool `json:"delete,omitempty"`
	Modify  bool `json:"modify,omitempty"`
}

MonitorSelect represents a monitor select according to RFC7047

type NotificationHandler

type NotificationHandler interface {
	// RFC 7047 section 4.1.6 Update Notification
	Update(context interface{}, tableUpdates TableUpdates)

	// RFC 7047 section 4.1.9 Locked Notification
	Locked([]interface{})

	// RFC 7047 section 4.1.10 Stolen Notification
	Stolen([]interface{})

	// RFC 7047 section 4.1.11 Echo Notification
	Echo([]interface{})

	Disconnected(*OvsdbClient)
}

NotificationHandler is the interface that must be implemented to receive notifcations

type Operation

type Operation struct {
	Op        string                   `json:"op"`
	Table     string                   `json:"table"`
	Row       map[string]interface{}   `json:"row,omitempty"`
	Rows      []map[string]interface{} `json:"rows,omitempty"`
	Columns   []string                 `json:"columns,omitempty"`
	Mutations []interface{}            `json:"mutations,omitempty"`
	Timeout   int                      `json:"timeout,omitempty"`
	Where     []interface{}            `json:"where,omitempty"`
	Until     string                   `json:"until,omitempty"`
	UUIDName  string                   `json:"uuid-name,omitempty"`
}

Operation represents an operation according to RFC7047 section 5.2

func (Operation) MarshalJSON

func (o Operation) MarshalJSON() ([]byte, error)

MarshalJSON marshalls 'Operation' to a byte array For 'select' operations, we dont omit the 'Where' field to allow selecting all rows of a table

type OperationResult

type OperationResult struct {
	Count   int                      `json:"count,omitempty"`
	Error   string                   `json:"error,omitempty"`
	Details string                   `json:"details,omitempty"`
	UUID    UUID                     `json:"uuid,omitempty"`
	Rows    []map[string]interface{} `json:"rows,omitempty"`
}

OperationResult is the result of an Operation

type OvsMap

type OvsMap struct {
	GoMap map[interface{}]interface{}
}

OvsMap is the JSON map structure used for OVSDB RFC 7047 uses the following notation for map as JSON doesnt support non-string keys for maps. A 2-element JSON array that represents a database map value. The first element of the array must be the string "map", and the second element must be an array of zero or more <pair>s giving the values in the map. All of the <pair>s must have the same key and value types.

func NewOvsMap

func NewOvsMap(goMap interface{}) (*OvsMap, error)

NewOvsMap will return an OVSDB style map from a provided Golang Map

func (OvsMap) MarshalJSON

func (o OvsMap) MarshalJSON() ([]byte, error)

MarshalJSON marshalls an OVSDB style Map to a byte array

func (*OvsMap) UnmarshalJSON

func (o *OvsMap) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON unmarshalls an OVSDB style Map from a byte array

type OvsSet

type OvsSet struct {
	GoSet []interface{}
}

OvsSet is an OVSDB style set RFC 7047 has a wierd (but understandable) notation for set as described as : Either an <atom>, representing a set with exactly one element, or a 2-element JSON array that represents a database set value. The first element of the array must be the string "set", and the second element must be an array of zero or more <atom>s giving the values in the set. All of the <atom>s must have the same type.

func NewOvsSet

func NewOvsSet(goSlice interface{}) (*OvsSet, error)

NewOvsSet creates a new OVSDB style set from a Go slice

func (OvsSet) MarshalJSON

func (o OvsSet) MarshalJSON() ([]byte, error)

MarshalJSON wil marshal an OVSDB style set in to a JSON byte array

func (*OvsSet) UnmarshalJSON

func (o *OvsSet) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON will unmarshal a JSON byte array to an OVSDB style set

type OvsdbClient

type OvsdbClient struct {
	Schema map[string]DatabaseSchema
	// contains filtered or unexported fields
}

OvsdbClient is an OVSDB client

func Connect

func Connect(ipAddr string, port int) (*OvsdbClient, error)

Connect creates an OVSDB connection and returns and OvsdbClient

func ConnectUsingProtocol

func ConnectUsingProtocol(protocol string, target string) (*OvsdbClient, error)

ConnectUsingProtocol creates an OVSDB connection and returns and OvsdbClient

func ConnectWithUnixSocket

func ConnectWithUnixSocket(socketFile string) (*OvsdbClient, error)

ConnectWithUnixSocket makes a OVSDB Connection via a Unix Socket

func (OvsdbClient) Disconnect

func (ovs OvsdbClient) Disconnect()

Disconnect will close the OVSDB connection

func (OvsdbClient) GetSchema

func (ovs OvsdbClient) GetSchema(dbName string) (*DatabaseSchema, error)

GetSchema returns the schema in use for the provided database name RFC 7047 : get_schema

func (OvsdbClient) ListDbs

func (ovs OvsdbClient) ListDbs() ([]string, error)

ListDbs returns the list of databases on the server RFC 7047 : list_dbs

func (OvsdbClient) Monitor

func (ovs OvsdbClient) Monitor(database string, jsonContext interface{}, requests map[string]MonitorRequest) (*TableUpdates, error)

Monitor will provide updates for a given table/column RFC 7047 : monitor

func (OvsdbClient) MonitorAll

func (ovs OvsdbClient) MonitorAll(database string, jsonContext interface{}) (*TableUpdates, error)

MonitorAll is a convenience method to monitor every table/column

func (*OvsdbClient) Register

func (ovs *OvsdbClient) Register(handler NotificationHandler)

Register registers the supplied NotificationHandler to recieve OVSDB Notifications

func (OvsdbClient) Transact

func (ovs OvsdbClient) Transact(database string, operation ...Operation) ([]OperationResult, error)

Transact performs the provided Operation's on the database RFC 7047 : transact

func (*OvsdbClient) Unregister

func (ovs *OvsdbClient) Unregister(handler NotificationHandler) error

Unregister the supplied NotificationHandler to not recieve OVSDB Notifications anymore

type OvsdbError

type OvsdbError struct {
	Error   string `json:"error"`
	Details string `json:"details,omitempty"`
}

OvsdbError is an OVS Error Condition

type Row

type Row struct {
	Fields map[string]interface{}
}

Row is a table Row according to RFC7047

func (*Row) UnmarshalJSON

func (r *Row) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON unmarshalls a byte array to an OVSDB Row

type RowUpdate

type RowUpdate struct {
	UUID UUID `json:"-,omitempty"`
	New  Row  `json:"new,omitempty"`
	Old  Row  `json:"old,omitempty"`
}

RowUpdate represents a row update according to RFC7047

type TableSchema

type TableSchema struct {
	Columns map[string]ColumnSchema `json:"columns"`
	Indexes [][]string              `json:"indexes,omitempty"`
}

TableSchema is a table schema according to RFC7047

type TableUpdate

type TableUpdate struct {
	Rows map[string]RowUpdate `json:"rows,overflow"`
}

TableUpdate represents a table update according to RFC7047

type TableUpdates

type TableUpdates struct {
	Updates map[string]TableUpdate `json:"updates,overflow"`
}

TableUpdates is a collection of TableUpdate entries We cannot use TableUpdates directly by json encoding by inlining the TableUpdate Map structure till GoLang issue #6213 makes it. The only option is to go with raw map[string]map[string]interface{} option :-( that sucks ! Refer to client.go : MonitorAll() function for more details

type TransactResponse

type TransactResponse struct {
	Result []OperationResult `json:"result"`
	Error  string            `json:"error"`
}

TransactResponse represents the response to a Transact Operation

type UUID

type UUID struct {
	GoUUID string `json:"uuid"`
}

UUID is a UUID according to RFC7047

func (UUID) MarshalJSON

func (u UUID) MarshalJSON() ([]byte, error)

MarshalJSON will marshal an OVSDB style UUID to a JSON encoded byte array

func (*UUID) UnmarshalJSON

func (u *UUID) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON will unmarshal a JSON encoded byte array to a OVSDB style UUID

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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