cloudinfo: identify gce from file

This commit is contained in:
Erez Freiberger 2016-06-23 13:10:59 +03:00
parent 6abe4db6f4
commit cf548f1b70

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 {