agent

package
v0.0.0-...-be26699 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2015 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LxcBridge              = "LXC_BRIDGE"
	ProviderType           = "PROVIDER_TYPE"
	ContainerType          = "CONTAINER_TYPE"
	Namespace              = "NAMESPACE"
	StorageDir             = "STORAGE_DIR"
	StorageAddr            = "STORAGE_ADDR"
	AgentServiceName       = "AGENT_SERVICE_NAME"
	MongoOplogSize         = "MONGO_OPLOG_SIZE"
	NumaCtlPreference      = "NUMA_CTL_PREFERENCE"
	AllowsSecureConnection = "SECURE_STATESERVER_CONNECTION"
)
View Source
const BootstrapMachineId = "0"
View Source
const (
	// BootstrapNonce is used as a nonce for the state server machine.
	BootstrapNonce = "user-admin:bootstrap"
)
View Source
const SystemIdentity = "system-identity"

SystemIdentity is the name of the file where the environment SSH key is kept.

Variables

View Source
var DefaultDataDir = dataDir

DefaultDataDir defines the default data directory for juju agents. It's defined as a variable so it could be overridden in tests.

View Source
var DefaultLogDir = path.Join(logDir, "juju")

DefaultLogDir defines the default log directory for juju agents. It's defined as a variable so it could be overridden in tests.

View Source
var ErrNoStateServingInfo = errors.New("StateServingInfo missing")

Functions

func ConfigPath

func ConfigPath(dataDir string, tag names.Tag) string

ConfigPath returns the full path to the agent config file. NOTE: Delete this once all agents accept --config instead of --data-dir - it won't be needed anymore.

func Dir

func Dir(dataDir string, tag names.Tag) string

Dir returns the agent-specific data directory.

func InitializeState

func InitializeState(adminUser names.UserTag, c ConfigSetter, envCfg *config.Config, machineCfg BootstrapMachineConfig, dialOpts mongo.DialOpts, policy state.Policy) (_ *state.State, _ *state.Machine, resultErr error)

InitializeState should be called on the bootstrap machine's agent configuration. It uses that information to create the state server, dial the state server, and initialize it. It also generates a new password for the bootstrap machine and calls Write to save the the configuration.

The envCfg values will be stored in the state's EnvironConfig; the machineCfg values will be used to configure the bootstrap Machine, and its constraints will be also be used for the environment-level constraints. The connection to the state server will respect the given timeout parameter.

InitializeState returns the newly initialized state and bootstrap machine. If it fails, the state may well be irredeemably compromised.

func LogFilename

func LogFilename(c Config) string

LogFileName returns the filename for the Agent's log file.

func WriteSystemIdentityFile

func WriteSystemIdentityFile(c Config) error

Types

type AgentConfigParams

type AgentConfigParams struct {
	DataDir           string
	LogDir            string
	Jobs              []multiwatcher.MachineJob
	UpgradedToVersion version.Number
	Tag               names.Tag
	Password          string
	Nonce             string
	Environment       names.EnvironTag
	StateAddresses    []string
	APIAddresses      []string
	CACert            string
	Values            map[string]string
	PreferIPv6        bool
}

type BootstrapMachineConfig

type BootstrapMachineConfig struct {
	// Addresses holds the bootstrap machine's addresses.
	Addresses []network.Address

	// Constraints holds the bootstrap machine's constraints.
	// This value is also used for the environment-level constraints.
	Constraints constraints.Value

	// Jobs holds the jobs that the machine agent will run.
	Jobs []multiwatcher.MachineJob

	// InstanceId holds the instance id of the bootstrap machine.
	InstanceId instance.Id

	// Characteristics holds hardware information on the
	// bootstrap machine.
	Characteristics instance.HardwareCharacteristics

	// SharedSecret is the Mongo replica set shared secret (keyfile).
	SharedSecret string
}

BootstrapMachineConfig holds configuration information to attach to the bootstrap machine.

type Config

type Config interface {
	// DataDir returns the data directory. Each agent has a subdirectory
	// containing the configuration files.
	DataDir() string

	// LogDir returns the log directory. All logs from all agents on
	// the machine are written to this directory.
	LogDir() string

	// SystemIdentityPath returns the path of the file where the environment
	// SSH key is kept.
	SystemIdentityPath() string

	// Jobs returns a list of MachineJobs that need to run.
	Jobs() []multiwatcher.MachineJob

	// Tag returns the tag of the entity on whose behalf the state connection
	// will be made.
	Tag() names.Tag

	// Dir returns the agent's directory.
	Dir() string

	// Nonce returns the nonce saved when the machine was provisioned
	// TODO: make this one of the key/value pairs.
	Nonce() string

	// CACert returns the CA certificate that is used to validate the state or
	// API server's certificate.
	CACert() string

	// APIAddresses returns the addresses needed to connect to the api server
	APIAddresses() ([]string, error)

	// WriteCommands returns shell commands to write the agent configuration.
	// It returns an error if the configuration does not have all the right
	// elements.
	WriteCommands(renderer shell.Renderer) ([]string, error)

	// StateServingInfo returns the details needed to run
	// a state server and reports whether those details
	// are available
	StateServingInfo() (params.StateServingInfo, bool)

	// APIInfo returns details for connecting to the API server.
	APIInfo() *api.Info

	// MongoInfo returns details for connecting to the state server's mongo
	// database and reports whether those details are available
	MongoInfo() (*mongo.MongoInfo, bool)

	// OldPassword returns the fallback password when connecting to the
	// API server.
	OldPassword() string

	// UpgradedToVersion returns the version for which all upgrade steps have been
	// successfully run, which is also the same as the initially deployed version.
	UpgradedToVersion() version.Number

	// Value returns the value associated with the key, or an empty string if
	// the key is not found.
	Value(key string) string

	// PreferIPv6 returns whether to prefer using IPv6 addresses (if
	// available) when connecting to the state or API server.
	PreferIPv6() bool

	// Environment returns the tag for the environment that the agent belongs
	// to.
	Environment() names.EnvironTag
}

The Config interface is the sole way that the agent gets access to the configuration information for the machine and unit agents. There should only be one instance of a config object for any given agent, and this interface is passed between multiple go routines. The mutable methods are protected by a mutex, and it is expected that the caller doesn't modify any slice that may be returned.

NOTE: should new mutating methods be added to this interface, consideration is needed around the synchronisation as a single instance is used in multiple go routines.

type ConfigMutator

type ConfigMutator func(ConfigSetter) error

type ConfigSetter

type ConfigSetter interface {
	Config
	ConfigSetterOnly
}

type ConfigSetterOnly

type ConfigSetterOnly interface {
	// Clone returns a copy of the configuration that
	// is unaffected by subsequent calls to the Set*
	// methods
	Clone() Config

	// SetOldPassword sets the password that is currently
	// valid but needs to be changed. This is used as
	// a fallback.
	SetOldPassword(oldPassword string)

	// SetPassword sets the password to be used when
	// connecting to the state.
	SetPassword(newPassword string)

	// SetValue updates the value for the specified key.
	SetValue(key, value string)

	// SetUpgradedToVersion sets the version that
	// the agent has successfully upgraded to.
	SetUpgradedToVersion(newVersion version.Number)

	// SetAPIHostPorts sets the API host/port addresses to connect to.
	SetAPIHostPorts(servers [][]network.HostPort)

	// Migrate takes an existing agent config and applies the given
	// parameters to change it.
	//
	// Only non-empty fields in newParams are used
	// to change existing config settings. All changes are written
	// atomically. UpgradedToVersion cannot be changed here, because
	// Migrate is most likely called during an upgrade, so it will be
	// changed at the end of the upgrade anyway, if successful.
	//
	// Migrate does not actually write the new configuration.
	//
	// Note that if the configuration file moves location,
	// (if DataDir is set), the the caller is responsible for removing
	// the old configuration.
	Migrate(MigrateParams) error

	// SetStateServingInfo sets the information needed
	// to run a state server
	SetStateServingInfo(info params.StateServingInfo)
}

type ConfigSetterWriter

type ConfigSetterWriter interface {
	Config
	ConfigSetterOnly
	ConfigWriter
}

func NewAgentConfig

func NewAgentConfig(configParams AgentConfigParams) (ConfigSetterWriter, error)

NewAgentConfig returns a new config object suitable for use for a machine or unit agent.

func NewStateMachineConfig

func NewStateMachineConfig(configParams AgentConfigParams, serverInfo params.StateServingInfo) (ConfigSetterWriter, error)

NewStateMachineConfig returns a configuration suitable for a machine running the state server.

func ReadConfig

func ReadConfig(configFilePath string) (ConfigSetterWriter, error)

ReadConfig reads configuration data from the given location.

type ConfigWriter

type ConfigWriter interface {
	// Write writes the agent configuration.
	Write() error
}

type MigrateParams

type MigrateParams struct {
	DataDir      string
	LogDir       string
	Jobs         []multiwatcher.MachineJob
	DeleteValues []string
	Values       map[string]string
	Environment  names.EnvironTag
}

MigrateParams holds agent config values to change in a Migrate call. Empty fields will be ignored. DeleteValues specifies a list of keys to delete.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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