Пример #1
0
// 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)
}
Пример #2
0
// findInstanceSpec returns the InstanceSpec that best satisfies the supplied
// InstanceConstraint.
func findInstanceSpec(env *azureEnviron, constraint *instances.InstanceConstraint) (*instances.InstanceSpec, error) {
	constraint.Constraints = defaultToBaselineSpec(constraint.Constraints)
	imageData, err := findMatchingImages(env, constraint.Region, constraint.Series, constraint.Arches)
	if err != nil {
		return nil, err
	}
	images := instances.ImageMetadataToImages(imageData)
	instanceTypes, err := listInstanceTypes(env)
	if err != nil {
		return nil, err
	}
	return instances.FindInstanceSpec(images, constraint, instanceTypes)
}