Documentation
¶
Index ¶
- Constants
- type Atomic
- type AtomicOrJSONBaseType
- type AtomicOrJSONColumnType
- type AtomicType
- type Client
- func (c *Client) GetSchema(db ID) (*DatabaseSchema, error)
- func (c *Client) ListDbs() ([]ID, error)
- func (c *Client) Lock(lockID ID) (bool, error)
- func (c *Client) Monitor(db ID, jsonValue Value, requests MonitorRequests) (TableUpdates, error)
- func (c *Client) MonitorCancel(jsonValue Value) error
- func (c *Client) SetNotificationHandler(handler NotificationHandler)
- func (c *Client) Steal(lockID ID) error
- func (c *Client) Transact(db ID, ops ...Operation) (*TransactResult, error)
- func (c *Client) Unlock(lockID ID) error
- type ColumnSchema
- type ColumnSet
- type Condition
- type DatabaseSchema
- type DeleteOperation
- type DeleteResult
- type Error
- type Function
- type ID
- type InsertOperation
- type InsertResult
- type IntOrString
- type JSONBaseType
- type JSONColumnType
- type LockResult
- type Map
- type MapPair
- type MonitorRequest
- type MonitorRequests
- type MonitorSelect
- type MutateOperation
- type MutateResult
- type Mutation
- type Mutator
- type NamedUUID
- type NotificationHandler
- type NotificationHandlerFuncs
- type Operation
- type OperationType
- type ResultErrors
- type Row
- type RowUpdate
- type SelectOperation
- type SelectResult
- type SelectType
- type Set
- type StringSet
- type TableSchema
- type TableUpdate
- type TableUpdates
- type TransactResult
- type UUID
- type UpdateOperation
- type UpdateResult
- type Value
- type Version
Constants ¶
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 (*Client) GetSchema ¶
func (c *Client) GetSchema(db ID) (*DatabaseSchema, error)
GetSchema get the schema of a OVSDB database
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 ¶
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 ¶
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
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 ¶
Condition is a 3-element JSON array of the form [<column>, <function>, <value>] that represents a test on a column value.
func (Condition) MarshalJSON ¶
MarshalJSON implements json.Marshaler interface
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 ¶
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 ¶
func (d *DeleteOperation) Op() OperationType
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
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
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 ¶
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 ¶
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 ¶
MarshalJSON implements json.Marshaler
func (*Map) UnmarshalJSON ¶
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 ¶
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 ¶
Mutation is a 3-element JSON array of the form [<column>, <mutator>, <value>] that represents a change to a column value.
func (Mutation) MarshalJSON ¶
MarshalJSON implements json.Marshaler interface
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
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 ¶
MarshalJSON implements json.Marshaler interface
func (*NamedUUID) UnmarshalJSON ¶
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
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 ¶
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 ¶
func (s *SelectOperation) Op() OperationType
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 ¶
MarshalJSON encode OVSDB set into json format
func (*Set) UnmarshalJSON ¶
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 ¶
MarshalJSON encode StringSet s into json format
func (*StringSet) UnmarshalJSON ¶
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 ¶
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 ¶
MarshalJSON implements json.Marshaler interface
func (*UUID) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler interface
type UpdateOperation ¶
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 ¶
func (u *UpdateOperation) Op() OperationType
Op implements Operation interface
type UpdateResult ¶
type UpdateResult struct {
Count int `json:"count"`
}
UpdateResult represents the result of a UpdateOperation in Transact method results