From 276f0b5d99edb374f52ebdecc601e8106dbb7c92 Mon Sep 17 00:00:00 2001 From: Alex Crawford Date: Tue, 1 Jul 2014 14:23:14 -0700 Subject: [PATCH] metadata: Fetch the public and private IP addresses --- datasource/metadata_service.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/datasource/metadata_service.go b/datasource/metadata_service.go index 4817a09..fff4423 100644 --- a/datasource/metadata_service.go +++ b/datasource/metadata_service.go @@ -110,6 +110,18 @@ func fetchMetadata(client getter) ([]byte, error) { return nil, err } + if localAddr, err := fetchAttribute(client, fmt.Sprintf("%s/local-ipv4", Ec2MetadataUrl)); err == nil { + attrs["local-ipv4"] = localAddr + } else if _, ok := err.(pkg.ErrNotFound); !ok { + return nil, err + } + + if publicAddr, err := fetchAttribute(client, fmt.Sprintf("%s/public-ipv4", Ec2MetadataUrl)); err == nil { + attrs["public-ipv4"] = publicAddr + } else if _, ok := err.(pkg.ErrNotFound); !ok { + return nil, err + } + if content_path, err := fetchAttribute(client, fmt.Sprintf("%s/network_config/content_path", Ec2MetadataUrl)); err == nil { attrs["network_config"] = map[string]string{ "content_path": content_path,