softwareupgrade

package
v0.0.0-...-8582fd7 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CGeth   string = "geth"
	CInt    string = "int"
	CPKill  string = "pkill"
	CQuorum string = "quorum"
	CVault  string = "vault"

	CError      string = "error"
	CStatus     string = "status"
	CStart      string = "Start"
	CStop       string = "Stop "
	CNodeMsgSSS string = "Node %s: %s: %v"

	CEximchainUpgradeTitle string = "Eximchain Blockchain Software Upgrade v0.4"
	CGetCountShouldReturn  string = "GetCount() should return"
)

exported constants

Variables

This section is empty.

Functions

func ClearSSHConfigCache

func ClearSSHConfigCache()

ClearSSHConfigCache closes the SSH session and client connection in the sshConfigCache

func EnsureSSHConfigCache

func EnsureSSHConfigCache()

EnsureSSHConfigCache initializes the sshConfigCache so it can be used to cache SSHConfig

func Expand

func Expand(path string) (string, error)

Expand expands the ~ in the given path to the home directory

func FileExists

func FileExists(filename string) bool

FileExists checks if the given filename exists

func GetBackupSuffix

func GetBackupSuffix() string

GetBackupSuffix returns the backup suffix

func IntToStr

func IntToStr(value int) string

IntToStr converts an integer to a string

func ReadDataFromFile

func ReadDataFromFile(filename string) ([]byte, error)

ReadDataFromFile reads the contents of the given filename into a byte array and returns it.

func SaveDataToFile

func SaveDataToFile(filename string, data []byte) (bool, error)

SaveDataToFile is a simple way of writing to a given filename. Returns true if successful If the filename given points to an existing file, its contents are overwritten.

func SetSSHTimeout

func SetSSHTimeout(t time.Duration)

SetSSHTimeout sets the global SSH timeout, which will be picked up by when NewSSHConfig is called.

Types

type CopyInfo

type CopyInfo struct {
	LocalFilename  string `json:"LocalFilename"`
	RemoteFilename string `json:"RemoteFilename"`
}

CopyInfo contains the local and remote filenames for a transfer

type Duration

type Duration struct {
	time.Duration
}

Duration contains the delay to sleep between upgrades

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

MarshalJSON marshals the duration into JSON format

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the JSON into native Go structure

type FailedUpgradeInfo

type FailedUpgradeInfo struct {
	FailedNodeSoftware map[string][]string `json:"NodeSoftware"`
}

FailedUpgradeInfo records the name of nodes together with the software it failed to upgrade.

func NewFailedUpgradeInfo

func NewFailedUpgradeInfo() *FailedUpgradeInfo

NewFailedUpgradeInfo creates a structure necessary to contain failed upgrades

func (*FailedUpgradeInfo) AddNodeSoftware

func (failedUpgradeInfo *FailedUpgradeInfo) AddNodeSoftware(node, software string)

AddNodeSoftware adds the node and software to the failed upgrades

func (*FailedUpgradeInfo) Clear

func (failedUpgradeInfo *FailedUpgradeInfo) Clear()

Clear clears the mapping

func (*FailedUpgradeInfo) Empty

func (failedUpgradeInfo *FailedUpgradeInfo) Empty() (empty bool)

Empty returns true if failedUpgradeInfo's FailedNodeSoftware does not have any keys

func (*FailedUpgradeInfo) ExistsNodeSoftware

func (failedUpgradeInfo *FailedUpgradeInfo) ExistsNodeSoftware(node, software string) (result bool)

ExistsNodeSoftware returns true if a particular software for a nade exists in the failed upgrade info

func (*FailedUpgradeInfo) FindNode

func (failedUpgradeInfo *FailedUpgradeInfo) FindNode(node string) []string

FindNode returns the software for a node

func (*FailedUpgradeInfo) GetCount

func (failedUpgradeInfo *FailedUpgradeInfo) GetCount() (totalCount int)

GetCount returns the total number of values currently available

func (*FailedUpgradeInfo) GetNodeSoftwareCount

func (failedUpgradeInfo *FailedUpgradeInfo) GetNodeSoftwareCount(node string) int

GetNodeSoftwareCount gets the number of failed upgrades for a particular node

func (*FailedUpgradeInfo) RemoveNodeSoftware

func (failedUpgradeInfo *FailedUpgradeInfo) RemoveNodeSoftware(node, software string)

RemoveNodeSoftware removes a software from a node

type HashInterface

type HashInterface interface {
	Hash(filename string) (string, error)
}

HashInterface defines the interface that must be implemented

type Hasher

type Hasher interface {
	Md5sum(path string) (result string, err error)
	Sha256sum(path string) (result string, err error)
}

Hasher specifies the functions required to be implemented for a stricture to be compatible to the Hasher interface

type LocalHostHasher

type LocalHostHasher struct {
}

LocalHostHasher ...

func NewLocalHostHasher

func NewLocalHostHasher() (result *LocalHostHasher)

NewLocalHostHasher returns an empty structure which implicitly implements Hasher interface

func (*LocalHostHasher) Md5sum

func (hasher *LocalHostHasher) Md5sum(path string) (result string, err error)

Md5sum calculates the MD5 hash for a specified path

func (*LocalHostHasher) Sha256sum

func (hasher *LocalHostHasher) Sha256sum(path string) (result string, err error)

Sha256sum calculates the SHA256 hash for a specified path

type NodeInfoContainer

type NodeInfoContainer struct {
	UpgradeInfo
	SSHInfo
}

NodeInfoContainer contains the information necessary to connect to a particular node and its upgrade information

func (*NodeInfoContainer) RunAdd

func (nodeInfo *NodeInfoContainer) RunAdd(sshConfig *SSHConfig) (err error)

RunAdd adds the given files specified in the nodeInfo to the target node specified in the sshConfig

func (*NodeInfoContainer) RunDeleteAdd

func (nodeInfo *NodeInfoContainer) RunDeleteAdd(sshConfig *SSHConfig) (err error)

RunDeleteAdd deletes the specified files in the nodeInfo on the target nodes specified in the sshConfig

func (*NodeInfoContainer) RunDeleteRollback

func (nodeInfo *NodeInfoContainer) RunDeleteRollback(sshConfig *SSHConfig, rollbackSuffix string) (err error)

RunDeleteRollback deletes the rollback for a particular node

func (*NodeInfoContainer) RunRollback

func (nodeInfo *NodeInfoContainer) RunRollback(sshConfig *SSHConfig, rollbackSuffix string) (err error)

RunRollback runs the rollback for a particular node

func (*NodeInfoContainer) RunUpgrade

func (nodeInfo *NodeInfoContainer) RunUpgrade(sshConfig *SSHConfig) (err error)

RunUpgrade runs the upgrade for a particular node

type NodeUpgradeConfig

type NodeUpgradeConfig struct {
	NodeUpgradeInfo map[string]UpgradeInfo
}

NodeUpgradeConfig specifies the upgrade configuration for each node, if the node is not specified

type ResProcessStatus

type ResProcessStatus struct {
	Exists bool
	// contains filtered or unexported fields
}

ResProcessStatus provides the status

type RollbackSession

type RollbackSession struct {
	SessionSuffix string             `json:"SessionSuffix"`
	RollbackInfo  *FailedUpgradeInfo `json:"RollbackInfo"`
	Mode          string             `json:"Mode"`
}

RollbackSession contains the information required to rollback an upgrade/add session

func NewRollbackSession

func NewRollbackSession(aSessionSuffix string) (result *RollbackSession)

NewRollbackSession creates a new RollbackSession

type RollbackStruct

type RollbackStruct struct {
	DestFilePath string
}

RollbackStruct contains the necessary information in order to rollback a particular software to its previous state

type SSHConfig

type SSHConfig struct {
	HostIPOrAddr string
	RemoteOS     string
	// contains filtered or unexported fields
}

SSHConfig is used to carry the username, privatekey and the host to connect to.

func NewSSHConfig

func NewSSHConfig(user, KeyFilename, HostIPOrAddr string) (result *SSHConfig)

NewSSHConfig initializes a SSHConfig structure for executing a Run or Copy* command.

func NewSSHConfigKeyBytes

func NewSSHConfigKeyBytes(user string, KeyBytes []byte, HostIPOrAddr string) (result *SSHConfig)

NewSSHConfigKeyBytes creates a new SSHConfig based on the given information

func (*SSHConfig) Clear

func (sshConfig *SSHConfig) Clear()

Clear clears the privateKey, user and host stored in the configuration.

func (*SSHConfig) ClearSudo

func (sshConfig *SSHConfig) ClearSudo() (result *SSHConfig)

ClearSudo removes Sudo from Copy, CreateDirectory, ChangeFileOwnership and Run

func (*SSHConfig) Close

func (sshConfig *SSHConfig) Close()

Close closes both the session and the connection to the client.

func (*SSHConfig) CloseClient

func (sshConfig *SSHConfig) CloseClient()

CloseClient closes the client that was opened implicitly during OpenSession.

func (*SSHConfig) CloseSession

func (sshConfig *SSHConfig) CloseSession()

CloseSession closes the session that was opened using OpenSession

func (*SSHConfig) Connect

func (sshConfig *SSHConfig) Connect() (err error)

Connect connects to the given host specified in the configuration

func (*SSHConfig) Copy

func (sshConfig *SSHConfig) Copy(reader io.Reader, remotePath string, permissions string, size int64) (err error)

Copy copies the contents of the specified io.Reader to the given remote location. Requires a session to be opened already, unless autoOpenSession is set in the SSHConfig, in which case, Copy connects to the specified host given in the SSHConfig. permissions is a string, like 0644, or 0700, etc.

func (*SSHConfig) CopyBytesToFile

func (sshConfig *SSHConfig) CopyBytesToFile(contentBytes []byte, remotePath string, permissions string) (err error)

CopyBytesToFile copies the contents of the given []byte to the specified remotePath

func (*SSHConfig) CopyBytesToFileAndVerify

func (sshConfig *SSHConfig) CopyBytesToFileAndVerify(contentBytes []byte, remotePath string, permissions string) (err error)

CopyBytesToFileAndVerify copies the contents of the given []byte to the specified remotePath, and verifies that it's on the remote side

func (*SSHConfig) CopyFile

func (sshConfig *SSHConfig) CopyFile(fileReader io.Reader, remotePath string, permissions string) error

CopyFile copies the contents of an io.Reader to a remote location, the length is determined by reading the io.Reader until EOF is reached. if the file length is known in advance, use "Copy" instead.

func (*SSHConfig) CopyFromFile

func (sshConfig *SSHConfig) CopyFromFile(file os.File, remotePath string, permissions string) error

CopyFromFile copies the contents of an os.File to a remote location, it will get the length of the file by looking it up from the filesystem.

func (*SSHConfig) CopyLocalFileToRemoteFile

func (sshConfig *SSHConfig) CopyLocalFileToRemoteFile(localFilename, remoteFilename, permissions string) error

CopyLocalFileToRemoteFile copies the given local filename to the remote filename with the given permissions localFilename must be the filename of a local file and remoteFilename must be the remote filename, not a directory.

func (*SSHConfig) CopyRemoteFileToLocalFile

func (sshConfig *SSHConfig) CopyRemoteFileToLocalFile(remoteFilename, localFilename, permissions string) (err error)

CopyRemoteFileToLocalFile copies the given remote file to the local file, setting the permissions for the local file.

func (*SSHConfig) CreateDirectory

func (sshConfig *SSHConfig) CreateDirectory(path string) (err error)

CreateDirectory creates the specified directory on the host specified in the given SSHConfig

func (*SSHConfig) Destroy

func (sshConfig *SSHConfig) Destroy()

Destroy closes the connection to the client and clears the privatKey, user and host stored in the configuration.

func (*SSHConfig) DirectoryExists

func (sshConfig *SSHConfig) DirectoryExists(path string) (result bool, err error)

DirectoryExists verifies that the given path exists on the host specified in the given SSHConfig Might not be able to deal with symlink as a directory.

func (*SSHConfig) DisableAutoOpen

func (sshConfig *SSHConfig) DisableAutoOpen()

DisableAutoOpen sets the autoOpenSession flag to false so tat sessions are not automatically opened.

func (*SSHConfig) DisableVerbose

func (sshConfig *SSHConfig) DisableVerbose() (result *SSHConfig)

DisableVerbose disables verbose response for file transfers

func (*SSHConfig) EnableAutoOpen

func (sshConfig *SSHConfig) EnableAutoOpen()

EnableAutoOpen sets the autoOpenSession flag to true so that sessions are automatically opened.

func (*SSHConfig) EnableVerbose

func (sshConfig *SSHConfig) EnableVerbose() (result *SSHConfig)

EnableVerbose enables verbose response for file transfers

func (*SSHConfig) FileExists

func (sshConfig *SSHConfig) FileExists(file string) (result bool, err error)

FileExists verifies that the given file exists on the host specified in the given SSHConfig Able to handle symlink. Tested.

func (*SSHConfig) GetOS

func (sshConfig *SSHConfig) GetOS() string

GetOS returns the OS that is running on the host specified in the given SSHConfig

func (*SSHConfig) InteractiveSession

func (sshConfig *SSHConfig) InteractiveSession()

InteractiveSession must always be followed by a deferred call to sshConfig.Destroy() or sshConfig.Close()

func (*SSHConfig) Interrupt

func (sshConfig *SSHConfig) Interrupt(processName string) (result string, err error)

Interrupt sends the interrupt signal to the given processName running on the host in the given SSHConfig

func (*SSHConfig) MakeSudo

func (sshConfig *SSHConfig) MakeSudo() (result *SSHConfig)

MakeSudo enables Sudo on Copy, CreateDirectory, and ChangeFileOwnership and Run

func (*SSHConfig) Md5sum

func (sshConfig *SSHConfig) Md5sum(path string) (result string, err error)

Md5sum calculates the MD5 for the given path on the host specified in the given SSHConfig

func (*SSHConfig) OpenSession

func (sshConfig *SSHConfig) OpenSession() (*ssh.Session, *ssh.Client, error)

OpenSession opens a SSH session to the host specified in the given SSHConfig

func (*SSHConfig) ProcessStatus

func (sshConfig *SSHConfig) ProcessStatus(processName string) *ResProcessStatus

ProcessStatus detects if a process is running in the environment specified in the SSHConfig.

func (*SSHConfig) ReadBytesFromFile

func (sshConfig *SSHConfig) ReadBytesFromFile(remotePath string) (result []byte, err error)

ReadsBytesFromFile reads the contents of a file.

func (*SSHConfig) Run

func (sshConfig *SSHConfig) Run(cmd string) (string, error)

Run runs a command on the given SSH environment, usage: output, err := Run("ls") Automatically closes the client and session

func (*SSHConfig) SetKeepAlive

func (sshConfig *SSHConfig) SetKeepAlive(t time.Duration)

SetKeepAlive sets the duration to send a keep-alive message on a SSH connection

func (*SSHConfig) SetMaxRetries

func (sshConfig *SSHConfig) SetMaxRetries(retries int) (result *SSHConfig)

SetMaxRetries sets the max. no. of retries on connection failure

func (*SSHConfig) SetSleepBtwRetries

func (sshConfig *SSHConfig) SetSleepBtwRetries(sleepMS int64) (result *SSHConfig)

SetSleepBtwRetries sets the max. no. of sleep between connection retries

func (*SSHConfig) Sha256sum

func (sshConfig *SSHConfig) Sha256sum(path string) (result string, err error)

Sha256sum calculates the SHA256 for the given path on the host specified in the given SSHConfig

func (*SSHConfig) Signal

func (sshConfig *SSHConfig) Signal(processName, signal string) (result string, err error)

Signal sends the specified signal to the given processName…

func (*SSHConfig) Sum

func (sshConfig *SSHConfig) Sum(path string) (result string, err error)

Sum calculates the checksum of any given file on the host specified in the given SSHConfig

type SSHInfo

type SSHInfo struct {
	SSHCert     string `json:"ssh_cert"`
	SSHUserName string `json:"ssh_username"`
	SSHTimeout  string `json:"ssh_timeout"`
}

SSHInfo contains the SSH cert and the username to be used for a SSH connection

type TDebugLog

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

TDebugLog specifies where to send debugs to, and whether to also print the debug log to the console

var (
	// DebugLog enables access to logging facilities
	DebugLog TDebugLog
)

func (*TDebugLog) CloseDebugLog

func (d *TDebugLog) CloseDebugLog()

CloseDebugLog flushes the debug log and closes it.

func (*TDebugLog) Debug

func (d *TDebugLog) Debug(format string, args ...interface{})

Debug decides whether to send the log to the debug log file

func (*TDebugLog) Debugf

func (d *TDebugLog) Debugf(format string, args ...interface{})

Debugf decides whether to send the log to the debug log file

func (*TDebugLog) Debugln

func (d *TDebugLog) Debugln(format string, args ...interface{})

Debugln adds a newline to the debug string

func (*TDebugLog) EnableDebug

func (d *TDebugLog) EnableDebug()

EnableDebug sets the printDebug flag

func (*TDebugLog) EnableDebugLog

func (d *TDebugLog) EnableDebugLog(LogFilename string) (err error)

EnableDebugLog changes the log output to a new file specified by the given filename

func (*TDebugLog) EnablePrintConsole

func (d *TDebugLog) EnablePrintConsole()

EnablePrintConsole sets the PrintConsole flag

func (*TDebugLog) GetFilename

func (d *TDebugLog) GetFilename() (result string)

GetFilename returns the filename that is currently in use by d, if it is assigned.

func (*TDebugLog) Print

func (d *TDebugLog) Print(format string, args ...interface{})

Print decides whether the debug log is sent to the console, or not, and also logs it to the debug log

func (*TDebugLog) Printf

func (d *TDebugLog) Printf(format string, args ...interface{})

Printf prints the specified debug log

func (*TDebugLog) Println

func (d *TDebugLog) Println(msg string, args ...interface{})

Println adds a newline to the specified debug log

func (*TDebugLog) SetOutput

func (d *TDebugLog) SetOutput(w io.Writer)

SetOutput changes the output writer for the log

type UpgradeConfig

type UpgradeConfig struct {
	Common struct {
		SSHInfo                           // This specifies the general and common SSL configuration for common nodes
		SoftwareGroup map[string][]string `json:"software_group"` // This specifies the software type that's possible to run on a node, the start and stop command, the command used to upgrade the software
		GroupPause    Duration            `json:"group_pause_after_upgrade"`
	} `json:"common"`
	Nodes    map[string]NodeInfoContainer `json:"nodes"`    // This is a map with the key as the DNS hostnames of each node that participates in the network
	Software map[string]UpgradeInfo       `json:"software"` // this defines each individual piece of software
	// This specifies the combination of software on each node.
	// So, say, vault and quorum is one group 1.
	// blockmetrics, cloudwatchmetrics, constellation is group 2.
	// So node1 and node3 runs group 1.
	// node2 and node4 runs group 2.
	// node5, node6, node7 runs group 3.
	SoftwareGroupNodes map[string][]string `json:"groupnodes"`
}

UpgradeConfig contains the configuration for upgrading nodes

func (*UpgradeConfig) GetGroupNames

func (config *UpgradeConfig) GetGroupNames() (result []string)

GetGroupNames gets the groups specified in the config

func (*UpgradeConfig) GetGroupNodes

func (config *UpgradeConfig) GetGroupNodes(groupName string) (result []string)

GetGroupNodes gets the nodes belonging to the spcified group

func (*UpgradeConfig) GetGroupSoftware

func (config *UpgradeConfig) GetGroupSoftware(groupName string) (result []string)

GetGroupSoftware gets the software belonging to the specified group

func (*UpgradeConfig) GetNodeCount

func (config *UpgradeConfig) GetNodeCount() (result int)

GetNodeCount retrieves the number of nodes that are defined under all software groups

func (*UpgradeConfig) GetNodeUpgradeInfo

func (config *UpgradeConfig) GetNodeUpgradeInfo(node, software string) (result *NodeInfoContainer)

GetNodeUpgradeInfo gets the specific upgrade information for a particular node's software.

func (*UpgradeConfig) GetNodes

func (config *UpgradeConfig) GetNodes() (result []string)

GetNodes return the DNS names of all the nodes in the configuration

func (*UpgradeConfig) VerifyFilesExist

func (config *UpgradeConfig) VerifyFilesExist() (err error)

VerifyFilesExist verifies that all the SourceFiles specified exists. If this is true, error is nil. If any of the files specified in the SourceFilePath does not exist, an error msg for each file that doesn't exist is returned.

type UpgradeInfo

type UpgradeInfo struct {
	PostUpgrade []string `json:"postupgrade"`
	PreUpgrade  []string `json:"preupgrade"`
	StartCmd    string   `json:"start"`
	StopCmd     string   `json:"stop"`

	// The key string is actually integer, and the order of the
	// copy will be numeric order.
	Copy map[string]UpgradeStruct `json:"Copy"`
	Exec []string                 `json:"Exec"`
}

UpgradeInfo contains the information necessary to start and stop a particular software on a node

type UpgradeStruct

type UpgradeStruct struct {
	SourceFilePath string `json:"Local_Filename"`  // local file path
	DestFilePath   string `json:"Remote_Filename"` // remote file path
	UserGroup      string `json:"UserGroup"`       // specifies user:group ownership
	Permissions    string `json:"Permissions"`     // permissions of the newly copied file
	VerifyCopy     string `json:"VerifyCopy"`      // command to run to verify copy is successful
	RollbackPath   string `json:"RollbackPath"`    // internal rollback
	BackupStrategy string `json:"BackupStrategy"`  // either copy or move
}

UpgradeStruct contains the information necessary to add/upgrade a particular software on a node

Jump to

Keyboard shortcuts

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