job

package
v0.0.0-...-40fe7e7 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// FAILED when a task failed
	FAILED = iota
	// SUCCESS when all tasks succedded
	SUCCESS
)

///////// DECLARATION OF ALL TYPES //////////////////////////

Variables

This section is empty.

Functions

func CmdRegister

func CmdRegister(cmd Cmd) error

CmdRegister registers a new command cmd: Command to register

func CmdUnregister

func CmdUnregister(cmd Cmd) error

CmdUnregister unregister a command in command registry cmd: command to unregister

func GetNbOfCmds

func GetNbOfCmds() int

GetNbOfCmds returns the number of commands in the registry

func LoadModules

func LoadModules(dir string) error

LoadModules loads all modules (plugins) present in the module directory

dir: string specifing the location of modules to load

Types

type Cmd

type Cmd struct {
	// Name is command name
	Name string
	// Func is command function
	Func CmdFunc
	// Plugin is the module to which the command belongs to
	Plugin Plugin
}

Cmd is a structure for a command of a given module

func GetCmdByName

func GetCmdByName(name string) (Cmd, bool)

GetCmdByName returns a command by its name

type CmdFunc

type CmdFunc func(map[string]interface{}) *CmdResult

CmdFunc is a command function

type CmdRegistry

type CmdRegistry struct {
	CmdList map[string]Cmd
}

CmdRegistry is a registry for commands

This is a map with Key: string composed of module name and command name and Cmd: command structure

func GetCmdRegistry

func GetCmdRegistry() *CmdRegistry

GetCmdRegistry returns the command registry initialized

type CmdResult

type CmdResult struct {
	// Error is command error
	Error error
	// Result is a map containing output of each task
	Result map[string]interface{}
}

CmdResult represents the result of a module's command executed.

func NewCmdResult

func NewCmdResult() *CmdResult

NewCmdResult instanciates a new command result

type Flow

type Flow struct {
	Variables map[string]interface{}
	Jobs      []*Job
	Inventory *Inventory

	RemoteExecDir string
	InventoryFile string

	// IsOnRemote indicates if the flow file is on remote machine
	// even if it is local
	IsOnRemote bool

	Status int
	Result map[string][]*Job
}

Flow represents job flow YAML file containing different sections such as variables, multiple jobs etc.

func NewFlow

func NewFlow() *Flow

NewFlow instancies a new Flow

func (*Flow) RunAllJobs

func (f *Flow) RunAllJobs()

RunAllJobs executes all jobs

func (*Flow) RunJob

func (f *Flow) RunJob(job string) error

RunJob executes a specified job with the name given

type Group

type Group struct {
	Name string

	Hosts []string
	Vars  map[string]interface{}
}

Group describes attributes of a group

type Host

type Host struct {
	Name string

	Groups []string
	Vars   map[string]interface{}
}

Host describes structure of a host

type Inventory

type Inventory struct {
	Global map[string]interface{}
	Hosts  map[string]Host
	Groups map[string]Group
}

Inventory describes attributes of a host inventory

func NewInventory

func NewInventory() *Inventory

NewInventory instancies a new Inventory

type Job

type Job struct {
	Name  string
	Hosts string
	Start *Task

	Tasks   []*Task
	Context map[string]interface{}

	Status int
	Result map[string]*CmdResult
}

Job describes structure of a job

func NewJob

func NewJob(name string) *Job

NewJob instancies a new Job

func (*Job) AddTask

func (job *Job) AddTask(task *Task)

AddTask adds a new task to the job

func (*Job) CheckTasks

func (job *Job) CheckTasks() error

CheckTasks checks all tasks to see if the name given for task on failure or on success matches valid task names

func (*Job) GetTaskByName

func (job *Job) GetTaskByName(name string) (*Task, error)

GetTaskByName returns task by its name in the task list of the job

func (*Job) RenderTaskTemplate

func (job *Job) RenderTaskTemplate(task *Task) error

RenderTaskTemplate renders go template in each param with the values in Job Context & Result

func (*Job) Run

func (job *Job) Run(tasks string) error

Run a job throught all tasks

Firstly, it checks to ensure that all task's names are valid task.fmt_unicode

func (*Job) RunAllTasks

func (job *Job) RunAllTasks(task *Task) error

RunAllTasks executes all task functions one by one.

If a task returns error, it will check if task's OnFailure is specified and then go on it. Otherwise, it return task error.

If a task returns success, check and continue with task's OnSuccess if specified or next task in order.

func (*Job) RunTaskByTask

func (job *Job) RunTaskByTask(tasks string) error

RunTaskByTask executes only tasks in the list specified in command line parameter. It return error if a task fails.

In this function, task's OnSuccess or OnFailure are ignored.

type ModuleRegistry

type ModuleRegistry struct {
	ModuleList map[string]string
}

ModuleRegistry is a registry for modules

func GetModuleRegistry

func GetModuleRegistry() *ModuleRegistry

GetModuleRegistry returns the module registry initialized

type Plugin

type Plugin struct {
	// Name is module name
	Name string
	// Version is module version
	Version string
	// Description describes shortly what the module does
	Description string
}

Plugin contains les informations of a module

type Task

type Task struct {
	Name      string
	Cmd       Cmd
	Params    map[string]interface{}
	OnSuccess string
	OnFailure string
}

Task describes attributes of a task

Jump to

Keyboard shortcuts

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