instancecfg

package
v0.0.0-...-e653fdf Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: AGPL-3.0 Imports: 34 Imported by: 212

Documentation

Index

Constants

View Source
const DefaultBridgeName = "br-eth0"

DefaultBridgeName is the network bridge device name used for LXC and KVM containers

Variables

This section is empty.

Functions

func FinishInstanceConfig

func FinishInstanceConfig(icfg *InstanceConfig, cfg *config.Config) (err error)

FinishInstanceConfig sets fields on a InstanceConfig that can be determined by inspecting a plain config.Config and the machine constraints at the last moment before creating the user-data. 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 InstanceTags

func InstanceTags(modelUUID, controllerUUID string, tagger tags.ResourceTagger, isController bool) map[string]string

InstanceTags returns the minimum set of tags that should be set on a machine instance, if the provider supports them.

func PopulateInstanceConfig

func PopulateInstanceConfig(icfg *InstanceConfig,
	providerType, authorizedKeys string,
	sslHostnameVerification bool,
	proxyCfg ProxyConfiguration,
	enableOSRefreshUpdates bool,
	enableOSUpgrade bool,
	cloudInitUserData map[string]interface{},
	profiles []string,
) error

PopulateInstanceConfig is called both from the FinishInstanceConfig 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.

Types

type BootstrapConfig

type BootstrapConfig struct {
	StateInitializationParams

	// ControllerCharm is a local controller charm to be used.
	ControllerCharm string

	// Timeout is the amount of time to wait for bootstrap to complete.
	Timeout time.Duration

	// InitialSSHHostKeys contains the initial SSH host keys to configure
	// on the bootstrap machine, indexed by algorithm. These will only be
	// valid for the initial SSH connection. The first thing we do upon
	// making the initial SSH connection is to replace each of these host
	// keys, to avoid the host keys being extracted from the metadata
	// service by a bad actor post-bootstrap.
	//
	// Any existing host keys on the machine with algorithms not specified
	// in the map will be left alone. This is important so that we do not
	// trample on the host keys of manually provisioned machines.
	InitialSSHHostKeys SSHHostKeys

	// StateServingInfo holds the information for serving the state.
	// This is only specified for bootstrap; controllers started
	// subsequently will acquire their serving info from another
	// server.
	StateServingInfo controller.StateServingInfo

	// JujuDbSnapPath is the path to a .snap file that will be used as the juju-db
	// service.
	JujuDbSnapPath string

	// JujuDbSnapAssertions is a path to a .assert file that will be used
	// to verify the .snap at JujuDbSnapPath
	JujuDbSnapAssertionsPath string

	// ControllerServiceType is the service type of a k8s controller.
	ControllerServiceType string

	// IgnoreProxy tells the boostrap provider to no deploy any controller
	// proxying resources. Currently only used in k8s
	IgnoreProxy bool

	// ControllerExternalName is the external name of a k8s controller.
	ControllerExternalName string

	// ControllerExternalIPs is the list of external ips for a k8s controller.
	ControllerExternalIPs []string
}

BootstrapConfig represents bootstrap-specific initialization information for a new juju instance. This is only relevant for the bootstrap machine.

func (*BootstrapConfig) VerifyConfig

func (cfg *BootstrapConfig) VerifyConfig() (err error)

VerifyConfig verifies that the BootstrapConfig is valid.

type InstanceConfig

type InstanceConfig struct {
	// Tags is a set of tags to set on the instance, if supported. This
	// should be populated using the InstanceTags method in this package.
	Tags map[string]string

	// Bootstrap contains bootstrap-specific configuration. If this is set,
	// Controller must also be set.
	Bootstrap *BootstrapConfig

	// Controller contains configuration for the controller
	// used to manage this new instance.
	ControllerConfig controller.Config

	// The public key used to sign Juju simplestreams image metadata.
	PublicImageSigningKey string

	// APIInfo holds the means for the new instance to communicate with the
	// juju state API. Unless the new instance is running a controller (Controller is
	// set), there must be at least one controller address supplied.
	// The entity name must match that of the instance being started,
	// or be empty when starting a controller.
	APIInfo *api.Info

	// ControllerTag identifies the controller.
	ControllerTag names.ControllerTag

	// MachineNonce is set at provisioning/bootstrap time and used to
	// ensure the agent is running on the correct instance.
	MachineNonce string

	// TransientDataDir holds the directory that juju can use to write
	// transient files that get purged after a system reboot.
	TransientDataDir string

	// DataDir holds the directory that juju state will be put in the new
	// instance.
	DataDir string

	// LogDir holds the directory that juju logs will be written to.
	LogDir string

	// MetricsSpoolDir represents the spool directory path, where all
	// metrics are stored.
	MetricsSpoolDir string

	// Jobs holds what machine jobs to run.
	Jobs []model.MachineJob

	// CloudInitOutputLog specifies the path to the output log for cloud-init.
	// The directory containing the log file must already exist.
	CloudInitOutputLog string

	// CloudInitUserData defines key/value pairs from the model-config
	// specified by the user.
	CloudInitUserData map[string]interface{}

	// MachineId identifies the new machine.
	MachineId string

	// MachineContainerType specifies the type of container that the instance
	// is.  If the instance is not a container, then the type is "".
	MachineContainerType instance.ContainerType

	// MachineContainerHostname specifies the hostname to be used with the
	// cloud config for the instance. If this is not set, hostname uses the default.
	MachineContainerHostname string

	// AuthorizedKeys specifies the keys that are allowed to
	// connect to the instance (see cloudinit.SSHAddAuthorizedKeys)
	// If no keys are supplied, there can be no ssh access to the node.
	// On a bootstrap instance, that is fatal. On other
	// instances it will mean that the ssh, scp and debug-hooks
	// commands cannot work.
	AuthorizedKeys string

	// AgentEnvironment defines additional configuration variables to set in
	// the instance agent config.
	AgentEnvironment map[string]string

	// DisableSSLHostnameVerification can be set to true to tell cloud-init
	// that it shouldn't verify SSL certificates
	DisableSSLHostnameVerification bool

	// Base represents the instance base.
	Base corebase.Base

	// MachineAgentServiceName is the init service name for the Juju machine agent.
	MachineAgentServiceName string

	// LegacyProxySettings define normal http, https and ftp proxies.
	// These values are written to the /etc for the user profile and systemd settings.
	LegacyProxySettings proxy.Settings

	// JujuProxySettings define normal http, https and ftp proxies for accessing
	// the outside network. These values are not written to disk.
	JujuProxySettings proxy.Settings

	// AptProxySettings define the http, https and ftp proxy settings to use
	// for apt, which may or may not be the same as the normal ProxySettings.
	AptProxySettings proxy.Settings

	// AptMirror defines an APT mirror location, which, if specified, will
	// override the default APT sources.
	AptMirror string

	// SnapProxySettings define the http, https and ftp proxy settings to
	// use for snap, which may or may not be the same as the normal
	// ProxySettings.
	SnapProxySettings proxy.Settings

	// SnapStoreAssertions contains a list of assertions that must be
	// passed to snapd together with a store proxy ID parameter before it
	// can connect to a snap store proxy.
	SnapStoreAssertions string

	// SnapStoreProxyID references a store entry in the snap store
	// assertion list that must be passed to snapd before it can connect to
	// a snap store proxy.
	SnapStoreProxyID string

	// SnapStoreProxyURL specifies the address of the snap store proxy. If
	// specified instead of the assertions/storeID settings above, juju can
	// directly contact the proxy to retrieve the assertions and store ID.
	SnapStoreProxyURL string

	// The type of Simple Stream to download and deploy on this instance.
	ImageStream string

	// EnableOSRefreshUpdate specifies whether Juju will refresh its
	// respective OS's updates list.
	EnableOSRefreshUpdate bool

	// EnableOSUpgrade defines Juju's behavior when provisioning
	// instances. If enabled, the OS will perform any upgrades
	// available as part of its provisioning.
	EnableOSUpgrade bool

	// NetBondReconfigureDelay defines the duration in seconds that the
	// networking bridgescript should pause between ifdown, then
	// ifup when bridging bonded interfaces. See bugs #1594855 and
	// #1269921.
	NetBondReconfigureDelay int

	// Profiles is a slice of (lxd) profile names to be used by a container
	Profiles []string
	// contains filtered or unexported fields
}

InstanceConfig represents initialization information for a new juju instance.

func NewBootstrapInstanceConfig

func NewBootstrapInstanceConfig(
	config controller.Config,
	cons, modelCons constraints.Value,
	base corebase.Base, publicImageSigningKey string,
	agentEnvironment map[string]string,
) (*InstanceConfig, error)

NewBootstrapInstanceConfig 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 NewInstanceConfig

func NewInstanceConfig(
	controllerTag names.ControllerTag,
	machineID,
	machineNonce,
	imageStream string,
	base corebase.Base,
	apiInfo *api.Info,
) (*InstanceConfig, error)

NewInstanceConfig 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 (*InstanceConfig) APIHostAddrs

func (cfg *InstanceConfig) APIHostAddrs() []string

func (*InstanceConfig) APIHosts

func (cfg *InstanceConfig) APIHosts() []string

func (*InstanceConfig) AgentConfig

func (cfg *InstanceConfig) AgentConfig(
	tag names.Tag,
	toolsVersion version.Number,
) (agent.ConfigSetter, error)

func (*InstanceConfig) AgentVersion

func (cfg *InstanceConfig) AgentVersion() version.Binary

AgentVersion returns the version of the Juju agent that will be configured on the instance. The zero value will be returned if there are no tools set.

func (*InstanceConfig) CharmDir

func (cfg *InstanceConfig) CharmDir() string

CharmDir returns the directory where system charms should be uploaded to.

func (*InstanceConfig) InitService

func (cfg *InstanceConfig) InitService(renderer shell.Renderer) (service.Service, error)

func (*InstanceConfig) IsController

func (cfg *InstanceConfig) IsController() bool

func (*InstanceConfig) JujuTools

func (cfg *InstanceConfig) JujuTools() string

JujuTools returns the directory where Juju tools are stored.

func (*InstanceConfig) SetControllerCharm

func (cfg *InstanceConfig) SetControllerCharm(controllerCharmPath string) error

SetControllerCharm annotates the instance configuration with the location of a local controller charm to upload during the instance's provisioning.

func (*InstanceConfig) SetSnapSource

func (cfg *InstanceConfig) SetSnapSource(snapPath string, snapAssertionsPath string) error

SetSnapSource annotates the instance configuration with the location of a local .snap to upload during the instance's provisioning.

func (*InstanceConfig) SetTools

func (cfg *InstanceConfig) SetTools(toolsList coretools.List) error

SetTools sets the tools that should be tried when provisioning this instance. There must be at least one. Other than the URL, each item must be the same.

TODO(axw) 2016-04-19 lp:1572116 SetTools should verify that the tools have URLs, since they will be needed for downloading on the instance. We can't do that until all usage-sites are updated to pass through non-empty URLs.

func (*InstanceConfig) SnapDir

func (cfg *InstanceConfig) SnapDir() string

SnapDir returns the directory where snaps should be uploaded to.

func (*InstanceConfig) ToolsDir

func (cfg *InstanceConfig) ToolsDir(renderer shell.Renderer) string

func (*InstanceConfig) ToolsList

func (cfg *InstanceConfig) ToolsList() coretools.List

ToolsList returns the list of tools in the order in which they will be tried.

func (*InstanceConfig) VerifyConfig

func (cfg *InstanceConfig) VerifyConfig() (err error)

VerifyConfig verifies that the InstanceConfig is valid.

type ProxyConfiguration

type ProxyConfiguration struct {
	// Legacy proxy settings.
	Legacy proxy.Settings

	// Juju-specific proxy settings.
	Juju proxy.Settings

	// Apt-specific proxy settings.
	Apt proxy.Settings

	// Snap-specific proxy settings.
	Snap proxy.Settings

	// Apt mirror.
	AptMirror string

	// SnapStoreAssertions contains a list of assertions that must be
	// passed to snapd together with a store proxy ID parameter before it
	// can connect to a snap store proxy.
	SnapStoreAssertions string

	// SnapStoreProxyID references a store entry in the snap store
	// assertion list that must be passed to snapd before it can connect to
	// a snap store proxy.
	SnapStoreProxyID string

	// SnapStoreProxyURL specifies the address of the snap store proxy. If
	// specified instead of the assertions/storeID settings above, juju can
	// directly contact the proxy to retrieve the assertions and store ID.
	SnapStoreProxyURL string
}

ProxyConfiguration encapsulates all proxy-related settings that can be used to populate an InstanceConfig.

type SSHHostKeys

type SSHHostKeys []SSHKeyPair

SSHHostKeys contains the SSH host keys to configure for a bootstrap host.

type SSHKeyPair

type SSHKeyPair struct {
	// Private contains the private key, PEM-encoded.
	Private string

	// Public contains the public key in authorized_keys format.
	Public string

	// PublicKeyAlgorithm contains the public key algorithm as defined by golang.org/x/crypto/ssh KeyAlgo*
	PublicKeyAlgorithm string
}

SSHKeyPair is an SSH host key pair.

type StateInitializationParams

type StateInitializationParams struct {
	// ControllerModelConfig holds the initial controller model configuration.
	ControllerModelConfig *config.Config

	// ControllerModelEnvironVersion holds the initial controller model
	// environ version.
	ControllerModelEnvironVersion int

	// ControllerCloud contains the properties of the cloud that Juju will
	// be bootstrapped in.
	ControllerCloud cloud.Cloud

	// ControllerCloudRegion is the name of the cloud region that Juju will be
	// bootstrapped in.
	ControllerCloudRegion string

	// ControllerCloudCredentialName is the name of the cloud credential that
	// Juju will be bootstrapped with.
	ControllerCloudCredentialName string

	// ControllerCloudCredential contains the cloud credential that Juju will
	// be bootstrapped with.
	ControllerCloudCredential *cloud.Credential

	// ControllerConfig is the set of config attributes relevant
	// to a controller.
	ControllerConfig controller.Config

	// ControllerCharmPath points to a controller charm on Charmhub.
	ControllerCharmPath string

	// ControllerCharmChannel is used when deploying the controller charm.
	ControllerCharmChannel charm.Channel

	// ControllerInheritedConfig is a set of config attributes to be shared by all
	// models managed by this controller.
	ControllerInheritedConfig map[string]interface{}

	// RegionInheritedConfig holds region specific configuration attributes to
	// be shared across all models in the same controller on a particular
	// cloud.
	RegionInheritedConfig cloud.RegionConfig

	// InitialModelConfig is a set of config attributes to be overlaid
	// on the controller model config (Config, above) to construct the
	// initial hosted model config.
	InitialModelConfig map[string]interface{}

	// BootstrapMachineInstanceId is the instance ID of the bootstrap
	// machine instance being initialized.
	BootstrapMachineInstanceId instance.Id

	// BootstrapMachineDisplayName is the human readable name for
	// the bootstrap machine instance being initialized.
	BootstrapMachineDisplayName string

	// BootstrapMachineConstraints holds the constraints for the bootstrap
	// machine.
	BootstrapMachineConstraints constraints.Value

	// BootstrapMachineHardwareCharacteristics contains the hardware
	// characteristics of the bootstrap machine instance being initialized.
	BootstrapMachineHardwareCharacteristics *instance.HardwareCharacteristics

	// ModelConstraints holds the initial model constraints.
	ModelConstraints constraints.Value

	// CustomImageMetadata is optional custom simplestreams image metadata
	// to store in environment storage at bootstrap time. This is ignored
	// in non-bootstrap instances.
	CustomImageMetadata []*imagemetadata.ImageMetadata

	// StoragePools is one or more named storage pools to create
	// in the controller model.
	StoragePools map[string]storage.Attrs
}

StateInitializationParams contains parameters for initializing the state database.

This structure will be passed to the bootstrap agent. To do so, the Marshal and Unmarshal methods must be used.

func (*StateInitializationParams) Marshal

func (p *StateInitializationParams) Marshal() ([]byte, error)

Marshal marshals StateInitializationParams to an opaque byte array.

func (*StateInitializationParams) Unmarshal

func (p *StateInitializationParams) Unmarshal(data []byte) error

Unmarshal unmarshals StateInitializationParams from a byte array that was generated with StateInitializationParams.Marshal.

Jump to

Keyboard shortcuts

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