Documentation
¶
Index ¶
- Constants
- Variables
- func Register(item RegistryItem) error
- type BaseFileResource
- type BasePackageResource
- type BaseResource
- type Config
- type FileResource
- type PacmanResource
- type Provider
- type RegistryItem
- type Resource
- func NewFileResource(title string, obj *ast.ObjectItem, config *Config) (Resource, error)
- func NewPackageResource(title string, obj *ast.ObjectItem, config *Config) (Resource, error)
- func NewPacmanResource(title string, obj *ast.ObjectItem, config *Config) (Resource, error)
- func NewServiceResource(title string, obj *ast.ObjectItem, config *Config) (Resource, error)
- func NewShellResource(title string, obj *ast.ObjectItem, config *Config) (Resource, error)
- func NewYumResource(title string, obj *ast.ObjectItem, config *Config) (Resource, error)
- type ServiceResource
- type ShellResource
- type State
- type YumResource
Constants ¶
const ( StateUnknown = "unknown" StatePresent = "present" StateAbsent = "absent" StateRunning = "running" StateStopped = "stopped" )
Resource states
Variables ¶
var ErrNoPackageProviderFound = errors.New("No suitable package provider found")
ErrNoPackageProviderFound is returned when no suitable provider is found
var Registry = make(map[string]RegistryItem)
Registry contains all known resources
Functions ¶
func Register ¶
func Register(item RegistryItem) error
Register adds a resource type to the registry
Types ¶
type BaseFileResource ¶
type BaseFileResource struct {
// Path to the file
Path string `hcl:"path"`
// Permission bits to set on the file
Mode int `hcl:"mode"`
// Owner of the file
Owner string `hcl:"owner"`
// Group of the file
Group string `hcl:"group"`
// Source file to use when creating/updating the file
Source string `hcl:"source"`
// The file type we manage
FileType string `hcl:"filetype"`
// Recursively manage the directory
Recursive bool `hcl:"recursive"`
// Purge extra files if found
Purge bool `hcl:"purge"`
}
BaseFileResource is the base resource for managing files
type BasePackageResource ¶
type BasePackageResource struct {
// Name of the package
Name string `hcl:"name"`
// Version of the package
Version string `hcl:"version"`
// Provider to use
Provider string `hcl:"provider"`
}
BasePackageResource is the base resource type for package management It's purpose is to be embeded into other package resource providers.
type BaseResource ¶
type BaseResource struct {
// Type of the resource
Type string `hcl:"-"`
// Title of the resource
Title string `hcl:"-"`
// Resource configuration settings
Config *Config `hcl:"-"`
// Desired state of the resource
State string `hcl:"state"`
// Resources before which this resource should be processed
Before []string `hcl:"before"`
// Resources after which this resource should be processed
After []string `hcl:"require"`
}
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) Printf ¶
func (br *BaseResource) Printf(format string, a ...interface{}) (int, error)
Printf works just like fmt.Printf except that it writes to the given resource writer object and prepends the resource id to the output
func (*BaseResource) ResourceID ¶
func (br *BaseResource) ResourceID() string
ResourceID returns the unique resource id
func (*BaseResource) SetType ¶
func (br *BaseResource) SetType(t string)
SetType sets the type for the resource. This method is primarily being used by meta resources.
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 Config ¶
type Config struct {
// The site repo which contains module and data files
SiteRepo string
// Writer used by the resources
Writer io.Writer
}
Config type contains various settings used by the resources
type FileResource ¶
type FileResource struct {
BaseResource `hcl:",squash"`
BaseFileResource `hcl:",squash"`
// contains filtered or unexported fields
}
FileResource is a resource which manages files and directories
func (*FileResource) Create ¶
func (fr *FileResource) Create() error
Create creates the file managed by the resource
func (*FileResource) Delete ¶
func (fr *FileResource) Delete() error
Delete deletes the file managed by the resource
func (*FileResource) Evaluate ¶
func (fr *FileResource) Evaluate() (State, error)
Evaluate evaluates the file resource
func (*FileResource) Update ¶
func (fr *FileResource) Update() error
Update updates the files managed by the resource
type PacmanResource ¶
type PacmanResource struct {
BaseResource `hcl:",squash"`
BasePackageResource `hcl:",squash"`
}
PacmanResource type represents the resource for package management on Arch Linux systems
func (*PacmanResource) Evaluate ¶
func (pr *PacmanResource) Evaluate() (State, error)
Evaluate evaluates the state of the resource
type RegistryItem ¶
type RegistryItem struct {
// Name of the resource type
Name string
// Short desription of the resource
Description string
// Resource provider
Provider Provider
}
RegistryItem type represents an item from the registry
type Resource ¶
type Resource interface {
// SetType sets the type for the resource
// Primary usage of this method is by meta resources
SetType(string)
// ResourceID returns the unique identifier of a resource
ResourceID() 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
}
Resource is the interface type for resources
func NewFileResource ¶
NewFileResource creates a new resource for managing files
func NewPackageResource ¶
NewPackageResource creates a new resource for managing packages
func NewPacmanResource ¶
NewPacmanResource creates a new resource for managing packages using the pacman package manager on an Arch Linux system
func NewServiceResource ¶
NewServiceResource creates a new resource for managing services using systemd on a GNU/Linux system
func NewShellResource ¶
NewShellResource creates a new resource for executing shell commands
func NewYumResource ¶
NewYumResource creates a new resource for managing packages using the yum package manager on RHEL/CentOS systems
type ServiceResource ¶
type ServiceResource struct {
BaseResource `hcl:",squash"`
// Name of the service
Name string `hcl:"name"`
// If true then enable service during boot-time
Enable bool `hcl:"enable"`
// Systemd unit name
UnitName string `hcl:"-"`
}
ServiceResource type is a resource which manages services on a GNU/Linux system running systemd
func (*ServiceResource) Create ¶
func (sr *ServiceResource) Create() error
Create starts the service unit
func (*ServiceResource) Delete ¶
func (sr *ServiceResource) Delete() error
Delete stops the service unit
func (*ServiceResource) Evaluate ¶
func (sr *ServiceResource) Evaluate() (State, error)
Evaluate evaluates the state of the resource
func (*ServiceResource) Update ¶
func (sr *ServiceResource) Update() error
Update updates the service unit state
type ShellResource ¶
type ShellResource struct {
BaseResource `hcl:",squash"`
Command string `hcl:"command"`
Creates string `hcl:"creates"`
}
ShellResource type is a resource which executes shell commands
func (*ShellResource) Create ¶
func (sr *ShellResource) Create() error
Create executes the shell command
func (*ShellResource) Evaluate ¶
func (sr *ShellResource) Evaluate() (State, error)
Evaluate evaluates the state of the resource
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 YumResource ¶
type YumResource struct {
BaseResource `hcl:",squash"`
BasePackageResource `hcl:",squash"`
}
YumResource type represents the resource for package management on RHEL/CentOS systems
func (*YumResource) Create ¶
func (yr *YumResource) Create() error
Create installs the package managed by the resource
func (*YumResource) Delete ¶
func (yr *YumResource) Delete() error
Delete deletes the package managed by the resource
func (*YumResource) Evaluate ¶
func (yr *YumResource) Evaluate() (State, error)
Evaluate evaluates the state of the package resource