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

Delta Between Two Patch Sets: environs/ec2/image.go

Issue 9419047: Support signed image metadata (Closed)
Left Patch Set: Support signed image metadata Created 11 years, 11 months ago
Right Patch Set: Support signed image metadata Created 11 years, 11 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « environs/ec2/export_test.go ('k') | environs/imagemetadata/decode.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
1 // Copyright 2011, 2012, 2013 Canonical Ltd. 1 // Copyright 2011, 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 ec2 4 package ec2
5 5
6 import ( 6 import (
7 "fmt" 7 "fmt"
8 "launchpad.net/juju-core/environs/imagemetadata" 8 "launchpad.net/juju-core/environs/imagemetadata"
9 "launchpad.net/juju-core/environs/instances" 9 "launchpad.net/juju-core/environs/instances"
10 ) 10 )
11 11
12 // signedImageDataOnly is defined here to allow tests to override the content. 12 // signedImageDataOnly is defined here to allow tests to override the content.
13 // If true, only inline PGP signed image metadata will be used. 13 // If true, only inline PGP signed image metadata will be used.
14 var signedImageDataOnly = true 14 var signedImageDataOnly = true
15 15
16 // defaultCpuPower is larger the smallest instance's cpuPower, and no larger tha n 16 // defaultCpuPower is larger the smallest instance's cpuPower, and no larger tha n
17 // any other instance type's cpuPower. It is used when no explicit CpuPower 17 // any other instance type's cpuPower. It is used when no explicit CpuPower
18 // constraint exists, preventing the smallest instance from being chosen unless 18 // constraint exists, preventing the smallest instance from being chosen unless
19 // the user has clearly indicated that they are willing to accept poor performan ce. 19 // the user has clearly indicated that they are willing to accept poor performan ce.
20 const defaultCpuPower = 100 20 const defaultCpuPower = 100
21 21
22 // findInstanceSpec returns an InstanceSpec satisfying the supplied instanceCons traint. 22 // findInstanceSpec returns an InstanceSpec satisfying the supplied instanceCons traint.
23 func findInstanceSpec(baseURLs []string, ic *instances.InstanceConstraint) (*ins tances.InstanceSpec, error) { 23 func findInstanceSpec(baseURLs []string, ic *instances.InstanceConstraint) (*ins tances.InstanceSpec, error) {
24 if ic.Constraints.CpuPower == nil { 24 if ic.Constraints.CpuPower == nil {
25 ic.Constraints.CpuPower = instances.CpuPower(defaultCpuPower) 25 ic.Constraints.CpuPower = instances.CpuPower(defaultCpuPower)
26 } 26 }
27 ec2Region := allRegions[ic.Region] 27 ec2Region := allRegions[ic.Region]
28 » imageConstraint := imagemetadata.NewImageConstraint(ic.Region, ec2Region .EC2Endpoint, ic.Series, ic.Arches, "") 28 » imageConstraint := imagemetadata.ImageConstraint{
29 » ebs := ebsStorage 29 » » CloudSpec: imagemetadata.CloudSpec{ic.Region, ec2Region.EC2Endpo int},
30 » imageConstraint.Storage = &ebs 30 » » Series: ic.Series,
31 » » Arches: ic.Arches,
32 » }
31 matchingImages, err := imagemetadata.Fetch( 33 matchingImages, err := imagemetadata.Fetch(
32 baseURLs, imagemetadata.DefaultIndexPath, &imageConstraint, sign edImageDataOnly) 34 baseURLs, imagemetadata.DefaultIndexPath, &imageConstraint, sign edImageDataOnly)
33 if err != nil { 35 if err != nil {
34 return nil, err 36 return nil, err
35 } 37 }
36 var images []instances.Image 38 var images []instances.Image
37 for _, imageMetadata := range matchingImages { 39 for _, imageMetadata := range matchingImages {
40 // For now, we only want images with "ebs" storage.
41 if imageMetadata.Storage != ebsStorage {
42 continue
43 }
38 im := *imageMetadata 44 im := *imageMetadata
39 images = append(images, instances.Image{ 45 images = append(images, instances.Image{
40 Id: im.Id, 46 Id: im.Id,
41 VType: im.VType, 47 VType: im.VType,
42 Arch: im.Arch, 48 Arch: im.Arch,
43 }) 49 })
44 } 50 }
45 51
46 // Make a copy of the known EC2 instance types, filling in the cost for the specified region. 52 // Make a copy of the known EC2 instance types, filling in the cost for the specified region.
47 regionCosts := allRegionCosts[ic.Region] 53 regionCosts := allRegionCosts[ic.Region]
48 if len(regionCosts) == 0 && len(allRegionCosts) > 0 { 54 if len(regionCosts) == 0 && len(allRegionCosts) > 0 {
49 return nil, fmt.Errorf("no instance types found in %s", ic.Regio n) 55 return nil, fmt.Errorf("no instance types found in %s", ic.Regio n)
50 } 56 }
51 57
52 var itypesWithCosts []instances.InstanceType 58 var itypesWithCosts []instances.InstanceType
53 for _, itype := range allInstanceTypes { 59 for _, itype := range allInstanceTypes {
54 cost, ok := regionCosts[itype.Name] 60 cost, ok := regionCosts[itype.Name]
55 if !ok { 61 if !ok {
56 continue 62 continue
57 } 63 }
58 itWithCost := itype 64 itWithCost := itype
59 itWithCost.Cost = cost 65 itWithCost.Cost = cost
60 itypesWithCosts = append(itypesWithCosts, itWithCost) 66 itypesWithCosts = append(itypesWithCosts, itWithCost)
61 } 67 }
62 » spec, err := instances.FindInstanceSpec(images, ic, itypesWithCosts) 68 » return instances.FindInstanceSpec(images, ic, itypesWithCosts)
63 » if err != nil {
64 » » return nil, err
65 » }
66 » return spec, nil
67 } 69 }
LEFTRIGHT

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