resource

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DefaultNamespace = "resource"

DefaultNamespace is the Lua table where resources are being registered to, when using the default namespace.

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 Register

func Register(items ...RegistryItem)

Register registers a provider to the registry

Types

type Base added in v0.4.0

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

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

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

	// Require contains the resource dependencies
	Require []string `luar:"require"`

	// PresentStates contains the list of states, for which the
	// resource is considered to be present
	PresentStates []string `luar:"-"`

	// AbsentStates contains the list of states, for which the
	// resource is considered to be absent
	AbsentStates []string `luar:"-"`

	// Concurrent flag indicates whether multiple instances of the
	// same resource type can be processed concurrently.
	Concurrent bool `luar:"-"`
}

Base 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 (*Base) Dependencies added in v0.4.0

func (b *Base) Dependencies() []string

Dependencies returns the list of resource dependencies.

func (*Base) GetAbsentStates added in v0.4.0

func (b *Base) GetAbsentStates() []string

GetAbsentStates returns the list of states, for which the resource is considered to be absent

func (*Base) GetPresentStates added in v0.4.0

func (b *Base) GetPresentStates() []string

GetPresentStates returns the list of states, for which the resource is considered to be present

func (*Base) ID added in v0.4.0

func (b *Base) ID() string

ID returns the unique resource id

func (*Base) IsConcurrent added in v0.4.0

func (b *Base) IsConcurrent() bool

IsConcurrent returns a boolean indicating whether multiple instances of the same resource type can be processed concurrently.

func (*Base) Log added in v0.4.0

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

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

func (*Base) Validate added in v0.4.0

func (b *Base) Validate() error

Validate validates the resource

type BasePackage added in v0.3.0

type BasePackage struct {
	Base

	// 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 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 {
	Base

	// 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 = resource.file.new("/tmp/foo")
foo.state = "present"
foo.mode = 0600

Example:

bar = resource.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

func (*File) Validate added in v0.4.0

func (f *File) Validate() error

Validate validates 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 = resource.pacman.new("tmux")
pkg.state = "installed"

type Provider

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

Provider type is the type which creates new resources

type RegistryItem

type RegistryItem struct {
	// Type name of the provider
	Type string

	// Provider is the actual resource provider
	Provider Provider

	// Namespace represents the Lua table that the
	// provider will be registered in
	Namespace string
}

ProviderItem type represents a single item from the provider registry

type Resource

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

	// Validate validates the resource
	Validate() error

	// Dependencies returns the list of resource dependencies.
	// Each item in the slice is a string representing the
	// resource id for each dependency.
	Dependencies() []string

	// GetPresentStates returns the list of states, for which the
	// resource is considered to be present
	GetPresentStates() []string

	// GetAbsentStates returns the list of states, for which the
	// resource is considered to be absent
	GetAbsentStates() []string

	// IsConcurrent returns a boolean, which indicates whether
	// multiple instances of the same resource type can be
	// processed concurrently.
	IsConcurrent() bool

	// 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 = resource.package.new("tmux")
pkg.state = "installed"

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 {
	Base

	// 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 = resource.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 {
	Base

	// 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"`

	// Mute flag indicates whether output from the command should be
	// dislayed or suppressed
	Mute bool `luar:"mute"`
}

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 = resource.shell.new("touch /tmp/foo")
sh.creates = "/tmp/foo"

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

Example:

sh = resource.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

	// Outdated indicates that a property of the resource is out of date
	Outdated 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 = resource.yum.new("emacs")
pkg.state = "installed"

Jump to

Keyboard shortcuts

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