Merge lp:~axwalk/juju-core/remove-1.16-client-support into lp:~go-bot/juju-core/trunk
- remove-1.16-client-support
- Merge into trunk
Proposed by
Andrew Wilkins
Status: | Merged |
---|---|
Approved by: | Andrew Wilkins |
Approved revision: | no longer in the source branch. |
Merged at revision: | 2580 |
Proposed branch: | lp:~axwalk/juju-core/remove-1.16-client-support |
Merge into: | lp:~go-bot/juju-core/trunk |
Diff against target: |
1021 lines (+21/-669) 13 files modified
cmd/juju/addmachine.go (+6/-58) cmd/juju/common.go (+0/-15) cmd/juju/constraints.go (+1/-43) cmd/juju/deploy.go (+0/-78) cmd/juju/destroymachine.go (+3/-28) cmd/juju/environment.go (+2/-71) cmd/juju/set.go (+1/-36) cmd/juju/status.go (+0/-16) cmd/juju/unset.go (+1/-35) cmd/juju/upgradecharm.go (+0/-81) cmd/juju/upgradejuju.go (+0/-96) environs/manual/provisioner.go (+7/-69) state/statecmd/destroymachines.go (+0/-43) |
To merge this branch: | bzr merge lp:~axwalk/juju-core/remove-1.16-client-support |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+214504@code.launchpad.net |
Commit message
Remove 1.16 support code
This drops most of the 1.16 support code from
the client-side. There's more to remove, this
is just a start.
Description of the change
Remove 1.16 support code
This drops most of the 1.16 support code from
the client-side. There's more to remove, this
is just a start.
To post a comment you must log in.
Revision history for this message
Andrew Wilkins (axwalk) wrote : | # |
Revision history for this message
Ian Booth (wallyworld) wrote : | # |
LGTM. Woohoo!
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'cmd/juju/addmachine.go' | |||
2 | --- cmd/juju/addmachine.go 2014-04-03 04:46:51 +0000 | |||
3 | +++ cmd/juju/addmachine.go 2014-04-07 10:13:32 +0000 | |||
4 | @@ -12,12 +12,10 @@ | |||
5 | 12 | "launchpad.net/juju-core/cmd" | 12 | "launchpad.net/juju-core/cmd" |
6 | 13 | "launchpad.net/juju-core/cmd/envcmd" | 13 | "launchpad.net/juju-core/cmd/envcmd" |
7 | 14 | "launchpad.net/juju-core/constraints" | 14 | "launchpad.net/juju-core/constraints" |
8 | 15 | "launchpad.net/juju-core/environs/config" | ||
9 | 16 | "launchpad.net/juju-core/environs/manual" | 15 | "launchpad.net/juju-core/environs/manual" |
10 | 17 | "launchpad.net/juju-core/instance" | 16 | "launchpad.net/juju-core/instance" |
11 | 18 | "launchpad.net/juju-core/juju" | 17 | "launchpad.net/juju-core/juju" |
12 | 19 | "launchpad.net/juju-core/names" | 18 | "launchpad.net/juju-core/names" |
13 | 20 | "launchpad.net/juju-core/state" | ||
14 | 21 | "launchpad.net/juju-core/state/api/params" | 19 | "launchpad.net/juju-core/state/api/params" |
15 | 22 | ) | 20 | ) |
16 | 23 | 21 | ||
17 | @@ -114,46 +112,6 @@ | |||
18 | 114 | return err | 112 | return err |
19 | 115 | } | 113 | } |
20 | 116 | 114 | ||
21 | 117 | // addMachine1dot16 runs Client.AddMachines using a direct DB connection to maintain | ||
22 | 118 | // compatibility with an API server running 1.16 or older (when AddMachines | ||
23 | 119 | // was not available). This fallback can be removed when we no longer maintain | ||
24 | 120 | // 1.16 compatibility. | ||
25 | 121 | // This was copied directly from the code in AddMachineCommand.Run in 1.16 | ||
26 | 122 | func (c *AddMachineCommand) addMachine1dot16() (string, error) { | ||
27 | 123 | conn, err := juju.NewConnFromName(c.EnvName) | ||
28 | 124 | if err != nil { | ||
29 | 125 | return "", err | ||
30 | 126 | } | ||
31 | 127 | defer conn.Close() | ||
32 | 128 | |||
33 | 129 | series := c.Series | ||
34 | 130 | if series == "" { | ||
35 | 131 | conf, err := conn.State.EnvironConfig() | ||
36 | 132 | if err != nil { | ||
37 | 133 | return "", err | ||
38 | 134 | } | ||
39 | 135 | series = config.PreferredSeries(conf) | ||
40 | 136 | } | ||
41 | 137 | template := state.MachineTemplate{ | ||
42 | 138 | Series: series, | ||
43 | 139 | Constraints: c.Constraints, | ||
44 | 140 | Jobs: []state.MachineJob{state.JobHostUnits}, | ||
45 | 141 | } | ||
46 | 142 | var m *state.Machine | ||
47 | 143 | switch { | ||
48 | 144 | case c.ContainerType == "": | ||
49 | 145 | m, err = conn.State.AddOneMachine(template) | ||
50 | 146 | case c.MachineId != "": | ||
51 | 147 | m, err = conn.State.AddMachineInsideMachine(template, c.MachineId, c.ContainerType) | ||
52 | 148 | default: | ||
53 | 149 | m, err = conn.State.AddMachineInsideNewMachine(template, template, c.ContainerType) | ||
54 | 150 | } | ||
55 | 151 | if err != nil { | ||
56 | 152 | return "", err | ||
57 | 153 | } | ||
58 | 154 | return m.String(), err | ||
59 | 155 | } | ||
60 | 156 | |||
61 | 157 | func (c *AddMachineCommand) Run(ctx *cmd.Context) error { | 115 | func (c *AddMachineCommand) Run(ctx *cmd.Context) error { |
62 | 158 | if c.SSHHost != "" { | 116 | if c.SSHHost != "" { |
63 | 159 | args := manual.ProvisionMachineArgs{ | 117 | args := manual.ProvisionMachineArgs{ |
64 | @@ -181,25 +139,15 @@ | |||
65 | 181 | Jobs: []params.MachineJob{params.JobHostUnits}, | 139 | Jobs: []params.MachineJob{params.JobHostUnits}, |
66 | 182 | } | 140 | } |
67 | 183 | results, err := client.AddMachines([]params.AddMachineParams{machineParams}) | 141 | results, err := client.AddMachines([]params.AddMachineParams{machineParams}) |
68 | 184 | var machineId string | ||
69 | 185 | if params.IsCodeNotImplemented(err) { | ||
70 | 186 | logger.Infof("AddMachines not supported by the API server, " + | ||
71 | 187 | "falling back to 1.16 compatibility mode (direct DB access)") | ||
72 | 188 | machineId, err = c.addMachine1dot16() | ||
73 | 189 | } else if err != nil { | ||
74 | 190 | return err | ||
75 | 191 | } else { | ||
76 | 192 | // Currently, only one machine is added, but in future there may be several added in one call. | ||
77 | 193 | machineInfo := results[0] | ||
78 | 194 | var machineErr *params.Error | ||
79 | 195 | machineId, machineErr = machineInfo.Machine, machineInfo.Error | ||
80 | 196 | if machineErr != nil { | ||
81 | 197 | err = machineErr | ||
82 | 198 | } | ||
83 | 199 | } | ||
84 | 200 | if err != nil { | 142 | if err != nil { |
85 | 201 | return err | 143 | return err |
86 | 202 | } | 144 | } |
87 | 145 | // Currently, only one machine is added, but in future there may be several added in one call. | ||
88 | 146 | machineInfo := results[0] | ||
89 | 147 | if machineInfo.Error != nil { | ||
90 | 148 | return machineInfo.Error | ||
91 | 149 | } | ||
92 | 150 | machineId := machineInfo.Machine | ||
93 | 203 | if c.ContainerType == "" { | 151 | if c.ContainerType == "" { |
94 | 204 | logger.Infof("created machine %v", machineId) | 152 | logger.Infof("created machine %v", machineId) |
95 | 205 | } else { | 153 | } else { |
96 | 206 | 154 | ||
97 | === modified file 'cmd/juju/common.go' | |||
98 | --- cmd/juju/common.go 2014-04-03 15:55:07 +0000 | |||
99 | +++ cmd/juju/common.go 2014-04-07 10:13:32 +0000 | |||
100 | @@ -69,18 +69,3 @@ | |||
101 | 69 | } | 69 | } |
102 | 70 | return &charm.URL{Reference: ref, Series: series}, nil | 70 | return &charm.URL{Reference: ref, Series: series}, nil |
103 | 71 | } | 71 | } |
104 | 72 | |||
105 | 73 | // resolveCharmURL1dot16 returns a resolved charm URL for older state servers | ||
106 | 74 | // that do not support ResolveCharm. The default series "precise" is | ||
107 | 75 | // appropriate for these environments. | ||
108 | 76 | func resolveCharmURL1dot16(url string, conf *config.Config) (*charm.URL, error) { | ||
109 | 77 | ref, series, err := charm.ParseReference(url) | ||
110 | 78 | if err != nil { | ||
111 | 79 | return nil, err | ||
112 | 80 | } | ||
113 | 81 | |||
114 | 82 | if series == "" { | ||
115 | 83 | series = config.PreferredSeries(conf) | ||
116 | 84 | } | ||
117 | 85 | return &charm.URL{Reference: ref, Series: series}, err | ||
118 | 86 | } | ||
119 | 87 | 72 | ||
120 | === modified file 'cmd/juju/constraints.go' | |||
121 | --- cmd/juju/constraints.go 2014-04-01 04:53:43 +0000 | |||
122 | +++ cmd/juju/constraints.go 2014-04-07 10:13:32 +0000 | |||
123 | @@ -13,7 +13,6 @@ | |||
124 | 13 | "launchpad.net/juju-core/constraints" | 13 | "launchpad.net/juju-core/constraints" |
125 | 14 | "launchpad.net/juju-core/juju" | 14 | "launchpad.net/juju-core/juju" |
126 | 15 | "launchpad.net/juju-core/names" | 15 | "launchpad.net/juju-core/names" |
127 | 16 | "launchpad.net/juju-core/state/api/params" | ||
128 | 17 | ) | 16 | ) |
129 | 18 | 17 | ||
130 | 19 | const getConstraintsDoc = ` | 18 | const getConstraintsDoc = ` |
131 | @@ -93,21 +92,6 @@ | |||
132 | 93 | return cmd.CheckEmpty(args) | 92 | return cmd.CheckEmpty(args) |
133 | 94 | } | 93 | } |
134 | 95 | 94 | ||
135 | 96 | // getEnvironConstraints1dot16 uses direct DB access to get the Environment | ||
136 | 97 | // constraints against an API server running 1.16 or older (when GetEnvironmentConstraints | ||
137 | 98 | // was not available). This fallback can be removed when we no longer maintain | ||
138 | 99 | // 1.16 compatibility. | ||
139 | 100 | // This only does the GetEnvironmentConstraints portion of Run, since | ||
140 | 101 | // GetServiceConstraints was already implemented. | ||
141 | 102 | func (c *GetConstraintsCommand) getEnvironConstraints1dot16() (constraints.Value, error) { | ||
142 | 103 | conn, err := juju.NewConnFromName(c.EnvName) | ||
143 | 104 | if err != nil { | ||
144 | 105 | return constraints.Value{}, err | ||
145 | 106 | } | ||
146 | 107 | defer conn.Close() | ||
147 | 108 | return conn.State.EnvironConstraints() | ||
148 | 109 | } | ||
149 | 110 | |||
150 | 111 | func (c *GetConstraintsCommand) Run(ctx *cmd.Context) error { | 95 | func (c *GetConstraintsCommand) Run(ctx *cmd.Context) error { |
151 | 112 | apiclient, err := juju.NewAPIClientFromName(c.EnvName) | 96 | apiclient, err := juju.NewAPIClientFromName(c.EnvName) |
152 | 113 | if err != nil { | 97 | if err != nil { |
153 | @@ -118,11 +102,6 @@ | |||
154 | 118 | var cons constraints.Value | 102 | var cons constraints.Value |
155 | 119 | if c.ServiceName == "" { | 103 | if c.ServiceName == "" { |
156 | 120 | cons, err = apiclient.GetEnvironmentConstraints() | 104 | cons, err = apiclient.GetEnvironmentConstraints() |
157 | 121 | if params.IsCodeNotImplemented(err) { | ||
158 | 122 | logger.Infof("GetEnvironmentConstraints not supported by the API server, " + | ||
159 | 123 | "falling back to 1.16 compatibility mode (direct DB access)") | ||
160 | 124 | cons, err = c.getEnvironConstraints1dot16() | ||
161 | 125 | } | ||
162 | 126 | } else { | 105 | } else { |
163 | 127 | cons, err = apiclient.GetServiceConstraints(c.ServiceName) | 106 | cons, err = apiclient.GetServiceConstraints(c.ServiceName) |
164 | 128 | } | 107 | } |
165 | @@ -166,21 +145,6 @@ | |||
166 | 166 | return err | 145 | return err |
167 | 167 | } | 146 | } |
168 | 168 | 147 | ||
169 | 169 | // setEnvironConstraints1dot16 uses direct DB access to get the Environment | ||
170 | 170 | // constraints against an API server running 1.16 or older (when SetEnvironmentConstraints | ||
171 | 171 | // was not available). This fallback can be removed when we no longer maintain | ||
172 | 172 | // 1.16 compatibility. | ||
173 | 173 | // This only does the SetEnvironmentConstraints portion of Run, since | ||
174 | 174 | // SetServiceConstraints was already implemented. | ||
175 | 175 | func (c *SetConstraintsCommand) setEnvironConstraints1dot16() error { | ||
176 | 176 | conn, err := juju.NewConnFromName(c.EnvName) | ||
177 | 177 | if err != nil { | ||
178 | 178 | return err | ||
179 | 179 | } | ||
180 | 180 | defer conn.Close() | ||
181 | 181 | return conn.State.SetEnvironConstraints(c.Constraints) | ||
182 | 182 | } | ||
183 | 183 | |||
184 | 184 | func (c *SetConstraintsCommand) Run(_ *cmd.Context) (err error) { | 148 | func (c *SetConstraintsCommand) Run(_ *cmd.Context) (err error) { |
185 | 185 | apiclient, err := juju.NewAPIClientFromName(c.EnvName) | 149 | apiclient, err := juju.NewAPIClientFromName(c.EnvName) |
186 | 186 | if err != nil { | 150 | if err != nil { |
187 | @@ -188,13 +152,7 @@ | |||
188 | 188 | } | 152 | } |
189 | 189 | defer apiclient.Close() | 153 | defer apiclient.Close() |
190 | 190 | if c.ServiceName == "" { | 154 | if c.ServiceName == "" { |
198 | 191 | err = apiclient.SetEnvironmentConstraints(c.Constraints) | 155 | return apiclient.SetEnvironmentConstraints(c.Constraints) |
192 | 192 | if params.IsCodeNotImplemented(err) { | ||
193 | 193 | logger.Infof("SetEnvironmentConstraints not supported by the API server, " + | ||
194 | 194 | "falling back to 1.16 compatibility mode (direct DB access)") | ||
195 | 195 | err = c.setEnvironConstraints1dot16() | ||
196 | 196 | } | ||
197 | 197 | return err | ||
199 | 198 | } | 156 | } |
200 | 199 | return apiclient.SetServiceConstraints(c.ServiceName, c.Constraints) | 157 | return apiclient.SetServiceConstraints(c.ServiceName, c.Constraints) |
201 | 200 | } | 158 | } |
202 | 201 | 159 | ||
203 | === modified file 'cmd/juju/deploy.go' | |||
204 | --- cmd/juju/deploy.go 2014-04-03 04:46:51 +0000 | |||
205 | +++ cmd/juju/deploy.go 2014-04-07 10:13:32 +0000 | |||
206 | @@ -142,11 +142,6 @@ | |||
207 | 142 | defer client.Close() | 142 | defer client.Close() |
208 | 143 | 143 | ||
209 | 144 | attrs, err := client.EnvironmentGet() | 144 | attrs, err := client.EnvironmentGet() |
210 | 145 | if params.IsCodeNotImplemented(err) { | ||
211 | 146 | logger.Infof("EnvironmentGet not supported by the API server, " + | ||
212 | 147 | "falling back to 1.16 compatibility mode (direct DB access)") | ||
213 | 148 | return c.run1dot16(ctx) | ||
214 | 149 | } | ||
215 | 150 | if err != nil { | 145 | if err != nil { |
216 | 151 | return err | 146 | return err |
217 | 152 | } | 147 | } |
218 | @@ -249,79 +244,6 @@ | |||
219 | 249 | return err | 244 | return err |
220 | 250 | } | 245 | } |
221 | 251 | 246 | ||
222 | 252 | // run1dot16 implements the deploy command in 1.16 compatibility mode, | ||
223 | 253 | // with direct state access. Remove this when support for 1.16 is | ||
224 | 254 | // dropped. | ||
225 | 255 | func (c *DeployCommand) run1dot16(ctx *cmd.Context) error { | ||
226 | 256 | conn, err := juju.NewConnFromName(c.EnvName) | ||
227 | 257 | if err != nil { | ||
228 | 258 | return err | ||
229 | 259 | } | ||
230 | 260 | defer conn.Close() | ||
231 | 261 | conf, err := conn.State.EnvironConfig() | ||
232 | 262 | if err != nil { | ||
233 | 263 | return err | ||
234 | 264 | } | ||
235 | 265 | |||
236 | 266 | curl, err := resolveCharmURL1dot16(c.CharmName, conf) | ||
237 | 267 | if err != nil { | ||
238 | 268 | return err | ||
239 | 269 | } | ||
240 | 270 | |||
241 | 271 | repo, err := charm.InferRepository(curl.Reference, c.RepoPath) | ||
242 | 272 | if err != nil { | ||
243 | 273 | return err | ||
244 | 274 | } | ||
245 | 275 | repo = config.SpecializeCharmRepo(repo, conf) | ||
246 | 276 | |||
247 | 277 | // TODO(fwereade) it's annoying to roundtrip the bytes through the client | ||
248 | 278 | // here, but it's the original behaviour and not convenient to change. | ||
249 | 279 | // PutCharm will always be required in some form for local charms; and we | ||
250 | 280 | // will need an EnsureStoreCharm method somewhere that gets the state.Charm | ||
251 | 281 | // for use in the following checks. | ||
252 | 282 | ch, err := conn.PutCharm(curl, repo, c.BumpRevision) | ||
253 | 283 | if err != nil { | ||
254 | 284 | return err | ||
255 | 285 | } | ||
256 | 286 | numUnits := c.NumUnits | ||
257 | 287 | if ch.Meta().Subordinate { | ||
258 | 288 | if !constraints.IsEmpty(&c.Constraints) { | ||
259 | 289 | return errors.New("cannot use --constraints with subordinate service") | ||
260 | 290 | } | ||
261 | 291 | if numUnits == 1 && c.ToMachineSpec == "" { | ||
262 | 292 | numUnits = 0 | ||
263 | 293 | } else { | ||
264 | 294 | return errors.New("cannot use --num-units or --to with subordinate service") | ||
265 | 295 | } | ||
266 | 296 | } | ||
267 | 297 | |||
268 | 298 | serviceName := c.ServiceName | ||
269 | 299 | if serviceName == "" { | ||
270 | 300 | serviceName = ch.Meta().Name | ||
271 | 301 | } | ||
272 | 302 | var settings charm.Settings | ||
273 | 303 | if c.Config.Path != "" { | ||
274 | 304 | configYAML, err := c.Config.Read(ctx) | ||
275 | 305 | if err != nil { | ||
276 | 306 | return err | ||
277 | 307 | } | ||
278 | 308 | settings, err = ch.Config().ParseSettingsYAML(configYAML, serviceName) | ||
279 | 309 | if err != nil { | ||
280 | 310 | return err | ||
281 | 311 | } | ||
282 | 312 | } | ||
283 | 313 | _, err = juju.DeployService(conn.State, | ||
284 | 314 | juju.DeployServiceParams{ | ||
285 | 315 | ServiceName: serviceName, | ||
286 | 316 | Charm: ch, | ||
287 | 317 | NumUnits: numUnits, | ||
288 | 318 | ConfigSettings: settings, | ||
289 | 319 | Constraints: c.Constraints, | ||
290 | 320 | ToMachineSpec: c.ToMachineSpec, | ||
291 | 321 | }) | ||
292 | 322 | return err | ||
293 | 323 | } | ||
294 | 324 | |||
295 | 325 | // addCharmViaAPI calls the appropriate client API calls to add the | 247 | // addCharmViaAPI calls the appropriate client API calls to add the |
296 | 326 | // given charm URL to state. Also displays the charm URL of the added | 248 | // given charm URL to state. Also displays the charm URL of the added |
297 | 327 | // charm on stdout. | 249 | // charm on stdout. |
298 | 328 | 250 | ||
299 | === modified file 'cmd/juju/destroymachine.go' | |||
300 | --- cmd/juju/destroymachine.go 2014-04-01 04:53:43 +0000 | |||
301 | +++ cmd/juju/destroymachine.go 2014-04-07 10:13:32 +0000 | |||
302 | @@ -12,8 +12,6 @@ | |||
303 | 12 | "launchpad.net/juju-core/cmd/envcmd" | 12 | "launchpad.net/juju-core/cmd/envcmd" |
304 | 13 | "launchpad.net/juju-core/juju" | 13 | "launchpad.net/juju-core/juju" |
305 | 14 | "launchpad.net/juju-core/names" | 14 | "launchpad.net/juju-core/names" |
306 | 15 | "launchpad.net/juju-core/state/api/params" | ||
307 | 16 | "launchpad.net/juju-core/state/statecmd" | ||
308 | 17 | ) | 15 | ) |
309 | 18 | 16 | ||
310 | 19 | // DestroyMachineCommand causes an existing machine to be destroyed. | 17 | // DestroyMachineCommand causes an existing machine to be destroyed. |
311 | @@ -62,21 +60,6 @@ | |||
312 | 62 | return nil | 60 | return nil |
313 | 63 | } | 61 | } |
314 | 64 | 62 | ||
315 | 65 | func (c *DestroyMachineCommand) run1dot16() error { | ||
316 | 66 | if c.Force { | ||
317 | 67 | return fmt.Errorf("destroy-machine --force is not supported in Juju servers older than 1.16.4") | ||
318 | 68 | } | ||
319 | 69 | conn, err := juju.NewConnFromName(c.EnvName) | ||
320 | 70 | if err != nil { | ||
321 | 71 | return err | ||
322 | 72 | } | ||
323 | 73 | defer conn.Close() | ||
324 | 74 | // TODO: When this run1dot16 code is removed, we should remove the | ||
325 | 75 | // method in state as well (as long as add-machine also no longer | ||
326 | 76 | // needs it.) | ||
327 | 77 | return statecmd.DestroyMachines1dot16(conn.State, c.MachineIds...) | ||
328 | 78 | } | ||
329 | 79 | |||
330 | 80 | func (c *DestroyMachineCommand) Run(_ *cmd.Context) error { | 63 | func (c *DestroyMachineCommand) Run(_ *cmd.Context) error { |
331 | 81 | apiclient, err := juju.NewAPIClientFromName(c.EnvName) | 64 | apiclient, err := juju.NewAPIClientFromName(c.EnvName) |
332 | 82 | if err != nil { | 65 | if err != nil { |
333 | @@ -84,15 +67,7 @@ | |||
334 | 84 | } | 67 | } |
335 | 85 | defer apiclient.Close() | 68 | defer apiclient.Close() |
336 | 86 | if c.Force { | 69 | if c.Force { |
348 | 87 | err = apiclient.ForceDestroyMachines(c.MachineIds...) | 70 | return apiclient.ForceDestroyMachines(c.MachineIds...) |
349 | 88 | } else { | 71 | } |
350 | 89 | err = apiclient.DestroyMachines(c.MachineIds...) | 72 | return apiclient.DestroyMachines(c.MachineIds...) |
340 | 90 | } | ||
341 | 91 | // Juju 1.16.3 and older did not have DestroyMachines as an API command. | ||
342 | 92 | if params.IsCodeNotImplemented(err) { | ||
343 | 93 | logger.Infof("DestroyMachines not supported by the API server, " + | ||
344 | 94 | "falling back to <=1.16.3 compatibility") | ||
345 | 95 | return c.run1dot16() | ||
346 | 96 | } | ||
347 | 97 | return err | ||
351 | 98 | } | 73 | } |
352 | 99 | 74 | ||
353 | === modified file 'cmd/juju/environment.go' | |||
354 | --- cmd/juju/environment.go 2014-04-01 14:31:22 +0000 | |||
355 | +++ cmd/juju/environment.go 2014-04-07 10:13:32 +0000 | |||
356 | @@ -12,7 +12,6 @@ | |||
357 | 12 | "launchpad.net/juju-core/cmd" | 12 | "launchpad.net/juju-core/cmd" |
358 | 13 | "launchpad.net/juju-core/cmd/envcmd" | 13 | "launchpad.net/juju-core/cmd/envcmd" |
359 | 14 | "launchpad.net/juju-core/juju" | 14 | "launchpad.net/juju-core/juju" |
360 | 15 | "launchpad.net/juju-core/state/api/params" | ||
361 | 16 | ) | 15 | ) |
362 | 17 | 16 | ||
363 | 18 | // GetEnvironmentCommand is able to output either the entire environment or | 17 | // GetEnvironmentCommand is able to output either the entire environment or |
364 | @@ -59,26 +58,6 @@ | |||
365 | 59 | return | 58 | return |
366 | 60 | } | 59 | } |
367 | 61 | 60 | ||
368 | 62 | // environmentGet1dot16 runs matches client.EnvironmentGet using a direct DB | ||
369 | 63 | // connection to maintain compatibility with an API server running 1.16 or | ||
370 | 64 | // older (when EnvironmentGet was not available). This fallback can be removed | ||
371 | 65 | // when we no longer maintain 1.16 compatibility. | ||
372 | 66 | func (c *GetEnvironmentCommand) environmentGet1dot16() (map[string]interface{}, error) { | ||
373 | 67 | conn, err := juju.NewConnFromName(c.EnvName) | ||
374 | 68 | if err != nil { | ||
375 | 69 | return nil, err | ||
376 | 70 | } | ||
377 | 71 | defer conn.Close() | ||
378 | 72 | |||
379 | 73 | // Get the existing environment config from the state. | ||
380 | 74 | config, err := conn.State.EnvironConfig() | ||
381 | 75 | if err != nil { | ||
382 | 76 | return nil, err | ||
383 | 77 | } | ||
384 | 78 | attrs := config.AllAttrs() | ||
385 | 79 | return attrs, nil | ||
386 | 80 | } | ||
387 | 81 | |||
388 | 82 | func (c *GetEnvironmentCommand) Run(ctx *cmd.Context) error { | 61 | func (c *GetEnvironmentCommand) Run(ctx *cmd.Context) error { |
389 | 83 | client, err := juju.NewAPIClientFromName(c.EnvName) | 62 | client, err := juju.NewAPIClientFromName(c.EnvName) |
390 | 84 | if err != nil { | 63 | if err != nil { |
391 | @@ -87,11 +66,6 @@ | |||
392 | 87 | defer client.Close() | 66 | defer client.Close() |
393 | 88 | 67 | ||
394 | 89 | attrs, err := client.EnvironmentGet() | 68 | attrs, err := client.EnvironmentGet() |
395 | 90 | if params.IsCodeNotImplemented(err) { | ||
396 | 91 | logger.Infof("EnvironmentGet not supported by the API server, " + | ||
397 | 92 | "falling back to 1.16 compatibility mode (direct DB access)") | ||
398 | 93 | attrs, err = c.environmentGet1dot16() | ||
399 | 94 | } | ||
400 | 95 | if err != nil { | 69 | if err != nil { |
401 | 96 | return err | 70 | return err |
402 | 97 | } | 71 | } |
403 | @@ -159,36 +133,13 @@ | |||
404 | 159 | return nil | 133 | return nil |
405 | 160 | } | 134 | } |
406 | 161 | 135 | ||
407 | 162 | // run1dot16 runs matches client.EnvironmentSet using a direct DB | ||
408 | 163 | // connection to maintain compatibility with an API server running 1.16 or | ||
409 | 164 | // older (when EnvironmentSet was not available). This fallback can be removed | ||
410 | 165 | // when we no longer maintain 1.16 compatibility. | ||
411 | 166 | // This content was copied from SetEnvironmentCommand.Run in 1.16 | ||
412 | 167 | func (c *SetEnvironmentCommand) run1dot16() error { | ||
413 | 168 | conn, err := juju.NewConnFromName(c.EnvName) | ||
414 | 169 | if err != nil { | ||
415 | 170 | return err | ||
416 | 171 | } | ||
417 | 172 | defer conn.Close() | ||
418 | 173 | |||
419 | 174 | // Update state config with new values | ||
420 | 175 | return conn.State.UpdateEnvironConfig(c.values, nil, nil) | ||
421 | 176 | } | ||
422 | 177 | |||
423 | 178 | func (c *SetEnvironmentCommand) Run(ctx *cmd.Context) error { | 136 | func (c *SetEnvironmentCommand) Run(ctx *cmd.Context) error { |
424 | 179 | client, err := juju.NewAPIClientFromName(c.EnvName) | 137 | client, err := juju.NewAPIClientFromName(c.EnvName) |
425 | 180 | if err != nil { | 138 | if err != nil { |
426 | 181 | return err | 139 | return err |
427 | 182 | } | 140 | } |
428 | 183 | defer client.Close() | 141 | defer client.Close() |
437 | 184 | 142 | return client.EnvironmentSet(c.values) | |
430 | 185 | err = client.EnvironmentSet(c.values) | ||
431 | 186 | if params.IsCodeNotImplemented(err) { | ||
432 | 187 | logger.Infof("EnvironmentSet not supported by the API server, " + | ||
433 | 188 | "falling back to 1.16 compatibility mode (direct DB access)") | ||
434 | 189 | err = c.run1dot16() | ||
435 | 190 | } | ||
436 | 191 | return err | ||
438 | 192 | } | 143 | } |
439 | 193 | 144 | ||
440 | 194 | // UnsetEnvironment | 145 | // UnsetEnvironment |
441 | @@ -228,31 +179,11 @@ | |||
442 | 228 | return nil | 179 | return nil |
443 | 229 | } | 180 | } |
444 | 230 | 181 | ||
445 | 231 | // run1dot16 runs matches client.EnvironmentUnset using a direct DB | ||
446 | 232 | // connection to maintain compatibility with an API server running 1.16 or | ||
447 | 233 | // older (when EnvironmentUnset was not available). This fallback can be removed | ||
448 | 234 | // when we no longer maintain 1.16 compatibility. | ||
449 | 235 | func (c *UnsetEnvironmentCommand) run1dot16() error { | ||
450 | 236 | conn, err := juju.NewConnFromName(c.EnvName) | ||
451 | 237 | if err != nil { | ||
452 | 238 | return err | ||
453 | 239 | } | ||
454 | 240 | defer conn.Close() | ||
455 | 241 | return conn.State.UpdateEnvironConfig(nil, c.keys, nil) | ||
456 | 242 | } | ||
457 | 243 | |||
458 | 244 | func (c *UnsetEnvironmentCommand) Run(ctx *cmd.Context) error { | 182 | func (c *UnsetEnvironmentCommand) Run(ctx *cmd.Context) error { |
459 | 245 | client, err := juju.NewAPIClientFromName(c.EnvName) | 183 | client, err := juju.NewAPIClientFromName(c.EnvName) |
460 | 246 | if err != nil { | 184 | if err != nil { |
461 | 247 | return err | 185 | return err |
462 | 248 | } | 186 | } |
463 | 249 | defer client.Close() | 187 | defer client.Close() |
472 | 250 | 188 | return client.EnvironmentUnset(c.keys...) | |
465 | 251 | err = client.EnvironmentUnset(c.keys...) | ||
466 | 252 | if params.IsCodeNotImplemented(err) { | ||
467 | 253 | logger.Infof("EnvironmentUnset not supported by the API server, " + | ||
468 | 254 | "falling back to 1.16 compatibility mode (direct DB access)") | ||
469 | 255 | err = c.run1dot16() | ||
470 | 256 | } | ||
471 | 257 | return err | ||
473 | 258 | } | 189 | } |
474 | 259 | 190 | ||
475 | === modified file 'cmd/juju/set.go' | |||
476 | --- cmd/juju/set.go 2014-04-01 04:53:43 +0000 | |||
477 | +++ cmd/juju/set.go 2014-04-07 10:13:32 +0000 | |||
478 | @@ -13,7 +13,6 @@ | |||
479 | 13 | "launchpad.net/juju-core/cmd" | 13 | "launchpad.net/juju-core/cmd" |
480 | 14 | "launchpad.net/juju-core/cmd/envcmd" | 14 | "launchpad.net/juju-core/cmd/envcmd" |
481 | 15 | "launchpad.net/juju-core/juju" | 15 | "launchpad.net/juju-core/juju" |
482 | 16 | "launchpad.net/juju-core/state/api/params" | ||
483 | 17 | ) | 16 | ) |
484 | 18 | 17 | ||
485 | 19 | // SetCommand updates the configuration of a service. | 18 | // SetCommand updates the configuration of a service. |
486 | @@ -64,34 +63,6 @@ | |||
487 | 64 | return nil | 63 | return nil |
488 | 65 | } | 64 | } |
489 | 66 | 65 | ||
490 | 67 | // serviceSet1dot16 does the final ServiceSet step using direct DB access | ||
491 | 68 | // compatibility with an API server running 1.16 or older (when ServiceUnset | ||
492 | 69 | // was not available). This fallback can be removed when we no longer maintain | ||
493 | 70 | // 1.16 compatibility. | ||
494 | 71 | // This was copied directly from the code in SetCommand.Run in 1.16 | ||
495 | 72 | func (c *SetCommand) serviceSet1dot16() error { | ||
496 | 73 | conn, err := juju.NewConnFromName(c.EnvName) | ||
497 | 74 | if err != nil { | ||
498 | 75 | return err | ||
499 | 76 | } | ||
500 | 77 | defer conn.Close() | ||
501 | 78 | service, err := conn.State.Service(c.ServiceName) | ||
502 | 79 | if err != nil { | ||
503 | 80 | return err | ||
504 | 81 | } | ||
505 | 82 | ch, _, err := service.Charm() | ||
506 | 83 | if err != nil { | ||
507 | 84 | return err | ||
508 | 85 | } | ||
509 | 86 | // We don't need the multiple logic here, because that should have | ||
510 | 87 | // already been taken care of by the API code (which *was* in 1.16). | ||
511 | 88 | settings, err := ch.Config().ParseSettingsStrings(c.SettingsStrings) | ||
512 | 89 | if err != nil { | ||
513 | 90 | return err | ||
514 | 91 | } | ||
515 | 92 | return service.UpdateConfigSettings(settings) | ||
516 | 93 | } | ||
517 | 94 | |||
518 | 95 | // Run updates the configuration of a service. | 66 | // Run updates the configuration of a service. |
519 | 96 | func (c *SetCommand) Run(ctx *cmd.Context) error { | 67 | func (c *SetCommand) Run(ctx *cmd.Context) error { |
520 | 97 | api, err := juju.NewAPIClientFromName(c.EnvName) | 68 | api, err := juju.NewAPIClientFromName(c.EnvName) |
521 | @@ -109,13 +80,7 @@ | |||
522 | 109 | } else if len(c.SettingsStrings) == 0 { | 80 | } else if len(c.SettingsStrings) == 0 { |
523 | 110 | return nil | 81 | return nil |
524 | 111 | } | 82 | } |
532 | 112 | err = api.ServiceSet(c.ServiceName, c.SettingsStrings) | 83 | return api.ServiceSet(c.ServiceName, c.SettingsStrings) |
526 | 113 | if params.IsCodeNotImplemented(err) { | ||
527 | 114 | logger.Infof("NewServiceSetForClientAPI not supported by the API server, " + | ||
528 | 115 | "falling back to 1.16 compatibility mode (direct DB access)") | ||
529 | 116 | err = c.serviceSet1dot16() | ||
530 | 117 | } | ||
531 | 118 | return err | ||
533 | 119 | } | 84 | } |
534 | 120 | 85 | ||
535 | 121 | // parse parses the option k=v strings into a map of options to be | 86 | // parse parses the option k=v strings into a map of options to be |
536 | 122 | 87 | ||
537 | === modified file 'cmd/juju/status.go' | |||
538 | --- cmd/juju/status.go 2014-04-01 04:53:43 +0000 | |||
539 | +++ cmd/juju/status.go 2014-04-07 10:13:32 +0000 | |||
540 | @@ -68,16 +68,6 @@ | |||
541 | 68 | %v | 68 | %v |
542 | 69 | ` | 69 | ` |
543 | 70 | 70 | ||
544 | 71 | func (c *StatusCommand) getStatus1dot16() (*api.Status, error) { | ||
545 | 72 | conn, err := juju.NewConnFromName(c.EnvName) | ||
546 | 73 | if err != nil { | ||
547 | 74 | return nil, fmt.Errorf(connectionError, c.EnvName, err) | ||
548 | 75 | } | ||
549 | 76 | defer conn.Close() | ||
550 | 77 | |||
551 | 78 | return statecmd.Status(conn, c.patterns) | ||
552 | 79 | } | ||
553 | 80 | |||
554 | 81 | func (c *StatusCommand) Run(ctx *cmd.Context) error { | 71 | func (c *StatusCommand) Run(ctx *cmd.Context) error { |
555 | 82 | // Just verify the pattern validity client side, do not use the matcher | 72 | // Just verify the pattern validity client side, do not use the matcher |
556 | 83 | _, err := statecmd.NewUnitMatcher(c.patterns) | 73 | _, err := statecmd.NewUnitMatcher(c.patterns) |
557 | @@ -91,12 +81,6 @@ | |||
558 | 91 | defer apiclient.Close() | 81 | defer apiclient.Close() |
559 | 92 | 82 | ||
560 | 93 | status, err := apiclient.Status(c.patterns) | 83 | status, err := apiclient.Status(c.patterns) |
561 | 94 | if params.IsCodeNotImplemented(err) { | ||
562 | 95 | logger.Infof("Status not supported by the API server, " + | ||
563 | 96 | "falling back to 1.16 compatibility mode " + | ||
564 | 97 | "(direct DB access)") | ||
565 | 98 | status, err = c.getStatus1dot16() | ||
566 | 99 | } | ||
567 | 100 | // Display any error, but continue to print status if some was returned | 84 | // Display any error, but continue to print status if some was returned |
568 | 101 | if err != nil { | 85 | if err != nil { |
569 | 102 | fmt.Fprintf(ctx.Stderr, "%v\n", err) | 86 | fmt.Fprintf(ctx.Stderr, "%v\n", err) |
570 | 103 | 87 | ||
571 | === modified file 'cmd/juju/unset.go' | |||
572 | --- cmd/juju/unset.go 2014-04-01 04:53:43 +0000 | |||
573 | +++ cmd/juju/unset.go 2014-04-07 10:13:32 +0000 | |||
574 | @@ -8,11 +8,9 @@ | |||
575 | 8 | 8 | ||
576 | 9 | "launchpad.net/gnuflag" | 9 | "launchpad.net/gnuflag" |
577 | 10 | 10 | ||
578 | 11 | "launchpad.net/juju-core/charm" | ||
579 | 12 | "launchpad.net/juju-core/cmd" | 11 | "launchpad.net/juju-core/cmd" |
580 | 13 | "launchpad.net/juju-core/cmd/envcmd" | 12 | "launchpad.net/juju-core/cmd/envcmd" |
581 | 14 | "launchpad.net/juju-core/juju" | 13 | "launchpad.net/juju-core/juju" |
582 | 15 | "launchpad.net/juju-core/state/api/params" | ||
583 | 16 | ) | 14 | ) |
584 | 17 | 15 | ||
585 | 18 | // UnsetCommand sets configuration values of a service back | 16 | // UnsetCommand sets configuration values of a service back |
586 | @@ -58,32 +56,6 @@ | |||
587 | 58 | return nil | 56 | return nil |
588 | 59 | } | 57 | } |
589 | 60 | 58 | ||
590 | 61 | // run1dot16 runs 'juju unset' using a direct DB connection to maintain | ||
591 | 62 | // compatibility with an API server running 1.16 or older (when ServiceUnset | ||
592 | 63 | // was not available). This fallback can be removed when we no longer maintain | ||
593 | 64 | // 1.16 compatibility. | ||
594 | 65 | // This was copied directly from the code in UnsetCommand.Run in 1.16 | ||
595 | 66 | func (c *UnsetCommand) run1dot16() error { | ||
596 | 67 | conn, err := juju.NewConnFromName(c.EnvName) | ||
597 | 68 | if err != nil { | ||
598 | 69 | return err | ||
599 | 70 | } | ||
600 | 71 | defer conn.Close() | ||
601 | 72 | service, err := conn.State.Service(c.ServiceName) | ||
602 | 73 | if err != nil { | ||
603 | 74 | return err | ||
604 | 75 | } | ||
605 | 76 | if len(c.Options) > 0 { | ||
606 | 77 | settings := make(charm.Settings) | ||
607 | 78 | for _, option := range c.Options { | ||
608 | 79 | settings[option] = nil | ||
609 | 80 | } | ||
610 | 81 | return service.UpdateConfigSettings(settings) | ||
611 | 82 | } else { | ||
612 | 83 | return nil | ||
613 | 84 | } | ||
614 | 85 | } | ||
615 | 86 | |||
616 | 87 | // Run resets the configuration of a service. | 59 | // Run resets the configuration of a service. |
617 | 88 | func (c *UnsetCommand) Run(ctx *cmd.Context) error { | 60 | func (c *UnsetCommand) Run(ctx *cmd.Context) error { |
618 | 89 | apiclient, err := juju.NewAPIClientFromName(c.EnvName) | 61 | apiclient, err := juju.NewAPIClientFromName(c.EnvName) |
619 | @@ -91,11 +63,5 @@ | |||
620 | 91 | return err | 63 | return err |
621 | 92 | } | 64 | } |
622 | 93 | defer apiclient.Close() | 65 | defer apiclient.Close() |
630 | 94 | err = apiclient.ServiceUnset(c.ServiceName, c.Options) | 66 | return apiclient.ServiceUnset(c.ServiceName, c.Options) |
624 | 95 | if params.IsCodeNotImplemented(err) { | ||
625 | 96 | logger.Infof("ServiceUnset not supported by the API server, " + | ||
626 | 97 | "falling back to 1.16 compatibility mode (direct DB access)") | ||
627 | 98 | err = c.run1dot16() | ||
628 | 99 | } | ||
629 | 100 | return err | ||
631 | 101 | } | 67 | } |
632 | 102 | 68 | ||
633 | === modified file 'cmd/juju/upgradecharm.go' | |||
634 | --- cmd/juju/upgradecharm.go 2014-04-03 15:05:14 +0000 | |||
635 | +++ cmd/juju/upgradecharm.go 2014-04-07 10:13:32 +0000 | |||
636 | @@ -16,7 +16,6 @@ | |||
637 | 16 | "launchpad.net/juju-core/environs/config" | 16 | "launchpad.net/juju-core/environs/config" |
638 | 17 | "launchpad.net/juju-core/juju" | 17 | "launchpad.net/juju-core/juju" |
639 | 18 | "launchpad.net/juju-core/names" | 18 | "launchpad.net/juju-core/names" |
640 | 19 | "launchpad.net/juju-core/state/api/params" | ||
641 | 20 | ) | 19 | ) |
642 | 21 | 20 | ||
643 | 22 | // UpgradeCharm is responsible for upgrading a service's charm. | 21 | // UpgradeCharm is responsible for upgrading a service's charm. |
644 | @@ -115,10 +114,6 @@ | |||
645 | 115 | } | 114 | } |
646 | 116 | defer client.Close() | 115 | defer client.Close() |
647 | 117 | oldURL, err := client.ServiceGetCharmURL(c.ServiceName) | 116 | oldURL, err := client.ServiceGetCharmURL(c.ServiceName) |
648 | 118 | if params.IsCodeNotImplemented(err) { | ||
649 | 119 | logger.Infof("ServiceGetCharmURL is not implemented by the API server, switching to 1.16 compatibility mode (direct DB connection).") | ||
650 | 120 | return c.run1dot16(ctx) | ||
651 | 121 | } | ||
652 | 122 | if err != nil { | 117 | if err != nil { |
653 | 123 | return err | 118 | return err |
654 | 124 | } | 119 | } |
655 | @@ -178,79 +173,3 @@ | |||
656 | 178 | 173 | ||
657 | 179 | return client.ServiceSetCharm(c.ServiceName, addedURL.String(), c.Force) | 174 | return client.ServiceSetCharm(c.ServiceName, addedURL.String(), c.Force) |
658 | 180 | } | 175 | } |
659 | 181 | |||
660 | 182 | // run1dot16 perfoms the charm upgrade using a 1.16 compatible code | ||
661 | 183 | // path, with a direct state connection. Remove once the support for | ||
662 | 184 | // 1.16 is dropped. | ||
663 | 185 | func (c *UpgradeCharmCommand) run1dot16(ctx *cmd.Context) error { | ||
664 | 186 | conn, err := juju.NewConnFromName(c.EnvName) | ||
665 | 187 | if err != nil { | ||
666 | 188 | return err | ||
667 | 189 | } | ||
668 | 190 | defer conn.Close() | ||
669 | 191 | service, err := conn.State.Service(c.ServiceName) | ||
670 | 192 | if err != nil { | ||
671 | 193 | return err | ||
672 | 194 | } | ||
673 | 195 | |||
674 | 196 | conf, err := conn.State.EnvironConfig() | ||
675 | 197 | if err != nil { | ||
676 | 198 | return err | ||
677 | 199 | } | ||
678 | 200 | |||
679 | 201 | oldURL, _ := service.CharmURL() | ||
680 | 202 | var newURL *charm.URL | ||
681 | 203 | if c.SwitchURL != "" { | ||
682 | 204 | // A new charm URL was explicitly specified. | ||
683 | 205 | newURL, err = resolveCharmURL1dot16(c.SwitchURL, conf) | ||
684 | 206 | if err != nil { | ||
685 | 207 | return err | ||
686 | 208 | } | ||
687 | 209 | } else { | ||
688 | 210 | // No new URL specified, but revision might have been. | ||
689 | 211 | newURL = oldURL.WithRevision(c.Revision) | ||
690 | 212 | } | ||
691 | 213 | |||
692 | 214 | repo, err := charm.InferRepository(newURL.Reference, ctx.AbsPath(c.RepoPath)) | ||
693 | 215 | if err != nil { | ||
694 | 216 | return err | ||
695 | 217 | } | ||
696 | 218 | repo = config.SpecializeCharmRepo(repo, conf) | ||
697 | 219 | |||
698 | 220 | // If no explicit revision was set with either SwitchURL | ||
699 | 221 | // or Revision flags, discover the latest. | ||
700 | 222 | explicitRevision := true | ||
701 | 223 | if newURL.Revision == -1 { | ||
702 | 224 | explicitRevision = false | ||
703 | 225 | latest, err := charm.Latest(repo, newURL) | ||
704 | 226 | if err != nil { | ||
705 | 227 | return err | ||
706 | 228 | } | ||
707 | 229 | newURL = newURL.WithRevision(latest) | ||
708 | 230 | } | ||
709 | 231 | bumpRevision := false | ||
710 | 232 | if *newURL == *oldURL { | ||
711 | 233 | if explicitRevision { | ||
712 | 234 | return fmt.Errorf("already running specified charm %q", newURL) | ||
713 | 235 | } | ||
714 | 236 | // Only try bumping the revision when necessary (local dir charm). | ||
715 | 237 | if _, isLocal := repo.(*charm.LocalRepository); !isLocal { | ||
716 | 238 | // TODO(dimitern): If the --force flag is set to something | ||
717 | 239 | // different to before, we might actually want to allow this | ||
718 | 240 | // case (and the other error below). LP bug #1174287 | ||
719 | 241 | return fmt.Errorf("already running latest charm %q", newURL) | ||
720 | 242 | } | ||
721 | 243 | // This is a local repository. | ||
722 | 244 | if ch, err := repo.Get(newURL); err != nil { | ||
723 | 245 | return err | ||
724 | 246 | } else if _, bumpRevision = ch.(*charm.Dir); !bumpRevision { | ||
725 | 247 | // Only bump the revision when it's a directory. | ||
726 | 248 | return fmt.Errorf("cannot increment revision of charm %q: not a directory", newURL) | ||
727 | 249 | } | ||
728 | 250 | } | ||
729 | 251 | sch, err := conn.PutCharm(newURL, repo, bumpRevision) | ||
730 | 252 | if err != nil { | ||
731 | 253 | return err | ||
732 | 254 | } | ||
733 | 255 | return service.SetCharm(sch, c.Force) | ||
734 | 256 | } | ||
735 | 257 | 176 | ||
736 | === modified file 'cmd/juju/upgradejuju.go' | |||
737 | --- cmd/juju/upgradejuju.go 2014-04-01 04:53:43 +0000 | |||
738 | +++ cmd/juju/upgradejuju.go 2014-04-07 10:13:32 +0000 | |||
739 | @@ -16,10 +16,8 @@ | |||
740 | 16 | "launchpad.net/juju-core/environs" | 16 | "launchpad.net/juju-core/environs" |
741 | 17 | "launchpad.net/juju-core/environs/bootstrap" | 17 | "launchpad.net/juju-core/environs/bootstrap" |
742 | 18 | "launchpad.net/juju-core/environs/config" | 18 | "launchpad.net/juju-core/environs/config" |
743 | 19 | "launchpad.net/juju-core/environs/storage" | ||
744 | 20 | "launchpad.net/juju-core/environs/sync" | 19 | "launchpad.net/juju-core/environs/sync" |
745 | 21 | envtools "launchpad.net/juju-core/environs/tools" | 20 | envtools "launchpad.net/juju-core/environs/tools" |
746 | 22 | "launchpad.net/juju-core/errors" | ||
747 | 23 | "launchpad.net/juju-core/juju" | 21 | "launchpad.net/juju-core/juju" |
748 | 24 | "launchpad.net/juju-core/state/api" | 22 | "launchpad.net/juju-core/state/api" |
749 | 25 | "launchpad.net/juju-core/state/api/params" | 23 | "launchpad.net/juju-core/state/api/params" |
750 | @@ -132,9 +130,6 @@ | |||
751 | 132 | 130 | ||
752 | 133 | // Determine the version to upgrade to, uploading tools if necessary. | 131 | // Determine the version to upgrade to, uploading tools if necessary. |
753 | 134 | attrs, err := client.EnvironmentGet() | 132 | attrs, err := client.EnvironmentGet() |
754 | 135 | if params.IsCodeNotImplemented(err) { | ||
755 | 136 | return c.run1dot16() | ||
756 | 137 | } | ||
757 | 138 | if err != nil { | 133 | if err != nil { |
758 | 139 | return err | 134 | return err |
759 | 140 | } | 135 | } |
760 | @@ -372,94 +367,3 @@ | |||
761 | 372 | } | 367 | } |
762 | 373 | return vers | 368 | return vers |
763 | 374 | } | 369 | } |
764 | 375 | |||
765 | 376 | // run1dot16 implements the command without access to the API. This is | ||
766 | 377 | // needed for compatibility, so 1.16 can be upgraded to newer | ||
767 | 378 | // releases. It should be removed in 1.18. | ||
768 | 379 | func (c *UpgradeJujuCommand) run1dot16() error { | ||
769 | 380 | logger.Warningf("running in 1.16 compatibility mode") | ||
770 | 381 | conn, err := juju.NewConnFromName(c.EnvName) | ||
771 | 382 | if err != nil { | ||
772 | 383 | return err | ||
773 | 384 | } | ||
774 | 385 | defer conn.Close() | ||
775 | 386 | defer func() { | ||
776 | 387 | if err == errUpToDate { | ||
777 | 388 | logger.Infof(err.Error()) | ||
778 | 389 | err = nil | ||
779 | 390 | } | ||
780 | 391 | }() | ||
781 | 392 | |||
782 | 393 | // Determine the version to upgrade to, uploading tools if necessary. | ||
783 | 394 | env := conn.Environ | ||
784 | 395 | cfg, err := conn.State.EnvironConfig() | ||
785 | 396 | if err != nil { | ||
786 | 397 | return err | ||
787 | 398 | } | ||
788 | 399 | context, err := c.initVersions1dot16(cfg, env) | ||
789 | 400 | if err != nil { | ||
790 | 401 | return err | ||
791 | 402 | } | ||
792 | 403 | if c.UploadTools { | ||
793 | 404 | series := bootstrap.SeriesToUpload(cfg, c.Series) | ||
794 | 405 | if err := context.uploadTools1dot16(env.Storage(), series); err != nil { | ||
795 | 406 | return err | ||
796 | 407 | } | ||
797 | 408 | } | ||
798 | 409 | if err := context.validate(); err != nil { | ||
799 | 410 | return err | ||
800 | 411 | } | ||
801 | 412 | logger.Infof("upgrade version chosen: %s", context.chosen) | ||
802 | 413 | logger.Infof("available tools: %s", context.tools) | ||
803 | 414 | |||
804 | 415 | if err := conn.State.SetEnvironAgentVersion(context.chosen); err != nil { | ||
805 | 416 | return err | ||
806 | 417 | } | ||
807 | 418 | logger.Infof("started upgrade to %s", context.chosen) | ||
808 | 419 | return nil | ||
809 | 420 | } | ||
810 | 421 | |||
811 | 422 | func (c *UpgradeJujuCommand) initVersions1dot16(cfg *config.Config, env environs.Environ) (*upgradeContext, error) { | ||
812 | 423 | agent, ok := cfg.AgentVersion() | ||
813 | 424 | if !ok { | ||
814 | 425 | // Can't happen. In theory. | ||
815 | 426 | return nil, fmt.Errorf("incomplete environment configuration") | ||
816 | 427 | } | ||
817 | 428 | if c.Version == agent { | ||
818 | 429 | return nil, errUpToDate | ||
819 | 430 | } | ||
820 | 431 | client := version.Current.Number | ||
821 | 432 | available, err := envtools.FindTools(env, client.Major, -1, coretools.Filter{}, envtools.DoNotAllowRetry) | ||
822 | 433 | if err != nil { | ||
823 | 434 | if !errors.IsNotFoundError(err) { | ||
824 | 435 | return nil, err | ||
825 | 436 | } | ||
826 | 437 | if !c.UploadTools { | ||
827 | 438 | // No tools found and we shouldn't upload any, so if we are not asking for a | ||
828 | 439 | // major upgrade, pretend there is no more recent version available. | ||
829 | 440 | if c.Version == version.Zero && agent.Major == client.Major { | ||
830 | 441 | return nil, errUpToDate | ||
831 | 442 | } | ||
832 | 443 | return nil, err | ||
833 | 444 | } | ||
834 | 445 | } | ||
835 | 446 | return &upgradeContext{ | ||
836 | 447 | agent: agent, | ||
837 | 448 | client: client, | ||
838 | 449 | chosen: c.Version, | ||
839 | 450 | tools: available, | ||
840 | 451 | }, nil | ||
841 | 452 | } | ||
842 | 453 | |||
843 | 454 | func (context *upgradeContext) uploadTools1dot16(storage storage.Storage, series []string) error { | ||
844 | 455 | if context.chosen == version.Zero { | ||
845 | 456 | context.chosen = context.client | ||
846 | 457 | } | ||
847 | 458 | context.chosen = uploadVersion(context.chosen, context.tools) | ||
848 | 459 | uploaded, err := sync.Upload(storage, &context.chosen, series...) | ||
849 | 460 | if err != nil { | ||
850 | 461 | return err | ||
851 | 462 | } | ||
852 | 463 | context.tools = coretools.List{uploaded} | ||
853 | 464 | return nil | ||
854 | 465 | } | ||
855 | 466 | 370 | ||
856 | === modified file 'environs/manual/provisioner.go' | |||
857 | --- environs/manual/provisioner.go 2014-04-01 04:15:17 +0000 | |||
858 | +++ environs/manual/provisioner.go 2014-04-07 10:13:32 +0000 | |||
859 | @@ -21,7 +21,6 @@ | |||
860 | 21 | "launchpad.net/juju-core/state" | 21 | "launchpad.net/juju-core/state" |
861 | 22 | "launchpad.net/juju-core/state/api" | 22 | "launchpad.net/juju-core/state/api" |
862 | 23 | "launchpad.net/juju-core/state/api/params" | 23 | "launchpad.net/juju-core/state/api/params" |
863 | 24 | "launchpad.net/juju-core/state/statecmd" | ||
864 | 25 | "launchpad.net/juju-core/tools" | 24 | "launchpad.net/juju-core/tools" |
865 | 26 | "launchpad.net/juju-core/utils" | 25 | "launchpad.net/juju-core/utils" |
866 | 27 | "launchpad.net/juju-core/utils/shell" | 26 | "launchpad.net/juju-core/utils/shell" |
867 | @@ -72,34 +71,14 @@ | |||
868 | 72 | if err != nil { | 71 | if err != nil { |
869 | 73 | return "", err | 72 | return "", err |
870 | 74 | } | 73 | } |
871 | 75 | // Used for fallback to 1.16 code | ||
872 | 76 | var stateConn *juju.Conn | ||
873 | 77 | defer func() { | 74 | defer func() { |
874 | 78 | if machineId != "" && err != nil { | 75 | if machineId != "" && err != nil { |
875 | 79 | logger.Errorf("provisioning failed, removing machine %v: %v", machineId, err) | 76 | logger.Errorf("provisioning failed, removing machine %v: %v", machineId, err) |
891 | 80 | // If we have stateConn, then we are in 1.16 | 77 | if cleanupErr := client.DestroyMachines(machineId); cleanupErr != nil { |
877 | 81 | // compatibility mode and we should issue | ||
878 | 82 | // DestroyMachines directly on the state, rather than | ||
879 | 83 | // via API (because DestroyMachine *also* didn't exist | ||
880 | 84 | // in 1.16, though it will be in 1.16.5). | ||
881 | 85 | // TODO: When this compatibility code is removed, we | ||
882 | 86 | // should remove the method in state as well (as long | ||
883 | 87 | // as destroy-machine also no longer needs it.) | ||
884 | 88 | var cleanupErr error | ||
885 | 89 | if stateConn != nil { | ||
886 | 90 | cleanupErr = statecmd.DestroyMachines1dot16(stateConn.State, machineId) | ||
887 | 91 | } else { | ||
888 | 92 | cleanupErr = client.DestroyMachines(machineId) | ||
889 | 93 | } | ||
890 | 94 | if cleanupErr != nil { | ||
892 | 95 | logger.Warningf("error cleaning up machine: %s", cleanupErr) | 78 | logger.Warningf("error cleaning up machine: %s", cleanupErr) |
893 | 96 | } | 79 | } |
894 | 97 | machineId = "" | 80 | machineId = "" |
895 | 98 | } | 81 | } |
896 | 99 | if stateConn != nil { | ||
897 | 100 | stateConn.Close() | ||
898 | 101 | stateConn = nil | ||
899 | 102 | } | ||
900 | 103 | client.Close() | 82 | client.Close() |
901 | 104 | }() | 83 | }() |
902 | 105 | 84 | ||
903 | @@ -120,35 +99,16 @@ | |||
904 | 120 | 99 | ||
905 | 121 | // Inform Juju that the machine exists. | 100 | // Inform Juju that the machine exists. |
906 | 122 | machineId, err = recordMachineInState(client, *machineParams) | 101 | machineId, err = recordMachineInState(client, *machineParams) |
907 | 123 | if params.IsCodeNotImplemented(err) { | ||
908 | 124 | logger.Infof("AddMachines not supported by the API server, " + | ||
909 | 125 | "falling back to 1.16 compatibility mode (direct DB access)") | ||
910 | 126 | stateConn, err = juju.NewConnFromName(args.EnvName) | ||
911 | 127 | if err == nil { | ||
912 | 128 | machineId, err = recordMachineInState1dot16(stateConn, *machineParams) | ||
913 | 129 | } | ||
914 | 130 | } | ||
915 | 131 | if err != nil { | 102 | if err != nil { |
916 | 132 | return "", err | 103 | return "", err |
917 | 133 | } | 104 | } |
918 | 134 | 105 | ||
936 | 135 | var provisioningScript string | 106 | provisioningScript, err := client.ProvisioningScript(params.ProvisioningScriptParams{ |
937 | 136 | if stateConn == nil { | 107 | MachineId: machineId, |
938 | 137 | provisioningScript, err = client.ProvisioningScript(params.ProvisioningScriptParams{ | 108 | Nonce: machineParams.Nonce, |
939 | 138 | MachineId: machineId, | 109 | }) |
940 | 139 | Nonce: machineParams.Nonce, | 110 | if err != nil { |
941 | 140 | }) | 111 | return "", err |
925 | 141 | if err != nil { | ||
926 | 142 | return "", err | ||
927 | 143 | } | ||
928 | 144 | } else { | ||
929 | 145 | mcfg, err := statecmd.MachineConfig(stateConn.State, machineId, machineParams.Nonce, args.DataDir) | ||
930 | 146 | if err == nil { | ||
931 | 147 | provisioningScript, err = ProvisioningScript(mcfg) | ||
932 | 148 | } | ||
933 | 149 | if err != nil { | ||
934 | 150 | return "", err | ||
935 | 151 | } | ||
942 | 152 | } | 112 | } |
943 | 153 | 113 | ||
944 | 154 | // Finally, provision the machine agent. | 114 | // Finally, provision the machine agent. |
945 | @@ -194,28 +154,6 @@ | |||
946 | 194 | return outJobs, nil | 154 | return outJobs, nil |
947 | 195 | } | 155 | } |
948 | 196 | 156 | ||
949 | 197 | func recordMachineInState1dot16( | ||
950 | 198 | stateConn *juju.Conn, machineParams params.AddMachineParams) (machineId string, err error) { | ||
951 | 199 | stateJobs, err := convertToStateJobs(machineParams.Jobs) | ||
952 | 200 | if err != nil { | ||
953 | 201 | return "", err | ||
954 | 202 | } | ||
955 | 203 | template := state.MachineTemplate{ | ||
956 | 204 | Series: machineParams.Series, | ||
957 | 205 | Constraints: machineParams.Constraints, | ||
958 | 206 | InstanceId: machineParams.InstanceId, | ||
959 | 207 | Jobs: stateJobs, | ||
960 | 208 | Nonce: machineParams.Nonce, | ||
961 | 209 | HardwareCharacteristics: machineParams.HardwareCharacteristics, | ||
962 | 210 | Addresses: machineParams.Addrs, | ||
963 | 211 | } | ||
964 | 212 | machine, err := stateConn.State.AddOneMachine(template) | ||
965 | 213 | if err != nil { | ||
966 | 214 | return "", err | ||
967 | 215 | } | ||
968 | 216 | return machine.Id(), nil | ||
969 | 217 | } | ||
970 | 218 | |||
971 | 219 | // gatherMachineParams collects all the information we know about the machine | 157 | // gatherMachineParams collects all the information we know about the machine |
972 | 220 | // we are about to provision. It will SSH into that machine as the ubuntu user. | 158 | // we are about to provision. It will SSH into that machine as the ubuntu user. |
973 | 221 | // The hostname supplied should not include a username. | 159 | // The hostname supplied should not include a username. |
974 | 222 | 160 | ||
975 | === removed file 'state/statecmd/destroymachines.go' | |||
976 | --- state/statecmd/destroymachines.go 2013-12-10 12:24:25 +0000 | |||
977 | +++ state/statecmd/destroymachines.go 1970-01-01 00:00:00 +0000 | |||
978 | @@ -1,43 +0,0 @@ | |||
979 | 1 | // Copyright 2012, 2013 Canonical Ltd. | ||
980 | 2 | // Licensed under the AGPLv3, see LICENCE file for details. | ||
981 | 3 | |||
982 | 4 | package statecmd | ||
983 | 5 | |||
984 | 6 | import ( | ||
985 | 7 | "fmt" | ||
986 | 8 | "strings" | ||
987 | 9 | |||
988 | 10 | "launchpad.net/juju-core/errors" | ||
989 | 11 | "launchpad.net/juju-core/state" | ||
990 | 12 | ) | ||
991 | 13 | |||
992 | 14 | // DestroyMachines1dot16 destroys the machines with the specified ids. | ||
993 | 15 | // This is copied from the 1.16.3 code to enable compatibility. It should be | ||
994 | 16 | // removed when we release a version that goes via the API only (whatever is | ||
995 | 17 | // after 1.18) | ||
996 | 18 | func DestroyMachines1dot16(st *state.State, ids ...string) (err error) { | ||
997 | 19 | var errs []string | ||
998 | 20 | for _, id := range ids { | ||
999 | 21 | machine, err := st.Machine(id) | ||
1000 | 22 | switch { | ||
1001 | 23 | case errors.IsNotFoundError(err): | ||
1002 | 24 | err = fmt.Errorf("machine %s does not exist", id) | ||
1003 | 25 | case err != nil: | ||
1004 | 26 | case machine.Life() != state.Alive: | ||
1005 | 27 | continue | ||
1006 | 28 | default: | ||
1007 | 29 | err = machine.Destroy() | ||
1008 | 30 | } | ||
1009 | 31 | if err != nil { | ||
1010 | 32 | errs = append(errs, err.Error()) | ||
1011 | 33 | } | ||
1012 | 34 | } | ||
1013 | 35 | if len(errs) == 0 { | ||
1014 | 36 | return nil | ||
1015 | 37 | } | ||
1016 | 38 | msg := "some machines were not destroyed" | ||
1017 | 39 | if len(errs) == len(ids) { | ||
1018 | 40 | msg = "no machines were destroyed" | ||
1019 | 41 | } | ||
1020 | 42 | return fmt.Errorf("%s: %s", msg, strings.Join(errs, "; ")) | ||
1021 | 43 | } |
Reviewers: mp+214504_ code.launchpad. net,
Message:
Please take a look.
Description:
Remove 1.16 support code
This drops most of the 1.16 support code from
the client-side. There's more to remove, this
is just a start.
https:/ /code.launchpad .net/~axwalk/ juju-core/ remove- 1.16-client- support/ +merge/ 214504
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/84520046/
Affected files (+23, -669 lines): addmachine. go constraints. go destroymachine. go environment. go juju/upgradecha rm.go upgradejuju. go manual/ provisioner. go destroymachines .go
A [revision details]
M cmd/juju/
M cmd/juju/common.go
M cmd/juju/
M cmd/juju/deploy.go
M cmd/juju/
M cmd/juju/
M cmd/juju/set.go
M cmd/juju/status.go
M cmd/juju/unset.go
cmd/
M cmd/juju/
M environs/
D state/statecmd/