Merge pull request #1171 from enoodle/aws_cloudinfo_to_read_from_dmi_file
cloudinfo: bugfix openstack identified as aws
This commit is contained in:
commit
8ccd22d2e2
@ -15,24 +15,26 @@
|
|||||||
package cloudinfo
|
package cloudinfo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/aws/ec2metadata"
|
"github.com/aws/aws-sdk-go/aws/ec2metadata"
|
||||||
"github.com/aws/aws-sdk-go/aws/session"
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
|
"io/ioutil"
|
||||||
|
"strings"
|
||||||
|
|
||||||
info "github.com/google/cadvisor/info/v1"
|
info "github.com/google/cadvisor/info/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ProductVerFileName = "/sys/class/dmi/id/product_version"
|
||||||
|
Amazon = "amazon"
|
||||||
|
)
|
||||||
|
|
||||||
func onAWS() bool {
|
func onAWS() bool {
|
||||||
// the default client behavior retried the operation multiple times with a 5s timeout per attempt.
|
data, err := ioutil.ReadFile(ProductVerFileName)
|
||||||
// if you were not on aws, you would block for 20s when invoking this operation.
|
if err != nil {
|
||||||
// we reduce retries to 0 and set the timeout to 2s to reduce the time this blocks when not on aws.
|
return false
|
||||||
client := ec2metadata.New(session.New(&aws.Config{MaxRetries: aws.Int(0)}))
|
|
||||||
if client.Config.HTTPClient != nil {
|
|
||||||
client.Config.HTTPClient.Timeout = time.Duration(2 * time.Second)
|
|
||||||
}
|
}
|
||||||
return client.Available()
|
return strings.Contains(string(data), Amazon)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAwsMetadata(name string) string {
|
func getAwsMetadata(name string) string {
|
||||||
|
Loading…
Reference in New Issue
Block a user