-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also send node id v1 to BCDB when registring the node
this is required to be able to match nodes between v1 and v2.
- Loading branch information
Showing
4 changed files
with
64 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package network | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/vishvananda/netlink" | ||
) | ||
|
||
// NodeIDv1 returns the node ID as it was calculated in 0-OS v1 | ||
func NodeIDv1() (string, error) { | ||
zos, err := netlink.LinkByName(DefaultBridge) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
links, err := netlink.LinkList() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
// find the physical interface attached to the default bridge | ||
for _, l := range links { | ||
if l.Attrs().MasterIndex == zos.Attrs().Index { | ||
return convertMac(l.Attrs().HardwareAddr.String()), nil | ||
} | ||
} | ||
return "", fmt.Errorf("not physical interface attached to default bridge found") | ||
} | ||
|
||
func convertMac(mac string) string { | ||
return strings.Replace(mac, ":", "", -1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package network | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConvertMac(t *testing.T) { | ||
id := convertMac("fe:44:e1:67:a8:d2") | ||
assert.Equal(t, "fe44e167a8d2", id) | ||
} |