LEFT | RIGHT |
1 // Copyright 2012, 2013 Canonical Ltd. | 1 // Copyright 2012, 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 main | 4 package main |
5 | 5 |
6 import ( | 6 import ( |
7 "errors" | 7 "errors" |
8 "fmt" | 8 "fmt" |
9 "os" | 9 "os" |
10 | 10 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 } | 134 } |
135 curl, err := charm.InferURL(c.CharmName, conf.DefaultSeries()) | 135 curl, err := charm.InferURL(c.CharmName, conf.DefaultSeries()) |
136 if err != nil { | 136 if err != nil { |
137 return err | 137 return err |
138 } | 138 } |
139 repo, err := charm.InferRepository(curl, ctx.AbsPath(c.RepoPath)) | 139 repo, err := charm.InferRepository(curl, ctx.AbsPath(c.RepoPath)) |
140 if err != nil { | 140 if err != nil { |
141 return err | 141 return err |
142 } | 142 } |
143 | 143 |
144 » repo = config.AuthorizeCharmRepo(repo, conf) | 144 » repo = config.SpecializeCharmRepo(repo, conf) |
145 | 145 |
146 » curl, err = addCharmViaAPI(client, ctx, curl, repo, conf.Testing()) | 146 » curl, err = addCharmViaAPI(client, ctx, curl, repo) |
147 if err != nil { | 147 if err != nil { |
148 return err | 148 return err |
149 } | 149 } |
150 | 150 |
151 if c.BumpRevision { | 151 if c.BumpRevision { |
152 ctx.Stdout.Write([]byte("--upgrade (or -u) is deprecated and ign
ored; charms are always deployed with a unique revision.\n")) | 152 ctx.Stdout.Write([]byte("--upgrade (or -u) is deprecated and ign
ored; charms are always deployed with a unique revision.\n")) |
153 } | 153 } |
154 | 154 |
155 charmInfo, err := client.CharmInfo(curl.String()) | 155 charmInfo, err := client.CharmInfo(curl.String()) |
156 if err != nil { | 156 if err != nil { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 } | 205 } |
206 curl, err := charm.InferURL(c.CharmName, conf.DefaultSeries()) | 206 curl, err := charm.InferURL(c.CharmName, conf.DefaultSeries()) |
207 if err != nil { | 207 if err != nil { |
208 return err | 208 return err |
209 } | 209 } |
210 repo, err := charm.InferRepository(curl, ctx.AbsPath(c.RepoPath)) | 210 repo, err := charm.InferRepository(curl, ctx.AbsPath(c.RepoPath)) |
211 if err != nil { | 211 if err != nil { |
212 return err | 212 return err |
213 } | 213 } |
214 | 214 |
215 » repo = config.AuthorizeCharmRepo(repo, conf) | 215 » repo = config.SpecializeCharmRepo(repo, conf) |
216 | 216 |
217 // TODO(fwereade) it's annoying to roundtrip the bytes through the clien
t | 217 // TODO(fwereade) it's annoying to roundtrip the bytes through the clien
t |
218 // here, but it's the original behaviour and not convenient to change. | 218 // here, but it's the original behaviour and not convenient to change. |
219 // PutCharm will always be required in some form for local charms; and w
e | 219 // PutCharm will always be required in some form for local charms; and w
e |
220 // will need an EnsureStoreCharm method somewhere that gets the state.Ch
arm | 220 // will need an EnsureStoreCharm method somewhere that gets the state.Ch
arm |
221 // for use in the following checks. | 221 // for use in the following checks. |
222 ch, err := conn.PutCharm(curl, repo, c.BumpRevision) | 222 ch, err := conn.PutCharm(curl, repo, c.BumpRevision) |
223 if err != nil { | 223 if err != nil { |
224 return err | 224 return err |
225 } | 225 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 ConfigSettings: settings, | 258 ConfigSettings: settings, |
259 Constraints: c.Constraints, | 259 Constraints: c.Constraints, |
260 ToMachineSpec: c.ToMachineSpec, | 260 ToMachineSpec: c.ToMachineSpec, |
261 }) | 261 }) |
262 return err | 262 return err |
263 } | 263 } |
264 | 264 |
265 // addCharmViaAPI calls the appropriate client API calls to add the | 265 // addCharmViaAPI calls the appropriate client API calls to add the |
266 // given charm URL to state. Also displays the charm URL of the added | 266 // given charm URL to state. Also displays the charm URL of the added |
267 // charm on stdout. | 267 // charm on stdout. |
268 func addCharmViaAPI(client *api.Client, ctx *cmd.Context, curl *charm.URL, repo
charm.Repository, testing bool) (*charm.URL, error) { | 268 func addCharmViaAPI(client *api.Client, ctx *cmd.Context, curl *charm.URL, repo
charm.Repository) (*charm.URL, error) { |
269 if curl.Revision < 0 { | 269 if curl.Revision < 0 { |
270 » » latest, err := charm.Latest(repo, curl, testing) | 270 » » latest, err := charm.Latest(repo, curl) |
271 if err != nil { | 271 if err != nil { |
272 return nil, err | 272 return nil, err |
273 } | 273 } |
274 curl = curl.WithRevision(latest) | 274 curl = curl.WithRevision(latest) |
275 } | 275 } |
276 switch curl.Schema { | 276 switch curl.Schema { |
277 case "local": | 277 case "local": |
278 » » ch, err := repo.Get(curl, false) | 278 » » ch, err := repo.Get(curl) |
279 if err != nil { | 279 if err != nil { |
280 return nil, err | 280 return nil, err |
281 } | 281 } |
282 stateCurl, err := client.AddLocalCharm(curl, ch) | 282 stateCurl, err := client.AddLocalCharm(curl, ch) |
283 if err != nil { | 283 if err != nil { |
284 return nil, err | 284 return nil, err |
285 } | 285 } |
286 curl = stateCurl | 286 curl = stateCurl |
287 case "cs": | 287 case "cs": |
288 err := client.AddCharm(curl) | 288 err := client.AddCharm(curl) |
289 if err != nil { | 289 if err != nil { |
290 return nil, err | 290 return nil, err |
291 } | 291 } |
292 default: | 292 default: |
293 return nil, fmt.Errorf("unsupported charm URL schema: %q", curl.
Schema) | 293 return nil, fmt.Errorf("unsupported charm URL schema: %q", curl.
Schema) |
294 } | 294 } |
295 report := fmt.Sprintf("Added charm %q to the environment.\n", curl) | 295 report := fmt.Sprintf("Added charm %q to the environment.\n", curl) |
296 ctx.Stdout.Write([]byte(report)) | 296 ctx.Stdout.Write([]byte(report)) |
297 return curl, nil | 297 return curl, nil |
298 } | 298 } |
LEFT | RIGHT |