config

package
v0.0.0-...-bd03ed3 Latest Latest
Warning

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

Go to latest
Published: May 7, 2016 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package config handles the main config file.

Index

Constants

View Source
const (
	DefaultFilePath   = "/etc/tsp-controller/config"
	DefaultFilterPath = "/etc/tsp-controller/filter"
)

Variables

View Source
var (
	FilePath    = flag.String("f", DefaultFilePath, "configuration file")
	TestMode    = flag.Bool("t", false, "configuration test")
	VerboseMode = flag.Bool("v", false, "verbose mode")
	ListenAddr  = flag.String("l", ":8084", "listen address")
	VersionMode = flag.Bool("version", false, "echo version and exit")
)
View Source
var Debug *log.Logger

Functions

func Load

func Load()

Load loads configuration settings from FilePath, storing them in Loaded.

func Register

func Register(fn func(*Config) error)

Register registers a function that updates a Config by decoding the ExtraRaw fields.

Types

type Cluster

type Cluster struct {
	ID   string    `xml:"id,attr"`
	Host []*Host   `xml:"host"`
	Any  *xml.Name `xml:",any"`
}

Cluster represents a single <cluster> element.

func (*Cluster) Validate

func (cluster *Cluster) Validate() error

type Config

type Config struct {
	Hosts   *Hosts          `xml:"hostgroup"`
	Network *network.Config `xml:"network"`
	Filter  *Filter         `xml:"filter"`
	Extra   []*Element      `xml:",any"`
}

Config represents controller's entire configuration, i.e. the <config> block.

var Loaded *Config

Loaded contains the loaded configuration.

func Decode

func Decode(r io.Reader) (*Config, error)

Decode decodes from r the common configuration settings. It also validates that the extended settings are correct, but omits them from the returned config.

func (*Config) Cluster

func (c *Config) Cluster(id string) []*Host

Cluster returns hosts with the given cluster id.

func (*Config) Host

func (c *Config) Host(id string) (*Host, error)

Host returns a host with the given id.

func (*Config) UpdateHost

func (c *Config) UpdateHost(fn UpdateFunc) error

UpdateHost updates config to include extra Host-level elements.

type Element

type Element struct {
	Name  string      `xml:"-"`
	Value interface{} `xml:"-"`
	Raw   []byte      `xml:"-"`
}

An Element is an extended configuration element. Such elements are stored in Config for processing by extension modules.

func (*Element) String

func (e *Element) String() string

func (*Element) UnmarshalXML

func (e *Element) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error

type Filter

type Filter struct {
	Path string `xml:"path,attr"`
}

Filter is a system command that acts as a hook, allowing operators to serve custom rewrite/block filter rules.

func (*Filter) Run

func (f *Filter) Run(v interface{}, program, host, cluster string) error

Run decodes into v json-encoded rules generated by the filter program. The filter receives program, host, and cluster details as command-line arguments.

type Host

type Host struct {
	ID        string     `xml:"id,attr"`
	ClusterID string     `xml:"-"`
	Tags      []string   `xml:"-"`
	Extra     []*Element `xml:",any"`
}

Host represents a single <host> element.

func (*Host) String

func (h *Host) String() string

func (*Host) Validate

func (h *Host) Validate() error

type HostGroup

type HostGroup struct {
	Sub     []*HostGroup `xml:"hostgroup"`
	ID      string       `xml:"id,attr"`
	Cluster []*Cluster   `xml:"cluster"`
	Any     *xml.Name    `xml:",any"`
}

HostGroup represents a single <hostgroup> element.

func (*HostGroup) Validate

func (group *HostGroup) Validate() error

type Hosts

type Hosts struct {
	All []*Host
	NS  Namespace
	// contains filtered or unexported fields
}

Hosts is a set of all <host> elements.

func (*Hosts) String

func (hs *Hosts) String() string

func (*Hosts) UnmarshalXML

func (hs *Hosts) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error

type Namespace

type Namespace map[string]bool

Namespace is a set of identifiers.

func (Namespace) Add

func (ns Namespace) Add(id string) error

Add adds an identifier to the namespace. If the name is already taken, an error is returned.

type UpdateFunc

type UpdateFunc func(string, *Element) error

UpdateFunc is registered by extension module to decode custom Host-level elements. It is passed the Host.ID and an Element to decode. The decoded information must be stored in Element.Value. Any error encountered should be returned.

Directories

Path Synopsis
Package network handles the network config file.
Package network handles the network config file.

Jump to

Keyboard shortcuts

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