common

package
v0.0.0-...-6337964 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FinishBootstrap = func(ctx environs.BootstrapContext, client ssh.Client, inst instance.Instance, machineConfig *cloudinit.MachineConfig) error {
	interrupted := make(chan os.Signal, 1)
	ctx.InterruptNotify(interrupted)
	defer ctx.StopInterruptNotify(interrupted)

	nonceFile := utils.ShQuote(path.Join(machineConfig.DataDir, cloudinit.NonceFile))
	checkNonceCommand := fmt.Sprintf(`
	noncefile=%s
	if [ ! -e "$noncefile" ]; then
		echo "$noncefile does not exist" >&2
		exit 1
	fi
	content=$(cat $noncefile)
	if [ "$content" != %s ]; then
		echo "$noncefile contents do not match machine nonce" >&2
		exit 1
	fi
	`, nonceFile, utils.ShQuote(machineConfig.MachineNonce))
	addr, err := waitSSH(
		ctx,
		interrupted,
		client,
		checkNonceCommand,
		inst,
		machineConfig.Config.BootstrapSSHOpts(),
	)
	if err != nil {
		return err
	}

	cloudcfg := coreCloudinit.New()
	if err := cloudinit.ConfigureJuju(machineConfig, cloudcfg); err != nil {
		return err
	}
	configScript, err := sshinit.ConfigureScript(cloudcfg)
	if err != nil {
		return err
	}
	script := shell.DumpFileOnErrorScript(machineConfig.CloudInitOutputLog) + configScript
	return sshinit.RunConfigureScript(script, sshinit.ConfigureParams{
		Host:           "ubuntu@" + addr,
		Client:         client,
		Config:         cloudcfg,
		ProgressWriter: ctx.GetStderr(),
	})
}

FinishBootstrap completes the bootstrap process by connecting to the instance via SSH and carrying out the cloud-config.

Note: FinishBootstrap is exposed so it can be replaced for testing.

View Source
var LongAttempt = utils.AttemptStrategy{
	Total: 3 * time.Minute,
	Delay: 1 * time.Second,
}

A request may fail to due "eventual consistency" semantics, which should resolve fairly quickly. These delays are specific to the provider and best tuned there. Other requests fail due to a slow state transition (e.g. an instance taking a while to release a security group after termination). If you need to poll for the latter kind, use LongAttempt.

View Source
var ShortAttempt = utils.AttemptStrategy{
	Total: 5 * time.Second,
	Delay: 200 * time.Millisecond,
}

Use ShortAttempt to poll for short-term events. TODO: This may need tuning for different providers (or even environments).

Functions

func BestAvailabilityZoneAllocations

func BestAvailabilityZoneAllocations(env ZonedEnviron, group []instance.Id) (map[string][]instance.Id, error)

BestAvailabilityZoneAllocations returns the availability zones with the fewest instances from the specified group, along with the instances from the group currently allocated to those zones.

If the specified group is empty, then it will behave as if the result of AllInstances were provided.

func Bootstrap

func Bootstrap(ctx environs.BootstrapContext, env environs.Environ, args environs.BootstrapParams) (err error)

Bootstrap is a common implementation of the Bootstrap method defined on environs.Environ; we strongly recommend that this implementation be used when writing a new provider.

func Destroy

func Destroy(env environs.Environ) error

Destroy is a common implementation of the Destroy method defined on environs.Environ; we strongly recommend that this implementation be used when writing a new provider.

func DistributeInstances

func DistributeInstances(env ZonedEnviron, candidates, group []instance.Id) ([]instance.Id, error)

DistributeInstances is a common function for implement the state.InstanceDistributor policy based on availability zone spread.

func EnsureBootstrapTools

func EnsureBootstrapTools(ctx environs.BootstrapContext, env environs.Environ, series string, arch *string) (coretools.List, error)

EnsureBootstrapTools finds tools, syncing with an external tools source as necessary; it then selects the newest tools to bootstrap with, and sets agent-version.

func GenerateSystemSSHKey

func GenerateSystemSSHKey(env environs.Environ) (privateKey string, err error)

GenerateSystemSSHKey creates a new key for the system identity. The authorized_keys in the environment config is updated to include the public key for the generated key.

func StateInfo

func StateInfo(env environs.Environ) (*state.Info, *api.Info, error)

StateInfo is a reusable implementation of Environ.StateInfo, available to providers that also use the other functionality from this file.

func SupportedArchitectures

func SupportedArchitectures(env environs.Environ, imageConstraint *imagemetadata.ImageConstraint) ([]string, error)

SupportedArchitectures returns all the image architectures for env matching the constraints.

Types

type AvailabilityZone

type AvailabilityZone interface {
	// Name returns the name of the availability zone.
	Name() string

	// Available reports whether the availability zone is currently available.
	Available() bool
}

AvailabilityZone describes a provider availability zone.

type SupportsUnitPlacementPolicy

type SupportsUnitPlacementPolicy struct{}

SupportsUnitPlacementPolicy provides an implementation of SupportsUnitPlacement that never returns an error, and is intended for embedding in environs.Environ implementations.

func (*SupportsUnitPlacementPolicy) SupportsUnitPlacement

func (*SupportsUnitPlacementPolicy) SupportsUnitPlacement() error

type ZonedEnviron

type ZonedEnviron interface {
	environs.Environ

	// AvailabilityZones returns all availability zones in the environment.
	AvailabilityZones() ([]AvailabilityZone, error)

	// InstanceAvailabilityZoneNames returns the names of the availability
	// zones for the specified instances. The error returned follows the same
	// rules as Environ.Instances.
	InstanceAvailabilityZoneNames(ids []instance.Id) ([]string, error)
}

ZonedEnviron is an environs.Environ that has support for availability zones.

Jump to

Keyboard shortcuts

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