whereAmI determines which strategy the rack resolver should use.
()
| 48 | |
| 49 | // whereAmI determines which strategy the rack resolver should use. |
| 50 | func whereAmI() string { |
| 51 | // https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint.html |
| 52 | if os.Getenv(ecsContainerMetadataURI) != "" { |
| 53 | return "ecs" |
| 54 | } |
| 55 | // https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/identify_ec2_instances.html |
| 56 | for _, path := range [...]string{ |
| 57 | "/sys/devices/virtual/dmi/id/product_uuid", |
| 58 | "/sys/hypervisor/uuid", |
| 59 | } { |
| 60 | b, err := ioutil.ReadFile(path) |
| 61 | if err != nil { |
| 62 | continue |
| 63 | } |
| 64 | s := string(b) |
| 65 | switch { |
| 66 | case strings.HasPrefix(s, "EC2"), strings.HasPrefix(s, "ec2"): |
| 67 | return "ec2" |
| 68 | } |
| 69 | } |
| 70 | return "somewhere" |
| 71 | } |
| 72 | |
| 73 | // ecsAvailabilityZone queries the task endpoint for the metadata URI that ECS |
| 74 | // injects into the ECS_CONTAINER_METADATA_URI variable in order to retrieve |