Skip to content

Commit

Permalink
Merge pull request #353 from nak3/assign-ip
Browse files Browse the repository at this point in the history
Assign IP address when network device is specified
  • Loading branch information
diptanu committed Oct 28, 2015
2 parents baee91f + 11a46aa commit dfbbbaf
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions client/fingerprint/network_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ func (f *NetworkFingerprint) Fingerprint(cfg *config.Config, node *structs.Node)
// newNetwork is populated and addded to the Nodes resources
newNetwork := &structs.NetworkResource{}
defaultDevice := ""
ip := ""

// 1. Use user-defined network device
// 2. Use first interface found in the system for non-dev mode. (dev mode uses lo by default.)
if cfg.NetworkInterface != "" {
defaultDevice = cfg.NetworkInterface
ip = f.ipAddress(defaultDevice)
} else {

intfs, err := net.Interfaces()
Expand All @@ -48,19 +50,19 @@ func (f *NetworkFingerprint) Fingerprint(cfg *config.Config, node *structs.Node)

for _, i := range intfs {
if (i.Flags&net.FlagUp != 0) && (i.Flags&(net.FlagLoopback|net.FlagPointToPoint) == 0) {
if ip := f.ipAddress(i.Name); ip != "" {
if ip = f.ipAddress(i.Name); ip != "" {
defaultDevice = i.Name
node.Attributes["network.ip-address"] = ip
newNetwork.IP = ip
newNetwork.CIDR = newNetwork.IP + "/32"
break
}
}
}
}

if defaultDevice != "" {
if (defaultDevice != "") && (ip != "") {
newNetwork.Device = defaultDevice
node.Attributes["network.ip-address"] = ip
newNetwork.IP = ip
newNetwork.CIDR = newNetwork.IP + "/32"
} else {
return false, fmt.Errorf("Unable to find any network interface which has IP address")
}
Expand Down

0 comments on commit dfbbbaf

Please sign in to comment.