lvs

package module
v0.0.0-...-8d5e5e7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2023 License: MIT Imports: 8 Imported by: 0

README

Golang LVS Build Status Image

A small wrapper around ipvsadm to support go interacting with the Linux Virtual Server.

Data Types:
Ipvs

Data:

  • MulticastInterface: String with the name of the interface broadcast the multicast state information on.
  • Syncid: Id to use when broadcasting state.
  • Tcp: Timeout for TCP connections.
  • Tcpfin: Timeout for TCP-FIN packets.
  • Udp: Timeout for UDP connections.
  • Services: Slice of Services.

Methods:

  • FindService
  • AddService
  • EditService
  • RemoveService
  • SetTimeouts
  • Restore
  • Save
  • StartDaemon
  • StopDaemon
  • Zero
Service

Data:

  • Host: IP associated to the service.
  • Port: Port that the service listens to.
  • Type: Type of service (tcp, udp, fwmark).
  • Scheduler: Method of assigning connections to downstream servers (rr, wrr, lc, wlc, lblc, lblcr, dh, sh, sed, nq).
  • Persistence: Persistent connection timeout.
  • Netmask: Netmask to use to group connections together.
  • Servers: Slice of Servers.

Methods:

  • FindServer
  • AddServer
  • EditServer
  • RemoveServer
  • Zero
  • ToJson
  • FromJson
  • String
Server

Data:

  • Host: IP associated with the server.
  • Port: Port the downstream server is listening on.
  • Forwarder: Method to forward to the downstream server (g=gatewaying, i=ipip, m=masquerading).
  • Weight: Relative weight of this server to the others. 0 means no new connections.
  • UpperThreshold: Stop sending connections when this limit is reached. 0 means no limit.
  • LowerThreshold: Restart sending connections when connections drop to this number. 0 means not set.

Methods:

  • ToJson
  • FromJson
  • String

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Conflict       = errors.New("object already exists")
	NotFound       = errors.New("object was not found")
	DeleteFailed   = errors.New("object was not deleted")
	IpvsadmMissing = errors.New("unable to find the ipvsadm command on the system")
)
View Source
var (
	EOFError       = errors.New("ipvsadm terminated prematurely")
	UnexpecedToken = errors.New("Unexpected Token")
)
View Source
var (
	ServerForwarderFlag = map[string]string{
		"g": "-g",
		"i": "-i",
		"m": "-m",
		"":  "-g",
	}

	InvalidServerForwarder = errors.New("Invalid Server Forwarder")
	InvalidServerPort      = errors.New("Invalid Server Port for Forwarder")
)
View Source
var (
	ServiceTypeFlag = map[string]string{
		"tcp":    "-t",
		"udp":    "-u",
		"fwmark": "-f",
		"":       "-t",
	}

	ServiceSchedulerFlag = map[string]string{
		"rr":    "rr",
		"wrr":   "wrr",
		"lc":    "lc",
		"wlc":   "wlc",
		"lblc":  "lblc",
		"lblcr": "lblcr",
		"dh":    "dh",
		"sh":    "sh",
		"sed":   "sed",
		"nq":    "nq",
		"":      "wlc",
	}

	InvalidServiceType      = errors.New("Invalid Service Type")
	InvalidServiceScheduler = errors.New("Invalid Service Scheduler")
)
View Source
var (
	DefaultIpvs = &Ipvs{}
)

Functions

func Clear

func Clear() error

func Load

func Load() error

Load verifies that lvs can be used, and populates it with values from the backup file

func Restore

func Restore(services []Service) error

func Save

func Save() error

func SetTimeouts

func SetTimeouts() error

func StartDaemon

func StartDaemon() (error, error)

func StopDaemon

func StopDaemon() (error, error)

func Zero

func Zero() error

Types

type FromJson

type FromJson interface {
	FromJson([]byte) error
}

type Ipvs

type Ipvs struct {
	MulticastInterface string    `json:mcast_interface`
	Syncid             int       `json:syncid`
	Tcp                int       `json:tcp_timeout`
	Tcpfin             int       `json:tcp_fin_timeout`
	Udp                int       `json:udp_fin_timeout`
	Services           []Service `json:services`
}

func (*Ipvs) AddService

func (i *Ipvs) AddService(service Service) error

func (*Ipvs) Clear

func (i *Ipvs) Clear() error

func (*Ipvs) EditService

func (i *Ipvs) EditService(service Service) error

func (Ipvs) FindService

func (i Ipvs) FindService(netType, host string, port int) *Service

func (*Ipvs) RemoveService

func (i *Ipvs) RemoveService(netType, host string, port int) error

func (*Ipvs) Restore

func (i *Ipvs) Restore(services []Service) error

func (*Ipvs) Save

func (i *Ipvs) Save() error

save reads the applied ipvsadm rules from the host and saves them as i.Services

func (Ipvs) SetTimeouts

func (i Ipvs) SetTimeouts() error

func (Ipvs) StartDaemon

func (i Ipvs) StartDaemon() (error, error)

func (Ipvs) StopDaemon

func (i Ipvs) StopDaemon() (error, error)

func (Ipvs) Zero

func (i Ipvs) Zero() error

type Server

type Server struct {
	Host           string `json:"host"`
	Port           int    `json:"port"`
	Forwarder      string `json:"forwarder"`
	Weight         int    `json:"weight"`
	UpperThreshold int    `json:upper_threshold`
	LowerThreshold int    `json:lower_threshold`
}

func (*Server) FromJson

func (s *Server) FromJson(bytes []byte) error

func (Server) String

func (s Server) String() string

func (Server) ToJson

func (s Server) ToJson() ([]byte, error)

func (Server) Validate

func (s Server) Validate() error

type Service

type Service struct {
	Host        string   `json:"host"`
	Port        int      `json:"port"`
	Type        string   `json:"type"`
	Scheduler   string   `json:"scheduler"`
	Persistence int      `json:"persistence"`
	Netmask     string   `json:"netmask"`
	Servers     []Server `json:"servers"`
}

func (Service) Add

func (s Service) Add() error

func (*Service) AddServer

func (s *Service) AddServer(server Server) error

func (*Service) EditServer

func (s *Service) EditServer(server Server) error

func (Service) FindServer

func (s Service) FindServer(host string, port int) *Server

func (*Service) FromJson

func (s *Service) FromJson(bytes []byte) error

func (Service) Remove

func (s Service) Remove() error

func (*Service) RemoveServer

func (s *Service) RemoveServer(host string, port int) error

func (Service) String

func (s Service) String() string

func (Service) ToJson

func (s Service) ToJson() ([]byte, error)

func (Service) Validate

func (s Service) Validate() error

func (Service) Zero

func (s Service) Zero() error

type ToJson

type ToJson interface {
	ToJson() ([]byte, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL