client

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2022 License: Apache-2.0 Imports: 25 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRequestFailure is returned if client fails to send
	// the request mostly duo to network problem. Mostly
	// this error is resolved by retrying again later.
	ErrRequestFailure = fmt.Errorf("request failure")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	Phonebook Phonebook
	Directory Directory
	Workloads Workloads
}

Client structure

func NewClient

func NewClient(u string, id Identity) (*Client, error)

NewClient creates a new client, if identity is not nil, it will be used to authenticate requests against the server

type Directory

type Directory interface {
	FarmRegister(farm directory.Farm) (schema.ID, error)
	FarmUpdate(farm directory.Farm) error
	FarmList(tid schema.ID, name string, page *Pager) (farms []directory.Farm, err error)
	FarmGet(id schema.ID) (farm directory.Farm, err error)
	Farms(cacheSize int) FarmIter

	GatewayRegister(Gateway directory.Gateway) error
	GatewayList(tid schema.ID, name string, page *Pager) (farms []directory.Gateway, err error)
	GatewayGet(id string) (farm directory.Gateway, err error)
	GatewayUpdateUptime(id string, uptime uint64) error
	GatewayUpdateReservedResources(id string, resources directory.ResourceAmount, workloads directory.WorkloadAmount) error

	NodeRegister(node directory.Node) error
	NodeList(filter NodeFilter, pager *Pager) (nodes []directory.Node, err error)
	NodeGet(id string, proofs bool) (node directory.Node, err error)
	Nodes(cacheSize int, proofs bool) NodeIter

	NodeSetInterfaces(id string, ifaces []directory.Iface) error
	NodeSetPorts(id string, ports []uint) error
	NodeSetPublic(id string, pub directory.PublicIface) error
	NodeSetFreeToUse(id string, free bool) error

	//TODO: this method call uses types from zos that is not generated
	//from the schema. Which is wrong imho.
	NodeSetCapacity(
		id string,
		resources directory.ResourceAmount,
		dmiInfo dmi.DMI,
		disksInfo capacity.Disks,
		hypervisor []string,
	) error

	NodeUpdateUptime(id string, uptime uint64) error
	NodeUpdateUsedResources(id string, resources directory.ResourceAmount, workloads directory.WorkloadAmount) error
}

Directory API interface

type FarmIter

type FarmIter interface {
	Next() (*directory.Farm, error)
}

FarmIter iterator over all farms

If the iterator has finished, a nil error and nil farm pointer is returned

type HTTPError

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

HTTPError is the error type returned by the client it contains the error and the HTTP response

func (HTTPError) Error

func (h HTTPError) Error() string

func (HTTPError) Response

func (h HTTPError) Response() http.Response

Response return the HTTP response that trigger this error

type Identity

type Identity interface {
	// The unique ID as known by the explorer
	Identity() string
	// PrivateKey used to sign the requests
	PrivateKey() ed25519.PrivateKey
}

Identity is used by the client to authenticate to the explorer API

type NodeFilter

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

NodeFilter used to build a query for node list

func (NodeFilter) Apply

func (n NodeFilter) Apply(query url.Values)

Apply fills query

func (NodeFilter) WithCRU

func (n NodeFilter) WithCRU(cru int64) NodeFilter

WithCRU filter with CRU

func (NodeFilter) WithCity

func (n NodeFilter) WithCity(city string) NodeFilter

WithCity filter with city

func (NodeFilter) WithCountry

func (n NodeFilter) WithCountry(country string) NodeFilter

WithCountry filter with country

func (NodeFilter) WithDeleted

func (n NodeFilter) WithDeleted(deleted bool) NodeFilter

WithDeleted filter with deleted nodes

func (NodeFilter) WithFarm

func (n NodeFilter) WithFarm(id int64) NodeFilter

WithFarm filter with farm

func (NodeFilter) WithHRU

func (n NodeFilter) WithHRU(hru int64) NodeFilter

WithHRU filter with HRU

func (NodeFilter) WithMRU

func (n NodeFilter) WithMRU(sru int64) NodeFilter

WithMRU filter with mru

func (NodeFilter) WithProofs

func (n NodeFilter) WithProofs(proofs bool) NodeFilter

WithProofs filter with proofs

type NodeIter

type NodeIter interface {
	Next() (*directory.Node, error)
}

NodeIter iterator over all nodes

If the iterator has finished, a nil error and nil node pointer is returned

type Pager

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

Pager for listing

func Page

func Page(page, size int) *Pager

Page returns a pager

type Phonebook

type Phonebook interface {
	Create(user phonebook.User) (schema.ID, error)
	List(name, email string, page *Pager) (output []phonebook.User, err error)
	Get(id schema.ID) (phonebook.User, error)
	// Update() #TODO
	Validate(id schema.ID, message, signature string) (bool, error)
}

Phonebook interface

type Signer

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

Signer is a utility to easily sign payloads

func NewSigner

func NewSigner(seed []byte) (*Signer, error)

NewSigner create a signer with a seed

func NewSignerFromFile

func NewSignerFromFile(path string) (*Signer, error)

NewSignerFromFile loads signer from a seed file

func (*Signer) Sign

func (s *Signer) Sign(o ...interface{}) ([]byte, []byte, error)

Sign constructs a message from all it's arguments then sign it

func (*Signer) SignHex

func (s *Signer) SignHex(o ...interface{}) (string, string, error)

SignHex like sign, but return message and signature in hex encoded format

type Workloads

type Workloads interface {
	Create(reservation workloads.Workloader) (resp wrklds.ReservationCreateResponse, err error)
	List(nextAction *workloads.NextActionEnum, customerTid int64, page *Pager) (reservation []workloads.Reservation, err error)
	Get(id schema.ID) (reservation workloads.Workloader, err error)

	SignProvision(id schema.ID, user schema.ID, signature string) error
	SignDelete(id schema.ID, user schema.ID, signature string) error

	PoolCreate(reservation types.Reservation) (resp wrklds.CapacityPoolCreateResponse, err error)
	PoolGet(poolID string) (result types.Pool, err error)
	PoolsGetByOwner(ownerID string) (result []types.Pool, err error)

	NodeWorkloads(nodeID string, from uint64) ([]workloads.Workloader, uint64, error)
	NodeWorkloadGet(gwid string) (result workloads.Workloader, err error)
	NodeWorkloadPutResult(nodeID, gwid string, result workloads.Result) error
	NodeWorkloadPutDeleted(nodeID, gwid string) error
}

Workloads interface

Jump to

Keyboard shortcuts

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