Documentation ¶
Overview ¶
The cloudinit package implements a way of creating a cloud-init configuration file. See https://help.ubuntu.com/community/CloudInit.
Index ¶
- Constants
- func InitProgressCmd() string
- func LogProgressCmd(format string, args ...interface{}) string
- type AptGetWrapper
- type AptPreferences
- type AptSource
- type Config
- func (cfg *Config) AddAptSource(name, key string, prefs *AptPreferences)
- func (cfg *Config) AddBinaryFile(filename string, data []byte, mode uint)
- func (cfg *Config) AddBootCmd(cmd string)
- func (cfg *Config) AddBootCmdArgs(args ...string)
- func (cfg *Config) AddBootTextFile(filename, data string, mode uint)
- func (cfg *Config) AddMount(args ...string)
- func (cfg *Config) AddPackage(name string)
- func (cfg *Config) AddPackageFromTargetRelease(packageName, targetRelease string)
- func (cfg *Config) AddRunCmd(cmd string)
- func (cfg *Config) AddRunCmdArgs(args ...string)
- func (cfg *Config) AddSSHAuthorizedKeys(keyData string)
- func (cfg *Config) AddSSHKey(keyType SSHKeyType, keyData string)
- func (cfg *Config) AddScripts(scripts ...string)
- func (cfg *Config) AddTextFile(filename, data string, mode uint)
- func (cfg *Config) AptGetWrapper() AptGetWrapper
- func (cfg *Config) AptMirror() (string, bool)
- func (cfg *Config) AptSources() []*AptSource
- func (cfg *Config) AptUpdate() bool
- func (cfg *Config) AptUpgrade() bool
- func (cfg *Config) BootCmds() []interface{}
- func (cfg *Config) Output(kind OutputKind) (stdout, stderr string)
- func (cfg *Config) Packages() []string
- func (cfg *Config) RunCmds() []interface{}
- func (cfg *Config) SetAptGetWrapper(wrapper string)
- func (cfg *Config) SetAptMirror(url string)
- func (cfg *Config) SetAptPreserveSourcesList(yes bool)
- func (cfg *Config) SetAptProxy(url string)
- func (cfg *Config) SetAptUpdate(yes bool)
- func (cfg *Config) SetAptUpgrade(yes bool)
- func (cfg *Config) SetAttr(name string, value interface{})
- func (cfg *Config) SetDebconfSelections(answers string)
- func (cfg *Config) SetDisableEC2Metadata(yes bool)
- func (cfg *Config) SetDisableRoot(disable bool)
- func (cfg *Config) SetFinalMessage(msg string)
- func (cfg *Config) SetLocale(locale string)
- func (cfg *Config) SetOutput(kind OutputKind, stdout, stderr string)
- func (cfg *Config) SetUser(user string)
- type OutputKind
- type Renderer
- type SSHKeyType
- type UbuntuRenderer
- func (w *UbuntuRenderer) FromSlash(filepath string) string
- func (w *UbuntuRenderer) Mkdir(path string) []string
- func (w *UbuntuRenderer) PathJoin(filepath ...string) string
- func (w *UbuntuRenderer) Render(conf *Config) ([]byte, error)
- func (w *UbuntuRenderer) WriteFile(filename string, contents string, permission int) []string
- type WindowsRenderer
- func (w *WindowsRenderer) FromSlash(path string) string
- func (w *WindowsRenderer) Mkdir(path string) []string
- func (w *WindowsRenderer) PathJoin(filepath ...string) string
- func (w *WindowsRenderer) Render(conf *Config) ([]byte, error)
- func (w *WindowsRenderer) WriteFile(filename string, contents string, permission int) []string
Examples ¶
Constants ¶
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 ¶
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 (*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 ¶
AddBinaryFile will add multiple run_cmd entries to safely set the contents of a specific file to the requested contents.
func (*Config) AddBootCmd ¶
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 ¶
AddBootCmdArgs is like AddBootCmd except that the command will be executed with the given arguments properly quoted.
func (*Config) AddBootTextFile ¶
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 ¶
AddMount adds a mount point. The given arguments will be used as a line in /etc/fstab.
func (*Config) AddPackage ¶
AddPackage adds a package to be installed on first boot. If any packages are specified, "apt-get update" will be called.
func (*Config) AddPackageFromTargetRelease ¶
AddPackageFromTargetRelease adds a package to be installed using the given release, passed to apt-get with the --target-release argument.
func (*Config) AddRunCmd ¶
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 ¶
AddRunCmdArgs is like AddRunCmd except that the command will be executed with the given arguments properly quoted.
func (*Config) AddSSHAuthorizedKeys ¶
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 ¶
AddScripts is a simple shorthand for calling AddRunCmd multiple times.
func (*Config) AddTextFile ¶
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 ¶
AptMirror returns the value set by SetAptMirror, and a boolean flag indicating whether the mirror has been set.
func (*Config) AptSources ¶
AptSources returns the apt sources added with AddAptSource.
func (*Config) AptUpdate ¶
AptUpdate returns the value set by SetAptUpdate, or false if no call to SetAptUpdate has been made.
func (*Config) AptUpgrade ¶
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) 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 ¶
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 ¶
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 ¶
SetAptPreserveSourcesList sets whether /etc/apt/sources.list is overwritten by the mirror. If true, SetAptMirror above will have no effect.
func (*Config) SetAptProxy ¶
SetAptProxy sets the URL to be used as the apt proxy.
func (*Config) SetAptUpdate ¶
SetAptUpdate sets whether cloud-init runs "apt-get update" on first boot.
func (*Config) SetAptUpgrade ¶
SetAptUpgrade sets whether cloud-init runs "apt-get upgrade" on first boot.
func (*Config) SetAttr ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) 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.
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 ¶
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
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