Ejemplo n.º 1
0
func getRegionMap() (map[string]interface{}, error) {
	regionMap := map[string]map[string]string{}

	for _, channel := range supportedChannels {
		regions, err := coreosutil.GetAMIData(channel)

		if err != nil {
			return nil, err
		}

		for region, amis := range regions {
			if region == "release_info" {
				continue
			}

			if _, ok := regionMap[region]; !ok {
				regionMap[region] = map[string]string{}
			}

			if ami, ok := amis["hvm"]; ok {
				regionMap[region][channel] = ami
			}
		}
	}

	output := map[string]interface{}{}

	for key, val := range regionMap {
		output[key] = val
	}

	return output, nil
}
Ejemplo n.º 2
0
func getAMI(region, channel string) (string, error) {

	regions, err := coreosutil.GetAMIData(channel)

	if err != nil {
		return "", fmt.Errorf("error getting ami data for channel %s: %v", channel, err)
	}

	amis, ok := regions[region]
	if !ok {
		return "", fmt.Errorf("could not find region %s for channel %s", region, channel)
	}

	if ami, ok := amis["hvm"]; ok {
		return ami, nil
	}

	return "", fmt.Errorf("could not find hvm image for region %s, channel %s", region, channel)
}
Ejemplo n.º 3
0
// isMinImageVersion will return true if the supplied version is greater then
// or equal to the current CoreOS release indicated by the given release
// channel.
func isMinImageVersion(minVersion semver.Version, release string) (bool, error) {
	metaData, err := coreosutil.GetAMIData(release)
	if err != nil {
		return false, fmt.Errorf("Unable to retrieve current release channel version: %v", err)
	}

	version, ok := metaData["release_info"]["version"]
	if !ok {
		return false, fmt.Errorf("Error parsing image metadata for version")
	}

	current, err := semver.NewVersion(version)
	if err != nil {
		return false, fmt.Errorf("Error parsing semver from image version %v", err)
	}

	if minVersion.LessThan(*current) {
		return false, nil
	}

	return true, nil
}
Ejemplo n.º 4
0
func getAMI(region, channel string) (string, error) {
	regionMap := map[string]map[string]string{}

	for _, channel := range supportedChannels {
		regions, err := coreosutil.GetAMIData(channel)

		if err != nil {
			return "", err
		}

		for region, amis := range regions {
			if region == "release_info" {
				continue
			}

			if _, ok := regionMap[region]; !ok {
				regionMap[region] = map[string]string{}
			}

			if ami, ok := amis["hvm"]; ok {
				regionMap[region][channel] = ami
			}
		}
	}

	if regionMap[region] == nil {
		return "", fmt.Errorf("could not get AMI for region %s", region)
	}

	ami := regionMap[region][channel]
	if ami == "" {
		return "", fmt.Errorf("could not get AMI in region %s for channel %s", region, channel)
	}

	return ami, nil
}