本文整理匯總了Golang中github.com/vishvananda/netlink.Bridge.Attrs方法的典型用法代碼示例。如果您正苦於以下問題:Golang Bridge.Attrs方法的具體用法?Golang Bridge.Attrs怎麽用?Golang Bridge.Attrs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/vishvananda/netlink.Bridge
的用法示例。
在下文中一共展示了Bridge.Attrs方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: setupVeth
func setupVeth(netns string, br *netlink.Bridge, ifName string, mtu int, hairpinMode bool) error {
var hostVethName string
err := ns.WithNetNSPath(netns, false, func(hostNS *os.File) error {
// create the veth pair in the container and move host end into host netns
hostVeth, _, err := ip.SetupVeth(ifName, mtu, hostNS)
if err != nil {
return err
}
hostVethName = hostVeth.Attrs().Name
return nil
})
if err != nil {
return err
}
// need to lookup hostVeth again as its index has changed during ns move
hostVeth, err := netlink.LinkByName(hostVethName)
if err != nil {
return fmt.Errorf("failed to lookup %q: %v", hostVethName, err)
}
// connect host veth end to the bridge
if err = netlink.LinkSetMaster(hostVeth, br); err != nil {
return fmt.Errorf("failed to connect %q to bridge %v: %v", hostVethName, br.Attrs().Name, err)
}
// set hairpin mode
if err = netlink.LinkSetHairpin(hostVeth, hairpinMode); err != nil {
return fmt.Errorf("failed to setup hairpin mode for %v: %v", hostVethName, err)
}
return nil
}
示例2: NewBridgeAdapter
func NewBridgeAdapter(link *netlink.Bridge) *BridgeAdapter {
return &BridgeAdapter{
uuid: link.Attrs().Name,
name: link.Attrs().Name,
tags: []string{},
perm: PermR,
config: make(map[string]interface{}),
link: link,
}
}
示例3: ensureBridge
func (nm *NetlinkMonitor) ensureBridge(link *netlink.Bridge) canvas.Node {
b := nm.g.NodeByPath("b:" + link.Attrs().Name)
if b == nil {
a := canvas.NewBridgeAdapter(link)
node := canvas.NewAdapterNode(a)
node.SetID(nm.g.NewNodeID())
nm.g.AddNode(node)
b = node
}
return b
}