resource

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2016 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateUnknown = "unknown"
	StatePresent = "present"
	StateAbsent  = "absent"
	StateRunning = "running"
	StateStopped = "stopped"
)

Resource states

Variables

View Source
var DefaultConfig = &Config{
	Logger: DefaultLogger,
}

DefaultConfig is the default configuration used by the resources

View Source
var DefaultLogger = log.New(os.Stdout, "", log.LstdFlags)

DefaultLogger is the default logger instance used for logging events from the resources

View Source
var ErrNoPackageProviderFound = errors.New("No suitable package provider found")

ErrNoPackageProviderFound is returned when no suitable provider is found

View Source
var ErrNoSystemd = errors.New("No systemd support found")

ErrNoSystemd error is returned when the system is detected to have no support for systemd.

Functions

func Log added in v0.3.0

func Log(format string, a ...interface{})

Log logs an event using the default resource logger

func LuaRegisterBuiltin added in v0.3.0

func LuaRegisterBuiltin(L *lua.LState)

LuaRegisterBuiltin registers resource providers in Lua

func RegisterProvider added in v0.3.0

func RegisterProvider(typ string, p Provider) error

RegisterProvider registers a provider to the registry

Types

type BasePackage added in v0.3.0

type BasePackage struct {
	BaseResource

	// Name of the package to manage. Defaults to the resource name.
	Package string `luar:"-"`

	// Version of the package.
	Version string `luar:"version"`
	// contains filtered or unexported fields
}

BasePackage is the base resource type for package management It's purpose is to be embedded into other package resource providers.

func (*BasePackage) Create added in v0.3.0

func (bp *BasePackage) Create() error

Create installs the package

func (*BasePackage) Delete added in v0.3.0

func (bp *BasePackage) Delete() error

Delete deletes the package

func (*BasePackage) Evaluate added in v0.3.0

func (bp *BasePackage) Evaluate() (State, error)

Evaluate evaluates the state of the package

func (*BasePackage) Update added in v0.3.0

func (bp *BasePackage) Update() error

Update updates the package

type BaseResource

type BaseResource struct {
	// Type of the resource
	Type string `luar:"-"`

	// Name of the resource
	Name string `luar:"-"`

	// Desired state of the resource
	State string `luar:"state"`

	// Resources before which this resource should be processed
	Before []string `luar:"before"`

	// Resources after which this resource should be processed
	After []string `luar:"after"`
}

BaseResource is the base resource type for all resources The purpose of this type is to be embedded into other resources Partially implements the Resource interface

func (*BaseResource) ID added in v0.3.0

func (br *BaseResource) ID() string

ID returns the unique resource id

func (*BaseResource) Log added in v0.3.0

func (br *BaseResource) Log(format string, a ...interface{})

Log writes to the default config writer object and prepends the resource id to the output

func (*BaseResource) WantAfter

func (br *BaseResource) WantAfter() []string

WantAfter returns the resources after which this resource should be processed

func (*BaseResource) WantBefore

func (br *BaseResource) WantBefore() []string

WantBefore returns the resources before which this resource should be processed

type Collection added in v0.3.0

type Collection map[string]Resource

Collection type is a map which keys are the resource ids and their values are the actual resources

func CreateCollection added in v0.3.0

func CreateCollection(resources []Resource) (Collection, error)

CreateCollection creates a map from

func (Collection) DependencyGraph added in v0.3.0

func (c Collection) DependencyGraph() (*graph.Graph, error)

DependencyGraph builds a dependency graph for the collection

type Config

type Config struct {
	// The site repo which contains module and data files
	SiteRepo string

	// Logger used by the resources to log events
	Logger *log.Logger
}

Config type contains various settings used by the resources

type File added in v0.3.0

type File struct {
	BaseResource

	// Path to the file. Defaults to the resource name.
	Path string `luar:"-"`

	// Permission bits to set on the file. Defaults to 0644.
	Mode os.FileMode `luar:"mode"`

	// Owner of the file. Defaults to the currently running user.
	Owner string `luar:"owner"`

	// Group of the file
	// Defaults to the group of the currently running user.
	Group string `luar:"group"`

	// Source file to use when creating/updating the file
	Source string `luar:"source"`

	// The file type we manage.
	FileType string `luar:"filetype"`

	// Recursively manage the directory if set to true.
	// Defaults to false.
	Recursive bool `luar:"recursive"`

	// Purge extra files in the target directory if set to true.
	// Defaults to false.
	Purge bool `luar:"purge"`
	// contains filtered or unexported fields
}

File resource manages files and directories.

Example:

foo = file.new("/tmp/foo")
foo.state = "present"
foo.mode = 0600

Example:

bar = file.new("/tmp/bar")
bar.state = "present"
bar.filetype = "directory"

func (*File) Create added in v0.3.0

func (f *File) Create() error

Create creates the file managed by the resource

func (*File) Delete added in v0.3.0

func (f *File) Delete() error

Delete deletes the file managed by the resource

func (*File) Evaluate added in v0.3.0

func (f *File) Evaluate() (State, error)

Evaluate evaluates the file resource

func (*File) Update added in v0.3.0

func (f *File) Update() error

Update updates the files managed by the resource

type Pacman added in v0.3.0

type Pacman struct {
	BasePackage
}

Pacman type represents the resource for package management on Arch Linux systems.

Example:

pkg = pacman.new("tmux")
pkg.state = "present"

type Provider

type Provider func(name string) (Resource, error)

Provider type is the type which creates new resources

type Resource

type Resource interface {
	// ResourceID returns the unique identifier of a resource
	ID() string

	// Returns the resources before which this resource shoud be processed
	WantBefore() []string

	// Returns the resources after which this resource should be processed
	WantAfter() []string

	// Evaluates the resource
	Evaluate() (State, error)

	// Creates the resource
	Create() error

	// Deletes the resource
	Delete() error

	// Updates the resource
	Update() error

	// Log logs events
	Log(format string, a ...interface{})
}

Resource is the interface type for resources

func NewFile added in v0.3.0

func NewFile(name string) (Resource, error)

NewFile creates a resource for managing files and directories

func NewPackage added in v0.3.0

func NewPackage(name string) (Resource, error)

NewPackage creates a new resource for managing packages. This provider tries to determine the most appropriate package provider for you, so it is more like a meta-provider.

Example:

pkg = package.new("tmux")
pkg.state = "present"

func NewPacman added in v0.3.0

func NewPacman(name string) (Resource, error)

NewPacman creates a new resource for managing packages using the pacman package manager on an Arch Linux system

func NewService added in v0.3.0

func NewService(name string) (Resource, error)

NewService creates a new resource for managing services using systemd on a GNU/Linux system

func NewShell added in v0.3.0

func NewShell(name string) (Resource, error)

NewShell creates a new resource for executing shell commands

func NewYum added in v0.3.0

func NewYum(name string) (Resource, error)

NewYum creates a new resource for managing packages using the yum package manager on RHEL and CentOS systems

type Service added in v0.3.0

type Service struct {
	BaseResource

	// If true then enable the service during boot-time
	Enable bool `luar:"enable"`
	// contains filtered or unexported fields
}

Service type is a resource which manages services on a GNU/Linux system running with systemd.

Example:

svc = service.new("nginx")
svc.state = "running"
svc.enable = true

func (*Service) Create added in v0.3.0

func (s *Service) Create() error

Create starts the service unit

func (*Service) Delete added in v0.3.0

func (s *Service) Delete() error

Delete stops the service unit

func (*Service) Evaluate added in v0.3.0

func (s *Service) Evaluate() (State, error)

Evaluate evaluates the state of the resource

func (*Service) Update added in v0.3.0

func (s *Service) Update() error

Update updates the service unit state

type Shell added in v0.3.0

type Shell struct {
	BaseResource

	// Command to be executed. Defaults to the resource name.
	Command string `luar:"command"`

	// File to be checked for existence before executing the command.
	Creates string `luar:"creates"`
}

Shell type is a resource which executes shell commands.

The command that is to be executed should be idempotent. If the command that is to be executed is not idempotent on it's own, in order to achieve idempotency of the resource you should set the "creates" field to a filename that can be checked for existence.

Example:

sh = shell.new("touch /tmp/foo")
sh.creates = "/tmp/foo"

Same example as the above one, but written in a different way.

Example:

sh = shell.new("creates the /tmp/foo file")
sh.command = "/usr/bin/touch /tmp/foo"
sh.creates = "/tmp/foo"

func (*Shell) Create added in v0.3.0

func (s *Shell) Create() error

Create executes the shell command

func (*Shell) Delete added in v0.3.0

func (s *Shell) Delete() error

Delete is a no-op

func (*Shell) Evaluate added in v0.3.0

func (s *Shell) Evaluate() (State, error)

Evaluate evaluates the state of the resource

func (*Shell) Update added in v0.3.0

func (s *Shell) Update() error

Update is a no-op

type State

type State struct {
	// Current state of the resource
	Current string

	// Wanted state of the resource
	Want string

	// Indicates that a resource is in the desired state, but is
	// out of date and needs to be updated, e.g. a file resource is
	// present, but its permissions need to be corrected.
	Update bool
}

State type represents the current and wanted states of a resource

type Yum added in v0.3.0

type Yum struct {
	BasePackage
}

Yum type represents the resource for package management on RHEL and CentOS systems.

Example:

pkg = yum.new("emacs")
pkg.state = "present"

Jump to

Keyboard shortcuts

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