// findInstanceSpec returns the InstanceSpec that best satisfies the supplied // InstanceConstraint. // // NOTE(axw) for now we ignore simplestreams altogether, and go straight to // Azure's image registry. func findInstanceSpec( client compute.VirtualMachineImagesClient, instanceTypesMap map[string]instances.InstanceType, constraint *instances.InstanceConstraint, imageStream string, ) (*instances.InstanceSpec, error) { if !constraintHasArch(constraint, arch.AMD64) { // Azure only supports AMD64. return nil, errors.NotFoundf("%s in arch constraints", arch.AMD64) } image, err := imageutils.SeriesImage(constraint.Series, imageStream, constraint.Region, client) if err != nil { return nil, errors.Trace(err) } images := []instances.Image{*image} instanceTypes := make([]instances.InstanceType, 0, len(instanceTypesMap)) for _, instanceType := range instanceTypesMap { instanceTypes = append(instanceTypes, instanceType) } constraint.Constraints = defaultToBaselineSpec(constraint.Constraints) return instances.FindInstanceSpec(images, constraint, instanceTypes) }
func (s *imageutilsSuite) TestSeriesImageInvalidSKU(c *gc.C) { s.mockSender.EmitContent( `[{"name": "12.04.invalid"}, {"name": "12.04.5-LTS"}]`, ) image, err := imageutils.SeriesImage("precise", "released", "westus", s.client) c.Assert(err, jc.ErrorIsNil) c.Assert(image, gc.NotNil) c.Assert(image, jc.DeepEquals, &instances.Image{ Id: "Canonical:UbuntuServer:12.04.5-LTS:latest", Arch: arch.AMD64, VirtType: "Hyper-V", }) }
func (s *imageutilsSuite) TestSeriesImage(c *gc.C) { s.mockSender.AppendResponse(mocks.NewResponseWithContent( `[{"name": "14.04.3"}, {"name": "14.04.1-LTS"}, {"name": "12.04.5"}]`, )) image, err := imageutils.SeriesImage("trusty", "released", "westus", s.client) c.Assert(err, jc.ErrorIsNil) c.Assert(image, gc.NotNil) c.Assert(image, jc.DeepEquals, &instances.Image{ Id: "Canonical:UbuntuServer:14.04.3:latest", Arch: arch.AMD64, VirtType: "Hyper-V", }) }
func (s *imageutilsSuite) assertImageId(c *gc.C, series, stream, id string) { image, err := imageutils.SeriesImage(series, stream, "westus", s.client) c.Assert(err, jc.ErrorIsNil) c.Assert(image.Id, gc.Equals, id) }
func (s *imageutilsSuite) TestSeriesImageStreamNotFound(c *gc.C) { s.mockSender.EmitContent(`[{"name": "14.04-beta1"}]`) _, err := imageutils.SeriesImage("trusty", "whatever", "westus", s.client) c.Assert(err, gc.ErrorMatches, "selecting SKU for trusty: Ubuntu SKUs for whatever stream not found") }
func (s *imageutilsSuite) TestSeriesImageNotFound(c *gc.C) { s.mockSender.EmitContent(`[]`) image, err := imageutils.SeriesImage("trusty", "released", "westus", s.client) c.Assert(err, gc.ErrorMatches, "selecting SKU for trusty: Ubuntu SKUs not found") c.Assert(image, gc.IsNil) }
func (s *imageutilsSuite) TestSeriesImageArch(c *gc.C) { _, err := imageutils.SeriesImage("arch", "released", "westus", s.client) c.Assert(err, gc.ErrorMatches, "deploying Arch not supported") }
func (s *imageutilsSuite) TestSeriesImageGenericLinux(c *gc.C) { _, err := imageutils.SeriesImage("genericlinux", "released", "westus", s.client) c.Assert(err, gc.ErrorMatches, "deploying GenericLinux not supported") }