This repository has been archived by the owner on Sep 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1852 from jorge07/flatcar-0.14.x
Flatcar migration for 0.14.x
- Loading branch information
Showing
8 changed files
with
57 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package amiregistry | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
func GetAMI(region, channel string) (string, error) { | ||
|
||
amis, err := GetAMIData(channel) | ||
|
||
if err != nil { | ||
return "", fmt.Errorf("uanble to fetch AMI for channel \"%s\": %v", channel, err) | ||
} | ||
|
||
for _, v := range amis { | ||
if v["name"] != region { | ||
continue | ||
} | ||
if hvm, ok := v["hvm"]; ok { | ||
return hvm, nil | ||
} else { | ||
break | ||
} | ||
} | ||
|
||
return "", fmt.Errorf("could not find \"hvm\" image for region \"%s\" in flatcar channel \"%s\"", region, channel) | ||
} | ||
|
||
func GetAMIData(channel string) ([]map[string]string, error) { | ||
url := fmt.Sprintf("https://%s.release.flatcar-linux.net/amd64-usr/current/flatcar_production_ami_all.json", channel) | ||
r, err := newHttp().Get(url) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get AMI data from url \"%s\": %v", channel, err) | ||
} | ||
|
||
if r.StatusCode != 200 { | ||
return nil, fmt.Errorf("failed to get AMI data from url \"%s\": invalid status code: %d", url, r.StatusCode) | ||
} | ||
|
||
output := map[string][]map[string]string{} | ||
|
||
err = json.NewDecoder(r.Body).Decode(&output) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to parse AMI data from url \"%s\": %v", url, err) | ||
} | ||
r.Body.Close() | ||
|
||
return output["amis"], nil | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters