Documentation ¶
Index ¶
- Constants
- Variables
- func Log(format string, a ...interface{})
- func LuaRegisterBuiltin(L *lua.LState)
- func Register(items ...RegistryItem)
- type Base
- type BasePackage
- type Collection
- type Config
- type File
- type Pacman
- type Provider
- type RegistryItem
- type Resource
- type Service
- type Shell
- type State
- type Yum
Constants ¶
const DefaultNamespace = "resource"
DefaultNamespace is the Lua table where resources are being registered to, when using the default namespace.
Variables ¶
var DefaultConfig = &Config{ Logger: DefaultLogger, }
DefaultConfig is the default configuration used by the resources
DefaultLogger is the default logger instance used for logging events from the resources
var ErrNoPackageProviderFound = errors.New("No suitable package provider found")
ErrNoPackageProviderFound is returned when no suitable provider is found
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
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
Dependencies returns the list of resource dependencies.
func (*Base) GetAbsentStates ¶ added in v0.4.0
GetAbsentStates returns the list of states, for which the resource is considered to be absent
func (*Base) GetPresentStates ¶ added in v0.4.0
GetPresentStates returns the list of states, for which the resource is considered to be present
func (*Base) IsConcurrent ¶ added in v0.4.0
IsConcurrent returns a boolean indicating whether multiple instances of the same resource type can be processed concurrently.
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
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"
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 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 NewPackage ¶ added in v0.3.0
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
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
NewService creates a new resource for managing services using systemd on a GNU/Linux system
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
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"
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"