Documentation ¶
Overview ¶
Package resources provides the resource framework and idempotent primitives.
Index ¶
- func ResToB64(res Res) (string, error)
- func ReturnSvcInFileList(fileList []string) []string
- func UIDExistsInUIDs(uid ResUID, uids []ResUID) bool
- type AutoEdge
- type Base
- type BaseRes
- func (obj *BaseRes) AssociateData(converger converger.Converger)
- func (obj *BaseRes) CollectPattern(pattern string)
- func (obj *BaseRes) Compare(res Res) bool
- func (obj *BaseRes) DoSend(processChan chan event.Event, comment string) (bool, error)
- func (obj *BaseRes) Events() chan event.Event
- func (obj *BaseRes) GetGroup() []Res
- func (obj *BaseRes) GetName() string
- func (obj *BaseRes) GetState() ResState
- func (obj *BaseRes) GroupCmp(res Res) bool
- func (obj *BaseRes) GroupRes(res Res) error
- func (obj *BaseRes) Init() error
- func (obj *BaseRes) IsGrouped() bool
- func (obj *BaseRes) IsWatching() bool
- func (obj *BaseRes) Kind() string
- func (obj *BaseRes) Meta() *MetaParams
- func (obj *BaseRes) ReadEvent(ev *event.Event) (exit, poke bool)
- func (obj *BaseRes) SendEvent(ev event.EventName, sync bool, activity bool) bool
- func (obj *BaseRes) SetGroup(g []Res)
- func (obj *BaseRes) SetGrouped(b bool)
- func (obj *BaseRes) SetKind(kind string)
- func (obj *BaseRes) SetName(name string)
- func (obj *BaseRes) SetState(state ResState)
- func (obj *BaseRes) SetWatching(b bool)
- type BaseUID
- type ExecRes
- func (obj *ExecRes) AutoEdges() AutoEdge
- func (obj *ExecRes) BufioChanScanner(scanner *bufio.Scanner) (chan string, chan error)
- func (obj *ExecRes) CheckApply(apply bool) (checkok bool, err error)
- func (obj *ExecRes) Compare(res Res) bool
- func (obj *ExecRes) GetUIDs() []ResUID
- func (obj *ExecRes) GroupCmp(r Res) bool
- func (obj *ExecRes) Init() error
- func (obj *ExecRes) Validate() error
- func (obj *ExecRes) Watch(processChan chan event.Event) error
- type ExecUID
- type FileInfo
- type FileRes
- func (obj *FileRes) AutoEdges() AutoEdge
- func (obj *FileRes) CheckApply(apply bool) (checkOK bool, _ error)
- func (obj *FileRes) CollectPattern(pattern string)
- func (obj *FileRes) Compare(res Res) bool
- func (obj *FileRes) GetPath() string
- func (obj *FileRes) GetUIDs() []ResUID
- func (obj *FileRes) GroupCmp(r Res) bool
- func (obj *FileRes) Init() error
- func (obj *FileRes) Validate() error
- func (obj *FileRes) Watch(processChan chan event.Event) error
- type FileResAutoEdges
- type FileUID
- type MetaParams
- type MsgRes
- func (obj *MsgRes) AutoEdges() AutoEdge
- func (obj *MsgRes) CheckApply(apply bool) (bool, error)
- func (obj *MsgRes) Compare(res Res) bool
- func (obj *MsgRes) GetUIDs() []ResUID
- func (obj *MsgRes) Init() error
- func (obj *MsgRes) Validate() error
- func (obj *MsgRes) Watch(processChan chan event.Event) error
- type MsgUID
- type NoopRes
- func (obj *NoopRes) AutoEdges() AutoEdge
- func (obj *NoopRes) CheckApply(apply bool) (checkok bool, err error)
- func (obj *NoopRes) Compare(res Res) bool
- func (obj *NoopRes) GetUIDs() []ResUID
- func (obj *NoopRes) GroupCmp(r Res) bool
- func (obj *NoopRes) Init() error
- func (obj *NoopRes) Validate() error
- func (obj *NoopRes) Watch(processChan chan event.Event) error
- type NoopUID
- type PkgRes
- func (obj *PkgRes) AutoEdges() AutoEdge
- func (obj *PkgRes) CheckApply(apply bool) (checkok bool, err error)
- func (obj *PkgRes) Compare(res Res) bool
- func (obj *PkgRes) GetUIDs() []ResUID
- func (obj *PkgRes) GroupCmp(r Res) bool
- func (obj *PkgRes) Init() error
- func (obj *PkgRes) Validate() error
- func (obj *PkgRes) Watch(processChan chan event.Event) error
- type PkgResAutoEdges
- type PkgUID
- type Res
- type ResState
- type ResUID
- type SvcRes
- func (obj *SvcRes) AutoEdges() AutoEdge
- func (obj *SvcRes) CheckApply(apply bool) (checkok bool, err error)
- func (obj *SvcRes) Compare(res Res) bool
- func (obj *SvcRes) GetUIDs() []ResUID
- func (obj *SvcRes) GroupCmp(r Res) bool
- func (obj *SvcRes) Init() error
- func (obj *SvcRes) Validate() error
- func (obj *SvcRes) Watch(processChan chan event.Event) error
- type SvcResAutoEdges
- type SvcUID
- type TimerRes
- func (obj *TimerRes) AutoEdges() AutoEdge
- func (obj *TimerRes) CheckApply(apply bool) (bool, error)
- func (obj *TimerRes) Compare(res Res) bool
- func (obj *TimerRes) GetUIDs() []ResUID
- func (obj *TimerRes) Init() error
- func (obj *TimerRes) Validate() error
- func (obj *TimerRes) Watch(processChan chan event.Event) error
- type TimerUID
- type VirtRes
- func (obj *VirtRes) AutoEdges() AutoEdge
- func (obj *VirtRes) CheckApply(apply bool) (bool, error)
- func (obj *VirtRes) CollectPattern(string)
- func (obj *VirtRes) Compare(res Res) bool
- func (obj *VirtRes) GetUIDs() []ResUID
- func (obj *VirtRes) GroupCmp(r Res) bool
- func (obj *VirtRes) Init() error
- func (obj *VirtRes) Validate() error
- func (obj *VirtRes) Watch(processChan chan event.Event) error
- type VirtUID
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReturnSvcInFileList ¶
ReturnSvcInFileList returns a list of svc names for matches like: `/usr/lib/systemd/system/*.service`.
func UIDExistsInUIDs ¶
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(converger.Converger) IsWatching() bool SetWatching(bool) GetState() ResState SetState(ResState) DoSend(chan event.Event, string) (bool, error) SendEvent(event.EventName, bool, bool) bool ReadEvent(*event.Event) (bool, bool) // TODO: optional here? 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) }
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 // contains filtered or unexported fields }
BaseRes is the base struct that gets used in every resource.
func (*BaseRes) AssociateData ¶
AssociateData associates some data with the object in question.
func (*BaseRes) CollectPattern ¶
CollectPattern is used for resource collection.
func (*BaseRes) DoSend ¶
DoSend sends off an event, but doesn't block the incoming event queue. It can also recursively call itself when events need processing during the wait. I'm not completely comfortable with this fn, but it will have to do for now.
func (*BaseRes) GroupCmp ¶
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) Init ¶
Init initializes structures like channels if created without New constructor.
func (*BaseRes) IsWatching ¶
IsWatching tells us if the Watch() function is running.
func (*BaseRes) Meta ¶
func (obj *BaseRes) Meta() *MetaParams
Meta returns the MetaParams as a reference, which we can then get/set on.
func (*BaseRes) ReadEvent ¶
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) SendEvent ¶
SendEvent pushes an event into the message queue for a particular vertex
func (*BaseRes) SetGrouped ¶
SetGrouped sets a flag to tell if we are grouped.
func (*BaseRes) SetWatching ¶
SetWatching stores the status of if the Watch() function is running.
type BaseUID ¶
type BaseUID struct {
// contains filtered or unexported fields
}
The BaseUID struct is used to provide a unique resource identifier.
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
NewExecRes is a constructor for this resource. It also calls Init() for you.
func (*ExecRes) AutoEdges ¶
AutoEdges returns the AutoEdge interface. In this case no autoedges are used.
func (*ExecRes) BufioChanScanner ¶
BufioChanScanner wraps the scanner output in a channel.
func (*ExecRes) CheckApply ¶
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) GetUIDs ¶
GetUIDs includes all params to make a unique identification of this object. Most resources only return one, although some resources can return multiple.
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.
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"` // FIXME: how do you describe: "leave content alone" - state = "create" ? 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, content, source, state string, recurse, force bool) *FileRes
NewFileRes is a constructor for this resource. It also calls Init() for you.
func (*FileRes) AutoEdges ¶
AutoEdges generates a simple linear sequence of each parent directory from the bottom up!
func (*FileRes) CheckApply ¶
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 ¶
CollectPattern applies the pattern for collection resources.
func (*FileRes) GetPath ¶
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 ¶
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) Watch ¶
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.
type MetaParams ¶
type MetaParams struct { AutoEdge bool `yaml:"autoedge"` // metaparam, should we generate auto edges? // XXX: should default to true AutoGroup bool `yaml:"autogroup"` // metaparam, should we auto group? // XXX: should default to true 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 }
MetaParams is a struct will all params that apply to every resource.
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 (*MsgRes) CheckApply ¶
CheckApply method for Msg resource. Every check leads to an apply, meaning that the message is flushed to the journal.
func (*MsgRes) GetUIDs ¶
GetUIDs includes all params to make a unique identification of this object. Most resources only return one, although some resources can return multiple.
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 ¶
NewNoopRes is a constructor for this resource. It also calls Init() for you.
func (*NoopRes) AutoEdges ¶
AutoEdges returns the AutoEdge interface. In this case no autoedges are used.
func (*NoopRes) CheckApply ¶
CheckApply method for Noop resource. Does nothing, returns happy!
func (*NoopRes) GetUIDs ¶
GetUIDs includes all params to make a unique identification of this object. Most resources only return one, although some resources can return multiple.
type NoopUID ¶
type NoopUID struct { BaseUID // contains filtered or unexported fields }
NoopUID is the UID struct for NoopRes.
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 (*PkgRes) AutoEdges ¶
AutoEdges produces an object which generates a minimal pkg file optimization sequence of edges.
func (*PkgRes) CheckApply ¶
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) GetUIDs ¶
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 ¶
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) Watch ¶
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.
type Res ¶
type Res interface { Base // include everything from the Base interface Init() error //Validate() error // TODO: this might one day be added 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.
type ResState ¶
type ResState int
The ResState type represents the current activity state of each 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 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 (*SvcRes) AutoEdges ¶
AutoEdges returns the AutoEdge interface. In this case the systemd units.
func (*SvcRes) CheckApply ¶
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) GetUIDs ¶
GetUIDs includes all params to make a unique identification of this object. Most resources only return one, although some resources can return multiple.
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.
type TimerRes ¶
type TimerRes struct { BaseRes `yaml:",inline"` Interval int `yaml:"interval"` // Interval : Interval between runs }
TimerRes is a timer resource for time based events.
func NewTimerRes ¶
NewTimerRes is a constructor for this resource. It also calls Init() for you.
func (*TimerRes) AutoEdges ¶
AutoEdges returns the AutoEdge interface. In this case no autoedges are used.
func (*TimerRes) CheckApply ¶
CheckApply method for Timer resource. Does nothing, returns happy!
func (*TimerRes) GetUIDs ¶
GetUIDs includes all params to make a unique identification of this object. Most resources only return one, although some resources can return multiple.
type TimerUID ¶
type TimerUID struct { BaseUID // contains filtered or unexported fields }
TimerUID is the UID struct for TimerRes.
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 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"` // 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 ¶
NewVirtRes is a constructor for this resource. It also calls Init() for you.
func (*VirtRes) AutoEdges ¶
AutoEdges returns the AutoEdge interface. In this case no autoedges are used.
func (*VirtRes) CheckApply ¶
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 ¶
CollectPattern applies the pattern for collection resources.
func (*VirtRes) GetUIDs ¶
GetUIDs includes all params to make a unique identification of this object. Most resources only return one, although some resources can return multiple.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package packagekit provides an interface to interact with packagekit.
|
Package packagekit provides an interface to interact with packagekit. |