e693d15a5b
Previously, Nomad was using a hand-made lookup table for looking up EC2 CPU performance characteristics (core count + speed = ticks). This data was incomplete and incorrect depending on region. The AWS API has the correct data but requires API keys to use (i.e. should not be queried directly from Nomad). This change introduces a lookup table generated by a small command line tool in Nomad's tools module which uses the Amazon AWS API. Running the tool requires AWS_* environment variables set. $ # in nomad/tools/cpuinfo $ go run . Going forward, Nomad can incorporate regeneration of the lookup table somewhere in the CI pipeline so that we remain up-to-date on the latest offerings from EC2. Fixes #7830
49 lines
980 B
Go
49 lines
980 B
Go
package main
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
"os/exec"
|
|
"text/template"
|
|
)
|
|
|
|
// open the output file for writing.
|
|
func open(output string) (io.ReadWriteCloser, error) {
|
|
return os.Create(output)
|
|
}
|
|
|
|
// flatten region data, assuming instance type is the same across regions.
|
|
func flatten(data map[string]map[string]specs) map[string]specs {
|
|
result := make(map[string]specs)
|
|
for _, m := range data {
|
|
for iType, specs := range m {
|
|
result[iType] = specs
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
|
|
type Template struct {
|
|
Package string
|
|
Data map[string]specs
|
|
}
|
|
|
|
// write the data using the cpu_table.go.template to w.
|
|
func write(w io.Writer, data map[string]specs, pkg string) error {
|
|
tmpl, err := template.ParseFiles("cpu_table.go.template")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return tmpl.Execute(w, Template{
|
|
Package: pkg,
|
|
Data: data,
|
|
})
|
|
}
|
|
|
|
// format the file using gofmt.
|
|
func format(file string) error {
|
|
cmd := exec.Command("gofmt", "-w", file)
|
|
_, err := cmd.CombinedOutput()
|
|
return err
|
|
}
|