libovsdb

package module
v0.0.0-...-f9bdc77 Latest Latest
Warning

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

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

README

libovsdb

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

Documentation

Index

Constants

View Source
const (
	SSL  = "ssl"
	TCP  = "tcp"
	UNIX = "unix"
)

Constants defined for libovsdb

View Source
const (
	//Unlimited is used to express unlimited "Max"
	Unlimited int = -1

	//Strong RefType
	Strong RefType = "strong"
	//Weak RefType
	Weak RefType = "weak"

	//TypeInteger is equivalent to 'int'
	TypeInteger ExtendedType = "integer"
	//TypeReal is equivalent to 'float64'
	TypeReal ExtendedType = "real"
	//TypeBoolean is equivalent to 'bool'
	TypeBoolean ExtendedType = "boolean"
	//TypeString is equivalent to 'string'
	TypeString ExtendedType = "string"
	//TypeUUID is equivalent to 'libovsdb.UUID'
	TypeUUID ExtendedType = "uuid"

	//TypeEnum is an enumerator of type defined by Key.Type
	TypeEnum ExtendedType = "enum"
	//TypeMap is a map whose type depend on Key.Type and Value.Type
	TypeMap ExtendedType = "map"
	//TypeSet is a set whose type depend on Key.Type
	TypeSet ExtendedType = "set"
)

Variables

This section is empty.

Functions

func NativeToOvs

func NativeToOvs(column *ColumnSchema, rawElem interface{}) (interface{}, error)

NativeToOvs transforms an native type to a ovs type based on the column type information

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 NewErrNoTable

func NewErrNoTable(table string) error

NewErrNoTable creates a new ErrNoTable

func NewErrWrongType

func NewErrWrongType(from, expected string, got interface{}) error

NewErrWrongType creates a new ErrWrongType

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

func OvsToNative

func OvsToNative(column *ColumnSchema, ovsElem interface{}) (interface{}, error)

OvsToNative transforms an ovs type to native one based on the column type information

Types

type BaseType

type BaseType struct {
	Type string `json:"type"`
	// Enum will be parsed manually and set to a slice
	// of possible values. They must be type-asserted to the
	// corret type depending on the Type field
	Enum       []interface{} `json:"_"`
	MinReal    float64       `json:"minReal,omitempty"`
	MaxReal    float64       `json:"maxReal,omitempty"`
	MinInteger int           `json:"minInteger,omitempty"`
	MaxInteger int           `json:"maxInteger,omitempty"`
	MinLength  int           `json:"minLength,omitempty"`
	MaxLength  int           `json:"maxLength,omitempty"`
	RefTable   string        `json:"refTable,omitempty"`
	RefType    RefType       `json:"refType,omitempty"`
}

BaseType is a base-type structure as per RFC7047

type ColumnSchema

type ColumnSchema struct {
	// According to RFC7047, "type" field can be, either an <atomic-type>
	// Or a ColumnTypeObject defined below. To try to simplify the usage, the
	// json message will be parsed manually and Type will indicate the "extended"
	// type. Depending on its value, more information may be available in TypeObj.
	// E.g: If Type == TypeEnum, TypeObj.Key.Enum contains the possible values
	Type      ExtendedType
	TypeObj   *ColumnType
	Ephemeral bool
	Mutable   bool
}

ColumnSchema is a column schema according to RFC7047

func (*ColumnSchema) String

func (column *ColumnSchema) String() string

String returns a string representation of the (native) column type

func (*ColumnSchema) UnmarshalJSON

func (column *ColumnSchema) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshalls a json-formatted column

type ColumnType

type ColumnType struct {
	Key   *BaseType
	Value *BaseType
	Min   int
	// Unlimited is expressed by the const value Unlimited (-1)
	Max int
}

ColumnType is a type object as per RFC7047

type Config

type Config struct {
	Addr      string
	TLSConfig *tls.Config
}

Config is a structure used in provisioning a connection to ovsdb.

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) GetColumn

func (schema DatabaseSchema) GetColumn(tableName, columnName string) (*ColumnSchema, error)

GetColumn returns a Column Schema for a given table and column name

func (DatabaseSchema) Print

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

Print will print the contents of the DatabaseSchema

type ErrNoTable

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

ErrNoTable describes a error in the provided table information

func (*ErrNoTable) Error

func (e *ErrNoTable) Error() string

type ErrWrongType

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

ErrWrongType describes typing error

func (*ErrWrongType) Error

func (e *ErrWrongType) Error() string

type ExtendedType

type ExtendedType = string

ExtendedType includes atomic types as defined in the RFC plus Enum, Map and Set

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"`
}

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 NativeAPI

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

NativeAPI is an API that offers functions to interact with libovsdb without having to handle it's internal objects. It uses a DatabaseSchema to infer the type of each value and make translations. OvsMaps are translated to go maps with specific key and values. I.e instead of

having to deal with map[interface{}][interface{}], the user will be able to
user  map[string] string (or whatever native type can hold the column value)

OvsSets will be translated to slices

OvsUUID are translated to and from strings If the column type is an enum, the native type associated with the underlying enum type is used (e.g: string or int) Also, type checkings are done. E.g: if you try to put an integer in a column that has type string, the API will refuse to create the Ovs object for you

func NewNativeAPI

func NewNativeAPI(schema *DatabaseSchema) NativeAPI

NewNativeAPI returns a NativeAPI

func (NativeAPI) GetData

func (na NativeAPI) GetData(tableName string, ovsData map[string]interface{}) (map[string]interface{}, error)

GetData transforms a map[string]interface{} containing OvS types (e.g: a ResultRow has this format) to native. The result object must be given as pointer to map[string] interface{}

func (NativeAPI) GetRowData

func (na NativeAPI) GetRowData(tableName string, row *Row) (map[string]interface{}, error)

GetRowData transforms a Row to a native type data map[string] interface{}

func (NativeAPI) NewCondition

func (na NativeAPI) NewCondition(tableName, columnName, function string, value interface{}) ([]interface{}, error)

NewCondition returns a valid condition to be used inside a Operation It accepts native golang types (sets and maps) TODO: check condition validity

func (NativeAPI) NewMutation

func (na NativeAPI) NewMutation(tableName, columnName, mutator string, value interface{}) ([]interface{}, error)

NewMutation returns a valid mutation to be used inside a Operation It accepts native golang types (sets and maps) TODO: check mutator validity

func (NativeAPI) NewRow

func (na NativeAPI) NewRow(tableName string, data interface{}) (map[string]interface{}, error)

NewRow creates a libovsdb Row from the input data data shall not contain libovsdb-specific types (except UUID)

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    []ResultRow `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(obj interface{}) (*OvsSet, error)

NewOvsSet creates a new OVSDB style set from a Go interface (object)

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
	Apis   map[string]NativeAPI
	// contains filtered or unexported fields
}

OvsdbClient is an OVSDB client

func Connect

func Connect(endpoints string, tlsConfig *tls.Config) (*OvsdbClient, error)

Connect to ovn, using endpoint in format ovsdb Connection Methods If address is empty, use default address for specified protocol

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) MonitorCancel

func (ovs OvsdbClient) MonitorCancel(jsonContext interface{}) error

MonitorCancel will request cancel a previously issued monitor request RFC 7047 : monitor_cancel

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 RefType

type RefType = string

RefType is used to define the possible RefTypes

type ResultRow

type ResultRow map[string]interface{}

ResultRow is an properly unmarshalled row returned by Transact

func (*ResultRow) UnmarshalJSON

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

UnmarshalJSON unmarshalls a byte array to an OVSDB Row

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 {
	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"`
}

TableUpdate represents a table update according to RFC7047

type TableUpdates

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

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
example

Jump to

Keyboard shortcuts

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