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

Delta Between Two Patch Sets: environs/maas/environ.go

Issue 9641044: Make the API address easily accessible by charms
Left Patch Set: Created 11 years, 9 months ago
Right Patch Set: Make the API address easily accessible by charms Created 11 years, 9 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:
Right: Side by side diff | Download
« no previous file with change/comment | « environs/ec2/ec2.go ('k') | environs/maas/environ_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2013 Canonical Ltd. 1 // Copyright 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 package maas 4 package maas
5 5
6 import ( 6 import (
7 "encoding/base64" 7 "encoding/base64"
8 "errors" 8 "errors"
9 "fmt" 9 "fmt"
10 "launchpad.net/gomaasapi" 10 "launchpad.net/gomaasapi"
11 "launchpad.net/juju-core/constraints" 11 "launchpad.net/juju-core/constraints"
12 "launchpad.net/juju-core/environs" 12 "launchpad.net/juju-core/environs"
13 "launchpad.net/juju-core/environs/cloudinit" 13 "launchpad.net/juju-core/environs/cloudinit"
14 "launchpad.net/juju-core/environs/config" 14 "launchpad.net/juju-core/environs/config"
15 "launchpad.net/juju-core/environs/tools" 15 "launchpad.net/juju-core/environs/tools"
16 "launchpad.net/juju-core/log" 16 "launchpad.net/juju-core/log"
17 "launchpad.net/juju-core/state" 17 "launchpad.net/juju-core/state"
18 "launchpad.net/juju-core/state/api" 18 "launchpad.net/juju-core/state/api"
19 "launchpad.net/juju-core/state/api/params" 19 "launchpad.net/juju-core/state/api/params"
20 "launchpad.net/juju-core/utils" 20 "launchpad.net/juju-core/utils"
21 "net/url" 21 "net/url"
22 "sync" 22 "sync"
23 "time" 23 "time"
24 ) 24 )
25 25
26 const ( 26 const (
27 mgoPort = 37017
28 apiPort = 17070
29 jujuDataDir = "/var/lib/juju" 27 jujuDataDir = "/var/lib/juju"
30 // We're using v1.0 of the MAAS API. 28 // We're using v1.0 of the MAAS API.
31 apiVersion = "1.0" 29 apiVersion = "1.0"
32 ) 30 )
33 31
34 var mgoPortSuffix = fmt.Sprintf(":%d", mgoPort)
35 var apiPortSuffix = fmt.Sprintf(":%d", apiPort)
36
37 var longAttempt = utils.AttemptStrategy{ 32 var longAttempt = utils.AttemptStrategy{
38 Total: 3 * time.Minute, 33 Total: 3 * time.Minute,
39 Delay: 1 * time.Second, 34 Delay: 1 * time.Second,
40 } 35 }
41 36
42 type maasEnviron struct { 37 type maasEnviron struct {
43 name string 38 name string
44 39
45 // ecfgMutex protects the *Unlocked fields below. 40 // ecfgMutex protects the *Unlocked fields below.
46 ecfgMutex sync.Mutex 41 ecfgMutex sync.Mutex
(...skipping 20 matching lines...) Expand all
67 return env, nil 62 return env, nil
68 } 63 }
69 64
70 func (env *maasEnviron) Name() string { 65 func (env *maasEnviron) Name() string {
71 return env.name 66 return env.name
72 } 67 }
73 68
74 // makeMachineConfig sets up a basic machine configuration for use with 69 // makeMachineConfig sets up a basic machine configuration for use with
75 // userData(). You may still need to supply more information, but this takes 70 // userData(). You may still need to supply more information, but this takes
76 // care of the fixed entries and the ones that are always needed. 71 // care of the fixed entries and the ones that are always needed.
77 func (env *maasEnviron) makeMachineConfig(machineID, machineNonce string, stateI nfo *state.Info, apiInfo *api.Info) *cloudinit.MachineConfig { 72 func (env *maasEnviron) makeMachineConfig(machineID, machineNonce string,
73 » stateInfo *state.Info, apiInfo *api.Info) *cloudinit.MachineConfig {
78 return &cloudinit.MachineConfig{ 74 return &cloudinit.MachineConfig{
79 // Fixed entries. 75 // Fixed entries.
80 » » MongoPort: mgoPort, 76 » » DataDir: jujuDataDir,
81 » » APIPort: apiPort,
82 » » DataDir: jujuDataDir,
83 77
84 // Parameter entries. 78 // Parameter entries.
85 MachineId: machineID, 79 MachineId: machineID,
86 MachineNonce: machineNonce, 80 MachineNonce: machineNonce,
87 StateInfo: stateInfo, 81 StateInfo: stateInfo,
88 APIInfo: apiInfo, 82 APIInfo: apiInfo,
89 } 83 }
90 } 84 }
91 85
92 // startBootstrapNode starts the juju bootstrap node for this environment. 86 // startBootstrapNode starts the juju bootstrap node for this environment.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // StateInfo is specified in the Environ interface. 128 // StateInfo is specified in the Environ interface.
135 func (env *maasEnviron) StateInfo() (*state.Info, *api.Info, error) { 129 func (env *maasEnviron) StateInfo() (*state.Info, *api.Info, error) {
136 // This code is cargo-culted from the openstack/ec2 providers. 130 // This code is cargo-culted from the openstack/ec2 providers.
137 // It's a bit unclear what the "longAttempt" loop is actually for 131 // It's a bit unclear what the "longAttempt" loop is actually for
138 // but this should probably be refactored outside of the provider 132 // but this should probably be refactored outside of the provider
139 // code. 133 // code.
140 st, err := env.loadState() 134 st, err := env.loadState()
141 if err != nil { 135 if err != nil {
142 return nil, nil, err 136 return nil, nil, err
143 } 137 }
144 » cert, hasCert := env.Config().CACert() 138 » config := env.Config()
139 » cert, hasCert := config.CACert()
145 if !hasCert { 140 if !hasCert {
146 return nil, nil, fmt.Errorf("no CA certificate in environment co nfiguration") 141 return nil, nil, fmt.Errorf("no CA certificate in environment co nfiguration")
147 } 142 }
148 var stateAddrs []string 143 var stateAddrs []string
149 var apiAddrs []string 144 var apiAddrs []string
150 // Wait for the DNS names of any of the instances 145 // Wait for the DNS names of any of the instances
151 // to become available. 146 // to become available.
152 log.Debugf("environs/maas: waiting for DNS name(s) of state server insta nces %v", st.StateInstances) 147 log.Debugf("environs/maas: waiting for DNS name(s) of state server insta nces %v", st.StateInstances)
153 for a := longAttempt.Start(); len(stateAddrs) == 0 && a.Next(); { 148 for a := longAttempt.Start(); len(stateAddrs) == 0 && a.Next(); {
154 insts, err := env.Instances(st.StateInstances) 149 insts, err := env.Instances(st.StateInstances)
155 if err != nil && err != environs.ErrPartialInstances { 150 if err != nil && err != environs.ErrPartialInstances {
156 log.Debugf("environs/maas: error getting state instance: %v", err.Error()) 151 log.Debugf("environs/maas: error getting state instance: %v", err.Error())
157 return nil, nil, err 152 return nil, nil, err
158 } 153 }
159 log.Debugf("environs/maas: started processing instances: %#v", i nsts) 154 log.Debugf("environs/maas: started processing instances: %#v", i nsts)
160 for _, inst := range insts { 155 for _, inst := range insts {
161 if inst == nil { 156 if inst == nil {
162 continue 157 continue
163 } 158 }
164 name, err := inst.DNSName() 159 name, err := inst.DNSName()
165 if err != nil { 160 if err != nil {
166 continue 161 continue
167 } 162 }
168 if name != "" { 163 if name != "" {
169 » » » » stateAddrs = append(stateAddrs, name+mgoPortSuff ix) 164 » » » » statePortSuffix := fmt.Sprintf(":%d", config.Sta tePort())
165 » » » » apiPortSuffix := fmt.Sprintf(":%d", config.APIPo rt())
166 » » » » stateAddrs = append(stateAddrs, name+statePortSu ffix)
170 apiAddrs = append(apiAddrs, name+apiPortSuffix) 167 apiAddrs = append(apiAddrs, name+apiPortSuffix)
171 } 168 }
172 } 169 }
173 } 170 }
174 if len(stateAddrs) == 0 { 171 if len(stateAddrs) == 0 {
175 return nil, nil, fmt.Errorf("timed out waiting for mgo address f rom %v", st.StateInstances) 172 return nil, nil, fmt.Errorf("timed out waiting for mgo address f rom %v", st.StateInstances)
176 } 173 }
177 return &state.Info{ 174 return &state.Info{
178 Addrs: stateAddrs, 175 Addrs: stateAddrs,
179 CACert: cert, 176 CACert: cert,
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 } 500 }
504 501
505 func (*maasEnviron) Ports() ([]params.Port, error) { 502 func (*maasEnviron) Ports() ([]params.Port, error) {
506 log.Debugf("environs/maas: unimplemented Ports() called") 503 log.Debugf("environs/maas: unimplemented Ports() called")
507 return []params.Port{}, nil 504 return []params.Port{}, nil
508 } 505 }
509 506
510 func (*maasEnviron) Provider() environs.EnvironProvider { 507 func (*maasEnviron) Provider() environs.EnvironProvider {
511 return &providerInstance 508 return &providerInstance
512 } 509 }
LEFTRIGHT

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