initialize via sub-function

This commit is contained in:
Bryan Boreham committed 2016-05-25 17:17:19 +01:00
1 parent 9f8b94645d
commit 9aaa7f19fd
3 files changed
+25 -27

No files matched your search

+11 -1
View File
@@ -9,7 +9,7 @@ import (
)
// create and attach local name to the Weave bridge
func CreateAndAttachVeth(localName, peerName, bridgeName string, mtu int) (*netlink.Veth, error) {
func CreateAndAttachVeth(localName, peerName, bridgeName string, mtu int, init func(local, guest netlink.Link) error) (*netlink.Veth, error) {
maybeBridge, err := netlink.LinkByName(bridgeName)
if err != nil {
return nil, fmt.Errorf(`bridge "%s" not present; did you launch weave?`, bridgeName)
@@ -54,6 +54,16 @@ func CreateAndAttachVeth(localName, peerName, bridgeName string, mtu int) (*netl
return cleanup(`device "%s" is not a bridge`, bridgeName)
}
if init != nil {
guest, err := netlink.LinkByName(peerName)
if err != nil {
return cleanup("unable to find guest veth %s: %s", peerName, err)
}
if err := init(local, guest); err != nil {
return cleanup("initializing veth: %s", err)
}
}
if err := netlink.LinkSetUp(local); err != nil {
return cleanup("unable to bring veth up: %s", err)
}