當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Bridge.Attrs方法代碼示例

本文整理匯總了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
}
開發者ID:squaremo,項目名稱:cni,代碼行數:35,代碼來源:bridge.go

示例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,
	}
}
開發者ID:iovisor,項目名稱:iomodules,代碼行數:10,代碼來源:adapter_bridge.go

示例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
}
開發者ID:iovisor,項目名稱:iomodules,代碼行數:11,代碼來源:netlink_monitor.go


注:本文中的github.com/vishvananda/netlink.Bridge.Attrs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。