helpers

package
v1.8.7 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2019 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package helpers contains functions to help make the task of deploying a blockchain easier and faster

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllNewNodeExecCon

func AllNewNodeExecCon(tn *testnet.TestNet, fn func(ssh.Client, *db.Server, ssh.Node) error) error

AllNewNodeExecCon is AllNodeExecCon but executes only for new nodes

func AllNewNodeExecConSC added in v1.7.1

func AllNewNodeExecConSC(ad *testnet.Adjunct, fn func(ssh.Client, *db.Server, ssh.Node) error) error

AllNewNodeExecConSC is AllNewNodeExecCon but executes only for sidecar nodes

func AllNodeExecCon

func AllNodeExecCon(tn *testnet.TestNet, fn func(ssh.Client, *db.Server, ssh.Node) error) error

AllNodeExecCon executes fn for every node concurrently. Will return once all of the calls to fn have been completely. Each call to fn is provided with, in order, the relevant ssh client, the server where the node exists, the local number of that node on the server and the absolute number of the node in the testnet. If any of the calls to fn return a non-nil error value, one of those errors will be returned. Currently there is no guarantee as to which one, however this should be implemented in the future.

func AllNodeExecConSC added in v1.7.1

func AllNodeExecConSC(ad *testnet.Adjunct, fn func(ssh.Client, *db.Server, ssh.Node) error) error

AllNodeExecConSC is AllNodeExecCon but executes only for sidecar nodes

func AllServerExecCon

func AllServerExecCon(tn *testnet.TestNet, fn func(ssh.Client, *db.Server) error) error

AllServerExecCon executes fn for every server in the testnet. Is sementatically similar to AllNodeExecCon. Every call to fn is provided with the relevant ssh client and server object.

func AllServerExecConSC added in v1.7.1

func AllServerExecConSC(ad *testnet.Adjunct, fn func(ssh.Client, *db.Server) error) error

AllServerExecConSC is like AllServerExecCon but for side cars

func CheckDeployFlag

func CheckDeployFlag(details *db.DeploymentDetails, flag string) bool

CheckDeployFlag checks for the presence of an extras flag.

func CopyAllToServers

func CopyAllToServers(tn *testnet.TestNet, srcDst ...string) error

CopyAllToServers copies all of the src files to all of the servers within the given testnet. This can handle multiple pairs in form of ...,source,destination,source2,destination2

func CopyBytesToAllNewNodes

func CopyBytesToAllNewNodes(tn *testnet.TestNet, dataDst ...string) error

CopyBytesToAllNewNodes is CopyBytesToAllNodes but only operates on newly built nodes

func CopyBytesToAllNewNodesSC added in v1.7.1

func CopyBytesToAllNewNodesSC(ad *testnet.Adjunct, dataDst ...string) error

CopyBytesToAllNewNodesSC is CopyBytesToAllNewNodes but only operates on sidecar nodes

func CopyBytesToAllNodes

func CopyBytesToAllNodes(tn *testnet.TestNet, dataDst ...string) error

CopyBytesToAllNodes functions similarly to CopyToAllNodes, except it operates on data and dst pairs instead of src and dest pairs, so you can just pass data directly to all of the nodes without having to call buildState.Write first.

func CopyBytesToAllNodesSC added in v1.7.1

func CopyBytesToAllNodesSC(ad *testnet.Adjunct, dataDst ...string) error

CopyBytesToAllNodesSC is CopyBytesToAllNodes but only operates on sidecar nodes

func CopyToAllNewNodes

func CopyToAllNewNodes(tn *testnet.TestNet, srcDst ...string) error

CopyToAllNewNodes copies files written with BuildState's write function over to all of the newly built nodes. Can handle multiple files, in pairs of src and dst

func CopyToAllNewNodesSC added in v1.7.1

func CopyToAllNewNodesSC(ad *testnet.Adjunct, srcDst ...string) error

CopyToAllNewNodesSC is CopyToAllNewNodes for side cars

func CopyToAllNodes

func CopyToAllNodes(tn *testnet.TestNet, srcDst ...string) error

CopyToAllNodes copies files written with BuildState's write function over to all of the nodes. Can handle multiple files, in pairs of src and dst

func CopyToAllNodesSC added in v1.7.1

func CopyToAllNodesSC(ad *testnet.Adjunct, srcDst ...string) error

CopyToAllNodesSC is CopyToAllNodes for side cars

func CreateConfigs

func CreateConfigs(tn *testnet.TestNet, dest string, fn func(ssh.Node) ([]byte, error)) error

CreateConfigs allows for individual generation of configuration files with error propagation. For each node, fn will be called, with (Server ID, local node number, absolute node number), and it will expect to have the configuration file returned or error.

func CreateConfigsNewNodes

func CreateConfigsNewNodes(tn *testnet.TestNet, dest string, fn func(ssh.Node) ([]byte, error)) error

CreateConfigsNewNodes is CreateConfigs but it only operates on new nodes

func CreateConfigsNewNodesSC added in v1.7.1

func CreateConfigsNewNodesSC(ad *testnet.Adjunct, dest string, fn func(ssh.Node) ([]byte, error)) error

CreateConfigsNewNodesSC is CreateConfigsNewNodes but it only operates on side cars

func CreateConfigsSC added in v1.7.1

func CreateConfigsSC(ad *testnet.Adjunct, dest string, fn func(ssh.Node) ([]byte, error)) error

CreateConfigsSC is CreateConfigs but it only operates on side cars

func DefaultGetDefaultsFn added in v1.7.7

func DefaultGetDefaultsFn(blockchain string) func() string

DefaultGetDefaultsFn creates the default function for getting a blockchains default parameters

func DefaultGetParamsFn added in v1.7.5

func DefaultGetParamsFn(blockchain string) func() string

DefaultGetParamsFn creates the default function for getting a blockchains parameters

func GetBlockchainConfig

func GetBlockchainConfig(blockchain string, node int, file string, details *db.DeploymentDetails) ([]byte, error)

GetBlockchainConfig fetches dynamic config template files for the blockchain. Should be used in most cases instead of GetStaticBlockchainConfig as it provides the user the functionality for `-t..` in the build command for the CLI

func GetDefaults

func GetDefaults(details *db.DeploymentDetails, term string) (interface{}, bool)

GetDefaults get any available default value for a given term. will be nil,false if it is not found

func GetFileDefault

func GetFileDefault(details *db.DeploymentDetails, file string) (string, bool)

GetFileDefault gets the default value for a file if it exists in the extras

func GetServiceIps added in v1.8.3

func GetServiceIps(services []Service) (map[string]string, error)

GetServiceIps creates a map of the service names to their ip addresses. Useful for determining the ip address of a service.

func GetStaticBlockchainConfig

func GetStaticBlockchainConfig(blockchain string, file string) ([]byte, error)

GetStaticBlockchainConfig fetches a static file resource for a blockchain, which will never change

func HandleBlockchainConfig added in v1.7.6

func HandleBlockchainConfig(blockchain string, data map[string]interface{}, out interface{}) error

HandleBlockchainConfig handles the creation of a blockchain configuration from the defaults and given data from the deployment details

func MkdirAllNewNodes added in v1.7.5

func MkdirAllNewNodes(tn *testnet.TestNet, dir string) error

MkdirAllNewNodes makes a dir on all new nodes

func MkdirAllNodes added in v1.7.5

func MkdirAllNodes(tn *testnet.TestNet, dir string) error

MkdirAllNodes makes a dir on all nodes

func ScpAndDeferRemoval

func ScpAndDeferRemoval(client ssh.Client, buildState *state.BuildState, src string, dst string)

ScpAndDeferRemoval Copy a file over to a server, and then defer it for removal after the build is completed

func SingleCp

func SingleCp(client ssh.Client, buildState *state.BuildState, node ssh.Node, data []byte, dest string) error

SingleCp copies over data to the given dest on node localNodeID.

Types

type KeyMaster

type KeyMaster struct {
	//PrivateKeys contains the static pool of private keys
	PrivateKeys []string
	//PublicKeys contains the static pool of private keys.
	PublicKeys []string
	// contains filtered or unexported fields
}

KeyMaster is a static resource key manager Uses keys stored in the blockchains resource directory, so that keys can remain consistent among builds and also to save time on builds where a large number of keys are needed. Note: This is not thread safe and may need external synchronization.

func NewKeyMaster

func NewKeyMaster(details *db.DeploymentDetails, blockchain string) (*KeyMaster, error)

NewKeyMaster creates a new KeyMaster using the provided deployment details and blockchain. Currently details is not used, but in the future, it should be used to allow the user to provide their own static keys to be used in the pool.

func (*KeyMaster) AddGenerator

func (km *KeyMaster) AddGenerator(gen func(client ssh.Client) (util.KeyPair, error))

AddGenerator sets the backup key generator function for km KeyMaster

func (*KeyMaster) GenerateKeyPair

func (km *KeyMaster) GenerateKeyPair(client ssh.Client) (util.KeyPair, error)

GenerateKeyPair generates a new key pair if a generator function has been provided

func (*KeyMaster) GetKeyPair

func (km *KeyMaster) GetKeyPair(client ssh.Client) (util.KeyPair, error)

GetKeyPair fetches a key pair, will use up keys in the static pool until it runs out, if it runs out, it will use the given generator to create new keys

func (*KeyMaster) GetMappedKeyPairs

func (km *KeyMaster) GetMappedKeyPairs(args []string, client ssh.Client) (map[string]util.KeyPair, error)

GetMappedKeyPairs returns key pairs mapped to arbitrary string values. Useful for named key pairs

func (*KeyMaster) GetServerKeyPairs

func (km *KeyMaster) GetServerKeyPairs(servers []db.Server, clients []ssh.Client) (map[string]util.KeyPair, error)

GetServerKeyPairs is DEPRECATED, but maps the ip addresses of nodes to their own key pair

type PrometheusService added in v1.8.3

type PrometheusService struct {
	SimpleService
}

PrometheusService represents the Prometheus service

func (PrometheusService) Prepare added in v1.8.3

func (p PrometheusService) Prepare(client ssh.Client, tn *testnet.TestNet) error

Prepare prepares the prometheus service

type Service added in v1.8.3

type Service interface {
	// Prepare prepares the service
	Prepare(client ssh.Client, tn *testnet.TestNet) error

	// GetName gets the name of service
	GetName() string

	// GetImage gets the image of service
	GetImage() string

	// GetEnv gets the environment variables of service
	GetEnv() map[string]string

	// GetNetwork gets the network of the service
	GetNetwork() string

	// GetPorts gets the ports published by the service
	GetPorts() []string

	// GetVolumes gets the volumes mounted on the service container
	GetVolumes() []string
}

Service represents a service

func RegisterPrometheus added in v1.8.3

func RegisterPrometheus() Service

RegisterPrometheus exposes a Prometheus service on the testnet.

type SimpleService added in v1.8.3

type SimpleService struct {
	Name    string            `json:"name"`
	Image   string            `json:"image"`
	Env     map[string]string `json:"env"`
	Network string            `json:"network"`
	Ports   []string          `json:"ports"`
	Volumes []string          `json:"volumes"`
}

SimpleService represents a service for a blockchain. All env variables will be passed to the container.

func (SimpleService) GetEnv added in v1.8.3

func (s SimpleService) GetEnv() map[string]string

GetEnv gets the environment variables of service

func (SimpleService) GetImage added in v1.8.3

func (s SimpleService) GetImage() string

GetImage gets the image of service

func (SimpleService) GetName added in v1.8.3

func (s SimpleService) GetName() string

GetName gets the name of service

func (SimpleService) GetNetwork added in v1.8.3

func (s SimpleService) GetNetwork() string

GetNetwork gets the network of the service

func (SimpleService) GetPorts added in v1.8.3

func (s SimpleService) GetPorts() []string

GetPorts gets the ports published by the service

func (SimpleService) GetVolumes added in v1.8.3

func (s SimpleService) GetVolumes() []string

GetVolumes gets the volumes mounted on the service container

func (SimpleService) Prepare added in v1.8.3

func (s SimpleService) Prepare(client ssh.Client, tn *testnet.TestNet) error

Prepare just returns nil. Simple service has no prepare step

Jump to

Keyboard shortcuts

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