hostspool

package
v4.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2022 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CheckpointError is an error of checkpoint between the current Hosts Pool
	// and an apply change request
	CheckpointError = "Checkpoint for Hosts Pool error"
)

Variables

This section is empty.

Functions

func IsBadRequestError

func IsBadRequestError(err error) bool

IsBadRequestError checks if an error is an error due to a bad input

func IsHostAlreadyExistError

func IsHostAlreadyExistError(err error) bool

IsHostAlreadyExistError checks if an error is an "host already exists" error

func IsHostConnectionError

func IsHostConnectionError(err error) bool

IsHostConnectionError checks if an error is an error due to host connection error

func IsHostNotFoundError

func IsHostNotFoundError(err error) bool

IsHostNotFoundError checks if an error is an "host not found" error

func IsNoMatchingHostFoundError

func IsNoMatchingHostFoundError(err error) bool

IsNoMatchingHostFoundError checks if an error is an error due to no hosts match the given filters if any

Types

type Allocation

type Allocation struct {
	ID               string             `json:"id"`
	NodeName         string             `json:"node_name"`
	Instance         string             `json:"instance"`
	DeploymentID     string             `json:"deployment_id"`
	Shareable        bool               `json:"shareable"`
	Resources        map[string]string  `json:"resource_labels,omitempty"`
	GenericResources []*GenericResource `json:"gres_labels,omitempty"`
	PlacementPolicy  string             `json:"placement_policy"`
}

An Allocation describes the related allocation associated to a host pool

func (*Allocation) String

func (alloc *Allocation) String() string

type Connection

type Connection struct {
	// The User that we should use for the connection. Defaults to root.
	User string `json:"user,omitempty" yaml:"user,omitempty"`
	// The Password that we should use for the connection. One of Password or PrivateKey is required. PrivateKey takes the precedence.
	Password string `json:"password,omitempty" yaml:"password,omitempty"`
	// The SSH Private Key that we should use for the connection. One of Password or PrivateKey is required. PrivateKey takes the precedence.
	// The mapstructure tag is needed for viper unmarshalling
	PrivateKey string `json:"private_key,omitempty"  yaml:"private_key,omitempty" mapstructure:"private_key"`
	// The address of the Host to connect to. Defaults to the hostname specified during the registration.
	Host string `json:"host,omitempty" yaml:"host,omitempty"`
	// The Port to connect to. Defaults to 22 if set to 0.
	Port uint64 `json:"port,omitempty" yaml:"port,omitempty"`
}

A Connection holds info used to connect to a host using SSH

func (Connection) String

func (conn Connection) String() string

String allows to stringify a connection

type GenericResource

type GenericResource struct {
	// name of the generic resource
	Name string `json:"name"`
	// label used in allocations and hosts pool as host.resource.<name>
	Label string `json:"label"`
	// allocation label value set once the generic resource is allocated/released
	Value string `json:"value"`
	// define if the generic resource can be only used by a single compute (consumable) or not
	NoConsumable bool `json:"no_consumable"`
	// contains filtered or unexported fields
}

GenericResource represents a generic resource requirement

type Host

type Host struct {
	Name        string            `json:"name,omitempty"`
	Connection  Connection        `json:"connection,omitempty"`
	Status      HostStatus        `json:"status,omitempty"`
	Message     string            `json:"reason,omitempty"`
	Labels      map[string]string `json:"labels,omitempty"`
	Allocations []Allocation      `json:"allocations,omitempty"`
}

An Host holds information on an Host as it is known by the hostspool

type HostConfig

type HostConfig struct {
	Name       string            `json:"name,omitempty"`
	Connection Connection        `json:"connection,omitempty"`
	Labels     map[string]string `json:"labels,omitempty"`
}

An HostConfig holds information on an Host basic configuration It's a short version of Host representation

type HostStatus

type HostStatus int

HostStatus is an enumerated type for hosts statuses

ENUM(

free allocated error )

const (
	// HostStatusFree is a HostStatus of type Free
	HostStatusFree HostStatus = iota
	// HostStatusAllocated is a HostStatus of type Allocated
	HostStatusAllocated
	// HostStatusError is a HostStatus of type Error
	HostStatusError
)

func ParseHostStatus

func ParseHostStatus(name string) (HostStatus, error)

ParseHostStatus attempts to convert a string to a HostStatus

func (HostStatus) MarshalJSON

func (hs HostStatus) MarshalJSON() ([]byte, error)

MarshalJSON is used to represent this enumeration as a string instead of an int

func (HostStatus) String

func (x HostStatus) String() string

String implements the Stringer interface.

func (*HostStatus) UnmarshalJSON

func (hs *HostStatus) UnmarshalJSON(b []byte) error

UnmarshalJSON is used to read this enumeration from a string

type Manager

type Manager interface {
	Add(locationName, hostname string, connection Connection, labels map[string]string) error
	Apply(locationName string, pool []Host, checkpoint *uint64) error
	Remove(locationName, hostname string) error
	UpdateResourcesLabels(locationName, hostname string, diff map[string]string, operation resourceOperationFunc, update resourceUpdateFunc, gResources []*GenericResource, gResourcesOperation genericResourceOperationFunc, updateGenericResources genericResourceUpdateFunc) error
	AddLabels(locationName, hostname string, labels map[string]string) error
	RemoveLabels(locationName, hostname string, labels []string) error
	UpdateConnection(locationName, hostname string, connection Connection) error
	List(locationName string, filters ...labelsutil.Filter) ([]string, []labelsutil.Warning, uint64, error)
	GetHost(locationName, hostname string) (Host, error)
	Allocate(locationName string, allocation *Allocation, filters ...labelsutil.Filter) (string, []labelsutil.Warning, error)
	Release(locationName, hostname, deploymentID, nodeName, instance string) (*Allocation, error)
	ListLocations() ([]string, error)
	RemoveLocation(locationName string) error
	CheckPlacementPolicy(placementPolicy string) error
}

A Manager is in charge of creating/updating/deleting hosts from the pool

func NewManager

func NewManager(cc *api.Client, cfg config.Configuration) Manager

NewManager creates a Manager backed to Consul

func NewManagerWithSSHFactory

func NewManagerWithSSHFactory(cc *api.Client, cfg config.Configuration, sshClientFactory SSHClientFactory) Manager

NewManagerWithSSHFactory creates a Manager with a given ssh factory

Currently this is used for testing purpose to mock the ssh connection.

type Pool

type Pool struct {
	Hosts []Host `json:"hosts,omitempty"`
}

A Pool holds information on a hosts pool

type PoolConfig

type PoolConfig struct {
	Hosts []HostConfig `json:"hosts,omitempty"`
}

A PoolConfig holds information on hosts configurations of a pool

type SSHClientFactory

type SSHClientFactory func(config *ssh.ClientConfig, conn Connection) sshutil.Client

SSHClientFactory is a that could be called to customize the client used to check the connection.

Currently this is used for testing purpose to mock the ssh connection.

Jump to

Keyboard shortcuts

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