本文整理汇总了Golang中github.com/contiv/netplugin/netmaster/mastercfg.CfgNetworkState.Write方法的典型用法代码示例。如果您正苦于以下问题:Golang CfgNetworkState.Write方法的具体用法?Golang CfgNetworkState.Write怎么用?Golang CfgNetworkState.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/contiv/netplugin/netmaster/mastercfg.CfgNetworkState
的用法示例。
在下文中一共展示了CfgNetworkState.Write方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: networkAllocAddress
// Allocate an address from the network
func networkAllocAddress(nwCfg *mastercfg.CfgNetworkState, reqAddr string) (string, error) {
var ipAddress string
var ipAddrValue uint
var found bool
var err error
// alloc address
if reqAddr == "" {
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 != "" {
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
}
// 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
}
示例2: networkAllocAddress
// Allocate an address from the network
func networkAllocAddress(nwCfg *mastercfg.CfgNetworkState, reqAddr string) (string, error) {
var ipAddress string
var ipAddrValue uint
var found bool
var err error
// alloc address
if reqAddr == "" {
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
}
} else if reqAddr != "" && nwCfg.SubnetIP != "" {
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
}
// 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
}
示例3: networkReleaseAddress
// networkReleaseAddress release the ip address
func networkReleaseAddress(nwCfg *mastercfg.CfgNetworkState, ipAddress string) error {
isIPv6 := netutils.IsIPv6(ipAddress)
if isIPv6 {
hostID, err := netutils.GetIPv6HostID(nwCfg.SubnetIP, nwCfg.SubnetLen, ipAddress)
if err != nil {
log.Errorf("error getting host id from hostIP %s Subnet %s/%d. Error: %s",
ipAddress, nwCfg.SubnetIP, nwCfg.SubnetLen, err)
return err
}
// networkReleaseAddress is called from multiple places
// Make sure we decrement the EpCount only if the IPAddress
// was not already freed earlier
if _, found := nwCfg.IPv6AllocMap[hostID]; found {
nwCfg.EpAddrCount--
}
delete(nwCfg.IPv6AllocMap, hostID)
} else {
ipAddrValue, err := netutils.GetIPNumber(nwCfg.SubnetIP, nwCfg.SubnetLen, 32, ipAddress)
if err != nil {
log.Errorf("error getting host id from hostIP %s Subnet %s/%d. Error: %s",
ipAddress, nwCfg.SubnetIP, nwCfg.SubnetLen, err)
return err
}
// networkReleaseAddress is called from multiple places
// Make sure we decrement the EpCount only if the IPAddress
// was not already freed earlier
if nwCfg.IPAllocMap.Test(ipAddrValue) {
nwCfg.EpAddrCount--
}
nwCfg.IPAllocMap.Clear(ipAddrValue)
}
err := nwCfg.Write()
if err != nil {
log.Errorf("error writing nw config. Error: %s", err)
return err
}
return nil
}