Documentation ¶
Index ¶
- Constants
- func ClearSSHConfigCache()
- func EnsureSSHConfigCache()
- func Expand(path string) (string, error)
- func FileExists(filename string) bool
- func GetBackupSuffix() string
- func IntToStr(value int) string
- func ReadDataFromFile(filename string) ([]byte, error)
- func SaveDataToFile(filename string, data []byte) (bool, error)
- func SetSSHTimeout(t time.Duration)
- type CopyInfo
- type Duration
- type FailedUpgradeInfo
- func (failedUpgradeInfo *FailedUpgradeInfo) AddNodeSoftware(node, software string)
- func (failedUpgradeInfo *FailedUpgradeInfo) Clear()
- func (failedUpgradeInfo *FailedUpgradeInfo) Empty() (empty bool)
- func (failedUpgradeInfo *FailedUpgradeInfo) ExistsNodeSoftware(node, software string) (result bool)
- func (failedUpgradeInfo *FailedUpgradeInfo) FindNode(node string) []string
- func (failedUpgradeInfo *FailedUpgradeInfo) GetCount() (totalCount int)
- func (failedUpgradeInfo *FailedUpgradeInfo) GetNodeSoftwareCount(node string) int
- func (failedUpgradeInfo *FailedUpgradeInfo) RemoveNodeSoftware(node, software string)
- type HashInterface
- type Hasher
- type LocalHostHasher
- type NodeInfoContainer
- func (nodeInfo *NodeInfoContainer) RunAdd(sshConfig *SSHConfig) (err error)
- func (nodeInfo *NodeInfoContainer) RunDeleteAdd(sshConfig *SSHConfig) (err error)
- func (nodeInfo *NodeInfoContainer) RunDeleteRollback(sshConfig *SSHConfig, rollbackSuffix string) (err error)
- func (nodeInfo *NodeInfoContainer) RunRollback(sshConfig *SSHConfig, rollbackSuffix string) (err error)
- func (nodeInfo *NodeInfoContainer) RunUpgrade(sshConfig *SSHConfig) (err error)
- type NodeUpgradeConfig
- type ResProcessStatus
- type RollbackSession
- type RollbackStruct
- type SSHConfig
- func (sshConfig *SSHConfig) Clear()
- func (sshConfig *SSHConfig) ClearSudo() (result *SSHConfig)
- func (sshConfig *SSHConfig) Close()
- func (sshConfig *SSHConfig) CloseClient()
- func (sshConfig *SSHConfig) CloseSession()
- func (sshConfig *SSHConfig) Connect() (err error)
- func (sshConfig *SSHConfig) Copy(reader io.Reader, remotePath string, permissions string, size int64) (err error)
- func (sshConfig *SSHConfig) CopyBytesToFile(contentBytes []byte, remotePath string, permissions string) (err error)
- func (sshConfig *SSHConfig) CopyBytesToFileAndVerify(contentBytes []byte, remotePath string, permissions string) (err error)
- func (sshConfig *SSHConfig) CopyFile(fileReader io.Reader, remotePath string, permissions string) error
- func (sshConfig *SSHConfig) CopyFromFile(file os.File, remotePath string, permissions string) error
- func (sshConfig *SSHConfig) CopyLocalFileToRemoteFile(localFilename, remoteFilename, permissions string) error
- func (sshConfig *SSHConfig) CopyRemoteFileToLocalFile(remoteFilename, localFilename, permissions string) (err error)
- func (sshConfig *SSHConfig) CreateDirectory(path string) (err error)
- func (sshConfig *SSHConfig) Destroy()
- func (sshConfig *SSHConfig) DirectoryExists(path string) (result bool, err error)
- func (sshConfig *SSHConfig) DisableAutoOpen()
- func (sshConfig *SSHConfig) DisableVerbose() (result *SSHConfig)
- func (sshConfig *SSHConfig) EnableAutoOpen()
- func (sshConfig *SSHConfig) EnableVerbose() (result *SSHConfig)
- func (sshConfig *SSHConfig) FileExists(file string) (result bool, err error)
- func (sshConfig *SSHConfig) GetOS() string
- func (sshConfig *SSHConfig) InteractiveSession()
- func (sshConfig *SSHConfig) Interrupt(processName string) (result string, err error)
- func (sshConfig *SSHConfig) MakeSudo() (result *SSHConfig)
- func (sshConfig *SSHConfig) Md5sum(path string) (result string, err error)
- func (sshConfig *SSHConfig) OpenSession() (*ssh.Session, *ssh.Client, error)
- func (sshConfig *SSHConfig) ProcessStatus(processName string) *ResProcessStatus
- func (sshConfig *SSHConfig) ReadBytesFromFile(remotePath string) (result []byte, err error)
- func (sshConfig *SSHConfig) Run(cmd string) (string, error)
- func (sshConfig *SSHConfig) SetKeepAlive(t time.Duration)
- func (sshConfig *SSHConfig) SetMaxRetries(retries int) (result *SSHConfig)
- func (sshConfig *SSHConfig) SetSleepBtwRetries(sleepMS int64) (result *SSHConfig)
- func (sshConfig *SSHConfig) Sha256sum(path string) (result string, err error)
- func (sshConfig *SSHConfig) Signal(processName, signal string) (result string, err error)
- func (sshConfig *SSHConfig) Sum(path string) (result string, err error)
- type SSHInfo
- type TDebugLog
- func (d *TDebugLog) CloseDebugLog()
- func (d *TDebugLog) Debug(format string, args ...interface{})
- func (d *TDebugLog) Debugf(format string, args ...interface{})
- func (d *TDebugLog) Debugln(format string, args ...interface{})
- func (d *TDebugLog) EnableDebug()
- func (d *TDebugLog) EnableDebugLog(LogFilename string) (err error)
- func (d *TDebugLog) EnablePrintConsole()
- func (d *TDebugLog) GetFilename() (result string)
- func (d *TDebugLog) Print(format string, args ...interface{})
- func (d *TDebugLog) Printf(format string, args ...interface{})
- func (d *TDebugLog) Println(msg string, args ...interface{})
- func (d *TDebugLog) SetOutput(w io.Writer)
- type UpgradeConfig
- func (config *UpgradeConfig) GetGroupNames() (result []string)
- func (config *UpgradeConfig) GetGroupNodes(groupName string) (result []string)
- func (config *UpgradeConfig) GetGroupSoftware(groupName string) (result []string)
- func (config *UpgradeConfig) GetNodeCount() (result int)
- func (config *UpgradeConfig) GetNodeUpgradeInfo(node, software string) (result *NodeInfoContainer)
- func (config *UpgradeConfig) GetNodes() (result []string)
- func (config *UpgradeConfig) VerifyFilesExist() (err error)
- type UpgradeInfo
- type UpgradeStruct
Constants ¶
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 FileExists ¶
FileExists checks if the given filename exists
func ReadDataFromFile ¶
ReadDataFromFile reads the contents of the given filename into a byte array and returns it.
func SaveDataToFile ¶
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 ¶
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 ¶
Duration contains the delay to sleep between upgrades
func (Duration) MarshalJSON ¶
MarshalJSON marshals the duration into JSON format
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON into native Go structure
type FailedUpgradeInfo ¶
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 ¶
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
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 ¶
NewSSHConfig initializes a SSHConfig structure for executing a Run or Copy* command.
func NewSSHConfigKeyBytes ¶
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 ¶
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) 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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
EnableVerbose enables verbose response for file transfers
func (*SSHConfig) FileExists ¶
FileExists verifies that the given file exists on the host specified in the given SSHConfig Able to handle symlink. Tested.
func (*SSHConfig) GetOS ¶
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 ¶
Interrupt sends the interrupt signal to the given processName running on the host in the given SSHConfig
func (*SSHConfig) MakeSudo ¶
MakeSudo enables Sudo on Copy, CreateDirectory, and ChangeFileOwnership and Run
func (*SSHConfig) Md5sum ¶
Md5sum calculates the MD5 for the given path on the host specified in the given SSHConfig
func (*SSHConfig) OpenSession ¶
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 ¶
ReadsBytesFromFile reads the contents of a file.
func (*SSHConfig) Run ¶
Run runs a command on the given SSH environment, usage: output, err := Run("ls") Automatically closes the client and session
func (*SSHConfig) SetKeepAlive ¶
SetKeepAlive sets the duration to send a keep-alive message on a SSH connection
func (*SSHConfig) SetMaxRetries ¶
SetMaxRetries sets the max. no. of retries on connection failure
func (*SSHConfig) SetSleepBtwRetries ¶
SetSleepBtwRetries sets the max. no. of sleep between connection retries
func (*SSHConfig) Sha256sum ¶
Sha256sum calculates the SHA256 for the given path 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) EnableDebug ¶
func (d *TDebugLog) EnableDebug()
EnableDebug sets the printDebug flag
func (*TDebugLog) EnableDebugLog ¶
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 ¶
GetFilename returns the filename that is currently in use by d, if it is assigned.
func (*TDebugLog) Print ¶
Print decides whether the debug log is sent to the console, or not, and also logs it to the debug 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