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


Golang EndpointInfo.Interface方法代碼示例

本文整理匯總了Golang中github.com/docker/libnetwork/driverapi.EndpointInfo.Interface方法的典型用法代碼示例。如果您正苦於以下問題:Golang EndpointInfo.Interface方法的具體用法?Golang EndpointInfo.Interface怎麽用?Golang EndpointInfo.Interface使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/docker/libnetwork/driverapi.EndpointInfo的用法示例。


在下文中一共展示了EndpointInfo.Interface方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: CreateEndpoint

func (d *driver) CreateEndpoint(nid, eid string, epInfo driverapi.EndpointInfo, epOptions map[string]interface{}) error {
	var reqIface *api.EndpointInterface

	if epInfo == nil {
		return fmt.Errorf("must not be called with nil EndpointInfo")
	}

	iface := epInfo.Interface()
	if iface != nil {
		addr4 := iface.Address()
		addr6 := iface.AddressIPv6()
		reqIface = &api.EndpointInterface{
			Address:     addr4.String(),
			AddressIPv6: addr6.String(),
			MacAddress:  iface.MacAddress().String(),
		}
	}
	create := &api.CreateEndpointRequest{
		NetworkID:  nid,
		EndpointID: eid,
		Interface:  reqIface,
		Options:    epOptions,
	}
	var res api.CreateEndpointResponse
	if err := d.call("CreateEndpoint", create, &res); err != nil {
		return err
	}

	inIface, err := parseInterface(res)
	if err != nil {
		return err
	}
	if reqIface != nil && inIface != nil {
		// We're not supposed to add interface if there is already
		// one. Attempt to roll back
		return errorWithRollback("driver attempted to add interface ignoring the one provided", d.DeleteEndpoint(nid, eid))
	}

	if inIface != nil {
		var addr4, addr6 net.IPNet
		if inIface.Address != nil {
			addr4 = *(inIface.Address)
		}
		if inIface.AddressIPv6 != nil {
			addr6 = *(inIface.AddressIPv6)
		}
		if err := epInfo.AddInterface(inIface.MacAddress, addr4, addr6); err != nil {
			return errorWithRollback(fmt.Sprintf("failed to AddInterface %v: %s", inIface, err), d.DeleteEndpoint(nid, eid))
		}
	}
	return nil
}
開發者ID:neonix888,項目名稱:docker,代碼行數:52,代碼來源:driver.go

示例2: CreateEndpoint

func (d *driver) CreateEndpoint(nid, eid string, epInfo driverapi.EndpointInfo,
	epOptions map[string]interface{}) error {
	if err := validateID(nid, eid); err != nil {
		return err
	}

	n := d.network(nid)
	if n == nil {
		return fmt.Errorf("network id %q not found", nid)
	}

	ep := &endpoint{
		id: eid,
	}

	if epInfo != nil && epInfo.Interface() != nil {
		addr := epInfo.Interface().Address()
		ep.addr = &addr
		ep.mac = epInfo.Interface().MacAddress()
		n.addEndpoint(ep)
		return nil
	}

	ipID, err := d.ipAllocator.GetID()
	if err != nil {
		return fmt.Errorf("could not allocate ip from subnet %s: %v",
			bridgeSubnet.String(), err)
	}

	ep.addr = &net.IPNet{
		Mask: bridgeSubnet.Mask,
	}
	ep.addr.IP = make([]byte, 4)

	binary.BigEndian.PutUint32(ep.addr.IP, bridgeSubnetInt+ipID)

	ep.mac = netutils.GenerateMACFromIP(ep.addr.IP)

	err = epInfo.AddInterface(ep.mac, *ep.addr, net.IPNet{})
	if err != nil {
		return fmt.Errorf("could not add interface to endpoint info: %v", err)
	}

	n.addEndpoint(ep)

	return nil
}
開發者ID:waterytowers,項目名稱:global-hack-day-3,代碼行數:47,代碼來源:ov_endpoint.go

示例3: CreateEndpoint

func (d *driver) CreateEndpoint(nid, eid string, epInfo driverapi.EndpointInfo, epOptions map[string]interface{}) error {
	var (
		ipv6Addr *net.IPNet
		err      error
	)

	defer osl.InitOSContext()()

	if epInfo == nil {
		return errors.New("invalid endpoint info passed")
	}

	if epInfo.Interface() != nil {
		return errors.New("non-nil interface passed to bridge(local) driver")
	}

	// Get the network handler and make sure it exists
	d.Lock()
	n, ok := d.networks[nid]
	dconfig := d.config
	d.Unlock()

	if !ok {
		return types.NotFoundErrorf("network %s does not exist", nid)
	}
	if n == nil {
		return driverapi.ErrNoNetwork(nid)
	}

	// Sanity check
	n.Lock()
	if n.id != nid {
		n.Unlock()
		return InvalidNetworkIDError(nid)
	}
	n.Unlock()

	// Check if endpoint id is good and retrieve correspondent endpoint
	ep, err := n.getEndpoint(eid)
	if err != nil {
		return err
	}

	// Endpoint with that id exists either on desired or other sandbox
	if ep != nil {
		return driverapi.ErrEndpointExists(eid)
	}

	// Try to convert the options to endpoint configuration
	epConfig, err := parseEndpointOptions(epOptions)
	if err != nil {
		return err
	}

	// Create and add the endpoint
	n.Lock()
	endpoint := &bridgeEndpoint{id: eid, config: epConfig}
	n.endpoints[eid] = endpoint
	n.Unlock()

	// On failure make sure to remove the endpoint
	defer func() {
		if err != nil {
			n.Lock()
			delete(n.endpoints, eid)
			n.Unlock()
		}
	}()

	// Generate a name for what will be the host side pipe interface
	hostIfName, err := netutils.GenerateIfaceName(vethPrefix, vethLen)
	if err != nil {
		return err
	}

	// Generate a name for what will be the sandbox side pipe interface
	containerIfName, err := netutils.GenerateIfaceName(vethPrefix, vethLen)
	if err != nil {
		return err
	}

	// Generate and add the interface pipe host <-> sandbox
	veth := &netlink.Veth{
		LinkAttrs: netlink.LinkAttrs{Name: hostIfName, TxQLen: 0},
		PeerName:  containerIfName}
	if err = netlink.LinkAdd(veth); err != nil {
		return types.InternalErrorf("failed to add the host (%s) <=> sandbox (%s) pair interfaces: %v", hostIfName, containerIfName, err)
	}

	// Get the host side pipe interface handler
	host, err := netlink.LinkByName(hostIfName)
	if err != nil {
		return types.InternalErrorf("failed to find host side interface %s: %v", hostIfName, err)
	}
	defer func() {
		if err != nil {
			netlink.LinkDel(host)
		}
	}()

//.........這裏部分代碼省略.........
開發者ID:wangxujun163163,項目名稱:libnetwork,代碼行數:101,代碼來源:bridge.go


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