juju: github.com/juju/juju/agent Index | Files | Directories

package agent

import "github.com/juju/juju/agent"


Package Files

agent.go format-2.0.go format.go identity.go


const (
    // BootstrapNonce is used as a nonce for the initial controller machine.
    BootstrapNonce = "user-admin:bootstrap"

    // BootstrapControllerId is the ID of the initial controller.
    BootstrapControllerId = "0"
const (
    // LxcBridge is deprecated, used LxdBridge instead.
    LxcBridge         = "LXC_BRIDGE"
    LxdBridge         = "LXD_BRIDGE"
    ProviderType      = "PROVIDER_TYPE"
    ContainerType     = "CONTAINER_TYPE"
    Namespace         = "NAMESPACE"
    AgentServiceName  = "AGENT_SERVICE_NAME"
    MongoOplogSize    = "MONGO_OPLOG_SIZE"

    MgoStatsEnabled = "MGO_STATS_ENABLED"

    // LoggingOverride will set the logging for this agent to the value
    // specified. Model configuration will be ignored and this value takes
    // precidence for the agent.
    LoggingOverride = "LOGGING_OVERRIDE"

    LogSinkDBLoggerBufferSize    = "LOGSINK_DBLOGGER_BUFFER_SIZE"
    LogSinkRateLimitBurst        = "LOGSINK_RATELIMIT_BURST"
    LogSinkRateLimitRefill       = "LOGSINK_RATELIMIT_REFILL"

    // CharmRevisionUpdateInterval controls how often the
    // charm revision update worker runs.
    CharmRevisionUpdateInterval = "CHARM_REVISION_UPDATE_INTERVAL"
const AgentConfigFilename = "agent.conf"

AgentConfigFilename is the default file name of used for the agent config.

const SystemIdentity = "system-identity"

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


var (
    // DefaultPaths defines the default paths for an agent.
    DefaultPaths = Paths{
        DataDir:          dataDir,
        TransientDataDir: transientDataDir,
        LogDir:           path.Join(logDir, "juju"),
        MetricsSpoolDir:  metricsSpoolDir,
        ConfDir:          confDir,
var ErrNoStateServingInfo = errors.New("StateServingInfo missing")

func BaseDir Uses

func BaseDir(dataDir string) string

BaseDir returns the directory containing the data directories for all the agents.

func ConfigPath Uses

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 Uses

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

Dir returns the agent-specific data directory.

func LogFilename Uses

func LogFilename(c Config) string

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

func MachineLockLogFilename Uses

func MachineLockLogFilename(c Config) string

MachineLockLogFilename returns the filename for the machine lock log file.

func WriteSystemIdentityFile Uses

func WriteSystemIdentityFile(c Config) error

type APIHostPortsSetter Uses

type APIHostPortsSetter struct {

APIHostPortsSetter trivially wraps an Agent to implement worker/apiaddressupdater/APIAddressSetter.

func (APIHostPortsSetter) SetAPIHostPorts Uses

func (s APIHostPortsSetter) SetAPIHostPorts(servers []network.HostPorts) error

SetAPIHostPorts is the APIAddressSetter interface.

type Agent Uses

type Agent interface {

    // CurrentConfig returns a copy of the agent's configuration. No
    // guarantees regarding ongoing correctness are made.
    CurrentConfig() Config

    // ChangeConfig allows clients to change the agent's configuration
    // by supplying a callback that applies the changes.
    ChangeConfig(ConfigMutator) error

Agent exposes the agent's configuration to other components. This interface should probably be segregated (agent.ConfigGetter and agent.ConfigChanger?) but YAGNI *currently* advises against same.

type AgentConfigParams Uses

type AgentConfigParams struct {
    Paths                    Paths
    Jobs                     []model.MachineJob
    UpgradedToVersion        version.Number
    Tag                      names.Tag
    Password                 string
    Nonce                    string
    Controller               names.ControllerTag
    Model                    names.ModelTag
    APIAddresses             []string
    CACert                   string
    Values                   map[string]string
    MongoVersion             mongo.Version
    MongoMemoryProfile       mongo.MemoryProfile
    JujuDBSnapChannel        string
    NonSyncedWritesToRaftLog bool

AgentConfigParams holds the parameters required to create a new AgentConfig.

type Config Uses

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

    // TransientDataDir returns the directory where this agent should store
    // any data that is not expected to survive a reboot.
    TransientDataDir() 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() []model.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 controller and reports whether those details
    // are available
    StateServingInfo() (controller.StateServingInfo, bool)

    // APIInfo returns details for connecting to the API server and
    // reports whether the details are available.
    APIInfo() (*api.Info, bool)

    // MongoInfo returns details for connecting to the controller'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

    // LoggingConfig returns the logging config for this agent. Initially this
    // value is empty, but as the agent gets notified of model agent config
    // changes this value is saved.
    LoggingConfig() string

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

    // Model returns the tag for the model that the agent belongs to.
    Model() names.ModelTag

    // Controller returns the tag for the controller that the agent belongs to.
    Controller() names.ControllerTag

    // MetricsSpoolDir returns the spool directory where workloads store
    // collected metrics.
    MetricsSpoolDir() string

    // MongoVersion returns the version of mongo that the state server
    // is using.
    MongoVersion() mongo.Version

    // MongoMemoryProfile returns the profile to be used when setting
    // mongo memory usage.
    MongoMemoryProfile() mongo.MemoryProfile

    // JujuDBSnapChannel returns the channel for installing mongo snaps in
    // focal or later.
    JujuDBSnapChannel() string

    // NonSyncedWritesToRaftLog returns true if an fsync calls should not be
    // performed after each write to the raft log.
    NonSyncedWritesToRaftLog() bool

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 Uses

type ConfigMutator func(ConfigSetter) error

type ConfigRenderer Uses

type ConfigRenderer interface {
    // Render generates the agent configuration
    // as a byte array.
    Render() ([]byte, error)

type ConfigSetter Uses

type ConfigSetter interface {
    // contains filtered or unexported methods

type ConfigSetterWriter Uses

type ConfigSetterWriter interface {

    // contains filtered or unexported methods

func NewAgentConfig Uses

func NewAgentConfig(configParams AgentConfigParams) (ConfigSetterWriter, error)

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

func NewStateMachineConfig Uses

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

NewStateMachineConfig returns a configuration suitable for a machine running the controller.

func ReadConfig Uses

func ReadConfig(configFilePath string) (ConfigSetterWriter, error)

ReadConfig reads configuration data from the given location.

type ConfigWriter Uses

type ConfigWriter interface {

    // Write writes the agent configuration.
    Write() error

type Paths Uses

type Paths struct {
    // DataDir is the data directory where each agent has a subdirectory
    // containing the configuration files.
    DataDir string
    // TransientDataDir is a directory where each agent can store data that
    // is not expected to survive a reboot.
    TransientDataDir string
    // LogDir is the log directory where all logs from all agents on
    // the machine are written.
    LogDir string
    // MetricsSpoolDir is the spool directory where workloads store
    // collected metrics.
    MetricsSpoolDir string
    // ConfDir is the directory where all  config file for
    // Juju agents are stored.
    ConfDir string

Paths holds the directory paths used by the agent.

func NewPathsWithDefaults Uses

func NewPathsWithDefaults(p Paths) Paths

NewPathsWithDefaults returns a Paths struct initialized with default locations if not otherwise specified.

func (*Paths) Migrate Uses

func (p *Paths) Migrate(newPaths Paths)

Migrate assigns the directory locations specified from the new path configuration.



Package agent imports 25 packages (graph) and is imported by 2075 packages. Updated 2020-09-30. Refresh now. Tools for package owners.