cloudinit

package
v0.0.0-...-f19ae85 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2015 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

The cloudinit package implements a way of creating a cloud-init configuration file. See https://help.ubuntu.com/community/CloudInit.

Index

Examples

Constants

View Source
const CloudToolsPrefsPath = "/etc/apt/preferences.d/50-cloud-tools"

CloudToolsPrefsPath defines the default location of apt_preferences(5) file for the cloud-tools pocket.

Variables

This section is empty.

Functions

func InitProgressCmd

func InitProgressCmd() string

InitProgressCmd will return a command to initialise progress reporting, sending messages to stderr. If LogProgressCmd is used in a script, InitProgressCmd MUST be executed beforehand.

The returned command is idempotent; this is important, to allow a script to be embedded in another with stderr redirected, in which case InitProgressCmd must precede the redirection.

func LogProgressCmd

func LogProgressCmd(format string, args ...interface{}) string

LogProgressCmd will return a command to log the specified progress message to stderr; the resultant command should be added to the configuration as a runcmd or bootcmd as appropriate.

If there are any uses of LogProgressCmd in a configuration, the configuration MUST precede the command with the result of InitProgressCmd.

Types

type AptGetWrapper

type AptGetWrapper struct {
	Command string
	Enabled interface{} // true, false or "auto"
}

AptGetWrapper describes a wrapper command for running apt-get.

type AptPreferences

type AptPreferences struct {
	Path        string
	Explanation string
	Package     string
	Pin         string
	PinPriority int
}

AptPreferences is a set of apt_preferences(5) compatible preferences for an apt source. It can be used to override the default priority for the source. Path where the file will be created (usually in /etc/apt/preferences.d/).

func (*AptPreferences) FileContents

func (prefs *AptPreferences) FileContents() string

FileContents generates an apt_preferences(5) file from the fields in prefs.

type AptSource

type AptSource struct {
	Source string          `yaml:"source"`
	Key    string          `yaml:"key,omitempty"`
	Prefs  *AptPreferences `yaml:"-"`
}

AptSource is an apt(8) source, comprising a source location, with an optional Key, and optional apt_preferences(5).

type Config

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

Config represents a set of cloud-init configuration options.

Example

#cloud-config packages: - juju - ubuntu

package main

import (
	"fmt"

	"github.com/juju/juju/cloudinit"
)

func main() {
	cfg := cloudinit.New()
	cfg.AddPackage("juju")
	cfg.AddPackage("ubuntu")
	renderer, err := cloudinit.NewRenderer("quantal")
	if err != nil {
		fmt.Printf("render error: %v", err)
		return
	}
	data, err := renderer.Render(cfg)
	if err != nil {
		fmt.Printf("render error: %v", err)
		return
	}
	fmt.Printf("%s", data)
}
Output:

func New

func New() *Config

New returns a new Config with no options set.

func (*Config) AddAptSource

func (cfg *Config) AddAptSource(name, key string, prefs *AptPreferences)

AddAptSource adds an apt source. The key holds the public key of the source, in the form expected by apt-key(8).

func (*Config) AddBinaryFile

func (cfg *Config) AddBinaryFile(filename string, data []byte, mode uint)

AddBinaryFile will add multiple run_cmd entries to safely set the contents of a specific file to the requested contents.

func (*Config) AddBootCmd

func (cfg *Config) AddBootCmd(cmd string)

AddBootCmd is like AddRunCmd except that the command will run very early in the boot process, and it will run on every boot, not just the first time.

func (*Config) AddBootCmdArgs

func (cfg *Config) AddBootCmdArgs(args ...string)

AddBootCmdArgs is like AddBootCmd except that the command will be executed with the given arguments properly quoted.

func (*Config) AddBootTextFile

func (cfg *Config) AddBootTextFile(filename, data string, mode uint)

AddBootTextFile will add multiple bootcmd entries to safely set the contents of a specific file to the requested contents early in the boot process.

func (*Config) AddMount

func (cfg *Config) AddMount(args ...string)

AddMount adds a mount point. The given arguments will be used as a line in /etc/fstab.

func (*Config) AddPackage

func (cfg *Config) AddPackage(name string)

AddPackage adds a package to be installed on first boot. If any packages are specified, "apt-get update" will be called.

func (*Config) AddPackageFromTargetRelease

func (cfg *Config) AddPackageFromTargetRelease(packageName, targetRelease string)

AddPackageFromTargetRelease adds a package to be installed using the given release, passed to apt-get with the --target-release argument.

func (*Config) AddRunCmd

func (cfg *Config) AddRunCmd(cmd string)

AddRunCmd adds a command to be executed at first boot. The command will be run by the shell with any metacharacters retaining their special meaning (that is, no quoting takes place).

func (*Config) AddRunCmdArgs

func (cfg *Config) AddRunCmdArgs(args ...string)

AddRunCmdArgs is like AddRunCmd except that the command will be executed with the given arguments properly quoted.

func (*Config) AddSSHAuthorizedKeys

func (cfg *Config) AddSSHAuthorizedKeys(keyData string)

AddSSHAuthorizedKeys adds a set of keys in ssh authorized_keys format (see ssh(8) for details) that will be added to ~/.ssh/authorized_keys for the configured user (see SetUser).

func (*Config) AddSSHKey

func (cfg *Config) AddSSHKey(keyType SSHKeyType, keyData string)

AddSSHKey adds a pre-generated ssh key to the server keyring. Keys that are added like this will be written to /etc/ssh and new random keys will not be generated.

func (*Config) AddScripts

func (cfg *Config) AddScripts(scripts ...string)

AddScripts is a simple shorthand for calling AddRunCmd multiple times.

func (*Config) AddTextFile

func (cfg *Config) AddTextFile(filename, data string, mode uint)

AddTextFile will add multiple run_cmd entries to safely set the contents of a specific file to the requested contents.

func (*Config) AptGetWrapper

func (cfg *Config) AptGetWrapper() AptGetWrapper

AptGetWrapper returns the value set by SetAptGetWrapper, or a zero AptGetWrapper struct if no call to SetAptGetWrapper has been made.

func (*Config) AptMirror

func (cfg *Config) AptMirror() (string, bool)

AptMirror returns the value set by SetAptMirror, and a boolean flag indicating whether the mirror has been set.

func (*Config) AptSources

func (cfg *Config) AptSources() []*AptSource

AptSources returns the apt sources added with AddAptSource.

func (*Config) AptUpdate

func (cfg *Config) AptUpdate() bool

AptUpdate returns the value set by SetAptUpdate, or false if no call to SetAptUpdate has been made.

func (*Config) AptUpgrade

func (cfg *Config) AptUpgrade() bool

AptUpgrade returns the value set by SetAptUpgrade, or false if no call to SetAptUpgrade has been made.

func (*Config) BootCmds

func (cfg *Config) BootCmds() []interface{}

BootCmds returns a list of commands added with AddBootCmd*.

Each element in the resultant slice is either a string or []string, corresponding to how the command was added.

func (*Config) Output

func (cfg *Config) Output(kind OutputKind) (stdout, stderr string)

Output returns the output destination passed to SetOutput for the specified output kind.

func (*Config) Packages

func (cfg *Config) Packages() []string

Packages returns a list of packages that will be installed on first boot.

func (*Config) RunCmds

func (cfg *Config) RunCmds() []interface{}

RunCmds returns a list of commands that will be run at first boot.

Each element in the resultant slice is either a string or []string, corresponding to how the command was added.

func (*Config) SetAptGetWrapper

func (cfg *Config) SetAptGetWrapper(wrapper string)

SetAptGetWrapper sets a wrapper program for "apt-get". If the command does not exist, the wrapper will be ignored.

Note: support for apt_get_wrapper was introduced in cloud-init 0.7.5, and will not be honoured by older versions.

func (*Config) SetAptMirror

func (cfg *Config) SetAptMirror(url string)

SetAptMirror sets the URL to be used as the apt mirror site. If not set, the URL is selected based on cloud metadata in EC2 - <region>.archive.ubuntu.com

func (*Config) SetAptPreserveSourcesList

func (cfg *Config) SetAptPreserveSourcesList(yes bool)

SetAptPreserveSourcesList sets whether /etc/apt/sources.list is overwritten by the mirror. If true, SetAptMirror above will have no effect.

func (*Config) SetAptProxy

func (cfg *Config) SetAptProxy(url string)

SetAptProxy sets the URL to be used as the apt proxy.

func (*Config) SetAptUpdate

func (cfg *Config) SetAptUpdate(yes bool)

SetAptUpdate sets whether cloud-init runs "apt-get update" on first boot.

func (*Config) SetAptUpgrade

func (cfg *Config) SetAptUpgrade(yes bool)

SetAptUpgrade sets whether cloud-init runs "apt-get upgrade" on first boot.

func (*Config) SetAttr

func (cfg *Config) SetAttr(name string, value interface{})

SetAttr sets an arbitrary attribute in the cloudinit config. If value is nil the attribute will be deleted; otherwise the value will be marshalled according to the rules of the goyaml Marshal function.

func (*Config) SetDebconfSelections

func (cfg *Config) SetDebconfSelections(answers string)

SetDebconfSelections provides preseeded debconf answers for the boot process. The given answers will be used as input to debconf-set-selections(1).

func (*Config) SetDisableEC2Metadata

func (cfg *Config) SetDisableEC2Metadata(yes bool)

SetDisableEC2Metadata sets whether access to the EC2 metadata service is disabled early in boot via a null route ( route del -host 169.254.169.254 reject).

func (*Config) SetDisableRoot

func (cfg *Config) SetDisableRoot(disable bool)

SetDisableRoot sets whether ssh login is disabled to the root account via the ssh authorized key associated with the instance metadata. It is true by default.

func (*Config) SetFinalMessage

func (cfg *Config) SetFinalMessage(msg string)

SetFinalMessage sets to message that will be written when the system has finished booting for the first time. By default, the message is: "cloud-init boot finished at $TIMESTAMP. Up $UPTIME seconds".

func (*Config) SetLocale

func (cfg *Config) SetLocale(locale string)

SetLocale sets the locale; it defaults to en_US.UTF-8.

func (*Config) SetOutput

func (cfg *Config) SetOutput(kind OutputKind, stdout, stderr string)

SetOutput specifies destination for command output. Valid values for the kind "init", "config", "final" and "all". Each of stdout and stderr can take one of the following forms:

>>file
    appends to file
>file
    overwrites file
|command
    pipes to the given command.

func (*Config) SetUser

func (cfg *Config) SetUser(user string)

SetUser sets the user name that will be used for some other options. The user will be assumed to already exist in the machine image. The default user is "ubuntu".

type OutputKind

type OutputKind string

OutputKind represents a destination for command output.

const (
	OutInit   OutputKind = "init"
	OutConfig OutputKind = "config"
	OutFinal  OutputKind = "final"
	OutAll    OutputKind = "all"
)

type Renderer

type Renderer interface {

	// Mkdir returns an OS specific script for creating a directory
	Mkdir(path string) []string

	// WriteFile returns a command to write data
	WriteFile(filename string, contents string, permission int) []string

	// Render renders the userdata script for a particular OS type
	Render(conf *Config) ([]byte, error)

	FromSlash(path string) string

	PathJoin(path ...string) string
}

func NewRenderer

func NewRenderer(series string) (Renderer, error)

NewRenderer returns a Renderer interface for selected series

type SSHKeyType

type SSHKeyType string
const (
	RSAPrivate SSHKeyType = "rsa_private"
	RSAPublic  SSHKeyType = "rsa_public"
	DSAPrivate SSHKeyType = "dsa_private"
	DSAPublic  SSHKeyType = "dsa_public"
)

type UbuntuRenderer

type UbuntuRenderer struct{}

UbuntuRenderer represents an Ubuntu specific script render type that is responsible for this particular OS. It implements the Renderer interface

func (*UbuntuRenderer) FromSlash

func (w *UbuntuRenderer) FromSlash(filepath string) string

func (*UbuntuRenderer) Mkdir

func (w *UbuntuRenderer) Mkdir(path string) []string

func (*UbuntuRenderer) PathJoin

func (w *UbuntuRenderer) PathJoin(filepath ...string) string

func (*UbuntuRenderer) Render

func (w *UbuntuRenderer) Render(conf *Config) ([]byte, error)

func (*UbuntuRenderer) WriteFile

func (w *UbuntuRenderer) WriteFile(filename string, contents string, permission int) []string

type WindowsRenderer

type WindowsRenderer struct{}

WindowsRenderer represents a Windows specific script render type that is responsible for this particular OS. It implements the Renderer interface

func (*WindowsRenderer) FromSlash

func (w *WindowsRenderer) FromSlash(path string) string

func (*WindowsRenderer) Mkdir

func (w *WindowsRenderer) Mkdir(path string) []string

func (*WindowsRenderer) PathJoin

func (w *WindowsRenderer) PathJoin(filepath ...string) string

func (*WindowsRenderer) Render

func (w *WindowsRenderer) Render(conf *Config) ([]byte, error)

func (*WindowsRenderer) WriteFile

func (w *WindowsRenderer) WriteFile(filename string, contents string, permission int) []string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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