github.com/alibaba/ilogtail/pkg@v0.0.0-20250526110833-c53b480d046c/helper/platformmeta/interface.go (about) 1 // Copyright 2023 iLogtail Authors 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 platformmeta 16 17 const ( 18 FlagInstanceID = "__cloud_instance_id__" 19 FlagInstanceName = "__cloud_instance_name__" 20 FlagInstanceRegion = "__cloud_region__" 21 FlagInstanceZone = "__cloud_zone__" 22 FlagInstanceVpcID = "__cloud_vpc_id__" 23 FlagInstanceVswitchID = "__cloud_vswitch_id__" 24 FlagInstanceTags = "__cloud_instance_tags__" 25 FlagInstanceType = "__cloud_instance_type__" 26 FlagInstanceImageID = "__cloud_image_id__" 27 FlagInstanceMaxIngress = "__cloud_max_ingress__" 28 FlagInstanceMaxEgress = "__cloud_max_egress__" 29 30 FlagInstanceNameWrapper = "{{" + FlagInstanceName + "}}" 31 FlagInstanceVpcIDWrapper = "{{" + FlagInstanceVpcID + "}}" 32 FlagInstanceVswitchIDWrapper = "{{" + FlagInstanceVswitchID + "}}" 33 FlagInstanceMaxIngressWrapper = "{{" + FlagInstanceMaxIngress + "}}" 34 FlagInstanceMaxEgressWrapper = "{{" + FlagInstanceMaxEgress + "}}" 35 ) 36 37 type Manager interface { 38 StartCollect() 39 GetInstanceID() string 40 GetInstanceImageID() string 41 GetInstanceType() string 42 GetInstanceRegion() string 43 GetInstanceZone() string 44 GetInstanceName() string 45 GetInstanceVpcID() string 46 GetInstanceVswitchID() string 47 GetInstanceMaxNetEgress() int64 48 GetInstanceMaxNetIngress() int64 49 GetInstanceTags() map[string]string 50 Ping() bool 51 } 52 53 type Platform string 54 type MetaType string 55 56 const ( 57 Aliyun Platform = "alibaba_cloud_ecs" 58 Mock Platform = "mock" 59 Auto Platform = "auto" 60 ) 61 62 var register map[Platform]Manager 63 64 func GetManager(platform Platform) Manager { 65 if platform == Auto { 66 for _, manager := range register { 67 if manager.Ping() { 68 return manager 69 } 70 } 71 return nil 72 } 73 return register[platform] 74 } 75 76 func init() { 77 register = make(map[Platform]Manager) 78 initAliyun() 79 initMock() 80 }