runtime

package
v6.0.0-...-4670363 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

README

HAProxy runtime client

usage

package main

import (
	"log"

	"github.com/haproxytech/client-native/v6/runtime"
	runtime_options "github.com/haproxytech/client-native/v6/runtime/options"
)

func main() {
	nbproc := 8
	ms := runtime_options.MasterSocket("/var/run/haproxy-mw.sock", nbproc)
	client, err = runtime_api.New(ctx, ms)
	if err != nil {
		return nil, fmt.Errorf("error setting up runtime client: %s", err.Error())
	}
	// or if not using master-worker
	socketList := map[int]string{
		1: "/var/run/haproxy-runtime-api.sock"
	}
	sockets := runtime_options.Sockets(socketList)
	client, err = runtime_api.New(ctx, mapsDir, sockets)
	if err != nil {
		return nil, fmt.Errorf("error setting up runtime client: %s", err.Error())
	}

	statsCollection := client.GetStats()
	if statsCollection.Error != "" {
		log.Println(err)
	}
	log.Println(statsCollection.Stats)

	processInfo := client.GetInfo()
	if processInfo.Error != "" {
		log.Println(err)
	}
	log.Println(processInfo.Info)

	env, err := client.ExecuteRaw("show env")
	if err != nil {
		log.Println(err)
	}
	log.Println(env)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateMap

func CreateMap(name string, file io.Reader) (*models.Map, error)

CreateMap creates a new map file with its entries. Returns an error if file already exists

func IsBiggerOrEqual

func IsBiggerOrEqual(minimum, current *HAProxyVersion) bool

func ParseACLFileEntries

func ParseACLFileEntries(output string, hasID bool) (models.ACLFilesEntries, error)

ParseACLFileEntries parses array of entries in one Acl file One line sample entry: ID Value 0x560f3f9e8600 10.178.160.0

func ParseMapEntries

func ParseMapEntries(output string, hasID bool) models.MapEntries

ParseMapEntries parses array of entries in one map file One line sample entry: ID Key Value 0x55d155c6fbf0 static.example.com be_static

func ServerHealthValid

func ServerHealthValid(health string) bool

ServerHealthValid checks if server health is valid

func ServerStateValid

func ServerStateValid(state string) bool

ServerStateValid checks if server state is valid

func ServerWeightValid

func ServerWeightValid(weight string) bool

ServerWeightValid checks if server state is valid

Types

type ACLs

type ACLs interface {
	GetACLFiles() (files models.ACLFiles, err error)
	GetACLFile(id string) (files *models.ACLFile, err error)
	GetACLFilesEntries(id string) (files models.ACLFilesEntries, err error)
	GetACLFileEntry(id, value string) (fileEntry *models.ACLFileEntry, err error)
	AddACLFileEntry(id, value string) error
	DeleteACLFileEntry(id, value string) error
	AddACLAtomic(aclID string, entries models.ACLFilesEntries) error
}

type CrtList

type CrtList struct {
	File string
}

type CrtListEntries

type CrtListEntries []*CrtListEntry

func ParseCrtListEntries

func ParseCrtListEntries(output string) (CrtListEntries, error)

ParseCrtListEntries parses array of entries in one CrtList file One line sample entry: /etc/ssl/cert-0.pem !*.crt-test.platform.domain.com !connectivitynotification.platform.domain.com !connectivitytunnel.platform.domain.com !authentication.cert.another.domain.com !*.authentication.cert.another.domain.com /etc/ssl/cert-1.pem [verify optional ca-file /etc/ssl/ca-file-1.pem] *.crt-test.platform.domain.com !connectivitynotification.platform.domain.com !connectivitytunnel.platform.domain.com !authentication.cert.another.domain.com !*.authentication.cert.another.domain.com /etc/ssl/cert-2.pem [verify required ca-file /etc/ssl/ca-file-2.pem]

type CrtListEntry

type CrtListEntry struct {
	File          string
	SSLBindConfig string
	SNIFilter     []string
	LineNumber    int
}

type CrtLists

type CrtLists []*CrtList

type Frontend

type Frontend interface {
	// SetFrontendMaxConn set maxconn for frontend
	SetFrontendMaxConn(frontend string, maxconn int) error
}

type HAProxyMock

type HAProxyMock struct {
	net.Listener
	// contains filtered or unexported fields
}

HAProxyMock - Mock HAProxy Server for testing the socket communication

func NewHAProxyMock

func NewHAProxyMock(t *testing.T) *HAProxyMock

NewHAProxyMock - create new haproxy mock

func (*HAProxyMock) SetResponses

func (haproxy *HAProxyMock) SetResponses(responses *map[string]string)

SetResponses - setting the expected responses, safe for concurrent use

func (*HAProxyMock) Start

func (haproxy *HAProxyMock) Start()

Start - start mock

func (*HAProxyMock) Stop

func (haproxy *HAProxyMock) Stop()

Stop - stop mock

type HAProxyVersion

type HAProxyVersion struct {
	Commit  string
	Version string
	Major   int
	Minor   int
	Patch   int
}

func (*HAProxyVersion) ParseHAProxyVersion

func (v *HAProxyVersion) ParseHAProxyVersion(version string) error

type Info

type Info interface {
	// GetStats returns stats from the socket
	GetStats() models.NativeStats
	// GetInfo returns info from the socket
	GetInfo() (models.ProcessInfos, error)
	// GetVersion() returns running HAProxy version
	GetVersion() (HAProxyVersion, error)
}

type Manage

type Manage interface {
	// Reloads HAProxy's configuration file. Similar to SIGUSR2. Returns the startup logs.
	Reload() (string, error)
}

type Maps

type Maps interface {
	GetMapsDir() (string, error)
	// GetMapsPath returns runtime map file path or map id
	GetMapsPath(name string) (string, error)
	// ShowMaps returns structured unique map files
	ShowMaps() (models.Maps, error)
	// CreateMap creates a new map file with its entries
	CreateMap(file io.Reader, header multipart.FileHeader) (*models.Map, error)
	// GetMap returns one structured runtime map file
	GetMap(name string) (*models.Map, error)
	// ClearMap removes all map entries from the map file. If forceDelete is true, deletes file from disk
	ClearMap(name string, forceDelete bool) error
	// ShowMapEntries list all map entries by map file name
	ShowMapEntries(name string) (models.MapEntries, error)
	// AddMapPayload adds multiple entries to the map file
	AddMapPayload(name, payload string) error
	// AddMapEntry adds an entry into the map file
	AddMapEntry(name, key, value string) error
	// GetMapEntry returns one map runtime setting
	GetMapEntry(name, id string) (*models.MapEntry, error)
	// SetMapEntry replace the value corresponding to each id in a map
	SetMapEntry(name, id, value string) error
	// DeleteMapEntry deletes all the map entries from the map by its id
	DeleteMapEntry(name, id string) error
	ParseMapEntries(output string) models.MapEntries
	// ParseMapEntriesFromFile reads entries from file
	ParseMapEntriesFromFile(inputFile io.Reader, hasID bool) models.MapEntries
	AddMapPayloadVersioned(name string, entries models.MapEntries) error
	// PrepareMap allocates a new map version
	PrepareMap(name string) (version string, err error)
	// CommitMap commits all changes made to a map version
	CommitMap(version, name string) error
}

type Raw

type Raw interface {
	// ExecuteRaw does not process response, just returns its values for all processes
	ExecuteRaw(command string) ([]string, error)
}

type Runtime

type Runtime interface {
	Info
	Frontend
	Manage
	Maps
	Servers
	ACLs
	Tables
	Raw
}

func New

func New(ctx context.Context, opt ...options.RuntimeOption) (Runtime, error)

type Servers

type Servers interface {
	// AddServer adds a new server to a backend
	AddServer(backend, name, attributes string) error
	// DeleteServer removes a server from a backend
	DeleteServer(backend, name string) error
	// SetServerAddr set ip [port] for server
	SetServerAddr(backend, server string, ip string, port int) error
	// SetServerState set state for server
	SetServerState(backend, server string, state string) error
	// SetServerWeight set weight for server
	SetServerWeight(backend, server string, weight string) error
	// SetServerHealth set health for server
	SetServerHealth(backend, server string, health string) error
	// EnableAgentCheck enable agent check for server
	EnableAgentCheck(backend, server string) error
	// DisableAgentCheck disable agent check for server
	DisableAgentCheck(backend, server string) error
	// EnableServer marks server as UP
	EnableServer(backend, server string) error
	// DisableServer marks server as DOWN for maintenance
	DisableServer(backend, server string) error
	// SetServerAgentAddr set agent-addr for server
	SetServerAgentAddr(backend, server string, addr string) error
	// SetServerAgentSend set agent-send for server
	SetServerAgentSend(backend, server string, send string) error
	// GetServerState returns server runtime state
	GetServersState(backend string) (models.RuntimeServers, error)
	// GetServerState returns server runtime state
	GetServerState(backend, server string) (*models.RuntimeServer, error)
	// SetServerCheckPort set health heck port for server
	SetServerCheckPort(backend, server string, port int) error
}

type SingleRuntime

type SingleRuntime struct {
	// contains filtered or unexported fields
}

SingleRuntime handles one runtime API

func (*SingleRuntime) AbortCertEntry

func (s *SingleRuntime) AbortCertEntry(storageName string) error

AbortCertEntry adds an entry into the CrtList file

func (*SingleRuntime) AddACLFileEntry

func (s *SingleRuntime) AddACLFileEntry(aclID, value string) error

AddACLFileEntry adds an entry into the Acl file

func (*SingleRuntime) AddACLVersioned

func (s *SingleRuntime) AddACLVersioned(version, aclID, value string) error

func (*SingleRuntime) AddCrtListEntry

func (s *SingleRuntime) AddCrtListEntry(crtList string, entry CrtListEntry) error

AddCrtListEntry adds an entry into the CrtList file

func (*SingleRuntime) AddMapEntry

func (s *SingleRuntime) AddMapEntry(name, key, value string) error

AddMapEntry adds an entry into the map file

func (*SingleRuntime) AddMapEntryVersioned

func (s *SingleRuntime) AddMapEntryVersioned(version, name, key, value string) error

AddMapEntryVersioned adds an entry into the map file

func (*SingleRuntime) AddMapPayload

func (s *SingleRuntime) AddMapPayload(name, payload string) error

AddMapPayload adds multiple entries to the map file payload param is a multi-line string where each line is a key/value pair

func (*SingleRuntime) AddMapPayloadVersioned

func (s *SingleRuntime) AddMapPayloadVersioned(version, name, payload string) error

func (*SingleRuntime) AddServer

func (s *SingleRuntime) AddServer(backend, name, attributes string) error

AddServer adds a new server to a backend

func (*SingleRuntime) ClearMap

func (s *SingleRuntime) ClearMap(name string) error

ClearMap removes all map entries from the map file.

func (*SingleRuntime) ClearMapVersioned

func (s *SingleRuntime) ClearMapVersioned(name, version string) error

ClearMapVersioned removes all map entries from the map file.

func (*SingleRuntime) CommitACL

func (s *SingleRuntime) CommitACL(version, aclID string) error

func (*SingleRuntime) CommitCertEntry

func (s *SingleRuntime) CommitCertEntry(storageName string) error

CommitCertEntry adds an entry into the CrtList file

func (*SingleRuntime) CommitMap

func (s *SingleRuntime) CommitMap(version, name string) error

func (*SingleRuntime) DeleteACLFileEntry

func (s *SingleRuntime) DeleteACLFileEntry(aclID, value string) error

DeleteACLFileEntry deletes all the Acl entries from the Acl by its value

func (*SingleRuntime) DeleteCertEntry

func (s *SingleRuntime) DeleteCertEntry(storageName string) error

DeleteCertEntry adds an entry into the CrtList file

func (*SingleRuntime) DeleteCrtListEntry

func (s *SingleRuntime) DeleteCrtListEntry(crtList, certFile string, lineNumber int) error

DeleteCrtListEntry deletes all the CrtList entries from the CrtList by its id

func (*SingleRuntime) DeleteMapEntry

func (s *SingleRuntime) DeleteMapEntry(name, id string) error

DeleteMapEntry deletes all the map entries from the map by its id

func (*SingleRuntime) DeleteServer

func (s *SingleRuntime) DeleteServer(backend, name string) error

DeleteServer removes a server from a backend

func (*SingleRuntime) DisableAgentCheck

func (s *SingleRuntime) DisableAgentCheck(backend, server string) error

DisableAgentCheck disable agent check for server

func (*SingleRuntime) DisableServer

func (s *SingleRuntime) DisableServer(backend, server string) error

DisableServer marks server as DOWN for maintenance

func (*SingleRuntime) EnableAgentCheck

func (s *SingleRuntime) EnableAgentCheck(backend, server string) error

EnableAgentCheck enable agent check for server

func (*SingleRuntime) EnableServer

func (s *SingleRuntime) EnableServer(backend, server string) error

EnableServer marks server as UP

func (*SingleRuntime) Execute

func (s *SingleRuntime) Execute(command string) error

Execute executes command on runtime API

func (*SingleRuntime) ExecuteMaster

func (s *SingleRuntime) ExecuteMaster(command string) (string, error)

func (*SingleRuntime) ExecuteRaw

func (s *SingleRuntime) ExecuteRaw(command string) (string, error)

ExecuteRaw executes command on runtime API and returns raw result

func (*SingleRuntime) ExecuteWithResponse

func (s *SingleRuntime) ExecuteWithResponse(command string) (string, error)

func (*SingleRuntime) GetACL

func (s *SingleRuntime) GetACL(storageName string) (*models.ACLFile, error)

GetACL returns one structured runtime Acl file

func (*SingleRuntime) GetACLFileEntry

func (s *SingleRuntime) GetACLFileEntry(aclID, value string) (*models.ACLFileEntry, error)

GetACLFileEntry returns one Acl runtime setting

func (*SingleRuntime) GetCert

func (s *SingleRuntime) GetCert(storageName string) (*models.SslCertificate, error)

GetCert returns one structured runtime certs

func (*SingleRuntime) GetCrtList

func (s *SingleRuntime) GetCrtList(file string) (*CrtList, error)

GetCrtList returns one structured runtime CrtList file

func (*SingleRuntime) GetInfo

func (s *SingleRuntime) GetInfo() models.ProcessInfo

GetInfo fetches HAProxy info from runtime API

func (*SingleRuntime) GetMap

func (s *SingleRuntime) GetMap(name string) (*models.Map, error)

GetMap returns one structured runtime map file

func (*SingleRuntime) GetMapEntry

func (s *SingleRuntime) GetMapEntry(name, id string) (*models.MapEntry, error)

GetMapEntry returns one map runtime setting

func (*SingleRuntime) GetServerState

func (s *SingleRuntime) GetServerState(backend, server string) (*models.RuntimeServer, error)

GetServersState returns server runtime state

func (*SingleRuntime) GetServersState

func (s *SingleRuntime) GetServersState(backend string) (models.RuntimeServers, error)

GetServersState returns servers runtime state

func (*SingleRuntime) GetStats

GetStats fetches HAProxy stats from runtime API

func (*SingleRuntime) GetTableEntries

func (s *SingleRuntime) GetTableEntries(name string, filter []string, key string) (models.StickTableEntries, error)

GetTableEntries returns Stick Tables entries

func (*SingleRuntime) Init

func (s *SingleRuntime) Init(ctx context.Context, socketPath string, worker int, process int, opt ...options.RuntimeOptions) error

Init must be given path to runtime socket and worker number. If in master-worker mode, give the path to the master socket path, and non 0 number for workers. Process is for nbproc > 1. In master-worker mode it's the same as the worker number, but when having multiple stats socket lines bound to processes then use the correct process number

func (*SingleRuntime) NewCertEntry

func (s *SingleRuntime) NewCertEntry(storageName string) error

NewCertEntry adds an entry into the CrtList file

func (*SingleRuntime) PrepareACL

func (s *SingleRuntime) PrepareACL(aclID string) (version string, err error)

func (*SingleRuntime) PrepareMap

func (s *SingleRuntime) PrepareMap(name string) (version string, err error)

func (*SingleRuntime) SetCertEntry

func (s *SingleRuntime) SetCertEntry(storageName string, payload string) error

SetCertEntry adds an entry into the CrtList file

func (*SingleRuntime) SetFrontendMaxConn

func (s *SingleRuntime) SetFrontendMaxConn(frontend string, maxconn int) error

SetFrontendMaxConn set maxconn for frontend

func (*SingleRuntime) SetMapEntry

func (s *SingleRuntime) SetMapEntry(name, id, value string) error

SetMapEntry replaces the value corresponding to each id in a map

func (*SingleRuntime) SetServerAddr

func (s *SingleRuntime) SetServerAddr(backend, server string, ip string, port int) error

SetServerAddr set ip [port] for server

func (*SingleRuntime) SetServerAgentAddr

func (s *SingleRuntime) SetServerAgentAddr(backend, server string, addr string) error

SetServerAgentAddr set agent-addr for server

func (*SingleRuntime) SetServerAgentSend

func (s *SingleRuntime) SetServerAgentSend(backend, server string, send string) error

SetServerAgentSend set agent-send for server

func (*SingleRuntime) SetServerCheckPort

func (s *SingleRuntime) SetServerCheckPort(backend, server string, port int) error

SetServerCheckPort set health heck port for server

func (*SingleRuntime) SetServerHealth

func (s *SingleRuntime) SetServerHealth(backend, server string, health string) error

SetServerHealth set health for server

func (*SingleRuntime) SetServerState

func (s *SingleRuntime) SetServerState(backend, server string, state string) error

SetServerState set state for server

func (*SingleRuntime) SetServerWeight

func (s *SingleRuntime) SetServerWeight(backend, server string, weight string) error

SetServerWeight set weight for server

func (*SingleRuntime) SetTableEntry

func (s *SingleRuntime) SetTableEntry(table, key string, dataType models.StickTableEntry) error

SetTableEntry create or update a stick-table entry in the table.

func (*SingleRuntime) ShowACLFileEntries

func (s *SingleRuntime) ShowACLFileEntries(storageName string) (models.ACLFilesEntries, error)

ShowACLFileEntries returns one acl runtime entries

func (*SingleRuntime) ShowACLS

func (s *SingleRuntime) ShowACLS() (models.ACLFiles, error)

ShowACLS returns Acl files description from runtime

func (*SingleRuntime) ShowCertEntry

func (s *SingleRuntime) ShowCertEntry(storageName string) (*models.SslCertEntry, error)

ShowCertEntry returns one CrtList runtime entries

func (*SingleRuntime) ShowCerts

func (s *SingleRuntime) ShowCerts() (models.SslCertificates, error)

ShowCerts returns Certs files description from runtime

func (*SingleRuntime) ShowCrtListEntries

func (s *SingleRuntime) ShowCrtListEntries(file string) (CrtListEntries, error)

ShowCrtListEntries returns one CrtList runtime entries

func (*SingleRuntime) ShowCrtLists

func (s *SingleRuntime) ShowCrtLists() (CrtLists, error)

ShowCrtLists returns CrtList files description from runtime

func (*SingleRuntime) ShowMapEntries

func (s *SingleRuntime) ShowMapEntries(name string) (models.MapEntries, error)

ShowMapEntries returns one map runtime entries

func (*SingleRuntime) ShowMapEntriesVersioned

func (s *SingleRuntime) ShowMapEntriesVersioned(name, version string) (models.MapEntries, error)

ShowMapEntriesVersioned returns one map runtime entries

func (*SingleRuntime) ShowMaps

func (s *SingleRuntime) ShowMaps() (models.Maps, error)

ShowMaps returns map files description from runtime

func (*SingleRuntime) ShowTable

func (s *SingleRuntime) ShowTable(name string) (*models.StickTable, error)

ShowTables returns one Stick Table descriptions from runtime

func (*SingleRuntime) ShowTables

func (s *SingleRuntime) ShowTables() (models.StickTables, error)

ShowTables returns Stick Tables descriptions from runtime

type Tables

type Tables interface {
	// SetTableEntry create or update a stick-table entry in the table.
	SetTableEntry(table, key string, dataType models.StickTableEntry, process int) error
	// Show tables show tables from runtime API and return it structured, if process is 0, return for all processes
	ShowTables(process int) (models.StickTables, error)
	// GetTableEntries returns all entries for specified table in the given process with filters and a key
	GetTableEntries(name string, process int, filter []string, key string) (models.StickTableEntries, error)
	// Show table show tables {name} from runtime API associated with process id and return it structured
	ShowTable(name string, process int) (*models.StickTable, error)
}

type Task

type Task struct {
	// contains filtered or unexported fields
}

Task has command to execute on runtime api, and response channel for result

type TaskResponse

type TaskResponse struct {
	// contains filtered or unexported fields
}

TaskResponse ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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