blob: 7e66c2bcd07c5b31550ab010cb25ffc1a0946900 [file] [log] [blame]
Cosmos Nicolaou43b95352014-10-14 11:09:52 -07001// +build linux
2
3package internal
4
5import (
6 "net"
7
8 "veyron.io/veyron/veyron2/vlog"
9
10 "veyron.io/veyron/veyron/profiles/internal/gce"
11)
12
13// GCEPublicAddress returns the public IP address of the GCE instance
14// it is run from, or nil if run from anywhere else. The returned address
15// is the public address of a 1:1 NAT tunnel to this host.
16func GCEPublicAddress(log vlog.Logger) *net.IPAddr {
17 if !gce.RunningOnGCE() {
18 return nil
19 }
20 var pub *net.IPAddr
21 // Determine the IP address from GCE's metadata
22 if ip, err := gce.ExternalIPAddress(); err != nil {
23 log.Infof("failed to query GCE metadata: %s", err)
24 } else {
25 // 1:1 NAT case, our network config will not change.
26 pub = &net.IPAddr{IP: ip}
27 }
28 if pub == nil {
29 log.Infof("failed to determine public IP address to publish with")
30 }
31 return pub
32}