resources

package
v0.0.0-...-54296da Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2017 License: AGPL-3.0 Imports: 38 Imported by: 0

Documentation

Overview

Package resources provides the resource framework and idempotent primitives.

Index

Constants

This section is empty.

Variables

View Source
var DefaultMetaParams = MetaParams{
	AutoEdge:  true,
	AutoGroup: true,
	Noop:      false,
	Retry:     0,
	Delay:     0,
	Poll:      0,
	Limit:     rate.Inf,
	Burst:     0,
}

DefaultMetaParams are the defaults to be used for undefined metaparams.

View Source
var ErrResourceInsufficientParameters = errors.New(
	"Insufficient parameters for this resource")

ErrResourceInsufficientParameters is returned when the configuration of the resource is insufficient for the resource to do any useful work.

Functions

func ResToB64

func ResToB64(res Res) (string, error)

ResToB64 encodes a resource to a base64 encoded string (after serialization)

func ReturnSvcInFileList

func ReturnSvcInFileList(fileList []string) []string

ReturnSvcInFileList returns a list of svc names for matches like: `/usr/lib/systemd/system/*.service`.

func TypeCmp

func TypeCmp(a, b reflect.Value) error

TypeCmp compares two reflect values to see if they are the same Kind. It can look into a ptr Kind to see if the underlying pair of ptr's can TypeCmp too!

func UIDExistsInUIDs

func UIDExistsInUIDs(uid ResUID, uids []ResUID) bool

UIDExistsInUIDs wraps the IFF method when used with a list of UID's.

Types

type AutoEdge

type AutoEdge interface {
	Next() []ResUID   // call to get list of edges to add
	Test([]bool) bool // call until false
}

The AutoEdge interface is used to implement the autoedges feature.

type Base

type Base interface {
	GetName() string // can't be named "Name()" because of struct field
	SetName(string)
	SetKind(string)
	Kind() string
	Meta() *MetaParams
	Events() chan *event.Event
	AssociateData(*Data)
	IsWorking() bool
	SetWorking(bool)
	Converger() converger.Converger
	RegisterConverger()
	UnregisterConverger()
	ConvergerUID() converger.ConvergerUID
	GetState() ResState
	SetState(ResState)
	Event(chan *event.Event) error
	SendEvent(event.EventName, error) error
	ReadEvent(*event.Event) (*error, bool)
	Refresh() bool                         // is there a pending refresh to run?
	SetRefresh(bool)                       // set the refresh state of this resource
	SendRecv(Res) (map[string]bool, error) // send->recv data passing function
	IsStateOK() bool
	StateOK(b bool)
	GroupCmp(Res) bool  // TODO: is there a better name for this?
	GroupRes(Res) error // group resource (arg) into self
	IsGrouped() bool    // am I grouped?
	SetGrouped(bool)    // set grouped bool
	GetGroup() []Res    // return everyone grouped inside me
	SetGroup([]Res)
	VarDir(string) (string, error)
	Running(chan *event.Event) error // notify the engine that Watch started
	Started() <-chan struct{}        // returns when the resource has started
	Starter(bool)
	Poll(chan *event.Event) error // poll alternative to watching :(
}

The Base interface is everything that is common to all resources. Everything here only needs to be implemented once, in the BaseRes.

type BaseRes

type BaseRes struct {
	Name       string           `yaml:"name"`
	MetaParams MetaParams       `yaml:"meta"` // struct of all the metaparams
	Recv       map[string]*Send // mapping of key to receive on from value
	// contains filtered or unexported fields
}

BaseRes is the base struct that gets used in every resource.

func (*BaseRes) AssociateData

func (obj *BaseRes) AssociateData(data *Data)

AssociateData associates some data with the object in question.

func (*BaseRes) Close

func (obj *BaseRes) Close() error

Close shuts down and performs any cleanup.

func (*BaseRes) CollectPattern

func (obj *BaseRes) CollectPattern(pattern string)

CollectPattern is used for resource collection.

func (*BaseRes) Compare

func (obj *BaseRes) Compare(res Res) bool

Compare is the base compare method, which also handles the metaparams cmp.

func (*BaseRes) Converger

func (obj *BaseRes) Converger() converger.Converger

Converger returns the converger object used by the system. It can be used to register new convergers if needed.

func (*BaseRes) ConvergerUID

func (obj *BaseRes) ConvergerUID() converger.ConvergerUID

ConvergerUID returns the ConvergerUID for the resource. This should be called by the Watch method of the resource to set the converged state.

func (*BaseRes) Event

func (obj *BaseRes) Event(processChan chan *event.Event) error

Event sends off an event, but doesn't block the incoming event queue.

func (*BaseRes) Events

func (obj *BaseRes) Events() chan *event.Event

Events returns the channel of events to listen on.

func (*BaseRes) GetGroup

func (obj *BaseRes) GetGroup() []Res

GetGroup returns everyone grouped inside me.

func (*BaseRes) GetName

func (obj *BaseRes) GetName() string

GetName is used by all the resources to Get the name.

func (*BaseRes) GetState

func (obj *BaseRes) GetState() ResState

GetState returns the state of the resource.

func (*BaseRes) GroupCmp

func (obj *BaseRes) GroupCmp(res Res) bool

GroupCmp compares two resources and decides if they're suitable for grouping You'll probably want to override this method when implementing a resource...

func (*BaseRes) GroupRes

func (obj *BaseRes) GroupRes(res Res) error

GroupRes groups resource (arg) into self.

func (*BaseRes) Init

func (obj *BaseRes) Init() error

Init initializes structures like channels if created without New constructor.

func (*BaseRes) IsGrouped

func (obj *BaseRes) IsGrouped() bool

IsGrouped determines if we are grouped.

func (*BaseRes) IsStateOK

func (obj *BaseRes) IsStateOK() bool

IsStateOK returns the cached state value.

func (*BaseRes) IsWorking

func (obj *BaseRes) IsWorking() bool

IsWorking tells us if the Worker() function is running.

func (*BaseRes) Kind

func (obj *BaseRes) Kind() string

Kind returns the kind of resource this is.

func (*BaseRes) Meta

func (obj *BaseRes) Meta() *MetaParams

Meta returns the MetaParams as a reference, which we can then get/set on.

func (*BaseRes) Poll

func (obj *BaseRes) Poll(processChan chan *event.Event) error

Poll is the watch replacement for when we want to poll, which outputs events.

func (*BaseRes) ReadEvent

func (obj *BaseRes) ReadEvent(ev *event.Event) (exit *error, send bool)

ReadEvent processes events when a select gets one, and handles the pause code too! The return values specify if we should exit and poke respectively.

func (*BaseRes) Refresh

func (obj *BaseRes) Refresh() bool

Refresh returns the pending state of a notification. It should only be called in the CheckApply portion of a resource where a refresh should be acted upon.

func (*BaseRes) RegisterConverger

func (obj *BaseRes) RegisterConverger()

RegisterConverger sets up the cuid for the resource. This is a helper function for the engine, and shouldn't be called by the resources directly.

func (*BaseRes) Running

func (obj *BaseRes) Running(processChan chan *event.Event) error

Running is called by the Watch method of the resource once it has started up. This signals to the engine to kick off the initial CheckApply resource check.

func (*BaseRes) SendEvent

func (obj *BaseRes) SendEvent(ev event.EventName, err error) error

SendEvent pushes an event into the message queue for a particular vertex.

func (*BaseRes) SendRecv

func (obj *BaseRes) SendRecv(res Res) (map[string]bool, error)

SendRecv pulls in the sent values into the receive slots. It is called by the receiver and must be given as input the full resource struct to receive on.

func (*BaseRes) SetGroup

func (obj *BaseRes) SetGroup(g []Res)

SetGroup sets the grouped resources into me.

func (*BaseRes) SetGrouped

func (obj *BaseRes) SetGrouped(b bool)

SetGrouped sets a flag to tell if we are grouped.

func (*BaseRes) SetKind

func (obj *BaseRes) SetKind(kind string)

SetKind sets the kind. This is used internally for exported resources.

func (*BaseRes) SetName

func (obj *BaseRes) SetName(name string)

SetName is used to set the name of the resource.

func (*BaseRes) SetRefresh

func (obj *BaseRes) SetRefresh(b bool)

SetRefresh sets the pending state of a notification. It should only be called by the mgmt engine.

func (*BaseRes) SetState

func (obj *BaseRes) SetState(state ResState)

SetState sets the state of the resource.

func (*BaseRes) SetWorking

func (obj *BaseRes) SetWorking(b bool)

SetWorking tracks the state of if Worker() function is running.

func (*BaseRes) Started

func (obj *BaseRes) Started() <-chan struct{}

Started returns a channel that closes when the resource has started up.

func (*BaseRes) Starter

func (obj *BaseRes) Starter(b bool)

Starter sets the starter bool. This defines if a vertex has an indegree of 0. If we have an indegree of 0, we'll need to be a poke initiator in the graph.

func (*BaseRes) StateOK

func (obj *BaseRes) StateOK(b bool)

StateOK sets the cached state value.

func (*BaseRes) UnregisterConverger

func (obj *BaseRes) UnregisterConverger()

UnregisterConverger tears down the cuid for the resource. This is a helper function for the engine, and shouldn't be called by the resources directly.

func (*BaseRes) Validate

func (obj *BaseRes) Validate() error

Validate reports any problems with the struct definition.

func (*BaseRes) VarDir

func (obj *BaseRes) VarDir(extra string) (string, error)

VarDir returns the path to a working directory for the resource. It will try and create the directory first, and return an error if this failed.

type BaseUID

type BaseUID struct {
	// contains filtered or unexported fields
}

The BaseUID struct is used to provide a unique resource identifier.

func (*BaseUID) GetName

func (obj *BaseUID) GetName() string

GetName returns the name of the resource.

func (*BaseUID) IFF

func (obj *BaseUID) IFF(uid ResUID) bool

IFF looks at two UID's and if and only if they are equivalent, returns true. If they are not equivalent, it returns false. Most resources will want to override this method, since it does the important work of actually discerning if two resources are identical in function.

func (*BaseUID) Kind

func (obj *BaseUID) Kind() string

Kind returns the kind of resource.

func (*BaseUID) Reversed

func (obj *BaseUID) Reversed() bool

Reversed is part of the ResUID interface, and true means this resource happens before the generator.

type Data

type Data struct {
	//Hostname string         // uuid for the host
	//Noop     bool
	Converger converger.Converger
	Prefix    string // the prefix to be used for the pgraph namespace
	Debug     bool
}

Data is the set of input values passed into the pgraph for the resources.

type DiskBool

type DiskBool struct {
	Path string // path to token
}

DiskBool stores a boolean variable on disk for stateful access across runs. The absence of the path is treated as false. If the path contains a special value, then it is treated as true. All the other non-error cases are false.

func (*DiskBool) Del

func (obj *DiskBool) Del() error

Del stores the false boolean value, if no error clearing the value occurs.

func (*DiskBool) Get

func (obj *DiskBool) Get() (bool, error)

Get returns if the boolean setting, if no error reading the value occurs.

func (*DiskBool) Set

func (obj *DiskBool) Set() error

Set stores the true boolean value, if no error setting the value occurs.

type ExecRes

type ExecRes struct {
	BaseRes    `yaml:",inline"`
	State      string `yaml:"state"`      // state: exists/present?, absent, (undefined?)
	Cmd        string `yaml:"cmd"`        // the command to run
	Shell      string `yaml:"shell"`      // the (optional) shell to use to run the cmd
	Timeout    int    `yaml:"timeout"`    // the cmd timeout in seconds
	WatchCmd   string `yaml:"watchcmd"`   // the watch command to run
	WatchShell string `yaml:"watchshell"` // the (optional) shell to use to run the watch cmd
	IfCmd      string `yaml:"ifcmd"`      // the if command to run
	IfShell    string `yaml:"ifshell"`    // the (optional) shell to use to run the if cmd
	PollInt    int    `yaml:"pollint"`    // the poll interval for the ifcmd
}

ExecRes is an exec resource for running commands.

func NewExecRes

func NewExecRes(name, cmd, shell string, timeout int, watchcmd, watchshell, ifcmd, ifshell string, pollint int, state string) (*ExecRes, error)

NewExecRes is a constructor for this resource. It also calls Init() for you.

func (*ExecRes) AutoEdges

func (obj *ExecRes) AutoEdges() AutoEdge

AutoEdges returns the AutoEdge interface. In this case no autoedges are used.

func (*ExecRes) BufioChanScanner

func (obj *ExecRes) BufioChanScanner(scanner *bufio.Scanner) (chan string, chan error)

BufioChanScanner wraps the scanner output in a channel.

func (*ExecRes) CheckApply

func (obj *ExecRes) CheckApply(apply bool) (checkOK bool, err error)

CheckApply checks the resource state and applies the resource if the bool input is true. It returns error info and if the state check passed or not. TODO: expand the IfCmd to be a list of commands

func (*ExecRes) Compare

func (obj *ExecRes) Compare(res Res) bool

Compare two resources and return if they are equivalent.

func (*ExecRes) Default

func (obj *ExecRes) Default() Res

Default returns some sensible defaults for this resource.

func (*ExecRes) GetUIDs

func (obj *ExecRes) GetUIDs() []ResUID

GetUIDs includes all params to make a unique identification of this object. Most resources only return one, although some resources can return multiple.

func (*ExecRes) GroupCmp

func (obj *ExecRes) GroupCmp(r Res) bool

GroupCmp returns whether two resources can be grouped together or not.

func (*ExecRes) Init

func (obj *ExecRes) Init() error

Init runs some startup code for this resource.

func (*ExecRes) UnmarshalYAML

func (obj *ExecRes) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is the custom unmarshal handler for this struct. It is primarily useful for setting the defaults.

func (*ExecRes) Validate

func (obj *ExecRes) Validate() error

Validate if the params passed in are valid data.

func (*ExecRes) Watch

func (obj *ExecRes) Watch(processChan chan *event.Event) error

Watch is the primary listener for this resource and it outputs events.

type ExecUID

type ExecUID struct {
	BaseUID
	Cmd   string
	IfCmd string
}

ExecUID is the UID struct for ExecRes.

func (*ExecUID) IFF

func (obj *ExecUID) IFF(uid ResUID) bool

IFF aka if and only if they are equivalent, return true. If not, false.

type FileInfo

type FileInfo struct {
	os.FileInfo        // embed
	AbsPath     string // smart variant
	RelPath     string // smart variant
}

FileInfo is an enhanced variant of the traditional os.FileInfo struct. It can store both the absolute and the relative paths (when built from our ReadDir), and those two paths contain a trailing slash when they refer to a directory.

func ReadDir

func ReadDir(path string) ([]FileInfo, error)

ReadDir reads a directory path, and returns a list of enhanced FileInfo's.

type FileRes

type FileRes struct {
	BaseRes  `yaml:",inline"`
	Path     string  `yaml:"path"` // path variable (should default to name)
	Dirname  string  `yaml:"dirname"`
	Basename string  `yaml:"basename"`
	Content  *string `yaml:"content"` // nil to mark as undefined
	Source   string  `yaml:"source"`  // file path for source content
	State    string  `yaml:"state"`   // state: exists/present?, absent, (undefined?)
	Recurse  bool    `yaml:"recurse"`
	Force    bool    `yaml:"force"`
	// contains filtered or unexported fields
}

FileRes is a file and directory resource.

func NewFileRes

func NewFileRes(name, path, dirname, basename string, content *string, source, state string, recurse, force bool) (*FileRes, error)

NewFileRes is a constructor for this resource. It also calls Init() for you.

func (*FileRes) AutoEdges

func (obj *FileRes) AutoEdges() AutoEdge

AutoEdges generates a simple linear sequence of each parent directory from the bottom up!

func (*FileRes) CheckApply

func (obj *FileRes) CheckApply(apply bool) (checkOK bool, _ error)

CheckApply checks the resource state and applies the resource if the bool input is true. It returns error info and if the state check passed or not.

func (*FileRes) CollectPattern

func (obj *FileRes) CollectPattern(pattern string)

CollectPattern applies the pattern for collection resources.

func (*FileRes) Compare

func (obj *FileRes) Compare(res Res) bool

Compare two resources and return if they are equivalent.

func (*FileRes) Default

func (obj *FileRes) Default() Res

Default returns some sensible defaults for this resource.

func (*FileRes) GetPath

func (obj *FileRes) GetPath() string

GetPath returns the actual path to use for this resource. It computes this after analysis of the Path, Dirname and Basename values. Dirs end with slash.

func (*FileRes) GetUIDs

func (obj *FileRes) GetUIDs() []ResUID

GetUIDs includes all params to make a unique identification of this object. Most resources only return one, although some resources can return multiple.

func (*FileRes) GroupCmp

func (obj *FileRes) GroupCmp(r Res) bool

GroupCmp returns whether two resources can be grouped together or not.

func (*FileRes) Init

func (obj *FileRes) Init() error

Init runs some startup code for this resource.

func (*FileRes) UnmarshalYAML

func (obj *FileRes) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is the custom unmarshal handler for this struct. It is primarily useful for setting the defaults.

func (*FileRes) Validate

func (obj *FileRes) Validate() error

Validate reports any problems with the struct definition.

func (*FileRes) Watch

func (obj *FileRes) Watch(processChan chan *event.Event) error

Watch is the primary listener for this resource and it outputs events. This one is a file watcher for files and directories. Modify with caution, it is probably important to write some test cases first! If the Watch returns an error, it means that something has gone wrong, and it must be restarted. On a clean exit it returns nil. FIXME: Also watch the source directory when using obj.Source !!!

type FileResAutoEdges

type FileResAutoEdges struct {
	// contains filtered or unexported fields
}

FileResAutoEdges holds the state of the auto edge generator.

func (*FileResAutoEdges) Next

func (obj *FileResAutoEdges) Next() []ResUID

Next returns the next automatic edge.

func (*FileResAutoEdges) Test

func (obj *FileResAutoEdges) Test(input []bool) bool

Test gets results of the earlier Next() call, & returns if we should continue!

type FileUID

type FileUID struct {
	BaseUID
	// contains filtered or unexported fields
}

FileUID is the UID struct for FileRes.

func (*FileUID) IFF

func (obj *FileUID) IFF(uid ResUID) bool

IFF aka if and only if they are equivalent, return true. If not, false.

type HostnameRes

type HostnameRes struct {
	BaseRes           `yaml:",inline"`
	Hostname          string `yaml:"hostname"`
	PrettyHostname    string `yaml:"pretty_hostname"`
	StaticHostname    string `yaml:"static_hostname"`
	TransientHostname string `yaml:"transient_hostname"`
	// contains filtered or unexported fields
}

HostnameRes is a resource that allows setting and watching the hostname.

StaticHostname is the one configured in /etc/hostname or a similar file. It is chosen by the local user. It is not always in sync with the current host name as returned by the gethostname() system call.

TransientHostname is the one configured via the kernel's sethostbyname(). It can be different from the static hostname in case DHCP or mDNS have been configured to change the name based on network information.

PrettyHostname is a free-form UTF8 host name for presentation to the user.

Hostname is the fallback value for all 3 fields above, if only Hostname is specified, it will set all 3 fields to this value.

func NewHostnameRes

func NewHostnameRes(name, staticHostname, transientHostname, prettyHostname string) (*HostnameRes, error)

NewHostnameRes is a constructor for this resource. It also calls Init() for you.

func (*HostnameRes) AutoEdges

func (obj *HostnameRes) AutoEdges() AutoEdge

AutoEdges returns the AutoEdge interface. In this case no autoedges are used.

func (*HostnameRes) CheckApply

func (obj *HostnameRes) CheckApply(apply bool) (checkOK bool, err error)

CheckApply method for Hostname resource.

func (*HostnameRes) Compare

func (obj *HostnameRes) Compare(res Res) bool

Compare two resources and return if they are equivalent.

func (*HostnameRes) Default

func (obj *HostnameRes) Default() Res

Default returns some sensible defaults for this resource.

func (*HostnameRes) GetUIDs

func (obj *HostnameRes) GetUIDs() []ResUID

GetUIDs includes all params to make a unique identification of this object. Most resources only return one, although some resources can return multiple.

func (*HostnameRes) GroupCmp

func (obj *HostnameRes) GroupCmp(r Res) bool

GroupCmp returns whether two resources can be grouped together or not.

func (*HostnameRes) Init

func (obj *HostnameRes) Init() error

Init runs some startup code for this resource.

func (*HostnameRes) UnmarshalYAML

func (obj *HostnameRes) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is the custom unmarshal handler for this struct. It is primarily useful for setting the defaults.

func (*HostnameRes) Validate

func (obj *HostnameRes) Validate() error

Validate if the params passed in are valid data.

func (*HostnameRes) Watch

func (obj *HostnameRes) Watch(processChan chan *event.Event) error

Watch is the primary listener for this resource and it outputs events.

type HostnameUID

type HostnameUID struct {
	BaseUID
	// contains filtered or unexported fields
}

HostnameUID is the UID struct for HostnameRes.

type MetaParams

type MetaParams struct {
	AutoEdge  bool `yaml:"autoedge"`  // metaparam, should we generate auto edges?
	AutoGroup bool `yaml:"autogroup"` // metaparam, should we auto group?
	Noop      bool `yaml:"noop"`
	// NOTE: there are separate Watch and CheckApply retry and delay values,
	// but I've decided to use the same ones for both until there's a proper
	// reason to want to do something differently for the Watch errors.
	Retry int16      `yaml:"retry"` // metaparam, number of times to retry on error. -1 for infinite
	Delay uint64     `yaml:"delay"` // metaparam, number of milliseconds to wait between retries
	Poll  uint32     `yaml:"poll"`  // metaparam, number of seconds between poll intervals, 0 to watch
	Limit rate.Limit `yaml:"limit"` // metaparam, number of events per second to allow through
	Burst int        `yaml:"burst"` // metaparam, number of events to allow in a burst
}

MetaParams is a struct will all params that apply to every resource.

func (*MetaParams) UnmarshalYAML

func (obj *MetaParams) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is the custom unmarshal handler for the MetaParams struct. It is primarily useful for setting the defaults.

type MsgRes

type MsgRes struct {
	BaseRes  `yaml:",inline"`
	Body     string            `yaml:"body"`
	Priority string            `yaml:"priority"`
	Fields   map[string]string `yaml:"fields"`
	Journal  bool              `yaml:"journal"` // enable systemd journal output
	Syslog   bool              `yaml:"syslog"`  // enable syslog output
	// contains filtered or unexported fields
}

MsgRes is a resource that writes messages to logs.

func NewMsgRes

func NewMsgRes(name, body, priority string, journal, syslog bool, fields map[string]string) (*MsgRes, error)

NewMsgRes is a constructor for this resource.

func (*MsgRes) AutoEdges

func (obj *MsgRes) AutoEdges() AutoEdge

AutoEdges returns the AutoEdges. In this case none are used.

func (*MsgRes) CheckApply

func (obj *MsgRes) CheckApply(apply bool) (bool, error)

CheckApply method for Msg resource. Every check leads to an apply, meaning that the message is flushed to the journal.

func (*MsgRes) Compare

func (obj *MsgRes) Compare(res Res) bool

Compare two resources and return if they are equivalent.

func (*MsgRes) Default

func (obj *MsgRes) Default() Res

Default returns some sensible defaults for this resource.

func (*MsgRes) GetUIDs

func (obj *MsgRes) GetUIDs() []ResUID

GetUIDs includes all params to make a unique identification of this object. Most resources only return one, although some resources can return multiple.

func (*MsgRes) Init

func (obj *MsgRes) Init() error

Init runs some startup code for this resource.

func (*MsgRes) UnmarshalYAML

func (obj *MsgRes) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is the custom unmarshal handler for this struct. It is primarily useful for setting the defaults.

func (*MsgRes) Validate

func (obj *MsgRes) Validate() error

Validate the params that are passed to MsgRes.

func (*MsgRes) Watch

func (obj *MsgRes) Watch(processChan chan *event.Event) error

Watch is the primary listener for this resource and it outputs events.

type MsgUID

type MsgUID struct {
	BaseUID
	// contains filtered or unexported fields
}

MsgUID is a unique representation for a MsgRes object.

type NoopRes

type NoopRes struct {
	BaseRes `yaml:",inline"`
	Comment string `yaml:"comment"` // extra field for example purposes
}

NoopRes is a no-op resource that does nothing.

func NewNoopRes

func NewNoopRes(name string) (*NoopRes, error)

NewNoopRes is a constructor for this resource. It also calls Init() for you.

func (*NoopRes) AutoEdges

func (obj *NoopRes) AutoEdges() AutoEdge

AutoEdges returns the AutoEdge interface. In this case no autoedges are used.

func (*NoopRes) CheckApply

func (obj *NoopRes) CheckApply(apply bool) (checkOK bool, err error)

CheckApply method for Noop resource. Does nothing, returns happy!

func (*NoopRes) Compare

func (obj *NoopRes) Compare(res Res) bool

Compare two resources and return if they are equivalent.

func (*NoopRes) Default

func (obj *NoopRes) Default() Res

Default returns some sensible defaults for this resource.

func (*NoopRes) GetUIDs

func (obj *NoopRes) GetUIDs() []ResUID

GetUIDs includes all params to make a unique identification of this object. Most resources only return one, although some resources can return multiple.

func (*NoopRes) GroupCmp

func (obj *NoopRes) GroupCmp(r Res) bool

GroupCmp returns whether two resources can be grouped together or not.

func (*NoopRes) Init

func (obj *NoopRes) Init() error

Init runs some startup code for this resource.

func (*NoopRes) UnmarshalYAML

func (obj *NoopRes) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is the custom unmarshal handler for this struct. It is primarily useful for setting the defaults.

func (*NoopRes) Validate

func (obj *NoopRes) Validate() error

Validate if the params passed in are valid data.

func (*NoopRes) Watch

func (obj *NoopRes) Watch(processChan chan *event.Event) error

Watch is the primary listener for this resource and it outputs events.

type NoopUID

type NoopUID struct {
	BaseUID
	// contains filtered or unexported fields
}

NoopUID is the UID struct for NoopRes.

type NspawnRes

type NspawnRes struct {
	BaseRes `yaml:",inline"`
	State   string `yaml:"state"`
	// contains filtered or unexported fields
}

NspawnRes is an nspawn container resource

func NewNspawnRes

func NewNspawnRes(name string, state string) (*NspawnRes, error)

NewNspawnRes is the constructor for this resource

func (*NspawnRes) AutoEdges

func (obj *NspawnRes) AutoEdges() AutoEdge

AutoEdges returns the AutoEdge interface in this case no autoedges are used

func (*NspawnRes) CheckApply

func (obj *NspawnRes) CheckApply(apply bool) (checkOK bool, err error)

CheckApply is run to check the state and, if apply is true, to apply the necessary changes to reach the desired state. this is run before Watch and again if watch finds a change occurring to the state

func (*NspawnRes) Compare

func (obj *NspawnRes) Compare(res Res) bool

Compare two resources and return if they are equivalent

func (*NspawnRes) Default

func (obj *NspawnRes) Default() Res

Default returns some sensible defaults for this resource.

func (*NspawnRes) GetUIDs

func (obj *NspawnRes) GetUIDs() []ResUID

GetUIDs includes all params to make a unique identification of this object most resources only return one although some resources can return multiple

func (*NspawnRes) GroupCmp

func (obj *NspawnRes) GroupCmp(r Res) bool

GroupCmp returns whether two resources can be grouped together or not

func (*NspawnRes) Init

func (obj *NspawnRes) Init() error

Init runs some startup code for this resource.

func (*NspawnRes) UnmarshalYAML

func (obj *NspawnRes) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is the custom unmarshal handler for this struct. It is primarily useful for setting the defaults.

func (*NspawnRes) Validate

func (obj *NspawnRes) Validate() error

Validate if the params passed in are valid data.

func (*NspawnRes) Watch

func (obj *NspawnRes) Watch(processChan chan *event.Event) error

Watch for state changes and sends a message to the bus if there is a change

type NspawnUID

type NspawnUID struct {
	// NOTE: there is also a name variable in the BaseUID struct, this is
	// information about where this UID came from, and is unrelated to the
	// information about the resource we're matching. That data which is
	// used in the IFF function, is what you see in the struct fields here
	BaseUID
	// contains filtered or unexported fields
}

NspawnUID is a unique resource identifier

func (*NspawnUID) IFF

func (obj *NspawnUID) IFF(uid ResUID) bool

IFF aka if and only if they are equivalent, return true. If not, false

type PasswordRes

type PasswordRes struct {
	BaseRes `yaml:",inline"`
	// FIXME: is uint16 too big?
	Length        uint16  `yaml:"length"` // number of characters to return
	Saved         bool    // this caches the password in the clear locally
	CheckRecovery bool    // recovery from integrity checks by re-generating
	Password      *string // the generated password, read only, do not set!
	// contains filtered or unexported fields
}

PasswordRes is a no-op resource that returns a random password string.

func NewPasswordRes

func NewPasswordRes(name string, length uint16) (*PasswordRes, error)

NewPasswordRes is a constructor for this resource. It also calls Init() for you.

func (*PasswordRes) AutoEdges

func (obj *PasswordRes) AutoEdges() AutoEdge

AutoEdges returns the AutoEdge interface. In this case no autoedges are used.

func (*PasswordRes) CheckApply

func (obj *PasswordRes) CheckApply(apply bool) (checkOK bool, err error)

CheckApply method for Password resource. Does nothing, returns happy!

func (*PasswordRes) Compare

func (obj *PasswordRes) Compare(res Res) bool

Compare two resources and return if they are equivalent.

func (*PasswordRes) Default

func (obj *PasswordRes) Default() Res

Default returns some sensible defaults for this resource.

func (*PasswordRes) GetUIDs

func (obj *PasswordRes) GetUIDs() []ResUID

GetUIDs includes all params to make a unique identification of this object. Most resources only return one, although some resources can return multiple.

func (*PasswordRes) GroupCmp

func (obj *PasswordRes) GroupCmp(r Res) bool

GroupCmp returns whether two resources can be grouped together or not.

func (*PasswordRes) Init

func (obj *PasswordRes) Init() error

Init generates a new password for this resource if one was not provided. It will save this into a local file. It will load it back in from previous runs.

func (*PasswordRes) UnmarshalYAML

func (obj *PasswordRes) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is the custom unmarshal handler for this struct. It is primarily useful for setting the defaults.

func (*PasswordRes) Validate

func (obj *PasswordRes) Validate() error

Validate if the params passed in are valid data.

func (*PasswordRes) Watch

func (obj *PasswordRes) Watch(processChan chan *event.Event) error

Watch is the primary listener for this resource and it outputs events.

type PasswordUID

type PasswordUID struct {
	BaseUID
	// contains filtered or unexported fields
}

PasswordUID is the UID struct for PasswordRes.

type PkgRes

type PkgRes struct {
	BaseRes          `yaml:",inline"`
	State            string `yaml:"state"`            // state: installed, uninstalled, newest, <version>
	AllowUntrusted   bool   `yaml:"allowuntrusted"`   // allow untrusted packages to be installed?
	AllowNonFree     bool   `yaml:"allownonfree"`     // allow nonfree packages to be found?
	AllowUnsupported bool   `yaml:"allowunsupported"` // allow unsupported packages to be found?
	// contains filtered or unexported fields
}

PkgRes is a package resource for packagekit.

func NewPkgRes

func NewPkgRes(name, state string, allowuntrusted, allownonfree, allowunsupported bool) (*PkgRes, error)

NewPkgRes is a constructor for this resource. It also calls Init() for you.

func (*PkgRes) AutoEdges

func (obj *PkgRes) AutoEdges() AutoEdge

AutoEdges produces an object which generates a minimal pkg file optimization sequence of edges.

func (*PkgRes) CheckApply

func (obj *PkgRes) CheckApply(apply bool) (checkOK bool, err error)

CheckApply checks the resource state and applies the resource if the bool input is true. It returns error info and if the state check passed or not.

func (*PkgRes) Compare

func (obj *PkgRes) Compare(res Res) bool

Compare two resources and return if they are equivalent.

func (*PkgRes) Default

func (obj *PkgRes) Default() Res

Default returns some sensible defaults for this resource.

func (*PkgRes) GetUIDs

func (obj *PkgRes) GetUIDs() []ResUID

GetUIDs includes all params to make a unique identification of this object. Most resources only return one, although some resources can return multiple.

func (*PkgRes) GroupCmp

func (obj *PkgRes) GroupCmp(r Res) bool

GroupCmp returns whether two resources can be grouped together or not. can these two resources be merged ? (aka does this resource support doing so?) will resource allow itself to be grouped _into_ this obj?

func (*PkgRes) Init

func (obj *PkgRes) Init() error

Init runs some startup code for this resource.

func (*PkgRes) UnmarshalYAML

func (obj *PkgRes) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is the custom unmarshal handler for this struct. It is primarily useful for setting the defaults.

func (*PkgRes) Validate

func (obj *PkgRes) Validate() error

Validate checks if the resource data structure was populated correctly.

func (*PkgRes) Watch

func (obj *PkgRes) Watch(processChan chan *event.Event) error

Watch is the primary listener for this resource and it outputs events. It uses the PackageKit UpdatesChanged signal to watch for changes. TODO: https://github.com/hughsie/PackageKit/issues/109 TODO: https://github.com/hughsie/PackageKit/issues/110

type PkgResAutoEdges

type PkgResAutoEdges struct {
	// contains filtered or unexported fields
}

PkgResAutoEdges holds the state of the auto edge generator.

func (*PkgResAutoEdges) Next

func (obj *PkgResAutoEdges) Next() []ResUID

Next returns the next automatic edge.

func (*PkgResAutoEdges) Test

func (obj *PkgResAutoEdges) Test(input []bool) bool

Test gets results of the earlier Next() call, & returns if we should continue!

type PkgUID

type PkgUID struct {
	BaseUID
	// contains filtered or unexported fields
}

PkgUID is the UID struct for PkgRes.

func (*PkgUID) IFF

func (obj *PkgUID) IFF(uid ResUID) bool

IFF aka if and only if they are equivalent, return true. If not, false.

type Res

type Res interface {
	Base          // include everything from the Base interface
	Default() Res // return a struct with sane defaults as a Res
	Validate() error
	Init() error
	Close() error
	GetUIDs() []ResUID             // most resources only return one
	Watch(chan *event.Event) error // send on channel to signal process() events
	CheckApply(apply bool) (checkOK bool, err error)
	AutoEdges() AutoEdge
	Compare(Res) bool
	CollectPattern(string) // XXX: temporary until Res collection is more advanced

}

Res is the minimum interface you need to implement to define a new resource.

func B64ToRes

func B64ToRes(str string) (Res, error)

B64ToRes decodes a resource from a base64 encoded string (after deserialization)

type ResState

type ResState int

The ResState type represents the current activity state of each resource.

const (
	ResStateNil        ResState = iota
	ResStateProcess             // we're in process, but we haven't done much yet
	ResStateCheckApply          // we're about to run CheckApply
	ResStatePoking              // we're done CheckApply, and we're about to poke
)

Each ResState should be set properly in the relevant part of the resource.

type ResUID

type ResUID interface {
	GetName() string
	Kind() string
	IFF(ResUID) bool

	Reversed() bool // true means this resource happens before the generator
}

ResUID is a unique identifier for a resource, namely it's name, and the kind ("type").

type Send

type Send struct {
	Res Res    // a handle to the resource which is sending a value
	Key string // the key in the resource that we're sending

	Changed bool // set to true if this key was updated, read only!
}

Send points to a value that a resource will send.

type StatefulBool

type StatefulBool interface {
	Get() (bool, error) // get value of token
	Set() error         // set token to true
	Del() error         // rm token if it exists
}

StatefulBool is an interface for storing a boolean flag in a permanent spot.

type SvcRes

type SvcRes struct {
	BaseRes `yaml:",inline"`
	State   string `yaml:"state"`   // state: running, stopped, undefined
	Startup string `yaml:"startup"` // enabled, disabled, undefined
}

SvcRes is a service resource for systemd units.

func NewSvcRes

func NewSvcRes(name, state, startup string) (*SvcRes, error)

NewSvcRes is a constructor for this resource. It also calls Init() for you.

func (*SvcRes) AutoEdges

func (obj *SvcRes) AutoEdges() AutoEdge

AutoEdges returns the AutoEdge interface. In this case the systemd units.

func (*SvcRes) CheckApply

func (obj *SvcRes) CheckApply(apply bool) (checkOK bool, err error)

CheckApply checks the resource state and applies the resource if the bool input is true. It returns error info and if the state check passed or not.

func (*SvcRes) Compare

func (obj *SvcRes) Compare(res Res) bool

Compare two resources and return if they are equivalent.

func (*SvcRes) Default

func (obj *SvcRes) Default() Res

Default returns some sensible defaults for this resource.

func (*SvcRes) GetUIDs

func (obj *SvcRes) GetUIDs() []ResUID

GetUIDs includes all params to make a unique identification of this object. Most resources only return one, although some resources can return multiple.

func (*SvcRes) GroupCmp

func (obj *SvcRes) GroupCmp(r Res) bool

GroupCmp returns whether two resources can be grouped together or not.

func (*SvcRes) Init

func (obj *SvcRes) Init() error

Init runs some startup code for this resource.

func (*SvcRes) UnmarshalYAML

func (obj *SvcRes) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is the custom unmarshal handler for this struct. It is primarily useful for setting the defaults.

func (*SvcRes) Validate

func (obj *SvcRes) Validate() error

Validate checks if the resource data structure was populated correctly.

func (*SvcRes) Watch

func (obj *SvcRes) Watch(processChan chan *event.Event) error

Watch is the primary listener for this resource and it outputs events.

type SvcResAutoEdges

type SvcResAutoEdges struct {
	// contains filtered or unexported fields
}

SvcResAutoEdges holds the state of the auto edge generator.

func (*SvcResAutoEdges) Next

func (obj *SvcResAutoEdges) Next() []ResUID

Next returns the next automatic edge.

func (*SvcResAutoEdges) Test

func (obj *SvcResAutoEdges) Test(input []bool) bool

Test gets results of the earlier Next() call, & returns if we should continue!

type SvcUID

type SvcUID struct {
	// NOTE: there is also a name variable in the BaseUID struct, this is
	// information about where this UID came from, and is unrelated to the
	// information about the resource we're matching. That data which is
	// used in the IFF function, is what you see in the struct fields here.
	BaseUID
	// contains filtered or unexported fields
}

SvcUID is the UID struct for SvcRes.

func (*SvcUID) IFF

func (obj *SvcUID) IFF(uid ResUID) bool

IFF aka if and only if they are equivalent, return true. If not, false.

type TimerRes

type TimerRes struct {
	BaseRes  `yaml:",inline"`
	Interval uint32 `yaml:"interval"` // Interval : Interval between runs
	// contains filtered or unexported fields
}

TimerRes is a timer resource for time based events.

func NewTimerRes

func NewTimerRes(name string, interval uint32) (*TimerRes, error)

NewTimerRes is a constructor for this resource. It also calls Init() for you.

func (*TimerRes) AutoEdges

func (obj *TimerRes) AutoEdges() AutoEdge

AutoEdges returns the AutoEdge interface. In this case no autoedges are used.

func (*TimerRes) CheckApply

func (obj *TimerRes) CheckApply(apply bool) (bool, error)

CheckApply method for Timer resource. Triggers a timer reset on notify.

func (*TimerRes) Compare

func (obj *TimerRes) Compare(res Res) bool

Compare two resources and return if they are equivalent.

func (*TimerRes) Default

func (obj *TimerRes) Default() Res

Default returns some sensible defaults for this resource.

func (*TimerRes) GetUIDs

func (obj *TimerRes) GetUIDs() []ResUID

GetUIDs includes all params to make a unique identification of this object. Most resources only return one, although some resources can return multiple.

func (*TimerRes) Init

func (obj *TimerRes) Init() error

Init runs some startup code for this resource.

func (*TimerRes) UnmarshalYAML

func (obj *TimerRes) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is the custom unmarshal handler for this struct. It is primarily useful for setting the defaults.

func (*TimerRes) Validate

func (obj *TimerRes) Validate() error

Validate the params that are passed to TimerRes.

func (*TimerRes) Watch

func (obj *TimerRes) Watch(processChan chan *event.Event) error

Watch is the primary listener for this resource and it outputs events.

type TimerUID

type TimerUID struct {
	BaseUID
	// contains filtered or unexported fields
}

TimerUID is the UID struct for TimerRes.

type VirtAuth

type VirtAuth struct {
	Username string `yaml:"username"`
	Password string `yaml:"password"`
}

VirtAuth is used to pass credentials to libvirt.

type VirtRes

type VirtRes struct {
	BaseRes    `yaml:",inline"`
	URI        string             `yaml:"uri"`       // connection uri, eg: qemu:///session
	State      string             `yaml:"state"`     // running, paused, shutoff
	Transient  bool               `yaml:"transient"` // defined (false) or undefined (true)
	CPUs       uint               `yaml:"cpus"`
	Memory     uint64             `yaml:"memory"` // in KBytes
	OSInit     string             `yaml:"osinit"` // init used by lxc
	Boot       []string           `yaml:"boot"`   // boot order. values: fd, hd, cdrom, network
	Disk       []diskDevice       `yaml:"disk"`
	CDRom      []cdRomDevice      `yaml:"cdrom"`
	Network    []networkDevice    `yaml:"network"`
	Filesystem []filesystemDevice `yaml:"filesystem"`
	Auth       *VirtAuth          `yaml:"auth"`
	// contains filtered or unexported fields
}

VirtRes is a libvirt resource. A transient virt resource, which has its state set to `shutoff` is one which does not exist. The parallel equivalent is a file resource which removes a particular path.

func NewVirtRes

func NewVirtRes(name string, uri, state string, transient bool, cpus uint, memory uint64, osinit string) (*VirtRes, error)

NewVirtRes is a constructor for this resource. It also calls Init() for you.

func (*VirtRes) AutoEdges

func (obj *VirtRes) AutoEdges() AutoEdge

AutoEdges returns the AutoEdge interface. In this case no autoedges are used.

func (*VirtRes) CheckApply

func (obj *VirtRes) CheckApply(apply bool) (bool, error)

CheckApply checks the resource state and applies the resource if the bool input is true. It returns error info and if the state check passed or not.

func (*VirtRes) CollectPattern

func (obj *VirtRes) CollectPattern(string)

CollectPattern applies the pattern for collection resources.

func (*VirtRes) Compare

func (obj *VirtRes) Compare(res Res) bool

Compare two resources and return if they are equivalent.

func (*VirtRes) Default

func (obj *VirtRes) Default() Res

Default returns some sensible defaults for this resource.

func (*VirtRes) GetUIDs

func (obj *VirtRes) GetUIDs() []ResUID

GetUIDs includes all params to make a unique identification of this object. Most resources only return one, although some resources can return multiple.

func (*VirtRes) GroupCmp

func (obj *VirtRes) GroupCmp(r Res) bool

GroupCmp returns whether two resources can be grouped together or not.

func (*VirtRes) Init

func (obj *VirtRes) Init() error

Init runs some startup code for this resource.

func (*VirtRes) UnmarshalYAML

func (obj *VirtRes) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is the custom unmarshal handler for this struct. It is primarily useful for setting the defaults.

func (*VirtRes) Validate

func (obj *VirtRes) Validate() error

Validate if the params passed in are valid data.

func (*VirtRes) Watch

func (obj *VirtRes) Watch(processChan chan *event.Event) error

Watch is the primary listener for this resource and it outputs events.

type VirtUID

type VirtUID struct {
	BaseUID
}

VirtUID is the UID struct for FileRes.

Directories

Path Synopsis
Package packagekit provides an interface to interact with packagekit.
Package packagekit provides an interface to interact with packagekit.

Jump to

Keyboard shortcuts

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