ovsdb

package module
v0.0.0-...-1e0a063 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2018 License: BSD-2-Clause Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-ovsdb

CircleCI

A golang package to manipulate OVSDB(implementation of RFC 7047)

Documentation

Index

Constants

View Source
const (
	SelectInitial = "initial"
	SelectInsert  = "insert"
	SelectDelete  = "delete"
	SelectModify  = "modify"
)

Supported SelectTypes

Variables

This section is empty.

Functions

This section is empty.

Types

type Atomic

type Atomic interface{}

Atomic is a scalar value for a column <atom> A JSON value that represents a scalar value for a column, one of <string>, <number>, <boolean>, <uuid>, or <named-uuid>. FIXME: define more concrete type instead of interface{}

type AtomicOrJSONBaseType

type AtomicOrJSONBaseType struct {
	IsAtomic bool
	Atomic   AtomicType
	JSON     JSONBaseType
}

AtomicOrJSONBaseType is the type of a key or value in a database column. Either an <atomic-type> or a JSON object

func (*AtomicOrJSONBaseType) UnmarshalJSON

func (atomjson *AtomicOrJSONBaseType) UnmarshalJSON(value []byte) error

UnmarshalJSON implements json.Unmarshaler

type AtomicOrJSONColumnType

type AtomicOrJSONColumnType struct {
	IsAtomic bool
	Atomic   AtomicType
	JSON     JSONColumnType
}

AtomicOrJSONColumnType is the type of a database column. Either an <atomic-type> or a JSON object that describes the type of a database column

func (*AtomicOrJSONColumnType) UnmarshalJSON

func (atomjson *AtomicOrJSONColumnType) UnmarshalJSON(value []byte) error

UnmarshalJSON implements json.Unmarshaler

type AtomicType

type AtomicType string

AtomicType is one of the strings "integer", "real", "boolean", "string", or "uuid", representing the specified scalar type.

type Client

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

Client is a OVSDB client

func Dial

func Dial(address string) (*Client, error)

Dial create a ovsdb.Client and connect to OVSDB server at address

func (*Client) GetSchema

func (c *Client) GetSchema(db ID) (*DatabaseSchema, error)

GetSchema get the schema of a OVSDB database

func (*Client) ListDbs

func (c *Client) ListDbs() ([]ID, error)

ListDbs list databases in the connected OVSDB server

func (*Client) Lock

func (c *Client) Lock(lockID ID) (bool, error)

Lock acquire a lock named lockID from OVSDB server

func (*Client) Monitor

func (c *Client) Monitor(db ID, jsonValue Value, requests MonitorRequests) (TableUpdates, error)

Monitor enables a client to replicate tables or subsets of tables within an OVSDB database by requesting notifications of changes to those tables and by receiving the complete initial state of a table or a subset of a table

func (*Client) MonitorCancel

func (c *Client) MonitorCancel(jsonValue Value) error

MonitorCancel cancels a previously issued monitor request

func (*Client) SetNotificationHandler

func (c *Client) SetNotificationHandler(handler NotificationHandler)

SetNotificationHandler set handler as the notification handler FIXME: not thread-safe

func (*Client) Steal

func (c *Client) Steal(lockID ID) error

Steal acquire a lock named lockID from OVSDB server. If there is an existing owner, it loses ownership.

func (*Client) Transact

func (c *Client) Transact(db ID, ops ...Operation) (*TransactResult, error)

Transact do operations as a transact on OVSDB https://tools.ietf.org/html/rfc7047#section-4.1.3

func (*Client) Unlock

func (c *Client) Unlock(lockID ID) error

Unlock release a lock named lockID

type ColumnSchema

type ColumnSchema struct {
	// Type specifies the type of data stored in this column
	Type AtomicOrJSONColumnType `json:"type"`
	// Ephemeral if specified as true, then this column's values are not guaranteed to be durable
	Ephemeral bool `json:"ephemeral,omitempty"`
	// Mutable if specified as false, then this column's values may not be modified after they are initially set with the "insert" operation
	Mutable bool `json:"mutable,omitempty"`
}

ColumnSchema represents the schema of a column in table

func (*ColumnSchema) UnmarshalJSON

func (cs *ColumnSchema) UnmarshalJSON(value []byte) error

UnmarshalJSON implements json.Unmarshaler OVSDB has a wired default value of mutable, so need a custom json unmarshal function to set this default value

type ColumnSet

type ColumnSet []string

ColumnSet is an array of one or more strings,each of which names a column. Each Columnset is a set of columns whose values, taken together within any given row, must be unique within the table

type Condition

type Condition struct {
	Column   ID
	Function Function
	Value    Value
}

Condition is a 3-element JSON array of the form [<column>, <function>, <value>] that represents a test on a column value.

func (Condition) MarshalJSON

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

MarshalJSON implements json.Marshaler interface

func (Condition) Valid

func (c Condition) Valid() bool

Valid returns true if condition is valid, otherwise false

type DatabaseSchema

type DatabaseSchema struct {
	// Name identifies the database as a whole
	Name ID `json:"name"`
	// Version reports the version of the database schema
	Version Version `json:"version"`
	// Checksum optionally reports an implementation-defined checksum for the database schema
	Checksum string `json:"cksum,omitempty"`
	// Tables is a JSON object whose names are table names and whose values are <table-schema>s.
	Tables map[ID]*TableSchema `json:"tables"`
}

DatabaseSchema represents the schema of a ovsdb database

func (*DatabaseSchema) Dump

func (dbSchema *DatabaseSchema) Dump(w io.Writer)

Dump writes the schema of the DatabaseSchema to io.Writer

type DeleteOperation

type DeleteOperation struct {
	Table ID
	Where []Condition
}

DeleteOperation deletes all the rows from Table that match all the conditions specified in Where The corresponding result object contains the following member: "count": <integer>

func (DeleteOperation) MarshalJSON

func (d DeleteOperation) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface

func (*DeleteOperation) Op

Op implements Operation interface

type DeleteResult

type DeleteResult struct {
	Count int `json:"count"`
}

DeleteResult represents the result of a DeleteOperation in Transact method results

type Error

type Error struct {
	// Error is a short string that broadly indicates the class of the error
	Err string `json:"error"`
	// Details is a string that describes the error in more detail for the benefit of a human user or administrator
	Details string `json:"details,omitempty"`
}

Error is a struct to represents a ovsdb error

func (*Error) Error

func (err *Error) Error() string

Error implements error interface

type Function

type Function string

Function is the condition operator It is one of "<", "<=", "==", "!=", ">=", ">", "includes", or "excludes" and supported mutators depend on the type of column

const (
	FuncLt  Function = "<"
	FuncLe  Function = "<="
	FuncEq  Function = "=="
	FuncNe  Function = "!="
	FuncGt  Function = ">"
	FuncGe  Function = ">="
	FuncInc Function = "includes"
	FuncExc Function = "excludes"
)

Functions supported in Condition

type ID

type ID string

ID is a JSON string matching [a-zA-Z_][a-zA-Z0-9_]*. <id>s that begin with _ are reserved to the implementation and MUST NOT be used by the user.

type InsertOperation

type InsertOperation struct {
	Table    ID
	Row      Row
	UUIDName ID
}

InsertOperation insert Row into Table The corresponding result object contains the following member: "uuid": <uuid>

func (InsertOperation) MarshalJSON

func (insert InsertOperation) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface

func (*InsertOperation) Op

func (insert *InsertOperation) Op() OperationType

Op implements Operation interface

type InsertResult

type InsertResult struct {
	UUID UUID `json:"uuid"`
}

InsertResult represents the result of a InsertOperation in Transact method results

type IntOrString

type IntOrString struct {
	IsInt bool
	Int   int
	Str   string
}

IntOrString is a type that can hold an int or a string. When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type. This allows you to have, for example, a JSON field that can accept a name or number.

func (*IntOrString) UnmarshalJSON

func (intstr *IntOrString) UnmarshalJSON(value []byte) error

UnmarshalJSON implements the json.Unmarshaller interface.

type JSONBaseType

type JSONBaseType struct {
	Type       AtomicType `json:"type"`
	Enum       Set        `json:"enum,omitempty"`
	MinInteger int        `json:"minInteger,omitempty"`
	MaxInteger int        `json:"maxInteger,omitempty"`
	MinReal    float64    `json:"minReal,omitempty"`
	MaxReal    float64    `json:"maxReal,omitempty"`
	MinLength  int        `json:"minLength,omitempty"`
	MaxLength  int        `json:"maxLength,omitempty"`
	RefTable   ID         `json:"refTable,omitempty"`
	RefType    string     `json:"refType,omitempty"`
}

JSONBaseType is a JSON object that describes the type of key or value

type JSONColumnType

type JSONColumnType struct {
	Key   AtomicOrJSONBaseType `json:"key"`
	Value AtomicOrJSONBaseType `json:"value,omitempty"`
	Min   int                  `json:"min,omitempty"`
	Max   IntOrString          `json:"max,omitempty"`
}

JSONColumnType is a JSON object that describes the type of a database column

type LockResult

type LockResult struct {
	Locked bool `json:"locked"`
}

LockResult is the result of Lock method

type Map

type Map struct {
	Values []MapPair
}

Map represents an OVSDB map It's 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. https://tools.ietf.org/html/rfc7047#section-5.1

func (Map) MarshalJSON

func (m Map) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*Map) UnmarshalJSON

func (m *Map) UnmarshalJSON(value []byte) error

UnmarshalJSON implements json.Unmarshaler

type MapPair

type MapPair [2]Atomic

MapPair represents a pair within a OVSDB map <pair> A 2-element JSON array that represents a pair within a database map. The first element is an <atom> that represents the key, and the second element is an <atom> that represents the value.

type MonitorRequest

type MonitorRequest struct {
	// Columns, if present, define the columns within the table to be monitored,
	// if omitted, all columns in the table, except for "_uuid", are monitored.
	Columns []ID           `json:"columns,omitempty"`
	Select  *MonitorSelect `json:"select,omitempty"`
}

MonitorRequest selects the contents to monitor in a table

type MonitorRequests

type MonitorRequests map[ID]MonitorRequest

MonitorRequests maps the name of the table to be monitored to an array of MonitorRequest

type MonitorSelect

type MonitorSelect map[SelectType]bool

MonitorSelect specify how the columns or table are to be monitored

type MutateOperation

type MutateOperation struct {
	Table     ID
	Where     []Condition
	Mutations []Mutation
}

MutateOperation mutates rows that match all the conditions specified in Where in Table The corresponding result object contains the following member: "count": <integer>

func (MutateOperation) MarshalJSON

func (mutate MutateOperation) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface

func (*MutateOperation) Op

func (mutate *MutateOperation) Op() OperationType

Op implements Operation interface

type MutateResult

type MutateResult struct {
	Count int `json:"count"`
}

MutateResult represents the result of a MutateOperation in Transact method results

type Mutation

type Mutation struct {
	Column  ID
	Mutator Mutator
	Value   Value
}

Mutation is a 3-element JSON array of the form [<column>, <mutator>, <value>] that represents a change to a column value.

func (Mutation) MarshalJSON

func (m Mutation) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface

func (Mutation) Valid

func (m Mutation) Valid() bool

Valid returns true if mutation is valid, otherwise false

type Mutator

type Mutator string

Mutator define the mutation operation on column It is one of "+=", "-=", "*=", "/=", "%=", "insert", or "delete" and supported mutators depend on the type of column

const (
	MutatorPluEq  Mutator = "+="
	MutatorMinEq  Mutator = "-="
	MutatorMulEq  Mutator = "*="
	MutatorDivEq  Mutator = "/="
	MutatorModEq  Mutator = "%="
	MutatorInsert Mutator = "insert"
	MutatorDelete Mutator = "delete"
)

Mutators supported in Mutation

type NamedUUID

type NamedUUID string

NamedUUID is a 2-element JSON array that represents the UUID of a row inserted in an "insert" operation within the same transaction The first element of the array must be the string "named-uuid", and the second element should be the <id> specified as the "uuid-name" for an "insert" operation within the same transaction.

func (NamedUUID) MarshalJSON

func (nu NamedUUID) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface

func (*NamedUUID) UnmarshalJSON

func (nu *NamedUUID) UnmarshalJSON(value []byte) error

UnmarshalJSON implements json.Unmarshaler interface

type NotificationHandler

type NotificationHandler interface {
	// Update notification is sent by the server to the client to report changes in tables that are being monitored
	Update(jsonValue Value, updates TableUpdates) error
	// Locked notification is provided to notify a client that it has been granted a lock that it had previously requested with the Lock method
	Locked(lock ID) error
	// Stolen notification is provided to notify a client, which had previously obtained a lock, that another client has stolen ownership of that lock
	Stolen(lock ID) error
}

NotificationHandler is the interface for notification handlers to implement

type NotificationHandlerFuncs

type NotificationHandlerFuncs struct {
	UpdateFunc func(jsonValue Value, updates TableUpdates) error
	LockedFunc func(lock ID) error
	StolenFunc func(lock ID) error
}

NotificationHandlerFuncs is a adapter which implements NotificationHandler interface

func (*NotificationHandlerFuncs) Locked

func (nh *NotificationHandlerFuncs) Locked(lock ID) error

Locked implements NotificationHandler interface

func (*NotificationHandlerFuncs) Stolen

func (nh *NotificationHandlerFuncs) Stolen(lock ID) error

Stolen implements NotificationHandler interface

func (*NotificationHandlerFuncs) Update

func (nh *NotificationHandlerFuncs) Update(jsonValue Value, updates TableUpdates) error

Update implements NotificationHandler interface

type Operation

type Operation interface {
	Op() OperationType
}

Operation represents a operation on OVSDB see: https://tools.ietf.org/html/rfc7047#section-5.2

type OperationType

type OperationType string

OperationType is the type of operation

const (
	OpInsert  OperationType = "insert"
	OpSelect  OperationType = "select"
	OpUpdate  OperationType = "update"
	OpMutate  OperationType = "mutate"
	OpDelete  OperationType = "delete"
	OpWait    OperationType = "wait"
	OpCommit  OperationType = "commit"
	OpAbort   OperationType = "abort"
	OpComment OperationType = "comment"
	OpAssert  OperationType = "assert"
)

Operation types

type ResultErrors

type ResultErrors []*Error

ResultErrors is a slice of Error that can be treat as a single error

func (ResultErrors) Error

func (re ResultErrors) Error() string

Error implements error interface

type Row

type Row interface{}

Row represents a row in a OVSDB table <row> A JSON object that describes a table row or a subset of a table row. Each member is the name of a table column paired with the <value> of that column.

type RowUpdate

type RowUpdate struct {
	Old *json.RawMessage `json:"old,omitempty"`
	New *json.RawMessage `json:"new,omitempty"`
}

RowUpdate is an object with the following members: "old": <row> present for "delete" and "modify" updates "new": <row> present for "initial", "insert", and "modify" updates

type SelectOperation

type SelectOperation struct {
	Table   ID
	Where   []Condition
	Columns []ID
}

SelectOperation searches Table for rows that match all the conditions specified in Where The corresponding result object contains the following member: "rows": [<row>*]

func (SelectOperation) MarshalJSON

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

MarshalJSON implements json.Marshaler interface

func (*SelectOperation) Op

Op implements Operation interface

type SelectResult

type SelectResult struct {
	Rows []*json.RawMessage `json:"rows"`
}

SelectResult represents the result of a SelectOperation in Transact method results

type SelectType

type SelectType string

SelectType is the type of MonitorSelect, valid values are: "initial", "insert", "delete", "modify"

type Set

type Set struct {
	Values []Value
}

Set represents a OVSDB set https://tools.ietf.org/html/rfc7047#section-5.1 <set> 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 (Set) MarshalJSON

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

MarshalJSON encode OVSDB set into json format

func (*Set) UnmarshalJSON

func (s *Set) UnmarshalJSON(value []byte) error

UnmarshalJSON decode json into an OVSDB set

type StringSet

type StringSet struct {
	Values []string
}

StringSet is a Set with element of string type

func (StringSet) MarshalJSON

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

MarshalJSON encode StringSet s into json format

func (*StringSet) UnmarshalJSON

func (s *StringSet) UnmarshalJSON(value []byte) error

UnmarshalJSON decode json into an OVSDB set

type TableSchema

type TableSchema struct {
	// Columns is a JSON object whose names are column names and whose values are <column-schema>s.
	Columns map[ID]*ColumnSchema `json:"columns"`
	// MaxRows if specified, as a positive integer, it limits the maximum number of rows that may be present in the table
	MaxRows int `json:"maxRows,omitempty"`
	// IsRoot is used to determine whether rows in the table require strong references from other rows to avoid garbage collection
	IsRoot bool `json:"isRoot,omitempty"`
	// Indexes if specified, it must be an array of zero or more <ColumnSet>s
	Indexes []ColumnSet `json:"indexes,omitempty"`
}

TableSchema represents the schema of a table in database

type TableUpdate

type TableUpdate map[UUID]RowUpdate

TableUpdate is an object that maps from the row's UUID to a RowUpdate object

type TableUpdates

type TableUpdates map[ID]TableUpdate

TableUpdates is an object that maps from a table name to a TableUpdate

type TransactResult

type TransactResult struct {
	// Results contain operations' result
	Results []interface{}
	// Errors keeps operation errors in a separate slice for convenience
	Errors ResultErrors
}

TransactResult contains results for each operations in a transaction. See https://tools.ietf.org/html/rfc7047#section-4.1.3 for detailed explaination of the result array. For a failed operation, we decode the erorr message into ovsdb.Error, otherwise we keep the result as a json.RawMessage for user to decode it as proper operation result type.

func (*TransactResult) UnmarshalJSON

func (tr *TransactResult) UnmarshalJSON(value []byte) error

UnmarshalJSON implements json.Unmarshaler interface

type UUID

type UUID string

UUID is a 2-element JSON array that represents a UUID The first element of the array must be the string "uuid", and the second element must be a 36-character string giving the UUID in the format described by RFC 4122

func (UUID) MarshalJSON

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

MarshalJSON implements json.Marshaler interface

func (*UUID) UnmarshalJSON

func (uuid *UUID) UnmarshalJSON(value []byte) error

UnmarshalJSON implements json.Unmarshaler interface

type UpdateOperation

type UpdateOperation struct {
	Table ID
	Where []Condition
	Row   Row
}

UpdateOperation searches rows that match all the conditions specified in Where and changes the value of each column specified in Row to the value for that column specified in Row The corresponding result object contains the following member: "count": <integer>

func (UpdateOperation) MarshalJSON

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

MarshalJSON implements json.Marshaler interface

func (*UpdateOperation) Op

Op implements Operation interface

type UpdateResult

type UpdateResult struct {
	Count int `json:"count"`
}

UpdateResult represents the result of a UpdateOperation in Transact method results

type Value

type Value interface{}

Value is the value of a column <value> A JSON value that represents the value of a column in a table row, one of <atom>, <set>, or <map>. FIXME: define more concrete type instead of interface{}

type Version

type Version string

Version is a JSON string that contains a version number that matches [0-9]+ \.[0-9]+\.[0-9]+

Directories

Path Synopsis
examples
getschema command

Jump to

Keyboard shortcuts

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