Module: DataPlaneApi::Server

Defined in:
lib/data_plane_api/server.rb

Overview

Wraps endpoints regarding HAProxy servers.

Constant Summary collapse

ADMIN_STATES =

Returns:

  • (Set<Symbol>)
::Set[:ready, :maint, :drain]
OPERATIONAL_STATES =

Returns:

  • (Set<Symbol>)
::Set[:up, :down, :stopping]

Class Method Summary collapse

Class Method Details

.get_runtime_settings(backend:, name: nil, config: nil) ⇒ Faraday::Response

Parameters:

  • backend (String)

    Name of the backend

  • name (String, nil) (defaults to: nil)

    Name of the server whose settings will be returned. If ‘nil` then an array of settings of all servers under the passed `backend` will be returned.

  • config (HaProxy::DataPlaneApi::Configuration, nil) (defaults to: nil)

Returns:

  • (Faraday::Response)


21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/data_plane_api/server.rb', line 21

def get_runtime_settings(backend:, name: nil, config: nil)
  config ||= CONFIG
  if backend.nil? || backend.empty?
    raise ::ArgumentError, "`backend` should be present but was `#{backend.inspect}`"
  end

  path = "services/haproxy/runtime/servers/#{name}".delete_suffix('/')

  send_request(method: :get, path: path, config: config) do |req|
    req.params[:backend] = backend
  end
end

.update_transient_settings(backend:, name:, settings:, config: nil) ⇒ Faraday::Response

Parameters:

  • backend (String)

    Name of the backend

  • name (String, nil)

    Name of the server whose transient settings should be updated.

  • settings (Hash)
  • config (HaProxy::DataPlaneApi::Configuration, nil) (defaults to: nil)

Returns:

  • (Faraday::Response)

Raises:

  • (::ArgumentError)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/data_plane_api/server.rb', line 39

def update_transient_settings(backend:, name:, settings:, config: nil)
  config ||= CONFIG
  if backend.nil? || backend.empty?
    raise ::ArgumentError, "`backend` should be present but was `#{backend.inspect}`"
  end
  raise ::ArgumentError, "`name` should be present but was `#{name.inspect}`" if name.nil? || name.empty?

  path = "services/haproxy/runtime/servers/#{name}"

  send_request(method: :put, path: path, config: config) do |req|
    req.params[:backend] = backend
    req.body = settings
  end
end