Documentation ¶
Overview ¶
Package raccoon is a utility for simple automation of hosts by using Dockerfile syntax. You use ADD, RUN, MAINTAINER, etc. commands as you would do in Docker but to provision hosts instead of containers using SSH. In this aspect, you could need to have root privileges in a machine to do some specific actions.
Raccoon uses JSON syntax to define its behaviour. This way you can generate Raccoon jobs by simply writing a JSON with whichever language you want and it provides a nice way to interact with the Raccoon server.
You can use Raccoon as a standalone app, running as server or as a library. Ideally the three modes should work nicely but some errors are expected as the heavy test of the package is done as a standalone app.
How to use Raccoon as a library ¶
Raccoon can be easily used as a library. For each cluster and task, you need to create a hierarchy of Jobs. A Job is a type with two members: Cluster and Task. A Cluster is a list of Hosts and a
How to user Raccoon as server ¶
Raccoon can also be used as server. Doing POST request you can launch some automation on some infrastructure.
Index ¶
Constants ¶
const ( //VERSION number will be printed when using CLI VERSION string = "0.3.3" //APP_DESCRIPTION will be printed when using CLI APP_DESCRIPTION string = "WIP Automation utility made easy with Dockerfile syntax" //APP_NAME is just in case I forget the name of the app :) APP_NAME string = "Raccoon" )
Constants file define global constants around the app
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Authentication ¶
type Authentication struct { //Username to access remote host Username string `json:"username,omitempty"` //Password to access remote host Password string `json:"password,omitempty"` //Identity file for auth IdentityFile string `json:"identityFile,omitempty"` //Choose to enter user and password during Raccoon execution InteractiveAuth bool `json:"interactiveAuth,omitempty"` //SSHPort is a optional non standard port for SSH. We consider 22 as the //standard port so set this field in case you are using a different one in //any host SSHPort int `json:"sshPort,omitempty"` }
type Cluster ¶
type Cluster struct { Authentication //Name that identifies this cluster respect to others Name string `json:"name"` //Hosts are the array of hosts on this cluster Hosts []Host `json:"hosts"` //TasksToExecute is the name of the commands group that will be executed in // this cluster. This name must match the name written in the 'Title' member // of the Tasks file. In future version it will work with an array os tasks too. TasksToExecute []string `json:"tasks"` }
Cluster is an array of Nodes (remotes machines) that compose our machine cluster
It must have a name to identify it from other clusters.
It should also have a linked task. A task is a group of commands that will be executed on this cluster
type Command ¶
type Command struct { //Name if a must in each command. It could be ADD or ENV but every command //must have one so that the parser can recognize the intents of the user Name string //Description is an optional description of a command that will be print on //stdout for logging purposes. It's recommended to use a description on each //command Description string }
Command is the type that contains common command members. Every new command in the commands package must have a Command value inside so that logging can work properly.
type CommandsExecutor ¶
type CommandsExecutor interface { //Execute is the method that each strategy will execute on the provided //Host h Execute(h Host) //GetCommands returns the Command value that must be within every CommandExecutor implementor GetCommand() *Command }
CommandsExecutor is an interface that every command must implement. A command is any strategy of the Dockerfile syntax that Raccoon offers.
type Dispatcher ¶
type Dispatcher interface {
Dispatch(js []Job)
}
Dispatcher is the interface to implement new dispatching strategies in the app
type Host ¶
type Host struct { Authentication //IP of the remote host IP string `json:"ip"` //Description is optional information about the host Description string `json:"description,omitempty"` //Color that this host will output when printing in stdout Color color.Attribute //HostLogger is the logging mechanism for each host. Use this when logging //anything to stdout so it will be formatted and colored HostLogger *logrus.Logger // contains filtered or unexported fields }
Host is a remote machine (virtual or physical) where we will execute our instructions on.
func (*Host) CloseNode ¶
CloseNode closes stored ssh session in Host. Remember to call it explicitly after all instructions has finished
func (*Host) GetClient ¶
GetClient will create a random color for logging and a new connection to a Host on port 22.
func (*Host) GetSession ¶
GetSession returns a new session once a client is created. In case the connection was lost, it tries to connect again with the Host
func (*Host) InitializeNode ¶
InitializeNode must be called prior any execution on Hosts. It will try to get a ssh.Client object to open ssh session on host
type Infrastructure ¶
type Infrastructure struct { //Name for your infrastructure. It has no effect on the app but maintains //infrastructure json files ordered Name string `json:"name"` //Infrastructure is, in turn, the array of clusters that you want to execute //some automation on Infrastructure []Cluster `json:"infrastructure"` }
Infrastructure represents a group of clusters. Each cluster represents a group of hosts.
type Job ¶
type Job struct { //Cluster is a group of hosts Cluster Cluster //Task is a single task that could be composed of one or more commands Task Task }
Job is that relate a Cluster (group of hosts) with the Task that must be performed on it
type JobRequest ¶
type JobRequest struct { TaskList *[]Task `json:"tasks"` Infrastructure *Infrastructure `json:"infrastructure"` }
JobRequest is a job defined by the user in a single JSON object
type RelationList ¶
type RelationList []Relation
type SequentialDispatcher ¶
type SequentialDispatcher struct{}
SequentialDispatcher is a dispatching strategy that doesn't use any concurrent approach. It will execute each command on each host sequentially and waits for each to finish before starting the next.
func (*SequentialDispatcher) Dispatch ¶
func (s *SequentialDispatcher) Dispatch(jobs []Job)
Dispatch ranges over the hosts to execute the tasks on them sequentially without any kind of concurrency.
type SimpleDispatcher ¶
SimpleDispatcher is the dispatching strategy to use when the number of hosts isn't very high. It will open a new SSH connection to each host at the same time since the beginning so, if you are having performance issues, try the workers pool or the sequential dispatcher to see if they get solved. SimpleDispatcher is the default dispatching strategy
func (*SimpleDispatcher) Dispatch ¶
func (s *SimpleDispatcher) Dispatch(jobs []Job)
Dispatch will create a new goroutine for each host in the job and launch the tasks that were specified on it.
type Task ¶
type Task struct { //Title of the task that will be referenced from clusters Title string `json:"title"` //Maintainer is an optional member Maintainer string `json:"maintainer,omitempty"` //Commands are the array of commands that will be executed on some host. //This member must never come from JSON that's why it has that key name Commands []CommandsExecutor `json:"noJson,omitempty"` //Command is the syntax definition of a command that Raccoon will interpret //into a CommandExecutor value Command []map[string]string `json:"commands"` }
Task is a list of commands to execute on a host. A task must have a Title that must match with the title that was written in the task key of the infrastructure file
type WorkerPoolDispatcher ¶
WorkerPoolDispatcher is a dispatcher that acts as a worker pool. It won't maintain more connections to hosts atthe same time than the specified number in the Workers field
func (*WorkerPoolDispatcher) Dispatch ¶
func (w *WorkerPoolDispatcher) Dispatch(jobs []Job)
Dispatch will create the specified workers on the workers field, launching a goroutine with each. Then it will create a dispatcher routing in a different goroutine and finally it will send the jobs to the launched dispatcher for distribution.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package main contains the CLI application of Raccoon along with the options of the CLI interface
|
Package main contains the CLI application of Raccoon along with the options of the CLI interface |
Package instructions contains all implemented syntax in Raccoon.
|
Package instructions contains all implemented syntax in Raccoon. |
Package parser contains the interpreter that parses the JSON tasks and insfrastructure files into Jobs
|
Package parser contains the interpreter that parses the JSON tasks and insfrastructure files into Jobs |