environs

package
v0.0.0-...-732aecd Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2014 License: AGPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const CloudInitOutputLog = "/var/log/cloud-init-output.log"

CloudInitOutputLog is the default cloud-init-output.log file path.

View Source
const (
	VerificationFilename = "bootstrap-verify"
)

File named `VerificationFilename` in the storage will contain `verificationContent`. This is also used to differentiate between Python Juju and juju-core environments, so change the content with care (and update CheckEnvironment below when you do that).

Variables

View Source
var (
	ErrNotBootstrapped  = errors.New("environment is not bootstrapped")
	ErrNoInstances      = errors.New("no instances found")
	ErrPartialInstances = errors.New("only some instances were found")
)
View Source
var (
	VerifyStorageError error = fmt.Errorf(
		"provider storage is not writable")
	InvalidEnvironmentError = fmt.Errorf(
		"environment is not a juju-core environment")
)

DataDir is the default data directory. Tests can override this where needed, so they don't need to mess with global system state.

View Source
var EmptyStorage storage.StorageReader = emptyStorage{}

EmptyStorage holds a StorageReader object that contains no files and offers no URLs.

Functions

func BoilerplateConfig

func BoilerplateConfig() string

BoilerplateConfig returns a sample juju configuration.

func BootstrapConfig

func BootstrapConfig(cfg *config.Config) (*config.Config, error)

BootstrapConfig returns a copy of the supplied configuration with the admin-secret and ca-private-key attributes removed. If the resulting config is not suitable for bootstrapping an environment, an error is returned.

func CheckEnvironment

func CheckEnvironment(environ Environ) error

CheckEnvironment checks if an environment has a bootstrap-verify that is written by juju-core commands (as compared to one being written by Python juju).

If there is no bootstrap-verify file in the storage, it is still considered to be a Juju-core environment since early versions have not written it out.

Returns InvalidEnvironmentError on failure, nil otherwise.

func ComposeUserData

func ComposeUserData(mcfg *cloudinit.MachineConfig, cloudcfg *coreCloudinit.Config) ([]byte, error)

ComposeUserData fills out the provided cloudinit configuration structure so it is suitable for initialising a machine with the given configuration, and then renders it and returns it as a binary (gzipped) blob of user data.

If the provided cloudcfg is nil, a new one will be created internally.

func Destroy

func Destroy(env Environ, store configstore.Storage) error

Destroy destroys the environment and, if successful, its associated configuration data from the given store.

func DestroyInfo

func DestroyInfo(envName string, store configstore.Storage) error

DestroyInfo destroys the configuration data for the named environment from the given store.

func FinishMachineConfig

func FinishMachineConfig(mcfg *cloudinit.MachineConfig, cfg *config.Config, cons constraints.Value) (err error)

FinishMachineConfig sets fields on a MachineConfig that can be determined by inspecting a plain config.Config and the machine constraints at the last moment before bootstrapping. It assumes that the supplied Config comes from an environment that has passed through all the validation checks in the Bootstrap func, and that has set an agent-version (via finding the tools to, use for bootstrap, or otherwise). TODO(fwereade) This function is not meant to be "good" in any serious way: it is better that this functionality be collected in one place here than that it be spread out across 3 or 4 providers, but this is its only redeeming feature.

func GetStorage

func GetStorage(st *state.State) (storage.Storage, error)

GetStorage creates an Environ from the config in state and returns its storage interface.

func IsEmptyConfig

func IsEmptyConfig(err error) bool

IsEmptyConfig reports whether err is a EmptyConfig.

func IsNoEnv

func IsNoEnv(err error) bool

IsNoEnv reports whether err is a NoEnvError.

func NewBootstrapMachineConfig

func NewBootstrapMachineConfig(privateSystemSSHKey string) *cloudinit.MachineConfig

NewBootstrapMachineConfig sets up a basic machine configuration for a bootstrap node. You'll still need to supply more information, but this takes care of the fixed entries and the ones that are always needed.

func NewMachineConfig

func NewMachineConfig(
	machineID, machineNonce string, networks []string,
	stateInfo *state.Info, apiInfo *api.Info,
) *cloudinit.MachineConfig

NewMachineConfig sets up a basic machine configuration, for a non-bootstrap node. You'll still need to supply more information, but this takes care of the fixed entries and the ones that are always needed.

func NewStatePolicy

func NewStatePolicy() state.Policy

NewStatePolicy returns a state.Policy that is implemented in terms of Environ and related types.

func PopulateMachineConfig

func PopulateMachineConfig(mcfg *cloudinit.MachineConfig,
	providerType, authorizedKeys string,
	sslHostnameVerification bool,
	proxySettings, aptProxySettings proxy.Settings,
) error

PopulateMachineConfig is called both from the FinishMachineConfig below, which does have access to the environment config, and from the container provisioners, which don't have access to the environment config. Everything that is needed to provision a container needs to be returned to the provisioner in the ContainerConfig structure. Those values are then used to call this function.

func RegisterProvider

func RegisterProvider(name string, p EnvironProvider, alias ...string)

RegisterProvider registers a new environment provider. Name gives the name of the provider, and p the interface to that provider.

RegisterProvider will panic if the provider name or any of the aliases are registered more than once.

func VerifyStorage

func VerifyStorage(stor storage.Storage) error

VerifyStorage writes the bootstrap init file to the storage to indicate that the storage is writable.

func WriteEnvirons

func WriteEnvirons(path string, fileContents string) (string, error)

WriteEnvirons creates a new juju environments.yaml file with the specified contents.

Types

type AuthenticationProvider

type AuthenticationProvider interface {
	SetupAuthentication(machine TaggedPasswordChanger) (*state.Info, *api.Info, error)
}

AuthenticationProvider defines the single method that the provisioner task needs to set up authentication for a machine.

func NewAPIAuthenticator

func NewAPIAuthenticator(st *apiprovisioner.State) (AuthenticationProvider, error)

NewAPIAuthenticator gets the state and api info once from the provisioner API.

func NewEnvironAuthenticator

func NewEnvironAuthenticator(environ Environ) (AuthenticationProvider, error)

NewEnvironAuthenticator gets the state and api info once from the environ.

type BootstrapContext

type BootstrapContext interface {
	GetStdin() io.Reader
	GetStdout() io.Writer
	GetStderr() io.Writer
	Infof(format string, params ...interface{})
	Verbosef(format string, params ...interface{})

	// InterruptNotify starts watching for interrupt signals
	// on behalf of the caller, sending them to the supplied
	// channel.
	InterruptNotify(sig chan<- os.Signal)

	// StopInterruptNotify undoes the effects of a previous
	// call to InterruptNotify with the same channel. After
	// StopInterruptNotify returns, no more signals will be
	// delivered to the channel.
	StopInterruptNotify(chan<- os.Signal)
}

BootstrapContext is an interface that is passed to Environ.Bootstrap, providing a means of obtaining information about and manipulating the context in which it is being invoked.

type BootstrapParams

type BootstrapParams struct {
	// Constraints are used to choose the initial instance specification,
	// and will be stored in the new environment's state.
	Constraints constraints.Value

	// Placement, if non-empty, holds an environment-specific placement
	// directive used to choose the initial instance.
	Placement string
}

BootstrapParams holds the parameters for bootstrapping an environment.

type ConfigGetter

type ConfigGetter interface {
	// Config returns the configuration data with which the Environ was created.
	// Note that this is not necessarily current; the canonical location
	// for the configuration data is stored in the state.
	Config() *config.Config
}

ConfigGetter implements access to an environment's configuration.

type ConfigSource

type ConfigSource int

ConfigSource represents where some configuration data has come from. TODO(rog) remove this when we don't have to support old environments with no configstore info. See lp#1235217

const (
	ConfigFromNowhere ConfigSource = iota
	ConfigFromInfo
	ConfigFromEnvirons
)

func ConfigForName

func ConfigForName(name string, store configstore.Storage) (*config.Config, ConfigSource, error)

ConfigForName returns the configuration for the environment with the given name from the default environments file. If the name is blank, the default environment will be used. If the configuration is not found, an errors.NotFoundError is returned. If the given store contains an entry for the environment and it has associated bootstrap config, that configuration will be returned. ConfigForName also returns where the configuration was sourced from (this is also valid even when there is an error.

type EmptyConfig

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

EmptyConfig indicates the .jenv file is empty.

type Environ

type Environ interface {
	// Name returns the Environ's name.
	Name() string

	// Bootstrap initializes the state for the environment, possibly
	// starting one or more instances.  If the configuration's
	// AdminSecret is non-empty, the administrator password on the
	// newly bootstrapped state will be set to a hash of it (see
	// utils.PasswordHash), When first connecting to the
	// environment via the juju package, the password hash will be
	// automatically replaced by the real password.
	//
	// Bootstrap is responsible for selecting the appropriate tools,
	// and setting the agent-version configuration attribute prior to
	// bootstrapping the environment.
	Bootstrap(ctx BootstrapContext, params BootstrapParams) error

	// StateInfo returns information on the state initialized
	// by Bootstrap.
	StateInfo() (*state.Info, *api.Info, error)

	// InstanceBroker defines methods for starting and stopping
	// instances.
	InstanceBroker

	// AllocateAddress requests a new address to be allocated for the
	// given instance on the given network.
	AllocateAddress(instId instance.Id, netId network.Id) (instance.Address, error)

	// ConfigGetter allows the retrieval of the configuration data.
	ConfigGetter

	// EnvironCapability allows access to this environment's capabilities.
	state.EnvironCapability

	// ConstraintsValidator returns a Validator instance which
	// is used to validate and merge constraints.
	ConstraintsValidator() (constraints.Validator, error)

	// SetConfig updates the Environ's configuration.
	//
	// Calls to SetConfig do not affect the configuration of
	// values previously obtained from Storage.
	SetConfig(cfg *config.Config) error

	// Instances returns a slice of instances corresponding to the
	// given instance ids.  If no instances were found, but there
	// was no other error, it will return ErrNoInstances.  If
	// some but not all the instances were found, the returned slice
	// will have some nil slots, and an ErrPartialInstances error
	// will be returned.
	Instances(ids []instance.Id) ([]instance.Instance, error)

	EnvironStorage

	// Destroy shuts down all known machines and destroys the
	// rest of the environment. Note that on some providers,
	// very recently started instances may not be destroyed
	// because they are not yet visible.
	//
	// When Destroy has been called, any Environ referring to the
	// same remote environment may become invalid
	Destroy() error

	// OpenPorts opens the given ports for the whole environment.
	// Must only be used if the environment was setup with the
	// FwGlobal firewall mode.
	OpenPorts(ports []instance.Port) error

	// ClosePorts closes the given ports for the whole environment.
	// Must only be used if the environment was setup with the
	// FwGlobal firewall mode.
	ClosePorts(ports []instance.Port) error

	// Ports returns the ports opened for the whole environment.
	// Must only be used if the environment was setup with the
	// FwGlobal firewall mode.
	Ports() ([]instance.Port, error)

	// Provider returns the EnvironProvider that created this Environ.
	Provider() EnvironProvider

	state.Prechecker
}

An Environ represents a juju environment as specified in the environments.yaml file.

Due to the limitations of some providers (for example ec2), the results of the Environ methods may not be fully sequentially consistent. In particular, while a provider may retry when it gets an error for an operation, it will not retry when an operation succeeds, even if that success is not consistent with a previous operation.

Even though Juju takes care not to share an Environ between concurrent workers, it does allow concurrent method calls into the provider implementation. The typical provider implementation needs locking to avoid undefined behaviour when the configuration changes.

func New

func New(config *config.Config) (Environ, error)

New returns a new environment based on the provided configuration.

func NewFromAttrs

func NewFromAttrs(attrs map[string]interface{}) (Environ, error)

NewFromAttrs returns a new environment based on the provided configuration attributes. TODO(rog) remove this function - it's almost always wrong to use it.

func NewFromName

func NewFromName(name string, store configstore.Storage) (Environ, error)

NewFromName opens the environment with the given name from the default environments file. If the name is blank, the default environment will be used. If the given store contains an entry for the environment and it has associated bootstrap config, that configuration will be returned.

func Prepare

func Prepare(cfg *config.Config, ctx BootstrapContext, store configstore.Storage) (Environ, error)

Prepare prepares a new environment based on the provided configuration. If the environment is already prepared, it behaves like New.

func PrepareFromName

func PrepareFromName(name string, ctx BootstrapContext, store configstore.Storage) (Environ, error)

PrepareFromName is the same as NewFromName except that the environment is is prepared as well as opened, and environment information is created using the given store. If the environment is already prepared, it behaves like NewFromName.

type EnvironProvider

type EnvironProvider interface {
	// Prepare prepares an environment for use. Any additional
	// configuration attributes in the returned environment should
	// be saved to be used later. If the environment is already
	// prepared, this call is equivalent to Open.
	Prepare(ctx BootstrapContext, cfg *config.Config) (Environ, error)

	// Open opens the environment and returns it.
	// The configuration must have come from a previously
	// prepared environment.
	Open(cfg *config.Config) (Environ, error)

	// Validate ensures that config is a valid configuration for this
	// provider, applying changes to it if necessary, and returns the
	// validated configuration.
	// If old is not nil, it holds the previous environment configuration
	// for consideration when validating changes.
	Validate(cfg, old *config.Config) (valid *config.Config, err error)

	// Boilerplate returns a default configuration for the environment in yaml format.
	// The text should be a key followed by some number of attributes:
	//    `environName:
	//        type: environTypeName
	//        attr1: val1
	//    `
	// The text is used as a template (see the template package) with one extra template
	// function available, rand, which expands to a random hexadecimal string when invoked.
	BoilerplateConfig() string

	// SecretAttrs filters the supplied configuration returning only values
	// which are considered sensitive. All of the values of these secret
	// attributes need to be strings.
	SecretAttrs(cfg *config.Config) (map[string]string, error)
}

A EnvironProvider represents a computing and storage provider.

func Provider

func Provider(providerType string) (EnvironProvider, error)

Provider returns the previously registered provider with the given type.

type EnvironStorage

type EnvironStorage interface {
	// Storage returns storage specific to the environment.
	Storage() storage.Storage
}

EnvironStorage implements storage access for an environment

type Environs

type Environs struct {
	Default string // The name of the default environment.
	// contains filtered or unexported fields
}

Environs holds information about each named environment in an environments.yaml file.

func ReadEnvirons

func ReadEnvirons(path string) (*Environs, error)

ReadEnvirons reads the juju environments.yaml file and returns the result of running ParseEnvironments on the file's contents. If path is empty, $HOME/.juju/environments.yaml is used.

func ReadEnvironsBytes

func ReadEnvironsBytes(data []byte) (*Environs, error)

ReadEnvironsBytes parses the contents of an environments.yaml file and returns its representation. An environment with an unknown type will only generate an error when New is called for that environment. Attributes for environments with known types are checked.

func (*Environs) Config

func (envs *Environs) Config(name string) (*config.Config, error)

Config returns the environment configuration for the environment with the given name. If the configuration is not found, an errors.NotFoundError is returned.

func (*Environs) Names

func (e *Environs) Names() (names []string)

Names returns the list of environment names.

type InstanceBroker

type InstanceBroker interface {
	// StartInstance asks for a new instance to be created, associated with
	// the provided config in machineConfig. The given config describes the juju
	// state for the new instance to connect to. The config MachineNonce, which must be
	// unique within an environment, is used by juju to protect against the
	// consequences of multiple instances being started with the same machine
	// id.
	StartInstance(args StartInstanceParams) (instance.Instance, *instance.HardwareCharacteristics, []network.Info, error)

	// StopInstances shuts down the instances with the specified IDs.
	// Unknown instance IDs are ignored, to enable idempotency.
	StopInstances(...instance.Id) error

	// AllInstances returns all instances currently known to the broker.
	AllInstances() ([]instance.Instance, error)
}

TODO(wallyworld) - we want this in the environs/instance package but import loops stop that from being possible right now.

type NoEnvError

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

NoEnvError indicates the default environment config file is missing.

type StartInstanceParams

type StartInstanceParams struct {
	// Constraints is a set of constraints on
	// the kind of instance to create.
	Constraints constraints.Value

	// Tools is a list of tools that may be used
	// to start a Juju agent on the machine.
	Tools tools.List

	// MachineConfig describes the machine's configuration.
	MachineConfig *cloudinit.MachineConfig

	// Placement, if non-empty, contains an environment-specific
	// placement directive that may be used to decide how the
	// instance should be started.
	Placement string

	// DistributionGroup, if non-nil, is a function
	// that returns a slice of instance.Ids that belong
	// to the same distribution group as the machine
	// being provisioned. The InstanceBroker may use
	// this information to distribute instances for
	// high availability.
	DistributionGroup func() ([]instance.Id, error)
}

StartInstanceParams holds parameters for the InstanceBroker.StartInstance method.

type TaggedPasswordChanger

type TaggedPasswordChanger interface {
	SetPassword(string) error
	Tag() string
}

TaggedPasswordChanger defines an interface for a entity with a Tag() and SetPassword() methods.

Directories

Path Synopsis
The imagemetadata package supports locating, parsing, and filtering Ubuntu image metadata in simplestreams format.
The imagemetadata package supports locating, parsing, and filtering Ubuntu image metadata in simplestreams format.
The simplestreams package supports locating, parsing, and filtering metadata in simplestreams format.
The simplestreams package supports locating, parsing, and filtering metadata in simplestreams format.
The tools package supports locating, parsing, and filtering Ubuntu tools metadata in simplestreams format.
The tools package supports locating, parsing, and filtering Ubuntu tools metadata in simplestreams format.

Jump to

Keyboard shortcuts

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