Left: | ||
Right: |
OLD | NEW |
---|---|
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 openstack | 4 package openstack |
5 | 5 |
6 import ( | 6 import ( |
7 "launchpad.net/juju-core/environs/imagemetadata" | 7 "launchpad.net/juju-core/environs/imagemetadata" |
8 "launchpad.net/juju-core/environs/instances" | 8 "launchpad.net/juju-core/environs/instances" |
9 ) | 9 ) |
10 | 10 |
11 // findInstanceSpec returns an image and instance type satisfying the constraint . | 11 // findInstanceSpec returns an image and instance type satisfying the constraint . |
12 // The instance type comes from querying the flavors supported by the deployment . | 12 // The instance type comes from querying the flavors supported by the deployment . |
13 func findInstanceSpec(e *environ, ic *instances.InstanceConstraint) (*instances. InstanceSpec, error) { | 13 func findInstanceSpec(e *environ, ic *instances.InstanceConstraint) (*instances. InstanceSpec, error) { |
14 // first construct all available instance types from the supported flavo rs. | 14 // first construct all available instance types from the supported flavo rs. |
15 nova := e.nova() | 15 nova := e.nova() |
16 flavors, err := nova.ListFlavorsDetail() | 16 flavors, err := nova.ListFlavorsDetail() |
17 if err != nil { | 17 if err != nil { |
18 return nil, err | 18 return nil, err |
19 } | 19 } |
20 allInstanceTypes := []instances.InstanceType{} | 20 allInstanceTypes := []instances.InstanceType{} |
21 for _, flavor := range flavors { | 21 for _, flavor := range flavors { |
22 instanceType := instances.InstanceType{ | 22 instanceType := instances.InstanceType{ |
23 Id: flavor.Id, | 23 Id: flavor.Id, |
24 Name: flavor.Name, | 24 Name: flavor.Name, |
25 Arches: ic.Arches, | 25 Arches: ic.Arches, |
26 Mem: uint64(flavor.RAM), | 26 Mem: uint64(flavor.RAM), |
27 CpuCores: uint64(flavor.VCPUs), | 27 CpuCores: uint64(flavor.VCPUs), |
28 OsDisk: uint64(flavor.Disk * 1024), | |
gz
2013/08/14 17:15:09
0 is a valid special case, which does not mean the
sidnei.da.silva
2013/08/14 17:58:14
Done.
| |
28 } | 29 } |
29 allInstanceTypes = append(allInstanceTypes, instanceType) | 30 allInstanceTypes = append(allInstanceTypes, instanceType) |
30 } | 31 } |
31 | 32 |
32 imageConstraint := imagemetadata.ImageConstraint{ | 33 imageConstraint := imagemetadata.ImageConstraint{ |
33 CloudSpec: imagemetadata.CloudSpec{ic.Region, e.ecfg().authURL() }, | 34 CloudSpec: imagemetadata.CloudSpec{ic.Region, e.ecfg().authURL() }, |
34 Series: ic.Series, | 35 Series: ic.Series, |
35 Arches: ic.Arches, | 36 Arches: ic.Arches, |
36 } | 37 } |
37 baseURLs, err := e.getImageBaseURLs() | 38 baseURLs, err := e.getImageBaseURLs() |
38 if err != nil { | 39 if err != nil { |
39 return nil, err | 40 return nil, err |
40 } | 41 } |
41 // TODO (wallyworld): use an env parameter (default true) to mandate use of only signed image metadata. | 42 // TODO (wallyworld): use an env parameter (default true) to mandate use of only signed image metadata. |
42 matchingImages, err := imagemetadata.Fetch(baseURLs, imagemetadata.Defau ltIndexPath, &imageConstraint, false) | 43 matchingImages, err := imagemetadata.Fetch(baseURLs, imagemetadata.Defau ltIndexPath, &imageConstraint, false) |
43 if err != nil { | 44 if err != nil { |
44 return nil, err | 45 return nil, err |
45 } | 46 } |
46 images := instances.ImageMetadataToImages(matchingImages) | 47 images := instances.ImageMetadataToImages(matchingImages) |
47 spec, err := instances.FindInstanceSpec(images, ic, allInstanceTypes) | 48 spec, err := instances.FindInstanceSpec(images, ic, allInstanceTypes) |
48 if err != nil { | 49 if err != nil { |
49 return nil, err | 50 return nil, err |
50 } | 51 } |
51 return spec, nil | 52 return spec, nil |
52 } | 53 } |
OLD | NEW |