resources

package
v0.0.0-...-f33f84d Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2018 License: GPL-3.0 Imports: 65 Imported by: 0

Documentation

Overview

Package resources provides the resource framework and idempotent primitives.

Index

Constants

View Source
const (
	// AwsPrefix is a const which gets prepended onto object names. We can only use
	// alphanumeric chars, underscores and hyphens for sns topics and cloud watch rules.
	AwsPrefix = "_mgmt-"
	// Ec2Prefix is added to the names of sns and cloudwatch objects.
	Ec2Prefix = AwsPrefix + "ec2-"
	// SnsPrefix gets prepended onto the sns topic.
	SnsPrefix = Ec2Prefix + "sns-"
	// SnsTopicName is the name of the sns topic created by snsMakeTopic.
	SnsTopicName = SnsPrefix + "events"
	// SnsSubscriptionProto is used to tell sns that the subscriber uses the http protocol.
	// TODO: add https support
	SnsSubscriptionProto = "http"
	// SnsServerShutdownTimeout is the maximum number of seconds to wait for the http server to shutdown gracefully.
	SnsServerShutdownTimeout = 30
	// SnsPolicy is the topic attribute that defines the security policy for the topic.
	SnsPolicy = "Policy"
	// SnsPolicySid is the friendly name of the policy statement.
	SnsPolicySid = CwePrefix + "publish"
	// SnsPolicyEffect allows the action(s) defined in the policy statement.
	SnsPolicyEffect = "Allow"
	// SnsPolicyService is the cloudwatch events security principal that we are granting the permission to.
	SnsPolicyService = "events.amazonaws.com"
	// SnsPolicyAction is the specific permission we are granting in the policy.
	SnsPolicyAction = "SNS:Publish"
	// SnsCertURLRegex is used to make sure we only download certificates
	// from amazon. This regex will match "https://sns.***.amazonaws.com/"
	// where *** represents any combination of words and hyphens, and will
	// match any aws region name, eg: ca-central-1.
	SnsCertURLRegex = `(^https:\/\/sns\.([\w\-])+\.amazonaws.com\/)`
	// CwePrefix gets prepended onto the cloudwatch rule name.
	CwePrefix = Ec2Prefix + "cw-"
	// CweRuleName is the name of the rule created by makeCloudWatchRule.
	CweRuleName = CwePrefix + "state"
	// CweRuleSource describes the resource type to monitor for cloudwatch events.
	CweRuleSource = "aws.ec2"
	// CweRuleDetailType describes the specific type of events to trigger cloudwatch.
	CweRuleDetailType = "EC2 Instance State-change Notification"
	// CweTargetID is used to tell cloudwatch events to target the sns service.
	CweTargetID = "sns"
	// CweTargetJSON is the json field that cloudwatch will send to our endpoint so we don't get more than we need.
	CweTargetJSON = "$.detail"
	// AwsErrExceededWaitAttempts is the awserr.Message() that gets sent with
	// the ResourceStateNotReady awserr.Code() when the waiters time out.
	AwsErrExceededWaitAttempts = "exceeded wait attempts"
	// AwsErrIncorrectInstanceState is the error returned when an action
	// cannot be completed due to the current instance state.
	AwsErrIncorrectInstanceState = "IncorrectInstanceState"
)
View Source
const (
	// DefaultMaxCPUs is the default number of possible cpu "slots" used.
	DefaultMaxCPUs = 32

	// MaxShutdownDelayTimeout is the max time we wait for a vm to shutdown.
	MaxShutdownDelayTimeout = 60 * 5 // seconds

	// ShortPollInterval is how often we poll when expecting an event.
	ShortPollInterval = 5 // seconds
)
View Source
const (
	// NS is a namespace for augeas operations
	NS = "Xmgmt"
)
View Source
const SemaSep = ":"

SemaSep is the trailing separator to split the semaphore id from the size.

View Source
const (
	// StructTag is the key we use in struct field names for key mapping.
	StructTag = "lang"
)

Variables

View Source
var AwsRegions = []string{
	"ap-northeast-1",
	"ap-northeast-2",
	"ap-south-1",
	"ap-southeast-1",
	"ap-southeast-2",
	"ca-central-1",
	"cn-north-1",
	"eu-central-1",
	"eu-west-1",
	"eu-west-2",
	"sa-east-1",
	"us-east-1",
	"us-east-2",
	"us-gov-west-1",
	"us-west-1",
	"us-west-2",
}

AwsRegions is a list of all AWS regions generated using ec2.DescribeRegions. cn-north-1 and us-gov-west-1 are not returned, probably due to security. List available at http://docs.aws.amazon.com/general/latest/gr/rande.html

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 AutoEdges

func AutoEdges(g *pgraph.Graph) error

AutoEdges adds the automatic edges to the graph.

func AutoGroup

func AutoGroup(g *pgraph.Graph, ag AutoGrouper)

AutoGroup runs the auto grouping on the graph and prints out log messages.

func GetGID

func GetGID(group string) (int, error)

GetGID returns the GID of a group. It supports a GID or a group name. Caller should first check group is not empty. It will return an error if it can't lookup the GID or group name.

func GetUID

func GetUID(username string) (int, error)

GetUID returns the UID of an user. It supports an UID or an username. Caller should first check user is not empty. It will return an error if it can't lookup the UID or username.

func LangFieldNameToStructFieldName

func LangFieldNameToStructFieldName(kind string) (map[string]string, error)

LangFieldNameToStructFieldName returns the mapping from lang (AST) field names to field name as used in the struct. The logic here is a bit strange; if the resource has struct tags, then it uses those, otherwise it falls back to using the lower case versions of things. It might be clever to combine the two so that tagged fields are used as such, and others are used in lowercase, but this is currently not implemented. TODO: should this behaviour be changed?

func LangFieldNameToStructType

func LangFieldNameToStructType(kind string) (map[string]*types.Type, error)

LangFieldNameToStructType returns the mapping from lang (AST) field names, and the expected type in our type system for each.

func LowerStructFieldNameToFieldName

func LowerStructFieldNameToFieldName(res Res) (map[string]string, error)

LowerStructFieldNameToFieldName returns a mapping from the lower case version of each field name to the actual field name. It only returns public fields. It returns an error if it finds a collision.

func RegisterResource

func RegisterResource(kind string, fn func() Res)

RegisterResource registers a new resource by providing a constructor function that returns a resource object ready to be unmarshalled from YAML.

func RegisteredResourcesNames

func RegisteredResourcesNames() []string

RegisteredResourcesNames returns the kind of the registered resources.

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 SemaSize

func SemaSize(id string) int

SemaSize returns the size integer associated with the semaphore id. It defaults to 1 if not found.

func StructKindToFieldNameTypeMap

func StructKindToFieldNameTypeMap(kind string) (map[string]*types.Type, error)

StructKindToFieldNameTypeMap returns a map from field name to expected type in the lang type system.

func StructTagToFieldName

func StructTagToFieldName(res Res) (map[string]string, error)

StructTagToFieldName returns a mapping from recommended alias to actual field name. It returns an error if it finds a collision. It uses the `lang` tags.

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.

func VertexMerge

func VertexMerge(g *pgraph.Graph, v1, v2 pgraph.Vertex, vertexMergeFn func(pgraph.Vertex, pgraph.Vertex) (pgraph.Vertex, error), edgeMergeFn func(pgraph.Edge, pgraph.Edge) pgraph.Edge) error

VertexMerge merges v2 into v1 by reattaching the edges where appropriate, and then by deleting v2 from the graph. Since more than one edge between two vertices is not allowed, duplicate edges are merged as well. an edge merge function can be provided if you'd like to control how you merge the edges!

Types

type AugeasRes

type AugeasRes struct {
	BaseRes `yaml:",inline"`

	// File is the path to the file targeted by this resource.
	File string `yaml:"file"`

	// Lens is the lens used by this resource. If specified, mgmt
	// will lower the augeas overhead by only loading that lens.
	Lens string `yaml:"lens"`

	// Sets is a list of changes that will be applied to the file, in the form of
	// ["path", "value"]. mgmt will run augeas.Get() before augeas.Set(), to
	// prevent changing the file when it is not needed.
	Sets []AugeasSet `yaml:"sets"`
	// contains filtered or unexported fields
}

AugeasRes is a resource that enables you to use the augeas resource. Currently only allows you to change simple files (e.g sshd_config).

func (*AugeasRes) CheckApply

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

CheckApply method for Augeas resource.

func (*AugeasRes) Compare

func (obj *AugeasRes) Compare(r Res) bool

Compare two resources and return if they are equivalent.

func (*AugeasRes) Default

func (obj *AugeasRes) Default() Res

Default returns some sensible defaults for this resource.

func (*AugeasRes) GroupCmp

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

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

func (*AugeasRes) Init

func (obj *AugeasRes) Init() error

Init initiates the resource.

func (*AugeasRes) UIDs

func (obj *AugeasRes) UIDs() []ResUID

UIDs includes all params to make a unique identification of this object.

func (*AugeasRes) UnmarshalYAML

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

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

func (*AugeasRes) Validate

func (obj *AugeasRes) Validate() error

Validate if the params passed in are valid data.

func (*AugeasRes) Watch

func (obj *AugeasRes) Watch() error

Watch is the primary listener for this resource and it outputs events. Taken from the File resource. FIXME: DRY - This is taken from the file resource

type AugeasSet

type AugeasSet struct {
	Path  string `yaml:"path"`  // The relative path to the value to be changed.
	Value string `yaml:"value"` // The value to be set on the given Path.
}

AugeasSet represents a key/value pair of settings to be applied.

type AugeasUID

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

AugeasUID is the UID struct for AugeasRes.

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 AutoGrouper

type AutoGrouper interface {
	// contains filtered or unexported methods
}

AutoGrouper is the required interface to implement for an autogroup algorithm.

type AwsEc2Res

type AwsEc2Res struct {
	BaseRes `yaml:",inline"`
	State   string `yaml:"state"`   // state: running, stopped, terminated
	Region  string `yaml:"region"`  // region must match an element of AwsRegions
	Type    string `yaml:"type"`    // type of ec2 instance, eg: t2.micro
	ImageID string `yaml:"imageid"` // imageid must be available on the chosen region

	WatchEndpoint   string `yaml:"watchendpoint"`   // the public url of the sns endpoint, eg: http://server:12345/
	WatchListenAddr string `yaml:"watchlistenaddr"` // the local address or port that the sns listens on, eg: 10.0.0.0:23456 or 23456
	// ErrorOnMalformedPost controls whether or not malformed HTTP post
	// requests, that cause JSON decoder errors, will also make the engine
	// shut down. If ErrorOnMalformedPost set to true and an error occurs,
	// Watch() will return the error and the engine will shut down.
	ErrorOnMalformedPost bool `yaml:"erroronmalformedpost"`

	// UserData is used to run bash and cloud-init commands on first launch.
	// See http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html
	// for documantation and examples.
	UserData string `yaml:"userdata"`

	// store read-only values for send/recv.
	PublicIPv4  string
	PrivateIPv4 string
	InstanceID  string
	// contains filtered or unexported fields
}

AwsEc2Res is an AWS EC2 resource. In order to create a client session, your AWS credentials must be present in ~/.aws - For detailed instructions see http://docs.aws.amazon.com/cli/latest/userguide/cli-config-files.html

func (*AwsEc2Res) CheckApply

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

CheckApply method for AwsEc2 resource.

func (*AwsEc2Res) Close

func (obj *AwsEc2Res) Close() error

Close cleans up when we're done. This is needed to delete some of the AWS objects created for the SNS endpoint.

func (*AwsEc2Res) Compare

func (obj *AwsEc2Res) Compare(r Res) bool

Compare two resources and return if they are equivalent.

func (*AwsEc2Res) Default

func (obj *AwsEc2Res) Default() Res

Default returns some sensible defaults for this resource.

func (*AwsEc2Res) GroupCmp

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

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

func (*AwsEc2Res) Init

func (obj *AwsEc2Res) Init() error

Init initializes the resource.

func (*AwsEc2Res) UIDs

func (obj *AwsEc2Res) UIDs() []ResUID

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

func (*AwsEc2Res) UnmarshalYAML

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

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

func (*AwsEc2Res) Validate

func (obj *AwsEc2Res) Validate() error

Validate if the params passed in are valid data.

func (*AwsEc2Res) Watch

func (obj *AwsEc2Res) Watch() error

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

type AwsEc2UID

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

AwsEc2UID is the UID struct for AwsEc2Res.

type Base

type Base interface {
	fmt.Stringer // String() string

	GetName() string // can't be named "Name()" because of struct field
	SetName(string)
	SetKind(string)
	GetKind() string

	Meta() *MetaParams
	Events() chan *event.Event
	Data() *ResData
	Working() *bool
	Setup(*MGraph, pgraph.Vertex, Res)
	Reset()
	Exit()
	GetState() ResState
	SetState(ResState)
	Timestamp() int64
	UpdateTimestamp() int64
	Event() error
	SendEvent(event.Kind, 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
	SetRecv(map[string]*Send)
	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() error           // notify the engine that Watch started
	Started() <-chan struct{} // returns when the resource has started
	Stopped() <-chan struct{} // returns when the resource has stopped
	Starter(bool)
	Poll() error // poll alternative to watching :(
	Worker() error
}

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 {
	Res    Res           // pointer to full res
	Graph  *MGraph       // pointer to graph I'm currently in
	Vertex pgraph.Vertex // pointer to vertex I currently am

	Recv       map[string]*Send // mapping of key to receive on from value
	Kind       string
	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) AutoEdges

func (obj *BaseRes) AutoEdges() (AutoEdge, error)

AutoEdges returns the AutoEdge interface. By default, none are created. This should be implemented by the specific resource to be used. This base method does not need to be called by the resource specific implementing method.

func (*BaseRes) BackPoke

func (obj *BaseRes) BackPoke()

BackPoke pokes the pre-requisites that are stale and need to run before I can run.

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) Data

func (obj *BaseRes) Data() *ResData

Data returns an associable handle to some data passed in to the resource.

func (*BaseRes) Event

func (obj *BaseRes) 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) Exit

func (obj *BaseRes) Exit()

Exit the resource. Wrapper function to keep the logic in one place for now.

func (*BaseRes) GetGroup

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

GetGroup returns everyone grouped inside me.

func (*BaseRes) GetKind

func (obj *BaseRes) GetKind() string

GetKind returns the kind of resource this is.

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) Meta

func (obj *BaseRes) Meta() *MetaParams

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

func (*BaseRes) OKTimestamp

func (obj *BaseRes) OKTimestamp() bool

OKTimestamp returns true if this element can run right now?

func (*BaseRes) Poke

func (obj *BaseRes) Poke() error

Poke tells nodes after me in the dependency graph that they need to refresh.

func (*BaseRes) Poll

func (obj *BaseRes) Poll() error

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

func (*BaseRes) Process

func (obj *BaseRes) Process() error

Process is the primary function to execute for a particular vertex in the graph.

func (*BaseRes) ProcessExit

func (obj *BaseRes) ProcessExit()

ProcessExit causes the innerWorker to close and waits until it does so.

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) RefreshPending

func (obj *BaseRes) RefreshPending() bool

RefreshPending determines if any previous nodes have a refresh pending here. If this is true, it means I am expected to apply a refresh when I next run.

func (*BaseRes) Reset

func (obj *BaseRes) Reset()

Reset from Setup. These can get called for different vertices in parallel.

func (*BaseRes) Running

func (obj *BaseRes) Running() 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.Kind, 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) SetDownstreamRefresh

func (obj *BaseRes) SetDownstreamRefresh(b bool)

SetDownstreamRefresh sets the refresh value to any downstream vertices.

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) SetRecv

func (obj *BaseRes) SetRecv(recv map[string]*Send)

SetRecv sets the Res Recv field to given map of Send structs.

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) SetUpstreamRefresh

func (obj *BaseRes) SetUpstreamRefresh(b bool)

SetUpstreamRefresh sets the refresh value to any upstream vertices.

func (*BaseRes) Setup

func (obj *BaseRes) Setup(mgraph *MGraph, vertex pgraph.Vertex, res Res)

Setup does some work which must happen before the Worker starts. It happens once per Worker startup. It can happen in parallel with other Setup calls, so add locks around any operation that's not thread-safe.

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) Stopped

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

Stopped returns a channel that closes when the worker has finished running.

func (*BaseRes) String

func (obj *BaseRes) String() string

String returns the canonical string representation for a resource.

func (*BaseRes) Timestamp

func (obj *BaseRes) Timestamp() int64

Timestamp returns the timestamp of a resource.

func (*BaseRes) UpdateTimestamp

func (obj *BaseRes) UpdateTimestamp() int64

UpdateTimestamp updates the timestamp and returns the new value.

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.

func (*BaseRes) Worker

func (obj *BaseRes) Worker() error

Worker is the common run frontend of the vertex. It handles all of the retry and retry delay common code, and ultimately returns the final status of this vertex execution.

func (*BaseRes) Working

func (obj *BaseRes) Working() *bool

Working returns a pointer to the bool which should track Worker run state.

type BaseUID

type BaseUID struct {
	Name string // name and kind are the values of where this is coming from
	Kind string

	Reversed *bool // piggyback edge information here
}

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

func (*BaseUID) GetKind

func (obj *BaseUID) GetKind() string

GetKind returns the kind of the resource UID.

func (*BaseUID) GetName

func (obj *BaseUID) GetName() string

GetName returns the name of the resource UID.

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) IsReversed

func (obj *BaseUID) IsReversed() bool

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

func (*BaseUID) String

func (obj *BaseUID) String() string

String returns the canonical string representation for a resource UID.

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 Edge

type Edge struct {
	Name   string
	Notify bool // should we send a refresh notification along this edge?
	// contains filtered or unexported fields
}

Edge is a struct that represents a graph's edge.

func (*Edge) Compare

func (obj *Edge) Compare(edge *Edge) bool

Compare returns true if two edges are equivalent. Otherwise it returns false.

func (*Edge) Refresh

func (obj *Edge) Refresh() bool

Refresh returns the pending refresh status of this edge.

func (*Edge) SetRefresh

func (obj *Edge) SetRefresh(b bool)

SetRefresh sets the pending refresh status of this edge.

func (*Edge) String

func (obj *Edge) String() string

String is a required method of the Edge interface that we must fulfill.

type ExecRes

type ExecRes struct {
	BaseRes    `yaml:",inline"`
	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
	User       string  `yaml:"user"`       // the (optional) user to use to execute the command
	Group      string  `yaml:"group"`      // the (optional) group to use to execute the command
	Output     *string // all cmd output, read only, do not set!
	Stdout     *string // the cmd stdout, read only, do not set!
	Stderr     *string // the cmd stderr, read only, do not set!
}

ExecRes is an exec resource for running commands.

func (*ExecRes) AutoEdges

func (obj *ExecRes) AutoEdges() (AutoEdge, error)

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

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) (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. TODO: expand the IfCmd to be a list of commands

func (*ExecRes) Compare

func (obj *ExecRes) Compare(r 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) 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) UIDs

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

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

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() error

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

type ExecResAutoEdges

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

ExecResAutoEdges holds the state of the auto edge generator.

func (*ExecResAutoEdges) Next

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

Next returns the next automatic edge.

func (*ExecResAutoEdges) Test

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

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

type ExecUID

type ExecUID struct {
	BaseUID
	Cmd   string
	IfCmd string
}

ExecUID is the UID struct for ExecRes.

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 (usually defaults to name)
	Dirname  string  `yaml:"dirname"`  // override the path dirname
	Basename string  `yaml:"basename"` // override the path 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?)
	Owner    string  `yaml:"owner"`
	Group    string  `yaml:"group"`
	Mode     string  `yaml:"mode"`
	Recurse  bool    `yaml:"recurse"`
	Force    bool    `yaml:"force"`
	// contains filtered or unexported fields
}

FileRes is a file and directory resource. Dirs are defined by names ending in a slash.

func (*FileRes) AutoEdges

func (obj *FileRes) AutoEdges() (AutoEdge, error)

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(r 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) 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) UIDs

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

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

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() 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 Fs

type Fs interface {
	//fmt.Stringer // TODO: add this method?
	afero.Fs     // TODO: why doesn't this interface exist in the os pkg?
	URI() string // returns the URI for this file system

	//DirExists(path string) (bool, error)
	//Exists(path string) (bool, error)
	//FileContainsAnyBytes(filename string, subslices [][]byte) (bool, error)
	//FileContainsBytes(filename string, subslice []byte) (bool, error)
	//FullBaseFsPath(basePathFs *BasePathFs, relativePath string) string
	//GetTempDir(subPath string) string
	//IsDir(path string) (bool, error)
	//IsEmpty(path string) (bool, error)
	//NeuterAccents(s string) string
	//ReadAll(r io.Reader) ([]byte, error) // not needed
	ReadDir(dirname string) ([]os.FileInfo, error)
	ReadFile(filename string) ([]byte, error)
	//SafeWriteReader(path string, r io.Reader) (err error)
	TempDir(dir, prefix string) (name string, err error)
	TempFile(dir, prefix string) (f afero.File, err error) // slightly different from upstream
	//UnicodeSanitize(s string) string
	//Walk(root string, walkFn filepath.WalkFunc) error
	WriteFile(filename string, data []byte, perm os.FileMode) error
}

Fs is an interface that represents this file system API that we support. TODO: this should be in the gapi package or elsewhere.

type GraphRes

type GraphRes struct {
	BaseRes `yaml:",inline"`
	Graph   *pgraph.Graph `yaml:"graph"` // TODO: how do we suck in a graph via yaml?
	// contains filtered or unexported fields
}

GraphRes is a resource that recursively runs a sub graph of resources. TODO: should we name this SubGraphRes instead? TODO: we could also flatten "sub graphs" into the main graph to avoid this, and this could even be done with a graph transformation called flatten, similar to where autogroup and autoedges run. XXX: this resource is not complete, and hasn't even been tested

func (*GraphRes) CheckApply

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

CheckApply method for Graph resource. XXX: not implemented

func (*GraphRes) Close

func (obj *GraphRes) Close() error

Close runs some cleanup code for this resource.

func (*GraphRes) Compare

func (obj *GraphRes) Compare(r Res) bool

Compare two resources and return if they are equivalent.

func (*GraphRes) Default

func (obj *GraphRes) Default() Res

Default returns some sensible defaults for this resource.

func (*GraphRes) Init

func (obj *GraphRes) Init() error

Init runs some startup code for this resource.

func (*GraphRes) UIDs

func (obj *GraphRes) UIDs() []ResUID

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

func (*GraphRes) UnmarshalYAML

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

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

func (*GraphRes) Validate

func (obj *GraphRes) Validate() error

Validate the params and sub resources that are passed to GraphRes.

func (*GraphRes) Watch

func (obj *GraphRes) Watch() error

Watch is the primary listener for this resource and it outputs events. XXX: should this use mgraph.Start/Pause? if so then what does CheckApply do? XXX: we should probably refactor the core engine to make this work, which will hopefully lead us to a more elegant core that is easier to understand

type GraphUID

type GraphUID struct {
	BaseUID
}

GraphUID is a unique representation for a GraphRes object.

type GroupRes

type GroupRes struct {
	BaseRes `yaml:",inline"`
	State   string  `yaml:"state"` // state: exists, absent
	GID     *uint32 `yaml:"gid"`   // the group's gid
	// contains filtered or unexported fields
}

GroupRes is a user group resource.

func (*GroupRes) CheckApply

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

CheckApply method for Group resource.

func (*GroupRes) Compare

func (obj *GroupRes) Compare(r Res) bool

Compare two resources and return if they are equivalent.

func (*GroupRes) Default

func (obj *GroupRes) Default() Res

Default returns some sensible defaults for this resource.

func (*GroupRes) GroupCmp

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

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

func (*GroupRes) Init

func (obj *GroupRes) Init() error

Init initializes the resource.

func (*GroupRes) UIDs

func (obj *GroupRes) UIDs() []ResUID

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

func (*GroupRes) UnmarshalYAML

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

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

func (*GroupRes) Validate

func (obj *GroupRes) Validate() error

Validate if the params passed in are valid data.

func (*GroupRes) Watch

func (obj *GroupRes) Watch() error

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

type GroupUID

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

GroupUID is the UID struct for GroupRes.

func (*GroupUID) IFF

func (obj *GroupUID) 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 (*HostnameRes) CheckApply

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

CheckApply method for Hostname resource.

func (*HostnameRes) Compare

func (obj *HostnameRes) Compare(r 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) 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) UIDs

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

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

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() 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 KVRes

type KVRes struct {
	BaseRes `yaml:",inline"`
	// XXX: shouldn't the name be the key?
	Key          string            `yaml:"key"`          // key to set
	Value        *string           `yaml:"value"`        // value to set (nil to delete)
	SkipLessThan bool              `yaml:"skiplessthan"` // skip updates as long as stored value is greater
	SkipCmpStyle KVResSkipCmpStyle `yaml:"skipcmpstyle"` // how to do the less than cmp

}

KVRes is a resource which writes a key/value pair into cluster wide storage. It will ensure that the key is set to the requested value. The one exception is that if you use the SkipLessThan parameter, then it will only replace the stored value with the requested value if it is greater than that stored one. This allows the KV resource to be used in fast acting, finite state machines which have monotonically increasing state values that represent progression. The one exception is that when this resource receives a refresh signal, then it will set the value to be the exact one if they are not identical already.

func (*KVRes) CheckApply

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

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

func (*KVRes) Compare

func (obj *KVRes) Compare(r Res) bool

Compare two resources and return if they are equivalent.

func (*KVRes) Default

func (obj *KVRes) Default() Res

Default returns some sensible defaults for this resource.

func (*KVRes) GroupCmp

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

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

func (*KVRes) Init

func (obj *KVRes) Init() error

Init initializes the resource.

func (*KVRes) UIDs

func (obj *KVRes) UIDs() []ResUID

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

func (*KVRes) UnmarshalYAML

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

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

func (*KVRes) Validate

func (obj *KVRes) Validate() error

Validate if the params passed in are valid data. FIXME: This will catch most issues unless data is passed in after Init with the Send/Recv mechanism. Should the engine re-call Validate after Send/Recv?

func (*KVRes) Watch

func (obj *KVRes) Watch() error

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

type KVResSkipCmpStyle

type KVResSkipCmpStyle int

KVResSkipCmpStyle represents the different styles of comparison when using SkipLessThan.

const (
	SkipCmpStyleInt KVResSkipCmpStyle = iota
	SkipCmpStyleString
)

These are the different allowed comparison styles. Most folks will want SkipCmpStyleInt.

type KVUID

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

KVUID is the UID struct for KVRes.

type MGraph

type MGraph struct {
	//Graph *pgraph.Graph
	*pgraph.Graph // wrap a graph, and use its methods directly

	Data      *ResData
	FastPause bool
	Debug     bool
	// contains filtered or unexported fields
}

MGraph is a meta graph structure used to encapsulate a generic graph structure alongside some non-generic elements.

func (*MGraph) Exit

func (obj *MGraph) Exit()

Exit sends exit events to the graph in a topological sort order.

func (*MGraph) Init

func (obj *MGraph) Init()

Init initializes the internal structures.

func (*MGraph) Pause

func (obj *MGraph) Pause(fastPause bool)

Pause sends pause events to the graph in a topological sort order. If you set the fastPause argument to true, then it will ask future propagation waves to not run through the graph before exiting, and instead will exit much quicker.

func (*MGraph) SemaLock

func (obj *MGraph) SemaLock(semas []string) error

SemaLock acquires the list of semaphores in the graph.

func (*MGraph) SemaUnlock

func (obj *MGraph) SemaUnlock(semas []string) error

SemaUnlock releases the list of semaphores in the graph.

func (*MGraph) Start

func (obj *MGraph) Start(first bool)

Start is a main kick to start the graph. It goes through in reverse topological sort order so that events can't hit un-started vertices.

func (*MGraph) Update

func (obj *MGraph) Update(newGraph *pgraph.Graph)

Update switches our graph structure to the new graph that we pass to it. This also updates any references to the old graph so that they're now correct. It also updates references to the Data structure that should be passed around.

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
	Sema  []string   `yaml:"sema"`  // metaparam, list of semaphore ids (id | id:count)
}

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 (*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(r 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) Init

func (obj *MsgRes) Init() error

Init runs some startup code for this resource.

func (*MsgRes) UIDs

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

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

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() 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 NonReachabilityGrouper

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

NonReachabilityGrouper is the most straight-forward algorithm for grouping. TODO: this algorithm may not be correct in all cases. replace if needed!

type NoopRes

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

NoopRes is a no-op resource that does nothing.

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(r 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) 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) UIDs

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

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

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() 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 (*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(r 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) 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) UIDs

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

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

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() 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 (*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(r 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) 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) UIDs

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

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

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() 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 PkgFileUID

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

PkgFileUID is the UID struct for PkgRes files.

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

func (obj *PkgRes) AutoEdges() (AutoEdge, error)

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(r 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) 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) UIDs

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

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

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() 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 main 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 PrintRes

type PrintRes struct {
	BaseRes `lang:"" yaml:",inline"`

	Msg string `lang:"msg" yaml:"msg"` // the message to display
}

PrintRes is a resource that is useful for printing a message to the screen. It will also display a message when it receives a notification. It supports automatic grouping.

func (*PrintRes) CheckApply

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

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

func (*PrintRes) Compare

func (obj *PrintRes) Compare(r Res) bool

Compare two resources and return if they are equivalent.

func (*PrintRes) Default

func (obj *PrintRes) Default() Res

Default returns some sensible defaults for this resource.

func (*PrintRes) GroupCmp

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

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

func (*PrintRes) Init

func (obj *PrintRes) Init() error

Init runs some startup code for this resource.

func (*PrintRes) UIDs

func (obj *PrintRes) UIDs() []ResUID

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

func (*PrintRes) UnmarshalYAML

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

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

func (*PrintRes) Validate

func (obj *PrintRes) Validate() error

Validate if the params passed in are valid data.

func (*PrintRes) Watch

func (obj *PrintRes) Watch() error

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

type PrintUID

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

PrintUID is the UID struct for PrintRes.

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
	UIDs() []ResUID // most resources only return one
	Watch() error   // send on channel to signal process() events
	CheckApply(apply bool) (checkOK bool, err error)
	AutoEdges() (AutoEdge, error)
	Compare(Res) bool      // FIXME: rename to: `Cmp(Res) error`
	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).

func NewNamedResource

func NewNamedResource(kind, name string) (Res, error)

NewNamedResource returns an empty resource object from a registered kind. It also sets the name. It is a wrapper around NewResource. It also errors if the name is empty.

func NewResource

func NewResource(kind string) (Res, error)

NewResource returns an empty resource object from a registered kind. It errors if the resource kind doesn't exist.

func Sort

func Sort(rs []Res) []Res

Sort the list of resources and return a copy without modifying the input.

func VtoR

func VtoR(v pgraph.Vertex) Res

VtoR casts the Vertex into a Res for use. It panics if it can't convert.

type ResData

type ResData struct {
	Hostname string // uuid for the host
	//Noop     bool
	Converger  converger.Converger
	Prometheus *prometheus.Prometheus
	World      World
	Prefix     string // the prefix to be used for the pgraph namespace
	Debug      bool
	Logf       func(format string, v ...interface{})
}

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

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
	GetKind() string
	fmt.Stringer // String() string

	IFF(ResUID) bool

	IsReversed() 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 ResourceSlice

type ResourceSlice []Res

ResourceSlice is a linear list of resources. It can be sorted.

func (ResourceSlice) Len

func (rs ResourceSlice) Len() int

func (ResourceSlice) Less

func (rs ResourceSlice) Less(i, j int) bool

func (ResourceSlice) Swap

func (rs ResourceSlice) Swap(i, j int)

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 SentinelErr

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

SentinelErr is a sentinal as an error type that wraps an arbitrary error.

func (*SentinelErr) Error

func (obj *SentinelErr) Error() string

Error is the required method to fulfill the error type.

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
	Session bool   `yaml:"session"` // user session (true) or system?
}

SvcRes is a service resource for systemd units.

func (*SvcRes) AutoEdges

func (obj *SvcRes) AutoEdges() (AutoEdge, error)

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(r 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) 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) UIDs

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

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

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() 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 TestRes

type TestRes struct {
	BaseRes `lang:"" yaml:",inline"`

	Bool bool   `lang:"bool" yaml:"bool"`
	Str  string `lang:"str" yaml:"str"` // can't name it String because of String()

	Int   int   `lang:"int" yaml:"int"`
	Int8  int8  `lang:"int8" yaml:"int8"`
	Int16 int16 `lang:"int16" yaml:"int16"`
	Int32 int32 `lang:"int32" yaml:"int32"`
	Int64 int64 `lang:"int64" yaml:"int64"`

	Uint   uint   `lang:"uint" yaml:"uint"`
	Uint8  uint8  `lang:"uint8" yaml:"uint8"`
	Uint16 uint16 `lang:"uint16" yaml:"uint16"`
	Uint32 uint32 `lang:"uint32" yaml:"uint32"`
	Uint64 uint64 `lang:"uint64" yaml:"uint64"`

	//Uintptr uintptr `yaml:"uintptr"`
	Byte byte `lang:"byte" yaml:"byte"` // alias for uint8
	Rune rune `lang:"rune" yaml:"rune"` // alias for int32, represents a Unicode code point

	Float32    float32    `lang:"float32" yaml:"float32"`
	Float64    float64    `lang:"float64" yaml:"float64"`
	Complex64  complex64  `lang:"complex64" yaml:"complex64"`
	Complex128 complex128 `lang:"complex128" yaml:"complex128"`

	BoolPtr   *bool   `lang:"boolptr" yaml:"bool_ptr"`
	StringPtr *string `lang:"stringptr" yaml:"string_ptr"` // TODO: tag name?
	Int64Ptr  *int64  `lang:"int64ptr" yaml:"int64ptr"`
	Int8Ptr   *int8   `lang:"int8ptr" yaml:"int8ptr"`
	Uint8Ptr  *uint8  `lang:"uint8ptr" yaml:"uint8ptr"`

	// probably makes no sense, but is legal
	Int8PtrPtrPtr ***int8 `lang:"int8ptrptrptr" yaml:"int8ptrptrptr"`

	SliceString []string          `lang:"slicestring" yaml:"slicestring"`
	MapIntFloat map[int64]float64 `lang:"mapintfloat" yaml:"mapintfloat"`
	MixedStruct struct {
		// contains filtered or unexported fields
	} `lang:"mixedstruct" yaml:"mixedstruct"`
	Interface interface{} `lang:"interface" yaml:"interface"`

	AnotherStr string `lang:"anotherstr" yaml:"anotherstr"`

	ValidateBool  bool   `lang:"validatebool" yaml:"validate_bool"`   // set to true to cause a validate error
	ValidateError string `lang:"validateerror" yaml:"validate_error"` // set to cause a validate error
	AlwaysGroup   bool   `lang:"alwaysgroup" yaml:"always_group"`     // set to true to cause auto grouping
	CompareFail   bool   `lang:"comparefail" yaml:"compare_fail"`     // will compare fail?

	Comment string `lang:"comment" yaml:"comment"`
}

TestRes is a resource that is mostly harmless and is used for internal tests.

func (*TestRes) CheckApply

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

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

func (*TestRes) Compare

func (obj *TestRes) Compare(r Res) bool

Compare two resources and return if they are equivalent.

func (*TestRes) Default

func (obj *TestRes) Default() Res

Default returns some sensible defaults for this resource.

func (*TestRes) GroupCmp

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

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

func (*TestRes) Init

func (obj *TestRes) Init() error

Init runs some startup code for this resource.

func (*TestRes) UIDs

func (obj *TestRes) UIDs() []ResUID

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

func (*TestRes) UnmarshalYAML

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

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

func (*TestRes) Validate

func (obj *TestRes) Validate() error

Validate if the params passed in are valid data.

func (*TestRes) Watch

func (obj *TestRes) Watch() error

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

type TestUID

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

TestUID is the UID struct for TestRes.

type TimerRes

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

TimerRes is a timer resource for time based events. It outputs an event every interval seconds.

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(r 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) Init

func (obj *TimerRes) Init() error

Init runs some startup code for this resource.

func (*TimerRes) UIDs

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

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

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() 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 UserRes

type UserRes struct {
	BaseRes           `yaml:",inline"`
	State             string   `yaml:"state"`             // state: exists, absent
	UID               *uint32  `yaml:"uid"`               // uid must be unique unless AllowDuplicateUID is true
	GID               *uint32  `yaml:"gid"`               // gid of the user's primary group
	Group             *string  `yaml:"group"`             // name of the user's primary group
	Groups            []string `yaml:"groups"`            // list of supplemental groups
	HomeDir           *string  `yaml:"homedir"`           // path to the user's home directory
	AllowDuplicateUID bool     `yaml:"allowduplicateuid"` // allow duplicate uid
	// contains filtered or unexported fields
}

UserRes is a user account resource.

func (*UserRes) AutoEdges

func (obj *UserRes) AutoEdges() (AutoEdge, error)

AutoEdges returns edges from the user resource to each group found in its definition. The groups can be in any of the three applicable fields (GID, Group and Groups.) If the user exists, reversed ensures the edge goes from group to user, and if the user is absent the edge goes from user to group. This ensures that we don't add users to groups that don't exist or delete groups before we delete their members.

func (*UserRes) CheckApply

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

CheckApply method for User resource.

func (*UserRes) Compare

func (obj *UserRes) Compare(r Res) bool

Compare two resources and return if they are equivalent.

func (*UserRes) Default

func (obj *UserRes) Default() Res

Default returns some sensible defaults for this resource.

func (*UserRes) GroupCmp

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

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

func (*UserRes) Init

func (obj *UserRes) Init() error

Init initializes the resource.

func (*UserRes) UIDs

func (obj *UserRes) UIDs() []ResUID

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

func (*UserRes) UnmarshalYAML

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

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

func (*UserRes) Validate

func (obj *UserRes) Validate() error

Validate if the params passed in are valid data.

func (*UserRes) Watch

func (obj *UserRes) Watch() error

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

type UserResAutoEdges

type UserResAutoEdges struct {
	UIDs []ResUID
	// contains filtered or unexported fields
}

UserResAutoEdges holds the state of the auto edge generator.

func (*UserResAutoEdges) Next

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

Next returns the next automatic edge.

func (*UserResAutoEdges) Test

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

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

type UserUID

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

UserUID is the UID struct for UserRes.

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"`
	MaxCPUs    uint               `yaml:"maxcpus"`
	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"`

	HotCPUs bool `yaml:"hotcpus"` // allow hotplug of cpus?
	// FIXME: values here should be enum's!
	RestartOnDiverge string `yaml:"restartondiverge"` // restart policy: "ignore", "ifneeded", "error"
	RestartOnRefresh bool   `yaml:"restartonrefresh"` // restart on refresh?
	// 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 (*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) Close

func (obj *VirtRes) Close() error

Close runs some cleanup code for this resource.

func (*VirtRes) Compare

func (obj *VirtRes) Compare(r 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) 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) UIDs

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

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

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() 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.

type World

type World interface {
	ResWatch() chan error
	ResExport([]Res) error
	// FIXME: should this method take a "filter" data struct instead of many args?
	ResCollect(hostnameFilter, kindFilter []string) ([]Res, error)

	StrWatch(namespace string) chan error
	StrIsNotExist(error) bool
	StrGet(namespace string) (string, error)
	StrSet(namespace, value string) error
	StrDel(namespace string) error

	// XXX: add the exchange primitives in here directly?
	StrMapWatch(namespace string) chan error
	StrMapGet(namespace string) (map[string]string, error)
	StrMapSet(namespace, value string) error
	StrMapDel(namespace string) error

	Scheduler(namespace string, opts ...scheduler.Option) (*scheduler.Result, error)

	Fs(uri string) (Fs, error)
}

World is an interface to the rest of the different graph state. It allows the GAPI to store state and exchange information throughout the cluster. It is the interface each machine uses to communicate with the rest of the world.

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