state

package
v0.0.0-...-9575221 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2016 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

A service represents a running daemonized process on an operating system States -

running: The service is running
stopped: The service is stopped

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	Mode     string   `json:"mode"`   // File should be set to this octal mode
	Path     string   `json:"path"`   // File destination
	Source   string   `json:"source"` // File source
	Metadata Metadata `json:"metadata"`
}

func (*File) Apply

func (file *File) Apply() *Result

func (*File) Meta

func (file *File) Meta() Metadata

func (*File) State

func (file *File) State() *Result

type Metadata

type Metadata struct {
	Name         string   // Unique name to associate with a state
	Type         string   // The type of state "package", "file", etc.
	State        string   // The desired state "installed", "rendered", etc.
	Requirements []string `json:"require"` // List of dependent states.
}

func MetadataFromJSON

func MetadataFromJSON(data json.RawMessage) (Metadata, error)

func (*Metadata) Equal

func (md *Metadata) Equal(metadata *Metadata) bool

type Package

type Package struct {
	Name     string   `json:"name"`
	Version  string   `json:"version"`
	Metadata Metadata `json:"metadata"`
}

func (*Package) Apply

func (pkg *Package) Apply() *Result

func (*Package) GetDpkgPackage

func (pkg *Package) GetDpkgPackage(name string) (string, string, error)

Get the status of a package in DPKG

func (*Package) GetPackageStatus

func (pkg *Package) GetPackageStatus(name string) (string, string, error)

Check to see if a package is installed on the operating system

func (*Package) InstallPackage

func (pkg *Package) InstallPackage(name, version string) error

Install a package on the operating system

func (*Package) Meta

func (pkg *Package) Meta() Metadata

func (*Package) RemovePackage

func (pkg *Package) RemovePackage(name string) error

Remove a package from the operating system

func (*Package) State

func (pkg *Package) State() *Result

type Result

type Result struct {
	Host       string    // The host that produced this Result object
	Consistent bool      // The state is consistent with the operating system
	Metadata   *Metadata // The metadata of the state which returned this result
	Message    string    // A message returned by the state
}

type ResultMap

type ResultMap struct {
	Results map[string][]*Result
	Host    string
}

func NewResultMap

func NewResultMap() *ResultMap

Get a new ResultMap object

func ResultMapFromError

func ResultMapFromError(host string, err error) *ResultMap

Return an array with a single result in state "Faulted", add the error message to the Result.

func ResultMapFromJson

func ResultMapFromJson(data []byte) (*ResultMap, error)

Create a ResultMap from JSON byte array

func (*ResultMap) Add

func (rm *ResultMap) Add(result *Result)

Add a new Result to the ResultMap

func (*ResultMap) Exists

func (rm *ResultMap) Exists(other *Result) bool

Check to see if there is a result for the specified host and metadata

func (*ResultMap) Merge

func (rm *ResultMap) Merge(other *ResultMap)

func (*ResultMap) ToJSON

func (rm *ResultMap) ToJSON() ([]byte, error)

Dump the ResultMap to JSON

type Service

type Service struct {
	Name     string   `json:"name"`
	Running  bool     `json:"running"`
	Metadata Metadata `json:"metadata"`
}

func (*Service) Apply

func (service *Service) Apply() *Result

func (*Service) Meta

func (service *Service) Meta() Metadata

func (*Service) State

func (service *Service) State() *Result

type State

type State interface {
	Apply() *Result // Execute the state if it is not already Consistent
	State() *Result // Check to see if the state is consistent with the operating system's state
	Meta() Metadata // Return the state's metadata ("Name", "Type", and "state")
}

func StateFactory

func StateFactory(metadata Metadata, data []byte) (State, error)

type StateMap

type StateMap struct {
	States []State
}

func NewStateMap

func NewStateMap() *StateMap

func StateMapFromJson

func StateMapFromJson(data []byte) (*StateMap, error)

Load a StateMap from a JSON byte array

func StateMapFromProcessedJson

func StateMapFromProcessedJson(data []byte) (*StateMap, error)

Load a StateMap from a JSON Byte array which has already been initialized (contains State Metadata)

func StateMapFromYaml

func StateMapFromYaml(data []byte) (*StateMap, error)

Load a StateMap from a YAML byte array

func StateMapFromYamlPath

func StateMapFromYamlPath(path string) (*StateMap, error)

Load a YAML file from a given path, if the file doesn't exist default to ~/.otter

func (*StateMap) Add

func (sm *StateMap) Add(entry State) error

Add a new state to the StateMap

func (*StateMap) AddMany

func (sm *StateMap) AddMany(entries []State, attempts, max int) error

Add multiple states to the StateMap

func (*StateMap) Apply

func (sm *StateMap) Apply() *ResultMap

Apply all states loaded in the StateMap

func (*StateMap) Exists

func (sm *StateMap) Exists(other Metadata, nameOnly bool) bool

Check to see if a given state already exists

func (*StateMap) State

func (sm *StateMap) State() *ResultMap

Check if all states loaded in the StateMap are consistent

func (*StateMap) ToJson

func (sm *StateMap) ToJson() ([]byte, error)

Dump this StateMap to a JSON byte array

Jump to

Keyboard shortcuts

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