@@ -12,9 +12,8 @@ import (
12
12
13
13
"github.com/juju/juju/agent"
14
14
"github.com/juju/juju/apiserver/params"
15
- "github.com/juju/juju/constraints "
15
+ "github.com/juju/juju/cloudconfig/instancecfg "
16
16
"github.com/juju/juju/controller/modelmanager"
17
- "github.com/juju/juju/environs/config"
18
17
"github.com/juju/juju/instance"
19
18
"github.com/juju/juju/mongo"
20
19
"github.com/juju/juju/network"
@@ -24,27 +23,17 @@ import (
24
23
25
24
var logger = loggo .GetLogger ("juju.agent.agentbootstrap" )
26
25
27
- // BootstrapMachineConfig holds configuration information
28
- // to attach to the bootstrap machine.
29
- type BootstrapMachineConfig struct {
30
- // Addresses holds the bootstrap machine's addresses.
31
- Addresses []network.Address
26
+ // InitializeStateParams holds parameters used for initializing the state
27
+ // database.
28
+ type InitializeStateParams struct {
29
+ instancecfg.StateInitializationParams
32
30
33
- // BootstrapConstraints holds the bootstrap machine's constraints .
34
- BootstrapConstraints constraints. Value
31
+ // BootstrapMachineAddresses holds the bootstrap machine's addresses .
32
+ BootstrapMachineAddresses []network. Address
35
33
36
- // ModelConstraints holds the model-level constraints.
37
- ModelConstraints constraints.Value
38
-
39
- // Jobs holds the jobs that the machine agent will run.
40
- Jobs []multiwatcher.MachineJob
41
-
42
- // InstanceId holds the instance id of the bootstrap machine.
43
- InstanceId instance.Id
44
-
45
- // Characteristics holds hardware information on the
46
- // bootstrap machine.
47
- Characteristics instance.HardwareCharacteristics
34
+ // BootstrapMachineJobs holds the jobs that the bootstrap machine
35
+ // agent will run.
36
+ BootstrapMachineJobs []multiwatcher.MachineJob
48
37
49
38
// SharedSecret is the Mongo replica set shared secret (keyfile).
50
39
SharedSecret string
@@ -66,12 +55,7 @@ type BootstrapMachineConfig struct {
66
55
func InitializeState (
67
56
adminUser names.UserTag ,
68
57
c agent.ConfigSetter ,
69
- cfg * config.Config ,
70
- cloudName string ,
71
- cloudRegion string ,
72
- cloudConfigAttrs map [string ]interface {},
73
- hostedModelConfigAttrs map [string ]interface {},
74
- machineCfg BootstrapMachineConfig ,
58
+ args InitializeStateParams ,
75
59
dialOpts mongo.DialOpts ,
76
60
policy state.Policy ,
77
61
) (_ * state.State , _ * state.Machine , resultErr error ) {
@@ -96,7 +80,20 @@ func InitializeState(
96
80
}
97
81
98
82
logger .Debugf ("initializing address %v" , info .Addrs )
99
- st , err := state .Initialize (adminUser , info , cloudName , cloudRegion , cloudConfigAttrs , cfg , dialOpts , policy )
83
+ st , err := state .Initialize (state.InitializeParams {
84
+ ControllerModelArgs : state.ModelArgs {
85
+ Owner : adminUser ,
86
+ Config : args .ControllerModelConfig ,
87
+ CloudRegion : args .ControllerCloudRegion ,
88
+ Constraints : args .ModelConstraints ,
89
+ },
90
+ CloudName : args .ControllerCloudName ,
91
+ Cloud : args .ControllerCloud ,
92
+ ModelConfigDefaults : args .ModelConfigDefaults ,
93
+ MongoInfo : info ,
94
+ MongoDialOpts : dialOpts ,
95
+ Policy : policy ,
96
+ })
100
97
if err != nil {
101
98
return nil , nil , errors .Errorf ("failed to initialize state: %v" , err )
102
99
}
@@ -106,46 +103,46 @@ func InitializeState(
106
103
st .Close ()
107
104
}
108
105
}()
109
- servingInfo .SharedSecret = machineCfg .SharedSecret
106
+ servingInfo .SharedSecret = args .SharedSecret
110
107
c .SetStateServingInfo (servingInfo )
111
108
112
109
// Filter out any LXC bridge addresses from the machine addresses.
113
- machineCfg . Addresses = network .FilterLXCAddresses (machineCfg . Addresses )
110
+ args . BootstrapMachineAddresses = network .FilterLXCAddresses (args . BootstrapMachineAddresses )
114
111
115
- if err = initAPIHostPorts (c , st , machineCfg . Addresses , servingInfo .APIPort ); err != nil {
112
+ if err = initAPIHostPorts (c , st , args . BootstrapMachineAddresses , servingInfo .APIPort ); err != nil {
116
113
return nil , nil , err
117
114
}
118
115
ssi := paramsStateServingInfoToStateStateServingInfo (servingInfo )
119
116
if err := st .SetStateServingInfo (ssi ); err != nil {
120
117
return nil , nil , errors .Errorf ("cannot set state serving info: %v" , err )
121
118
}
122
- m , err := initConstraintsAndBootstrapMachine (c , st , machineCfg )
119
+ m , err := initBootstrapMachine (c , st , args )
123
120
if err != nil {
124
- return nil , nil , err
121
+ return nil , nil , errors . Annotate ( err , "cannot initialize bootstrap machine" )
125
122
}
126
123
127
124
// Create the initial hosted model, with the model config passed to
128
125
// bootstrap, which contains the UUID, name for the hosted model,
129
126
// and any user supplied config.
130
127
attrs := make (map [string ]interface {})
131
- for k , v := range hostedModelConfigAttrs {
128
+ for k , v := range args . HostedModelConfig {
132
129
attrs [k ] = v
133
130
}
134
- hostedModelConfig , err := modelmanager.ModelConfigCreator {}.NewModelConfig (modelmanager .IsAdmin , cfg , attrs )
131
+ hostedModelConfig , err := modelmanager.ModelConfigCreator {}.NewModelConfig (
132
+ modelmanager .IsAdmin , args .ControllerModelConfig , attrs ,
133
+ )
135
134
if err != nil {
136
135
return nil , nil , errors .Annotate (err , "creating hosted model config" )
137
136
}
138
137
_ , hostedModelState , err := st .NewModel (state.ModelArgs {
139
- CloudRegion : cloudRegion ,
140
- Config : hostedModelConfig ,
141
138
Owner : adminUser ,
139
+ Config : hostedModelConfig ,
140
+ CloudRegion : args .ControllerCloudRegion ,
141
+ Constraints : args .ModelConstraints ,
142
142
})
143
143
if err != nil {
144
144
return nil , nil , errors .Annotate (err , "creating hosted model" )
145
145
}
146
- if err := hostedModelState .SetModelConstraints (machineCfg .ModelConstraints ); err != nil {
147
- return nil , nil , errors .Annotate (err , "cannot set initial hosted model constraints" )
148
- }
149
146
hostedModelState .Close ()
150
147
151
148
return st , m , nil
@@ -163,17 +160,6 @@ func paramsStateServingInfoToStateStateServingInfo(i params.StateServingInfo) st
163
160
}
164
161
}
165
162
166
- func initConstraintsAndBootstrapMachine (c agent.ConfigSetter , st * state.State , cfg BootstrapMachineConfig ) (* state.Machine , error ) {
167
- if err := st .SetModelConstraints (cfg .ModelConstraints ); err != nil {
168
- return nil , errors .Annotate (err , "cannot set initial model constraints" )
169
- }
170
- m , err := initBootstrapMachine (c , st , cfg )
171
- if err != nil {
172
- return nil , errors .Annotate (err , "cannot initialize bootstrap machine" )
173
- }
174
- return m , nil
175
- }
176
-
177
163
// initMongoAdminUser adds the admin user with the specified
178
164
// password to the admin database in Mongo.
179
165
func initMongoAdminUser (info mongo.Info , dialOpts mongo.DialOpts , password string ) error {
@@ -186,24 +172,28 @@ func initMongoAdminUser(info mongo.Info, dialOpts mongo.DialOpts, password strin
186
172
}
187
173
188
174
// initBootstrapMachine initializes the initial bootstrap machine in state.
189
- func initBootstrapMachine (c agent.ConfigSetter , st * state.State , cfg BootstrapMachineConfig ) (* state.Machine , error ) {
190
- logger .Infof ("initialising bootstrap machine with config: %+v" , cfg )
175
+ func initBootstrapMachine (c agent.ConfigSetter , st * state.State , args InitializeStateParams ) (* state.Machine , error ) {
176
+ logger .Infof ("initialising bootstrap machine with config: %+v" , args )
191
177
192
- jobs := make ([]state.MachineJob , len (cfg . Jobs ))
193
- for i , job := range cfg . Jobs {
178
+ jobs := make ([]state.MachineJob , len (args . BootstrapMachineJobs ))
179
+ for i , job := range args . BootstrapMachineJobs {
194
180
machineJob , err := machineJobFromParams (job )
195
181
if err != nil {
196
182
return nil , errors .Errorf ("invalid bootstrap machine job %q: %v" , job , err )
197
183
}
198
184
jobs [i ] = machineJob
199
185
}
186
+ var hardware instance.HardwareCharacteristics
187
+ if args .BootstrapMachineHardwareCharacteristics != nil {
188
+ hardware = * args .BootstrapMachineHardwareCharacteristics
189
+ }
200
190
m , err := st .AddOneMachine (state.MachineTemplate {
201
- Addresses : cfg . Addresses ,
191
+ Addresses : args . BootstrapMachineAddresses ,
202
192
Series : series .HostSeries (),
203
193
Nonce : agent .BootstrapNonce ,
204
- Constraints : cfg . BootstrapConstraints ,
205
- InstanceId : cfg . InstanceId ,
206
- HardwareCharacteristics : cfg . Characteristics ,
194
+ Constraints : args . BootstrapMachineConstraints ,
195
+ InstanceId : args . BootstrapMachineInstanceId ,
196
+ HardwareCharacteristics : hardware ,
207
197
Jobs : jobs ,
208
198
})
209
199
if err != nil {
0 commit comments