~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/provider/openstack/image.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
        ic *instances.InstanceConstraint,
16
16
        imageMetadata []*imagemetadata.ImageMetadata,
17
17
) (*instances.InstanceSpec, error) {
18
 
        // first construct all available instance types from the supported flavors.
 
18
        // First construct all available instance types from the supported flavors.
19
19
        nova := e.nova()
20
20
        flavors, err := nova.ListFlavorsDetail()
21
21
        if err != nil {
22
22
                return nil, err
23
23
        }
 
24
        // Not all needed information is available in flavors,
 
25
        // for e.g. architectures or virtualisation types.
 
26
        // For these properties, we assume that all instance types support
 
27
        // all values.
24
28
        allInstanceTypes := []instances.InstanceType{}
25
29
        for _, flavor := range flavors {
26
30
                instanceType := instances.InstanceType{
32
36
                        RootDisk: uint64(flavor.Disk * 1024),
33
37
                        // tags not currently supported on openstack
34
38
                }
 
39
                if ic.Constraints.HasVirtType() {
 
40
                        // Instance Type virtual type depends on the virtual type of the selected image, i.e.
 
41
                        // picking an image with a virt type gives a machine with this virt type.
 
42
                        instanceType.VirtType = ic.Constraints.VirtType
 
43
                }
35
44
                allInstanceTypes = append(allInstanceTypes, instanceType)
36
45
        }
37
46
 
40
49
        if err != nil {
41
50
                return nil, err
42
51
        }
 
52
 
 
53
        // If instance constraints did not have a virtualisation type,
 
54
        // but image metadata did, we will have an instance type
 
55
        // with virtualisation type of an image.
 
56
        if !ic.Constraints.HasVirtType() && spec.Image.VirtType != "" {
 
57
                spec.InstanceType.VirtType = &spec.Image.VirtType
 
58
        }
43
59
        return spec, nil
44
60
}