storageos

package module
v2.6.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2022 License: BSD-2-Clause, MIT Imports: 21 Imported by: 24

README

StorageOS API client library

Swagger Spec

Swagger specification for this repo is available in the StorageOS public documentation.

Documentation

Index

Constants

View Source
const (
	// DefaultUserAgent is the default User-Agent header to include in HTTP requests.
	DefaultUserAgent = "go-storageosclient"
	// DefaultVersionStr is the string value of the default API version.
	DefaultVersionStr = "1"
	// DefaultVersion is the default API version.
	DefaultVersion = 1
)
View Source
const (
	// IDFormat are the characters allowed to represent an ID.
	IDFormat = `[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}`

	// NameFormat are the characters allowed to represent a name.
	NameFormat = `[a-zA-Z0-9][a-zA-Z0-9~_.-]+`
)

Variables

View Source
var (
	// ErrConnectionRefused is returned when the client cannot connect to the given endpoint.
	ErrConnectionRefused = errors.New("cannot connect to StorageOS API endpoint")

	// ErrInactivityTimeout is returned when a streamable call has been inactive for some time.
	ErrInactivityTimeout = errors.New("inactivity time exceeded timeout")

	// ErrInvalidVersion is returned when a versioned client was requested but no version specified.
	ErrInvalidVersion = errors.New("invalid version")

	// ErrProxyNotSupported is returned when a client is unable to set a proxy for http requests.
	ErrProxyNotSupported = errors.New("client does not support http proxy")

	// ErrDialerNotSupported is returned when a client is unable to set a DialContext for http requests.
	ErrDialerNotSupported = errors.New("client does not support setting DialContext")

	// DefaultPort is the default API port.
	DefaultPort = "5705"

	// DataplaneHealthPort is the the port used by the dataplane health-check service.
	DataplaneHealthPort = "5704"

	// DefaultHost is the default API host.
	DefaultHost = "http://localhost:" + DefaultPort
)
View Source
var (
	// LoginAPIPrefix is a partial path to the HTTP endpoint.
	LoginAPIPrefix = "auth/login"
	// ErrLoginFailed is the error returned on an unsuccessful login.
	ErrLoginFailed = errors.New("failed to get token from API endpoint")
)
View Source
var (

	// NamespaceAPIPrefix is a partial path to the HTTP endpoint.
	NamespaceAPIPrefix = "namespaces"

	// ErrNoSuchNamespace is the error returned when the namespace does not exist.
	ErrNoSuchNamespace = errors.New("no such namespace")

	// ErrNamespaceInUse is the error returned when the namespace requested to be removed is still in use.
	ErrNamespaceInUse = errors.New("namespace in use and cannot be removed")
)
View Source
var (

	// NodeAPIPrefix is a partial path to the HTTP endpoint.
	NodeAPIPrefix = "nodes"

	// ErrNoSuchNode is the error returned when the node does not exist.
	ErrNoSuchNode = errors.New("no such node")

	// ErrNodeInUse is the error returned when the node requested to be removed is still in use.
	ErrNodeInUse = errors.New("node in use and cannot be removed")
)
View Source
var (
	// PolicyAPIPrefix is a partial path to the HTTP endpoint.
	PolicyAPIPrefix = "policies"
	// ErrNoSuchPolicy is the error returned when the policy does not exist.
	ErrNoSuchPolicy = errors.New("no such policy")
)
View Source
var (

	// PoolAPIPrefix is a partial path to the HTTP endpoint.
	PoolAPIPrefix = "pools"

	// ErrNoSuchPool is the error returned when the pool does not exist.
	ErrNoSuchPool = errors.New("no such pool")

	// ErrPoolInUse is the error returned when the pool requested to be removed is still in use.
	ErrPoolInUse = errors.New("pool in use and cannot be removed")
)
View Source
var (

	// RuleAPIPrefix is a partial path to the HTTP endpoint.
	RuleAPIPrefix = "rules"

	// ErrNoSuchRule is the error returned when the rule does not exist.
	ErrNoSuchRule = errors.New("no such rule")

	// ErrRuleInUse is the error returned when the rule requested to be removed is still in use.
	ErrRuleInUse = errors.New("rule in use and cannot be removed")
)
View Source
var (

	// TemplateAPIPrefix is a partial path to the HTTP endpoint.
	TemplateAPIPrefix = "/templates"

	// ErrNoSuchTemplate is the error returned when the template does not exist.
	ErrNoSuchTemplate = errors.New("no such template")

	// ErrTemplateInUse is the error returned when the template requested to be removed is still in use.
	ErrTemplateInUse = errors.New("template in use and cannot be removed")
)
View Source
var (
	// UserAPIPrefix is a partial path to the HTTP endpoint.
	UserAPIPrefix = "users"

	// ErrNoSuchUser is the error returned when the user does not exist.
	ErrNoSuchUser = errors.New("no such user")
)
View Source
var (
	// IDPattern is a regular expression to validate a unique id against the
	// collection of restricted characters.
	IDPattern = regexp.MustCompile(`^` + IDFormat + `$`)

	// NamePattern is a regular expression to validate names against the
	// collection of restricted characters.
	NamePattern = regexp.MustCompile(`^` + NameFormat + `$`)

	// ErrNoRef is given when the reference given is invalid.
	ErrNoRef = errors.New("no ref provided or incorrect format")
	// ErrNoNamespace is given when the namespace given is invalid.
	ErrNoNamespace = errors.New("no namespace provided or incorrect format")
)
View Source
var (

	// VolumeAPIPrefix is a partial path to the HTTP endpoint.
	VolumeAPIPrefix = "volumes"

	// ErrNoSuchVolume is the error returned when the volume does not exist.
	ErrNoSuchVolume = errors.New("no such volume")

	// ErrVolumeInUse is the error returned when the volume requested to be removed is still in use.
	ErrVolumeInUse = errors.New("volume in use and cannot be removed")
)
View Source
var (
	// ClusterMaintenanceAPIPrefix is a path to the HTTP endpoint for managing
	// the cluster maintenance mode.
	ClusterMaintenanceAPIPrefix = "cluster/maintenance"
)
View Source
var (
	// HealthAPIPrefix is a partial path to the HTTP endpoint.
	HealthAPIPrefix = "health"
)
View Source
var (
	// LoggerAPIPrefix is a partial path to the HTTP endpoint.
	LoggerAPIPrefix = "logs"
)
View Source
var (
	// NetworkDiagnosticsAPIPrefix is a partial path to the HTTP endpoint for
	// the node connectivity diagnostics report.
	NetworkDiagnosticsAPIPrefix = "diagnostics/network"
)

Functions

func IsName

func IsName(s string) bool

IsName returns true if the string input is a valid Name string.

func IsUUID

func IsUUID(s string) bool

IsUUID returns true if the string input is a valid UUID string.

func ParseRef

func ParseRef(ref string) (namespace string, name string, err error)

ParseRef is a helper to split out the namespace and name from a path reference.

func ValidateNamespace

func ValidateNamespace(namespace string) error

ValidateNamespace returns true if the namespace uses a valid name.

func ValidateNamespaceAndRef

func ValidateNamespaceAndRef(namespace, ref string) error

ValidateNamespaceAndRef returns true if both the namespace and ref are valid.

Types

type APIVersion

type APIVersion int

APIVersion is an internal representation of a version of the Remote API.

func NewAPIVersion

func NewAPIVersion(input string) (APIVersion, error)

NewAPIVersion returns an instance of APIVersion for the given string.

The given string must be in the form <major>

func (APIVersion) String

func (version APIVersion) String() string

type Client

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

Client is the basic type of this package. It provides methods for interaction with the API.

func NewClient

func NewClient(nodes string) (*Client, error)

NewClient returns a Client instance ready for communication with the given server endpoint. It will use the latest remote API version available in the server.

func NewVersionedClient

func NewVersionedClient(nodestring string, apiVersionString string) (*Client, error)

NewVersionedClient returns a Client instance ready for communication with the given server endpoint, using a specific remote API version.

func (*Client) CPHealth

func (c *Client) CPHealth(ctx context.Context, hostname string) (*types.CPHealthStatus, error)

CPHealth returns the health of the control plane server at a given url.

func (*Client) ClientVersion

func (c *Client) ClientVersion() string

ClientVersion returns the API version of the client

func (*Client) ClusterHealth

func (c *Client) ClusterHealth(ctx context.Context) ([]*types.ClusterHealthNode, error)

func (*Client) DPHealth

func (c *Client) DPHealth(ctx context.Context, hostname string) (*types.DPHealthStatus, error)

DPHealth returns the health of the data plane server at a given url.

func (*Client) DisableMaintenance

func (c *Client) DisableMaintenance() error

DisableMaintenance disables maintenance mode in the cluster

func (*Client) EnableMaintenance

func (c *Client) EnableMaintenance() error

EnableMaintenance enables maintenance mode in the cluster

func (*Client) GetDialContext

func (c *Client) GetDialContext() dialContext

GetDialContext returns the current DialContext function, or nil if there is none.

func (*Client) Licence

func (c *Client) Licence() (*types.Licence, error)

Licence returns the current licence on the server.

func (*Client) LicenceApply

func (c *Client) LicenceApply(licenceKey string) error

LicenceApply applies a licence on the server.

func (*Client) LicenceDelete

func (c *Client) LicenceDelete() error

LicenceDelete removes the current licence.

func (*Client) LoggerConfig

func (c *Client) LoggerConfig(opts types.ListOptions) ([]*types.Logger, error)

LoggerConfig returns every cluster node's logging configuration.

func (*Client) LoggerUpdate

func (c *Client) LoggerUpdate(opts types.LoggerUpdateOptions) ([]*types.Logger, error)

LoggerUpdate patches updates to logging configuration. Fields to update must be listed in the Fields value, and if a list of Nodes is given it will only apply to the nodes listed. Returns the updated configuration.

func (*Client) Login

func (c *Client) Login() (token string, err error)

Login attemps to get a token from the API

func (*Client) Maintenance

func (c *Client) Maintenance() (*types.Maintenance, error)

Maintenance returns the maintenance status of the cluster

func (*Client) Namespace

func (c *Client) Namespace(ref string) (*types.Namespace, error)

Namespace returns a namespace by its reference.

func (*Client) NamespaceCreate

func (c *Client) NamespaceCreate(opts types.NamespaceCreateOptions) (*types.Namespace, error)

NamespaceCreate creates a namespace on the server and returns the new object.

func (*Client) NamespaceDelete

func (c *Client) NamespaceDelete(opts types.DeleteOptions) error

NamespaceDelete removes a namespace by its reference.

func (*Client) NamespaceList

func (c *Client) NamespaceList(opts types.ListOptions) ([]*types.Namespace, error)

NamespaceList returns the list of available namespaces.

func (*Client) NamespaceUpdate

func (c *Client) NamespaceUpdate(opts types.NamespaceCreateOptions) (*types.Namespace, error)

NamespaceUpdate updates a namespace on the server and returns the updated object.

func (*Client) NetworkDiagnostics

func (c *Client) NetworkDiagnostics(ref string) (types.ConnectivityResults, error)

NetworkDiagnostics returns a collection of network connectivity reports. If a reference to a node is given, it will only check connectivity from that node. Otherwise, connectivity between all cluster nodes will be returned.

func (*Client) Node

func (c *Client) Node(ref string) (*types.Node, error)

Node returns a node by its reference.

func (*Client) NodeDelete

func (c *Client) NodeDelete(opts types.DeleteOptions) error

NodeDelete removes a node by its reference.

func (*Client) NodeList

func (c *Client) NodeList(opts types.ListOptions) ([]*types.Node, error)

NodeList returns the list of available nodes.

func (*Client) NodeUpdate

func (c *Client) NodeUpdate(opts types.NodeUpdateOptions) (*types.Node, error)

NodeUpdate updates a node on the server.

func (*Client) Ping

func (c *Client) Ping() error

Ping pings the API server

See https://goo.gl/wYfgY1 for more details.

func (*Client) Policy

func (c *Client) Policy(id string) (*types.Policy, error)

Policy returns a policy on the server by ID.

func (*Client) PolicyCreate

func (c *Client) PolicyCreate(ctx context.Context, jsonl []byte) error

PolicyCreate creates a policy on the server.

func (*Client) PolicyDelete

func (c *Client) PolicyDelete(opts types.DeleteOptions) error

PolicyDelete deletes a policy on the server by ID.

func (*Client) PolicyList

func (c *Client) PolicyList(opts types.ListOptions) (types.PolicySet, error)

PolicyList returns the list of policies on the server.

func (*Client) Pool

func (c *Client) Pool(ref string) (*types.Pool, error)

Pool returns a pool by its reference.

func (*Client) PoolCreate

func (c *Client) PoolCreate(opts types.PoolOptions) (*types.Pool, error)

PoolCreate creates a pool on the server and returns the new object.

func (*Client) PoolDelete

func (c *Client) PoolDelete(opts types.DeleteOptions) error

PoolDelete removes a pool by its reference.

func (*Client) PoolList

func (c *Client) PoolList(opts types.ListOptions) ([]*types.Pool, error)

PoolList returns the list of available pools.

func (*Client) PoolUpdate

func (c *Client) PoolUpdate(opts types.PoolOptions) (*types.Pool, error)

PoolUpdate - update pool

func (*Client) Rule

func (c *Client) Rule(namespace string, ref string) (*types.Rule, error)

Rule returns a rule by its reference.

func (*Client) RuleCreate

func (c *Client) RuleCreate(opts types.RuleCreateOptions) (*types.Rule, error)

RuleCreate creates a rule on the server and returns the new object.

func (*Client) RuleDelete

func (c *Client) RuleDelete(opts types.DeleteOptions) error

RuleDelete removes a rule by its reference.

func (*Client) RuleList

func (c *Client) RuleList(opts types.ListOptions) ([]*types.Rule, error)

RuleList returns the list of available rules.

func (*Client) RuleUpdate

func (c *Client) RuleUpdate(opts types.RuleUpdateOptions) (*types.Rule, error)

RuleUpdate updates a rule on the server.

func (*Client) ServerVersion

func (c *Client) ServerVersion(ctx context.Context) (*types.VersionInfo, error)

ServerVersion returns the server's version and runtime info.

func (*Client) SetAuth

func (c *Client) SetAuth(username string, secret string)

SetAuth sets the API username and secret to be used for all API requests. It should not be called concurrently with any other Client methods.

func (*Client) SetDialContext

func (c *Client) SetDialContext(dial dialContext) error

SetDialContext uses the given dial function to establish TCP connections in the HTTPClient.

func (*Client) SetProxy

func (c *Client) SetProxy(proxy *url.URL) error

SetProxy will set the proxy URL for both the HTTPClient. If the transport method does not support usage of proxies, an error will be returned.

func (*Client) SetTimeout

func (c *Client) SetTimeout(t time.Duration)

SetTimeout takes a timeout and applies it to both the HTTPClient and nativeHTTPClient. It should not be called concurrently with any other Client methods.

func (*Client) SetUserAgent

func (c *Client) SetUserAgent(useragent string)

SetUserAgent sets the client useragent.

func (*Client) Template

func (c *Client) Template(ref string) (*types.Template, error)

Template returns a template by its reference.

func (*Client) TemplateCreate

func (c *Client) TemplateCreate(opts types.TemplateCreateOptions) (string, error)

TemplateCreate creates a template on the server and returns the new object.

func (*Client) TemplateDelete

func (c *Client) TemplateDelete(ref string) error

TemplateDelete removes a template by its reference.

func (*Client) TemplateList

func (c *Client) TemplateList(opts types.ListOptions) ([]types.Template, error)

TemplateList returns the list of available templates.

func (*Client) User

func (c *Client) User(username string) (*types.User, error)

User returns a user by its username/id.

func (*Client) UserCreate

func (c *Client) UserCreate(opts types.UserCreateOptions) error

UserCreate creates a user on the server.

func (*Client) UserDelete

func (c *Client) UserDelete(opts types.DeleteOptions) error

UserDelete removes a user by its reference.

func (*Client) UserList

func (c *Client) UserList(opts types.ListOptions) ([]*types.User, error)

UserList returns the list of available users.

func (*Client) UserUpdate

func (c *Client) UserUpdate(ctx context.Context, user *types.User) error

UserUpdate updates a user on the server.

func (*Client) Volume

func (c *Client) Volume(namespace string, ref string) (*types.Volume, error)

Volume returns a volume by its reference.

func (*Client) VolumeCreate

func (c *Client) VolumeCreate(opts types.VolumeCreateOptions) (*types.Volume, error)

VolumeCreate creates a volume on the server and returns the new object.

func (*Client) VolumeDelete

func (c *Client) VolumeDelete(opts types.DeleteOptions) error

VolumeDelete removes a volume by its reference.

func (*Client) VolumeList

func (c *Client) VolumeList(opts types.ListOptions) ([]*types.Volume, error)

VolumeList returns the list of available volumes.

func (*Client) VolumeMount

func (c *Client) VolumeMount(opts types.VolumeMountOptions) error

VolumeMount updates the volume with the client that mounted it.

func (*Client) VolumeUnmount

func (c *Client) VolumeUnmount(opts types.VolumeUnmountOptions) error

VolumeUnmount removes the client from the mount reference.

func (*Client) VolumeUpdate

func (c *Client) VolumeUpdate(opts types.VolumeUpdateOptions) (*types.Volume, error)

VolumeUpdate updates a volume on the server.

type Dialer

type Dialer interface {
	Dial(network, address string) (net.Conn, error)
}

Dialer is an interface that allows network connections to be dialed (net.Dialer fulfills this interface) and named pipes (a shim using winio.DialPipe)

type Error

type Error struct {
	Status  int
	Message string
}

Error represents failures in the API. It represents a failure from the API.

func (*Error) Error

func (e *Error) Error() string

Directories

Path Synopsis
Package netutil provides network related errors and helper functions.
Package netutil provides network related errors and helper functions.

Jump to

Keyboard shortcuts

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