contrail

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

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

Go to latest
Published: Apr 19, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

README

Build Status

contrail-go-api

golang API bindings for OpenContrail

The library consists on the contrail package plus an autogenerated package "contrail-go-api/types" that contains types corresponding to the OpenContrail datamodel defined in contrail-controller/src/schema.

The contail-go-api package can be installed with the "go get" command:

go get github.com/Juniper/contrail-go-api

The types package is generated using the command:

tools/generateds/generateDS.py -f -o $GOPATH/src/github.com/Juniper/contrail-go-api/types -g golang-api controller/src/schema/vnc_cfg.xsd

Pre-generated tar files with the generated types are also available as part of each release. The golang types corresponding to the schema defined by OpenContrail R2.20 are available at:

To build the CLI command:

go install github.com/Juniper/contrail-go-api/cli

TODO items:

  • Links between two identifiers often have metadata which consists of a list of elements (e.g. association between virtual-network and network-ipam is a list of subnets). Currently the way to modify this metadata on a link is to delete it and re-add it; the generator should generate helper methods to make manipulating these lists simpler.
  • VRouter API: The library needs to be extended in order to have a class that communicates with the vrouter-agent process in order to add/delete ports.
  • Provisioning taks: there is the need to capture common provisining tasks such as configuring BGP routers.
  • CLI: The CLI currently supports operations on networks, policies and virtual-routers. Additional support needs to be added for other common configuration and provisioning tasks.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterTypeMap

func RegisterTypeMap(m TypeMap)

RegisterTypeMap is used by the generated types library to register the list of known object types.

Types

type ApiClient

type ApiClient interface {
	Create(ptr IObject) error
	Update(ptr IObject) error
	DeleteByUuid(typename, uuid string) error
	Delete(ptr IObject) error
	FindByUuid(typename string, uuid string) (IObject, error)
	UuidByName(typename string, fqn string) (string, error)
	FQNameByUuid(uuid string) ([]string, error)
	FindByName(typename string, fqn string) (IObject, error)
	List(typename string) ([]ListResult, error)
	ListByParent(typename string, parentID string) ([]ListResult, error)
	ListDetail(typename string, fields []string) ([]IObject, error)
	ListDetailByParent(typename string, parentID string, fields []string) ([]IObject, error)
}

ApiClient interface

type Authenticator

type Authenticator interface {
	AddAuthentication(*http.Request) error
}

The Authenticator interface is used to add an autentication token on a per request basis. This is used by the Keystone authentication class to decorate the requests with a token.

type Client

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

A Client of the OpenContrail API server.

func NewClient

func NewClient(server string, port int) *Client

NewClient allocates and initializes a Contrail API client.

func (*Client) AddEncryption

func (c *Client) AddEncryption(caFile string, keyFile string, certFile string, insecure bool) error

AddEncryption implements the Encryptor interface for Client.

func (*Client) Create

func (c *Client) Create(ptr IObject) error

Create an object in the OpenContrail API server.

The object must have been initialized with a name.

func (*Client) Delete

func (c *Client) Delete(ptr IObject) error

Delete an object from the API server.

func (*Client) DeleteByUuid

func (c *Client) DeleteByUuid(typename, uuid string) error

DeleteByUuid deletes the specified object.

func (*Client) FQNameByUuid

func (c *Client) FQNameByUuid(uuid string) ([]string, error)

FQNameByUuid returns the fully-qualified name of an object as identified by a UUID.

func (*Client) FindByName

func (c *Client) FindByName(typename string, fqn string) (IObject, error)

FindByName reads an object identified by fully-qualified name represented as a string.

func (*Client) FindByUuid

func (c *Client) FindByUuid(typename string, uuid string) (IObject, error)

FindByUuid reads an object identified by UUID.

func (*Client) GetField

func (c *Client) GetField(obj IObject, field string) error

GetField retrieves a specified field of an object from the API server. This API is used by the generated types library to retrieve reference lists.

func (*Client) GetServer

func (c *Client) GetServer() string

GetServer retrieves the name or address of the Contrail API server.

func (*Client) List

func (c *Client) List(typename string) ([]ListResult, error)

List retrieves the identifiers of all objects of a given type.

func (*Client) ListByParent

func (c *Client) ListByParent(
	typename string, parentID string) ([]ListResult, error)

ListByParent retrieves the identifiers of the objects of a specific type that are descendents of a specific object.

func (*Client) ListDetail

func (c *Client) ListDetail(typename string, fields []string) (
	[]IObject, error)

ListDetail reads all the objects of a specific type.

func (*Client) ListDetailByParent

func (c *Client) ListDetailByParent(
	typename string, parentID string, fields []string) (
	[]IObject, error)

ListDetailByParent reads all the objects of a given type that are descendents of the specified parent object.

func (*Client) ReadListResult

func (c *Client) ReadListResult(
	typename string, result *ListResult) (IObject, error)

Given a ListResult, retrieve an object from the API server.

func (*Client) ReadReference

func (c *Client) ReadReference(
	typename string, ref *Reference) (IObject, error)

Given a link reference, retrieve an object from the API server.

func (*Client) SetAuthenticator

func (c *Client) SetAuthenticator(auth Authenticator)

SetAuthenticator enables the user to configure an Authenticator (e.g. Keystone) to be used by Contrail API requests.

func (*Client) SetEncryptor

func (c *Client) SetEncryptor(encrypt Encryptor)

SetEncryptor enables the user to encrypt the API traffic

func (*Client) Update

func (c *Client) Update(ptr IObject) error

Update the API server with the changes made in the local representation of the object.

There is currently no mechanism to guarantee that the object as not been concurrently modified in the API server. Updates modify properties that have been marked as modified in the local representation.

func (*Client) UpdateReference

func (c *Client) UpdateReference(msg *ReferenceUpdateMsg) error

UpdateReference sends a reference update message to the API server. Used by the generated types library.

func (*Client) UuidByName

func (c *Client) UuidByName(typename string, fqn string) (string, error)

UuidByName returns the UUID of an object as identified by its fully qualified name.

type Encryptor

type Encryptor interface {
	AddEncryption(caFile string, keyFile string, certFile string, insecure bool) error
}

The Encryptor interface is used to add an encryption to the REST call

type IObject

type IObject interface {
	GetDefaultParent() []string
	GetDefaultParentType() string
	GetFQName() []string
	GetName() string
	GetType() string
	GetParentType() string
	GetUuid() string
	GetHref() string
	SetName(string)
	SetUuid(string)
	SetFQName(string, []string)

	SetClient(objectInterface)
	UpdateObject() ([]byte, error)
	UpdateReferences() error
	UpdateDone()
}

IObject describes the interface implemented by auto-generated types.

type KeepaliveKeystoneClient

type KeepaliveKeystoneClient struct {
	KeystoneClient
}

KeepaliveKeystoneClient embeds KeystoneClient

func NewKeepaliveKeystoneClient

func NewKeepaliveKeystoneClient(auth_url, tenant_name, username, password, token, domain_name string) *KeepaliveKeystoneClient

NewKeepaliveKeystoneClient allocates and initializes a KeepaliveKeystoneClient

func (*KeepaliveKeystoneClient) AddAuthentication

func (kClient *KeepaliveKeystoneClient) AddAuthentication(req *http.Request) error

AddAuthentication adds authentication token to the HTTP header of the KeepaliveKeystoneClient

type KeystoneClient

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

KeystoneClient is a client of the OpenStack Keystone service that adds authentication tokens to the Contrail API requests.

func NewKeystoneClient

func NewKeystoneClient(auth_url, tenant_name, username, password, token, domain_name, project_name, project_domain_name string) *KeystoneClient

NewKeystoneClient allocates and initializes a KeystoneClient

func (*KeystoneClient) AddAuthentication

func (kClient *KeystoneClient) AddAuthentication(req *http.Request) error

AddAuthentication adds the authentication token to the HTTP header.

func (*KeystoneClient) AddEncryption

func (kClient *KeystoneClient) AddEncryption(caFile string, keyFile string, certFile string, insecure bool) error

AddEncryption implements the Encryptor interface for Client.

func (*KeystoneClient) Authenticate

func (kClient *KeystoneClient) Authenticate() error

Authenticate sends an authentication request to keystone.

func (*KeystoneClient) AuthenticateV3

func (kClient *KeystoneClient) AuthenticateV3() error

Authenticate sends an authentication request to keystone.

type KeystoneToken

type KeystoneToken struct {
	Id      string
	Expires string
	Tenant  struct {
		Id          string
		Name        string
		Description string
		Enabled     bool
	}
	Issued_At string
}

KeystoneToken represents an auth token issued by OpenStack keystone service. The field names are defined by the Keystone API schema.

type KeystoneTokenv3

type KeystoneTokenv3 struct {
	Token struct {
		ExpiresAt string `json:"expires_at"`
		IssuedAt  string `json:"issued_at"`
	} `json:"token"`
}

type LinkAttribute

type LinkAttribute interface {
}

LinkAttribute is an attribute on a link between two objects.

type ListResult

type ListResult struct {
	Fq_name []string
	Href    string
	Uuid    string
}

ListResult is the return type of the {List, ListByParent} API calls.

type NopAuthenticator

type NopAuthenticator struct {
}

NopAuthenticator is an authentication that doesn't modify the request.

func (*NopAuthenticator) AddAuthentication

func (*NopAuthenticator) AddAuthentication(*http.Request) error

AddAuthentication implements the Authenticator interface for NopAuthenticator.

type NopEncryptor

type NopEncryptor struct {
}

NopEncryptor doesn't add encryption

func (*NopEncryptor) AddEncryption

func (*NopEncryptor) AddEncryption(caFile string, keyFile string, certFile string, insecure bool) error

AddEncryption implements the Encryptor interface for NopEncryptor.

type ObjectBase

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

ObjectBase is used as base class by the auto-generated types.

func (*ObjectBase) GetFQName

func (obj *ObjectBase) GetFQName() []string

GetFQName is the accessor method for the fully qualified name.

func (*ObjectBase) GetField

func (obj *ObjectBase) GetField(ptr IObject, field string) error

GetField is used to retrieve references. When an object is first read, children, forward and backward references are not fetched since these lists can be very large. This method explicitly retrieves a reference field. It is used implicitly when reading and/or modifying reference fields via the generated types library.

func (*ObjectBase) GetHref

func (obj *ObjectBase) GetHref() string

GetHref is the accessor for href.

func (*ObjectBase) GetName

func (obj *ObjectBase) GetName() string

GetName is the accessor method for object (unqualified) name

func (*ObjectBase) GetParentType

func (obj *ObjectBase) GetParentType() string

GetParentType is the access method for the parent type.

func (*ObjectBase) GetUuid

func (obj *ObjectBase) GetUuid() string

GetUuid is the accessor for object uuid.

func (*ObjectBase) IsTransient

func (obj *ObjectBase) IsTransient() bool

IsTransient returns true if the object has been allocated locally but not yet created in the Contrail API. Objects read from the API server via Find or ListDetail APIs are not considered to be transient and can be updated or deleted.

func (*ObjectBase) MarshalCommon

func (obj *ObjectBase) MarshalCommon(m map[string]*json.RawMessage) error

MarshalCommon encodes the information stored in the ObjectBase struct.

func (*ObjectBase) MarshalId

func (obj *ObjectBase) MarshalId(m map[string]*json.RawMessage) error

MarshalId encodes fq_name and uuid.

func (*ObjectBase) SetClient

func (obj *ObjectBase) SetClient(c objectInterface)

SetClient is used to mark an object as persistent (it has been created or read) from the API and supplying it with the methods required to perform an update.

func (*ObjectBase) SetFQName

func (obj *ObjectBase) SetFQName(parentType string, fqn []string)

SetFQName sets the fully qualified domain name. This implies that the parent is being specified also.

func (*ObjectBase) SetUuid

func (obj *ObjectBase) SetUuid(uuid string)

SetUuid set for object uuid on transient objects.

func (*ObjectBase) UnmarshalCommon

func (obj *ObjectBase) UnmarshalCommon(m map[string]json.RawMessage) error

UnmarshalCommon is used to unmarshal the JSON data on ObjectBase.

func (*ObjectBase) UpdateReference

func (obj *ObjectBase) UpdateReference(
	ptr IObject, field string, current, prev ReferenceList) error

UpdateReference is a helper function that compares two reference lists and generates the appropriate list of changes to be resented as POST requests to the ref-update URL on the API server.

func (*ObjectBase) VSetName

func (obj *ObjectBase) VSetName(vPtr IObject, name string)

VSetName implements IObject.SetName methods.

The implementation must be able to access both the ObjectBase fields as well as the IObject interface in order to retrieve data specific to a given type.

func (*ObjectBase) VSetParent

func (obj *ObjectBase) VSetParent(vPtr IObject, parent IObject)

VSetParent is used by the auto-generated types library to set the parent of an object that is being created.

type Reference

type Reference struct {
	To   []string      `json:"to,omitempty"`
	Uuid string        `json:"uuid,omitempty"`
	Href string        `json:"href,omitempty"`
	Attr LinkAttribute `json:"attr,omitempty"`
}

A Reference represents a link (and optional associated metadata) between two objects.

type ReferenceList

type ReferenceList []Reference

ReferenceList is a slice (list) of references

type ReferencePair

type ReferencePair struct {
	Object    IObject
	Attribute LinkAttribute
}

A ReferencePair is the data used to add a reference.

type ReferenceUpdateMsg

type ReferenceUpdateMsg struct {
	// object typename
	Type string `json:"type"`
	// object uuid
	Uuid string `json:"uuid"`
	// object field (without the trailing _refs and tr/_/-/)
	RefType string `json:"ref-type"`
	// reference uuid
	RefUuid string `json:"ref-uuid"`
	// reference fqn
	RefFQName []string `json:"ref-fq-name"`
	// ADD, DELETE
	Operation string `json:"operation"`
	// Attribute
	Attr LinkAttribute `json:"attr"`
}

ReferenceUpdateMsg is the data type used by POST requests to http://server:port/ref-update

type TlsConfig

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

type TypeMap

type TypeMap map[string]reflect.Type

TypeMap is used to inject the auto-generated types library.

Types are generated from the OpenContrail schema and allow the library to operate in terms of go structs that contain fields that represent IF-MAP properties (metadata associated with a single Identifier) and arrays of references to other Identifiers (with optional metadata). Each auto-generated type implements the IObject interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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