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

Side by Side Diff: provider/null/provider.go

Issue 13255051: Introduce the null provider
Patch Set: Introduce the null provider Created 11 years, 6 months 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
« no previous file with comments | « provider/null/instance.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details.
3
4 package null
5
6 import (
7 "errors"
8 "fmt"
9
10 "launchpad.net/juju-core/environs"
11 "launchpad.net/juju-core/environs/config"
12 "launchpad.net/juju-core/provider"
13 "launchpad.net/juju-core/utils"
14 )
15
16 type nullProvider struct{}
17
18 func init() {
19 environs.RegisterProvider(provider.Null, nullProvider{})
20 }
21
22 var errNoBootstrapHost = errors.New("bootstrap-host must be specified")
23
24 func (p nullProvider) Prepare(cfg *config.Config) (environs.Environ, error) {
25 return p.Open(cfg)
26 }
27
28 func (p nullProvider) Open(cfg *config.Config) (environs.Environ, error) {
29 envConfig, err := p.validate(cfg, nil)
30 if err != nil {
31 return nil, err
32 }
33 return &nullEnviron{cfg: envConfig}, nil
34 }
35
36 func checkImmutableString(cfg, old *environConfig, key string) error {
37 if old.attrs[key] != cfg.attrs[key] {
38 return fmt.Errorf("cannot change %s from %q to %q", key, old.att rs[key], cfg.attrs[key])
39 }
40 return nil
41 }
42
43 func (p nullProvider) validate(cfg, old *config.Config) (*environConfig, error) {
44 // Check for valid changes for the base config values.
45 if err := config.Validate(cfg, old); err != nil {
46 return nil, err
47 }
48 validated, err := cfg.ValidateUnknownAttrs(configFields, configDefaults)
49 if err != nil {
50 return nil, err
51 }
52 envConfig := newEnvironConfig(cfg, validated)
53 if envConfig.bootstrapHost() == "" {
54 return nil, errNoBootstrapHost
55 }
56 // Check various immutable attributes.
57 if old != nil {
58 oldEnvConfig, err := p.validate(old, nil)
59 if err != nil {
60 return nil, err
61 }
62 for _, key := range [...]string{
63 "bootstrap-user",
64 "bootstrap-host",
65 "storage-listen-ip",
66 } {
67 if err = checkImmutableString(envConfig, oldEnvConfig, k ey); err != nil {
68 return nil, err
69 }
70 }
71 oldPort, newPort := oldEnvConfig.storagePort(), envConfig.storag ePort()
72 if oldPort != newPort {
73 return nil, fmt.Errorf("cannot change storage-port from %q to %q", oldPort, newPort)
74 }
75 }
76 return envConfig, nil
77 }
78
79 func (p nullProvider) Validate(cfg, old *config.Config) (valid *config.Config, e rr error) {
80 envConfig, err := p.validate(cfg, old)
81 if err != nil {
82 return nil, err
83 }
84 return cfg.Apply(envConfig.attrs)
85 }
86
87 func (_ nullProvider) BoilerplateConfig() string {
88 return `
89 "null":
90 type: "null"
91 admin-secret: {{rand}}
92 ## set bootstrap-host to the host where the bootstrap machine agent
93 ## should be provisioned.
94 bootstrap-host:
95 ## set the login user to bootstrap the machine as. If left blank,
96 ## juju will connect to the bootstrap machine as the current user.
97 # bootstrap-user:
98 ## set the IP address for the bootstrap machine to listen on for
99 ## storage requests. If left blank, storage will be served on all
100 ## network interfaces.
101 # storage-listen-ip:
102 # storage-port: 8040
103 `
104 }
105
106 func (_ nullProvider) SecretAttrs(cfg *config.Config) (map[string]interface{}, e rror) {
107 return make(map[string]interface{}), nil
108 }
109
110 func (_ nullProvider) PublicAddress() (string, error) {
111 // TODO(axw) 2013-09-10 bug #1222643
112 //
113 // eth0 may not be the desired interface for traffic to route
114 // through. We should somehow make this configurable, and
115 // possibly also record the IP resolved during manual bootstrap.
116 return utils.GetAddressForInterface("eth0")
117 }
118
119 func (p nullProvider) PrivateAddress() (string, error) {
120 return p.PublicAddress()
121 }
OLDNEW
« no previous file with comments | « provider/null/instance.go ('k') | no next file » | no next file with comments »

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