cloudinfo: identify gce from file
This commit is contained in:
parent
6abe4db6f4
commit
cf548f1b70
@ -15,15 +15,27 @@
|
|||||||
package cloudinfo
|
package cloudinfo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
info "github.com/google/cadvisor/info/v1"
|
info "github.com/google/cadvisor/info/v1"
|
||||||
|
|
||||||
|
"github.com/golang/glog"
|
||||||
"google.golang.org/cloud/compute/metadata"
|
"google.golang.org/cloud/compute/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
gceProductName = "/sys/class/dmi/id/product_name"
|
||||||
|
google = "Google"
|
||||||
|
)
|
||||||
|
|
||||||
func onGCE() bool {
|
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 {
|
func getGceInstanceType() info.InstanceType {
|
||||||
|
Loading…
Reference in New Issue
Block a user