code: func (na *cnmNetworkAllocator) allocateVIP(vip *api.Endpoint_VirtualIP) error {
  	var opts map[string]string
  	localNet := na.getNetwork(vip.NetworkID)
  	if localNet == nil {
  		return errors.New("networkallocator: could not find local network state")
  	}
  
  	if localNet.isNodeLocal {
  		return nil
  	}
  
  	// 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 errors.Wrap(err, "failed to resolve IPAM while allocating")
  	}
  
  	var addr net.IP
  	if vip.Addr != "" {
  		var err error
  
  		addr, _, err = net.ParseCIDR(vip.Addr)
  		if err != nil {
  			return err
  		}
  	}
  	if localNet.nw.IPAM != nil && localNet.nw.IPAM.Driver != nil {
  		// set ipam allocation method to serial
  		opts = setIPAMSerialAlloc(localNet.nw.IPAM.Driver.Options)
  	}
  
  	for _, poolID := range localNet.pools {
  		ip, _, err := ipam.RequestAddress(poolID, addr, opts)
  		if err != nil && err != ipamapi.ErrNoAvailableIPs && err != ipamapi.ErrIPOutOfRange {
  			return errors.Wrap(err, "could not allocate VIP from IPAM")
  		}
  
  		// 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 errors.New("could not find an available IP while allocating VIP")
  }
docs: // allocate virtual IP for a single endpoint attachment of the service.