util

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2019 License: MIT Imports: 10 Imported by: 7

Documentation

Index

Constants

View Source
const (
	//StarterEnvVariableKey is the environment variable key used to pass
	// the environment descriptor location between several Ekara components.
	StarterEnvVariableKey string = "EKARA_ENV_DESCR"

	//StarterEnvNameVariableKey is the environment variable key used to pass
	// the environment descriptor name between several Ekara components.
	StarterEnvNameVariableKey string = "EKARA_ENV_DESCR_NAME"

	//StarterEnvLoginVariableKey is the environment variable key used to pass
	//the environment descriptor user
	StarterEnvLoginVariableKey string = "EKARA_ENV_DESCR_LOGIN"

	//StarterEnvPasswordVariableKey is the environment variable key used
	//to pass the environment descriptor password
	StarterEnvPasswordVariableKey string = "EKARA_ENV_DESCR_PASSWORD"

	//SSHPuplicKeyFileName is the Name of the SSH Public key file
	SSHPuplicKeyFileName string = "ssh.pub"

	//SSHPrivateKeyFileName is the Name of the SSH Private key file
	SSHPrivateKeyFileName string = "ssh.pem"

	//ActionEnvVariableKey is the environment variable key used to pass
	// the ekera action to perform between several Ekara components.
	ActionEnvVariableKey string = "EKARA_ACTION"

	//ExternalVarsFilename is the name of the file containing the map of all components locations
	ExternalVarsFilename string = "external_vars.yaml"

	//InstallerLogPrefix is the prefix for the installer logs
	InstallerLogPrefix string = "INST > "

	//InstallerVolume is the volume location used by the installer
	InstallerVolume string = "/opt/ekara/output"

	//ParamYamlFileName is the name of any file containing params
	ParamYamlFileName string = "params.yaml"

	//ExtraVarYamlFileName is the name of any file containing extra vars
	ExtraVarYamlFileName string = "extra-vars.yaml"

	//EnvYamlFileName is the name of any file containing environment variables
	EnvYamlFileName string = "env.yaml"

	//InventoryYamlFileName is the name of any file containing host inventories
	InventoryYamlFileName string = "inventory.yaml"

	//ComponentModuleFolder is the name of any folder containing component modules
	ComponentModuleFolder string = "modules"

	//InventoryModuleFolder is the name of any folder containing inventories
	InventoryModuleFolder string = "inventory"
)
View Source
const (
	ERROR                         string = "Error: %s"
	ERROR_MISSING                 string = "%s is missing"
	ERROR_CREATING_CONFIG_FILE    string = "Error creating the configuration file: %s, %s"
	ERROR_GENERATING_PROXY_CONFIG string = "Error generating the proxy configuration: %s"
	ERROR_REQUIRED_ENV            string = "the environment variable \"%s\" should be defined"
	LOG_SAVING                    string = "Saving: %s"
	LOG_CREATING_FILE             string = "Creation of the file %s"
	LOG_LAUNCHING_PLAYBOOK        string = "Launching playbook %s"
	LOG_STARTING_PLAYBOOK         string = "Starting playbook %s, in %s"
)

Variables

This section is empty.

Functions

func AdaptPath

func AdaptPath(path string) string

AdaptPath tunes the received path base on the runtime OS

Example for Windows: "c:\\" will be replaced by "/c", and

"\\" by "/"

func JoinPaths

func JoinPaths(paths ...string) string

JoinPaths joins the provided paths as a string

func RepositoryFlavor

func RepositoryFlavor(url string) (string, string)

RepositoryFlavor returns the repository flavor, branchn tag ..., based on the presence of '@' into the given url

func SaveFile

func SaveFile(folder FolderPath, name string, b []byte) (string, error)

SaveFile saves the given bytes into a fresh new file specified by its folder and name.

If the file already exists then it will be replaced.

Types

type ExchangeFolder

type ExchangeFolder struct {
	RootFolder string
	// Root location of the exchange folder
	Location FolderPath
	// Input data passed to the container
	Input FolderPath
	// Output data produced by the container
	Output FolderPath
}

ExchangeFolder represents a folder structure used to pass and get content to container.

func CreateExchangeFolder

func CreateExchangeFolder(location string, folderName string) (ExchangeFolder, error)

CreateExchangeFolder creates an ExchangeFolder at the provided location and with the give name

func (ExchangeFolder) CleanAll

func (f ExchangeFolder) CleanAll() error

CleanAll cleans all the ExchangeFolder content

func (ExchangeFolder) Create

func (f ExchangeFolder) Create() error

Create creates physically the ExchangeFolder. If the ExchangeFolder already exist it will remain untouched

func (ExchangeFolder) Delete

func (f ExchangeFolder) Delete() error

Delete deletes the ExchangeFolder

type FolderPath

type FolderPath struct {
	Children map[string]ExchangeFolder
	// contains filtered or unexported fields
}

FolderPath holds the location of a folder and its eventual children

func CreateFolderPath

func CreateFolderPath(path string) FolderPath

CreateFolderPath returns a FolderPath matching the given path

func (FolderPath) AdaptedPath

func (f FolderPath) AdaptedPath() string

AdaptedPath returns the path of this folder adapted depending on the OS we are running on For example on Windows it convert c:\Users\blablabla to /c/Users/blablabla

func (*FolderPath) AddChildExchangeFolder

func (f *FolderPath) AddChildExchangeFolder(childName string) (ExchangeFolder, error)

AddChildExchangeFolder creates a child of type ExchangeFolder having this folder as root location

func (FolderPath) Contains

func (f FolderPath) Contains(s string) bool

Contains returns true if this folder contains the given content

func (FolderPath) ContainsEnvYaml

func (f FolderPath) ContainsEnvYaml() (ok bool, b []byte, e error)

ContainsEnvYaml returns true if this folder contains a file named EnvYamlFileName

func (FolderPath) ContainsExtraVarsYaml

func (f FolderPath) ContainsExtraVarsYaml() (ok bool, b []byte, e error)

ContainsExtraVarsYaml returns true if this folder contains a file named ExtraVarYamlFileName

func (FolderPath) ContainsInventoryYamlFileName

func (f FolderPath) ContainsInventoryYamlFileName() (ok bool, b []byte, e error)

ContainsInventoryYamlFileName returns true if this folder contains a file named InventoryYamlFileName

func (FolderPath) ContainsParamYaml

func (f FolderPath) ContainsParamYaml() (ok bool, b []byte, e error)

ContainsParamYaml returns true if this folder contains a file named ParamYamlFileName

func (FolderPath) Copy

func (f FolderPath) Copy(content string, destination FolderPath) error

Copy copies, if it exists, the content to the destination foler

func (FolderPath) Exixts

func (f FolderPath) Exixts() (bool, error)

Exixts returns true if this folder exixts physically

func (FolderPath) Path

func (f FolderPath) Path() string

Path returns the path to this folder

func (FolderPath) Write

func (f FolderPath) Write(bytes []byte, fileName string) error

Write writes the given bytes into file within this folder

type LaunchContext

type LaunchContext interface {
	//Log the looger to used during the Ekara execution
	Log() *log.Logger
	//Ef the exchange folder
	Ef() ExchangeFolder
	//Descriptor name
	DescriptorName() string
	//Location specifies where to look for the environment descriptor
	Location() string
	//User The user to log into the descriptor repository
	User() string
	//Password The user to log into the descriptor repository
	Password() string
	//Proxy returns launch context proxy settings
	Proxy() model.Proxy
	//SSHPublicKey the public key used by the engine during the process execution to
	// connect the created nodes
	SSHPublicKey() string
	//SSHPrivateKey the private key used by the engine during the process execution to
	// connect the created nodes
	SSHPrivateKey() string
	//ParamsFile returns the content the parameters provided by the user to fill the environment descriptor as a template
	ExternalVars() model.Parameters
}

LaunchContext Represents the information required to run the engine

func CreateMockLaunchContext

func CreateMockLaunchContext(mainPath string, withLog bool) LaunchContext

func CreateMockLaunchContextWithData

func CreateMockLaunchContextWithData(mainPath string, params model.Parameters, withLog bool) LaunchContext

func CreateMockLaunchContextWithDataAndFolder

func CreateMockLaunchContextWithDataAndFolder(mainPath string, params model.Parameters, ef ExchangeFolder, withLog bool) LaunchContext

type MockLaunchContext

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

MockLaunchContext simulates the LaunchContext for testing purposes

func (MockLaunchContext) DescriptorName

func (lC MockLaunchContext) DescriptorName() string

User simulates the corresponding method in LaunchContext for testing purposes

func (MockLaunchContext) Ef

Ef simulates the corresponding method in LaunchContext for testing purposes

func (MockLaunchContext) ExternalVars

func (lC MockLaunchContext) ExternalVars() model.Parameters

ParamsFile simulates the corresponding method in LaunchContext for testing purposes

func (MockLaunchContext) Location

func (lC MockLaunchContext) Location() string

Location simulates the corresponding method in LaunchContext for testing purposes

func (MockLaunchContext) Log

func (lC MockLaunchContext) Log() *log.Logger

Log simulates the corresponding method in LaunchContext for testing purposes

func (MockLaunchContext) Password

func (lC MockLaunchContext) Password() string

Password simulates the corresponding method in LaunchContext for testing purposes

func (MockLaunchContext) Proxy

func (lC MockLaunchContext) Proxy() model.Proxy

Proxy simulates the corresponding method in LaunchContext for testing purposes

func (MockLaunchContext) SSHPrivateKey

func (lC MockLaunchContext) SSHPrivateKey() string

SSHPrivateKey simulates the corresponding method in LaunchContext for testing purposes

func (MockLaunchContext) SSHPublicKey

func (lC MockLaunchContext) SSHPublicKey() string

SSHPublicKey simulates the corresponding method in LaunchContext for testing purposes

func (MockLaunchContext) User

func (lC MockLaunchContext) User() string

User simulates the corresponding method in LaunchContext for testing purposes

Jump to

Keyboard shortcuts

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