本文整理汇总了Golang中github.com/docker/libnetwork/bitseq.Handle类的典型用法代码示例。如果您正苦于以下问题:Golang Handle类的具体用法?Golang Handle怎么用?Golang Handle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Handle类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: getAddress
func (a *Allocator) getAddress(nw *net.IPNet, bitmask *bitseq.Handle, prefAddress net.IP, ipr *AddressRange) (net.IP, error) {
var (
ordinal uint64
err error
base *net.IPNet
)
base = types.GetIPNetCopy(nw)
if bitmask.Unselected() <= 0 {
return nil, ipamapi.ErrNoAvailableIPs
}
if ipr == nil && prefAddress == nil {
ordinal, err = bitmask.SetAny()
} else if prefAddress != nil {
hostPart, e := types.GetHostPartIP(prefAddress, base.Mask)
if e != nil {
return nil, fmt.Errorf("failed to allocate preferred address %s: %v", prefAddress.String(), e)
}
ordinal = ipToUint64(types.GetMinimalIP(hostPart))
err = bitmask.Set(ordinal)
} else {
base.IP = ipr.Sub.IP
ordinal, err = bitmask.SetAnyInRange(ipr.Start, ipr.End)
}
if err != nil {
return nil, ipamapi.ErrNoAvailableIPs
}
// Convert IP ordinal for this subnet into IP address
return generateAddress(ordinal, base), nil
}
开发者ID:newdeamon,项目名称:docker,代码行数:32,代码来源:allocator.go
示例2: Release
// Release allows releasing the address from the specified address space
func (a *Allocator) Release(addrSpace AddressSpace, address net.IP) {
var (
space *bitseq.Handle
sub *net.IPNet
)
if address == nil {
log.Debugf("Requested to remove nil address from address space %s", addrSpace)
return
}
ver := getAddressVersion(address)
if ver == v4 {
address = address.To4()
}
// Find the subnet containing the address
for _, subKey := range a.getSubnetList(addrSpace, ver) {
sub = subKey.canonicalChildSubnet()
if sub.Contains(address) {
a.Lock()
space = a.addresses[subKey]
a.Unlock()
break
}
}
if space == nil {
log.Debugf("Could not find subnet on address space %s containing %s on release", addrSpace, address.String())
return
}
// Retrieve correspondent ordinal in the subnet
hostPart, err := types.GetHostPartIP(address, sub.Mask)
if err != nil {
log.Warnf("Failed to release address %s on address space %s because of internal error: %v", address.String(), addrSpace, err)
return
}
ordinal := ipToUint32(hostPart)
// Release it
if err := space.Unset(ordinal); err != nil {
log.Warnf("Failed to release address %s on address space %s because of internal error: %v", address.String(), addrSpace, err)
}
}
开发者ID:nkwilson,项目名称:libnetwork,代码行数:45,代码来源:allocator.go
示例3: getAddress
func (a *Allocator) getAddress(subnet *net.IPNet, bitmask *bitseq.Handle, prefAddress net.IP, ver ipVersion) (net.IP, error) {
var (
ordinal uint32
err error
)
if bitmask.Unselected() <= 0 {
return nil, ErrNoAvailableIPs
}
if prefAddress == nil {
ordinal, err = bitmask.SetAny()
} else {
hostPart, e := types.GetHostPartIP(prefAddress, subnet.Mask)
if e != nil {
return nil, fmt.Errorf("failed to allocate preferred address %s: %v", prefAddress.String(), e)
}
ordinal = ipToUint32(types.GetMinimalIP(hostPart))
err = bitmask.Set(ordinal)
}
if err != nil {
return nil, ErrNoAvailableIPs
}
// Convert IP ordinal for this subnet into IP address
return generateAddress(ordinal, subnet), nil
}
开发者ID:nkwilson,项目名称:libnetwork,代码行数:26,代码来源:allocator.go
示例4: getAddress
func (a *Allocator) getAddress(subnet *net.IPNet, bitmask *bitseq.Handle, prefAddress net.IP, ver ipVersion) (net.IP, error) {
var (
bytePos, bitPos int
ordinal int
err error
)
// Look for free IP, skip .0 and .255, they will be automatically reserved
for {
if bitmask.Unselected() <= 0 {
return nil, ErrNoAvailableIPs
}
if prefAddress == nil {
bytePos, bitPos, err = bitmask.GetFirstAvailable()
} else {
ordinal = ipToInt(getHostPortionIP(prefAddress, subnet))
bytePos, bitPos, err = bitmask.CheckIfAvailable(ordinal)
}
if err != nil {
return nil, ErrNoAvailableIPs
}
// Lock it
if err = bitmask.PushReservation(bytePos, bitPos, false); err != nil {
if _, ok := err.(types.RetryError); !ok {
return nil, fmt.Errorf("internal failure while reserving the address: %s", err.Error())
}
continue
}
// Build IP ordinal
ordinal = bitPos + bytePos*8
// For v4, let reservation of .0 and .255 happen automatically
if ver == v4 && !isValidIP(ordinal) {
continue
}
break
}
// Convert IP ordinal for this subnet into IP address
return generateAddress(ordinal, subnet), nil
}
开发者ID:hariharan16s,项目名称:libnetwork,代码行数:43,代码来源:allocator.go
示例5: getAddress
func (a *Allocator) getAddress(nw *net.IPNet, bitmask *bitseq.Handle, prefAddress net.IP, ipr *AddressRange) (net.IP, error) {
var (
ordinal uint64
err error
base *net.IPNet
)
base = types.GetIPNetCopy(nw)
if bitmask.Unselected() <= 0 {
return nil, ipamapi.ErrNoAvailableIPs
}
if ipr == nil && prefAddress == nil {
ordinal, err = bitmask.SetAny()
} else if prefAddress != nil {
hostPart, e := types.GetHostPartIP(prefAddress, base.Mask)
if e != nil {
return nil, types.InternalErrorf("failed to allocate requested address %s: %v", prefAddress.String(), e)
}
ordinal = ipToUint64(types.GetMinimalIP(hostPart))
err = bitmask.Set(ordinal)
} else {
ordinal, err = bitmask.SetAnyInRange(ipr.Start, ipr.End)
}
switch err {
case nil:
// Convert IP ordinal for this subnet into IP address
return generateAddress(ordinal, base), nil
case bitseq.ErrBitAllocated:
return nil, ipamapi.ErrIPAlreadyAllocated
case bitseq.ErrNoBitAvailable:
return nil, ipamapi.ErrNoAvailableIPs
default:
return nil, err
}
}
开发者ID:docker,项目名称:docker,代码行数:37,代码来源:allocator.go
注:本文中的github.com/docker/libnetwork/bitseq.Handle类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论