本文整理匯總了Golang中github.com/docker/swarmkit/api.Endpoint_VirtualIP.Addr方法的典型用法代碼示例。如果您正苦於以下問題:Golang Endpoint_VirtualIP.Addr方法的具體用法?Golang Endpoint_VirtualIP.Addr怎麽用?Golang Endpoint_VirtualIP.Addr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/docker/swarmkit/api.Endpoint_VirtualIP
的用法示例。
在下文中一共展示了Endpoint_VirtualIP.Addr方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: allocateVIP
// allocate virtual IP for a single endpoint attachment of the service.
func (na *NetworkAllocator) allocateVIP(vip *api.Endpoint_VirtualIP) error {
localNet := na.getNetwork(vip.NetworkID)
if localNet == nil {
return fmt.Errorf("networkallocator: could not find local network state")
}
ipam, _, err := na.resolveIPAM(localNet.nw)
if err != nil {
return fmt.Errorf("failed to resolve IPAM while allocating : %v", err)
}
for _, poolID := range localNet.pools {
ip, _, err := ipam.RequestAddress(poolID, nil, nil)
if err != nil && err != ipamapi.ErrNoAvailableIPs && err != ipamapi.ErrIPOutOfRange {
return fmt.Errorf("could not allocate VIP from IPAM: %v", err)
}
// If we got an address then we are done.
if err == nil {
ipStr := ip.String()
localNet.endpoints[ipStr] = poolID
vip.Addr = ipStr
return nil
}
}
return fmt.Errorf("could not find an available IP while allocating VIP")
}
示例2: allocateVIP
// allocate virtual IP for a single endpoint attachment of the service.
func (na *NetworkAllocator) allocateVIP(vip *api.Endpoint_VirtualIP) error {
localNet := na.getNetwork(vip.NetworkID)
if localNet == nil {
return fmt.Errorf("networkallocator: could not find local network state")
}
// If this IP is already allocated in memory we don't need to
// do anything.
if _, ok := localNet.endpoints[vip.Addr]; ok {
return nil
}
ipam, _, err := na.resolveIPAM(localNet.nw)
if err != nil {
return fmt.Errorf("failed to resolve IPAM while allocating : %v", err)
}
var addr net.IP
if vip.Addr != "" {
var err error
addr, _, err = net.ParseCIDR(vip.Addr)
if err != nil {
return err
}
}
for _, poolID := range localNet.pools {
ip, _, err := ipam.RequestAddress(poolID, addr, nil)
if err != nil && err != ipamapi.ErrNoAvailableIPs && err != ipamapi.ErrIPOutOfRange {
return fmt.Errorf("could not allocate VIP from IPAM: %v", err)
}
// If we got an address then we are done.
if err == nil {
ipStr := ip.String()
localNet.endpoints[ipStr] = poolID
vip.Addr = ipStr
return nil
}
}
return fmt.Errorf("could not find an available IP while allocating VIP")
}