func (bs *BalancingService) initLVS() error { res := C.init_ipvs() if res != 0 { error_text := C.GoString(C.ipvs_error()) return errors.New(error_text) } res = C.ipvs_flush() if res != 0 { error_text := C.GoString(C.ipvs_error()) return errors.New(error_text) } return nil }
func (bs *BalancingService) DropService() error { res := C.remove_service(bs.LvsService) if res != 0 { error_text := C.GoString(C.ipvs_error()) return errors.New(error_text) } return nil }
func (bs *BalancingService) CreateService() error { bs.LvsService = C.create_service(C.CString(bs.Address.IP), C.int(bs.Address.Port), C.CString(bs.Algorithm)) res := C.add_service(bs.LvsService) if res != 0 { error_text := C.GoString(C.ipvs_error()) return errors.New(error_text) } return nil }
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 }
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 }