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


Golang CfgNetworkState.IPv6LastHost方法代碼示例

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


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

示例1: networkAllocAddress

// Allocate an address from the network
func networkAllocAddress(nwCfg *mastercfg.CfgNetworkState, reqAddr string, isIPv6 bool) (string, error) {
	var ipAddress string
	var ipAddrValue uint
	var found bool
	var err error
	var hostID string

	// alloc address
	if reqAddr == "" {
		if isIPv6 {
			// Get the next available IPv6 address
			hostID, err = netutils.GetNextIPv6HostID(nwCfg.IPv6LastHost, nwCfg.IPv6Subnet, nwCfg.IPv6SubnetLen, nwCfg.IPv6AllocMap)
			if err != nil {
				log.Errorf("create eps: error allocating ip. Error: %s", err)
				return "", err
			}
			ipAddress, err = netutils.GetSubnetIPv6(nwCfg.IPv6Subnet, nwCfg.IPv6SubnetLen, hostID)
			if err != nil {
				log.Errorf("create eps: error acquiring subnet ip. Error: %s", err)
				return "", err
			}
			nwCfg.IPv6LastHost = hostID
		} else {
			ipAddrValue, found = nwCfg.IPAllocMap.NextClear(0)
			if !found {
				log.Errorf("auto allocation failed - address exhaustion in subnet %s/%d",
					nwCfg.SubnetIP, nwCfg.SubnetLen)
				err = core.Errorf("auto allocation failed - address exhaustion in subnet %s/%d",
					nwCfg.SubnetIP, nwCfg.SubnetLen)
				return "", err
			}
			ipAddress, err = netutils.GetSubnetIP(nwCfg.SubnetIP, nwCfg.SubnetLen, 32, ipAddrValue)
			if err != nil {
				log.Errorf("create eps: error acquiring subnet ip. Error: %s", err)
				return "", err
			}
		}

		// Docker, Mesos issue a Alloc Address first, followed by a CreateEndpoint
		// Kubernetes issues a create endpoint directly
		// since networkAllocAddress is called from both AllocAddressHandler and CreateEndpointHandler,
		// we need to make sure that the EpCount is incremented only when we are allocating
		// a new IP. In case of Docker, Mesos CreateEndPoint will already request a IP that
		// allocateAddress had allocated in the earlier call.
		nwCfg.EpAddrCount++

	} else if reqAddr != "" && nwCfg.SubnetIP != "" {
		if isIPv6 {
			hostID, err = netutils.GetIPv6HostID(nwCfg.IPv6Subnet, nwCfg.IPv6SubnetLen, reqAddr)
			if err != nil {
				log.Errorf("create eps: error getting host id from hostIP %s Subnet %s/%d. Error: %s",
					reqAddr, nwCfg.IPv6Subnet, nwCfg.IPv6SubnetLen, err)
				return "", err
			}
		} else {
			ipAddrValue, err = netutils.GetIPNumber(nwCfg.SubnetIP, nwCfg.SubnetLen, 32, reqAddr)
			if err != nil {
				log.Errorf("create eps: error getting host id from hostIP %s Subnet %s/%d. Error: %s",
					reqAddr, nwCfg.SubnetIP, nwCfg.SubnetLen, err)
				return "", err
			}
		}

		ipAddress = reqAddr
	}

	if isIPv6 {
		netutils.ReserveIPv6HostID(hostID, &nwCfg.IPv6AllocMap)
	} else {
		// Set the bitmap
		nwCfg.IPAllocMap.Set(ipAddrValue)
	}

	err = nwCfg.Write()
	if err != nil {
		log.Errorf("error writing nw config. Error: %s", err)
		return "", err
	}

	return ipAddress, nil
}
開發者ID:abhinandanpb,項目名稱:netplugin,代碼行數:82,代碼來源:network.go


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