Ejemplo n.º 1
0
func (bs *BalancingService) DeleteDestination(addrs ...Address) error {
	var dst unsafe.Pointer
	for _, d := range addrs {
		// Checking we have this address or not
		for i, d2 := range bs.destinations {
			if d2.IsEqual(d) {
				dst = C.create_dest(C.CString(d.IP), C.int(d.Port))
				res := C.remove_dest(bs.LvsService, dst)
				if res != 0 {
					error_text := C.GoString(C.ipvs_error())
					return errors.New(error_text)
				}
				bs.destinations = append(bs.destinations[:i], bs.destinations[i+1:]...)
			}
		}
	}
	return nil
}
Ejemplo n.º 2
0
func (bs *BalancingService) AddDestination(addrs ...Address) error {
	var dst unsafe.Pointer
	for _, d := range addrs {
		// Checking we have this address or not
		for _, d2 := range bs.destinations {
			if d2.IsEqual(d) {
				// If there is Address that we already added just exiting from this function without error
				return nil
			}
		}
		dst = C.create_dest(C.CString(d.IP), C.int(d.Port))
		res := C.add_dest(bs.LvsService, dst)
		if res != 0 {
			error_text := C.GoString(C.ipvs_error())
			return errors.New(error_text)
		}
		bs.destinations = append(bs.destinations, d)
	}
	return nil
}