Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2136)

Side by Side Diff: cloudinit/cloudinit.go

Issue 61410051: Fixed bug #1240667: pin priority for cloud-tools (Closed)
Patch Set: Fixed bug #1240667: pin priority for cloud-tools Created 11 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2011, 2013 Canonical Ltd. 1 // Copyright 2011, 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 // The cloudinit package implements a way of creating 4 // The cloudinit package implements a way of creating
5 // a cloud-init configuration file. 5 // a cloud-init configuration file.
6 // See https://help.ubuntu.com/community/CloudInit. 6 // See https://help.ubuntu.com/community/CloudInit.
7 package cloudinit 7 package cloudinit
8 8
9 import ( 9 import (
10 "bytes"
11 "text/template"
12
10 yaml "launchpad.net/goyaml" 13 yaml "launchpad.net/goyaml"
11 ) 14 )
12 15
13 // Config represents a set of cloud-init configuration options. 16 // Config represents a set of cloud-init configuration options.
14 type Config struct { 17 type Config struct {
15 attrs map[string]interface{} 18 attrs map[string]interface{}
16 } 19 }
17 20
18 // New returns a new Config with no options set. 21 // New returns a new Config with no options set.
19 func New() *Config { 22 func New() *Config {
(...skipping 11 matching lines...) Expand all
31 34
32 func (cfg *Config) set(opt string, yes bool, value interface{}) { 35 func (cfg *Config) set(opt string, yes bool, value interface{}) {
33 if yes { 36 if yes {
34 cfg.attrs[opt] = value 37 cfg.attrs[opt] = value
35 } else { 38 } else {
36 delete(cfg.attrs, opt) 39 delete(cfg.attrs, opt)
37 } 40 }
38 } 41 }
39 42
40 // AptSource is an apt(8) source, comprising a source location, 43 // AptSource is an apt(8) source, comprising a source location,
41 // with an optional Key. 44 // with an optional Key, and optional apt_preferences(5).
42 type AptSource struct { 45 type AptSource struct {
43 » Source string `yaml:"source"` 46 » Source string `yaml:"source"`
44 » Key string `yaml:"key,omitempty"` 47 » Key string `yaml:"key,omitempty"`
48 » Prefs *AptPreferences `yaml:"-"`
49 }
50
51 // AptPreferences is a set of apt_preferences(5) compatible
52 // preferences for an apt source. It can be used to override the
53 // default priority for the source. Path where the file will be
54 // created (usually in /etc/apt/preferences.d/).
55 type AptPreferences struct {
56 » Path string
57 » Explanation string
58 » Package string
59 » Pin string
60 » PinPriority int
61 }
62
63 // FileContents generates an apt_preferences(5) file from the fields
64 // in prefs.
65 func (prefs *AptPreferences) FileContents() string {
66 » const prefTemplate = `
67 Explanation: {{.Explanation}}
68 Package: {{.Package}}
69 Pin: {{.Pin}}
70 Pin-Priority: {{.PinPriority}}
71 `
72 » var buf bytes.Buffer
73 » t := template.Must(template.New("").Parse(prefTemplate[1:]))
74 » err := t.Execute(&buf, prefs)
75 » if err != nil {
76 » » panic(err)
77 » }
78 » return buf.String()
45 } 79 }
46 80
47 // command represents a shell command. 81 // command represents a shell command.
48 type command struct { 82 type command struct {
49 literal string 83 literal string
50 args []string 84 args []string
51 } 85 }
52 86
53 // GetYAML implements yaml.Getter 87 // GetYAML implements yaml.Getter
54 func (t *command) GetYAML() (tag string, value interface{}) { 88 func (t *command) GetYAML() (tag string, value interface{}) {
55 if t.args != nil { 89 if t.args != nil {
56 return "", t.args 90 return "", t.args
57 } 91 }
58 return "", t.literal 92 return "", t.literal
59 } 93 }
60 94
61 type SSHKeyType string 95 type SSHKeyType string
62 96
63 const ( 97 const (
64 RSAPrivate SSHKeyType = "rsa_private" 98 RSAPrivate SSHKeyType = "rsa_private"
65 RSAPublic SSHKeyType = "rsa_public" 99 RSAPublic SSHKeyType = "rsa_public"
66 DSAPrivate SSHKeyType = "dsa_private" 100 DSAPrivate SSHKeyType = "dsa_private"
67 DSAPublic SSHKeyType = "dsa_public" 101 DSAPublic SSHKeyType = "dsa_public"
68 ) 102 )
OLDNEW
« no previous file with comments | « [revision details] ('k') | cloudinit/cloudinit_test.go » ('j') | cloudinit/options.go » ('J')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b