Merge pull request #1347 from enoodle/cloudinfo_gce_id_from_file

cloudinfo: identify gce from file
This commit is contained in:
Tim St. Clair 2016-07-01 07:45:48 -07:00 committed by GitHub
commit c39c3f5b38

View File

@ -15,15 +15,27 @@
package cloudinfo
import (
"io/ioutil"
"strings"
info "github.com/google/cadvisor/info/v1"
"github.com/golang/glog"
"google.golang.org/cloud/compute/metadata"
)
const (
gceProductName = "/sys/class/dmi/id/product_name"
google = "Google"
)
func onGCE() bool {
return metadata.OnGCE()
data, err := ioutil.ReadFile(gceProductName)
if err != nil {
glog.V(2).Infof("Error while reading product_name: %v", err)
return false
}
return strings.Contains(string(data), google)
}
func getGceInstanceType() info.InstanceType {