-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudinit.go
97 lines (84 loc) · 2.3 KB
/
cloudinit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2011, 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
// The cloudinit package implements a way of creating
// a cloud-init configuration file.
// See https://help.ubuntu.com/community/CloudInit.
package cloudinit
import (
"bytes"
"text/template"
)
// Config represents a set of cloud-init configuration options.
type Config struct {
attrs map[string]interface{}
}
// New returns a new Config with no options set.
func New() *Config {
return &Config{make(map[string]interface{})}
}
func (cfg *Config) set(opt string, yes bool, value interface{}) {
if yes {
cfg.attrs[opt] = value
} else {
delete(cfg.attrs, opt)
}
}
// AptSource is an apt(8) source, comprising a source location,
// with an optional Key, and optional apt_preferences(5).
type AptSource struct {
Source string `yaml:"source"`
Key string `yaml:"key,omitempty"`
Prefs *AptPreferences `yaml:"-"`
}
// AptGetWrapper describes a wrapper command for running apt-get.
type AptGetWrapper struct {
Command string
Enabled interface{} // true, false or "auto"
}
// 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/).
type AptPreferences struct {
Path string
Explanation string
Package string
Pin string
PinPriority int
}
// FileContents generates an apt_preferences(5) file from the fields
// in prefs.
func (prefs *AptPreferences) FileContents() string {
const prefTemplate = `
Explanation: {{.Explanation}}
Package: {{.Package}}
Pin: {{.Pin}}
Pin-Priority: {{.PinPriority}}
`
var buf bytes.Buffer
t := template.Must(template.New("").Parse(prefTemplate[1:]))
err := t.Execute(&buf, prefs)
if err != nil {
panic(err)
}
return buf.String()
}
// command represents a shell command.
type command struct {
literal string
args []string
}
// GetYAML implements yaml.Getter
func (t *command) GetYAML() (tag string, value interface{}) {
if t.args != nil {
return "", t.args
}
return "", t.literal
}
type SSHKeyType string
const (
RSAPrivate SSHKeyType = "rsa_private"
RSAPublic SSHKeyType = "rsa_public"
DSAPrivate SSHKeyType = "dsa_private"
DSAPublic SSHKeyType = "dsa_public"
)