本文整理汇总了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
}