github.com/google/cadvisor@v0.49.1/utils/cloudinfo/azure/azure.go (about) 1 // Copyright 2015 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package cloudinfo 16 17 import ( 18 "os" 19 "strings" 20 21 info "github.com/google/cadvisor/info/v1" 22 "github.com/google/cadvisor/utils/cloudinfo" 23 ) 24 25 const ( 26 sysVendorFileName = "/sys/class/dmi/id/sys_vendor" 27 biosUUIDFileName = "/sys/class/dmi/id/product_uuid" 28 microsoftCorporation = "Microsoft Corporation" 29 ) 30 31 func init() { 32 cloudinfo.RegisterCloudProvider(info.Azure, &provider{}) 33 } 34 35 type provider struct{} 36 37 var _ cloudinfo.CloudProvider = provider{} 38 39 func (provider) IsActiveProvider() bool { 40 data, err := os.ReadFile(sysVendorFileName) 41 if err != nil { 42 return false 43 } 44 return strings.Contains(string(data), microsoftCorporation) 45 } 46 47 // TODO: Implement method. 48 func (provider) GetInstanceType() info.InstanceType { 49 return info.UnknownInstance 50 } 51 52 func (provider) GetInstanceID() info.InstanceID { 53 data, err := os.ReadFile(biosUUIDFileName) 54 if err != nil { 55 return info.UnNamedInstance 56 } 57 return info.InstanceID(strings.TrimSuffix(string(data), "\n")) 58 }