~juju-qa/ubuntu/yakkety/juju/2.0-rc3-again

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/cloudinit/cloudinit.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-04-24 22:34:47 UTC
  • Revision ID: package-import@ubuntu.com-20130424223447-f0qdji7ubnyo0s71
Tags: upstream-1.10.0.1
ImportĀ upstreamĀ versionĀ 1.10.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// The cloudinit package implements a way of creating
 
2
// a cloud-init configuration file.
 
3
// See https://help.ubuntu.com/community/CloudInit.
 
4
package cloudinit
 
5
 
 
6
import (
 
7
        yaml "launchpad.net/goyaml"
 
8
)
 
9
 
 
10
// Config represents a set of cloud-init configuration options.
 
11
type Config struct {
 
12
        attrs map[string]interface{}
 
13
}
 
14
 
 
15
// New returns a new Config with no options set.
 
16
func New() *Config {
 
17
        return &Config{make(map[string]interface{})}
 
18
}
 
19
 
 
20
// Render returns the cloud-init configuration as a YAML file.
 
21
func (cfg *Config) Render() ([]byte, error) {
 
22
        data, err := yaml.Marshal(cfg.attrs)
 
23
        if err != nil {
 
24
                return nil, err
 
25
        }
 
26
        return append([]byte("#cloud-config\n"), data...), nil
 
27
}
 
28
 
 
29
func (cfg *Config) set(opt string, yes bool, value interface{}) {
 
30
        if yes {
 
31
                cfg.attrs[opt] = value
 
32
        } else {
 
33
                delete(cfg.attrs, opt)
 
34
        }
 
35
}
 
36
 
 
37
// source is Key, or KeyId and KeyServer
 
38
type source struct {
 
39
        Source    string `yaml:"source"`
 
40
        Key       string `yaml:"key,omitempty"`
 
41
        KeyId     string `yaml:"keyid,omitempty"`
 
42
        KeyServer string `yaml:"keyserver,omitempty"`
 
43
}
 
44
 
 
45
// command represents a shell command.
 
46
type command struct {
 
47
        literal string
 
48
        args    []string
 
49
}
 
50
 
 
51
// GetYAML implements yaml.Getter
 
52
func (t *command) GetYAML() (tag string, value interface{}) {
 
53
        if t.args != nil {
 
54
                return "", t.args
 
55
        }
 
56
        return "", t.literal
 
57
}
 
58
 
 
59
type SSHKeyType string
 
60
 
 
61
const (
 
62
        RSAPrivate SSHKeyType = "rsa_private"
 
63
        RSAPublic  SSHKeyType = "rsa_public"
 
64
        DSAPrivate SSHKeyType = "dsa_private"
 
65
        DSAPublic  SSHKeyType = "dsa_public"
 
66
)