Documentation ¶
Index ¶
- Constants
- Variables
- func Log(format string, a ...interface{})
- func LuaRegisterBuiltin(L *lua.LState)
- func RegisterProvider(typ string, p Provider) error
- type BasePackage
- type BaseResource
- type Collection
- type Config
- type File
- type Pacman
- type Provider
- type Resource
- type Service
- type Shell
- type State
- type Yum
Constants ¶
const ( StateUnknown = "unknown" StatePresent = "present" StateAbsent = "absent" StateRunning = "running" StateStopped = "stopped" )
Resource states
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
func RegisterProvider ¶ added in v0.3.0
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
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"
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 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 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 = package.new("tmux") pkg.state = "present"
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 { 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
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"
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"