Class: Fog::Bluebox::BLB::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/bluebox/blb.rb,
lib/fog/bluebox/requests/blb/get_lb_backend.rb,
lib/fog/bluebox/requests/blb/get_lb_machine.rb,
lib/fog/bluebox/requests/blb/get_lb_service.rb,
lib/fog/bluebox/requests/blb/get_lb_backends.rb,
lib/fog/bluebox/requests/blb/get_lb_machines.rb,
lib/fog/bluebox/requests/blb/get_lb_services.rb,
lib/fog/bluebox/requests/blb/get_lb_application.rb,
lib/fog/bluebox/requests/blb/get_lb_applications.rb,
lib/fog/bluebox/requests/blb/add_machine_to_lb_backend.rb,
lib/fog/bluebox/requests/blb/update_lb_backend_machine.rb,
lib/fog/bluebox/requests/blb/add_machine_to_lb_application.rb,
lib/fog/bluebox/requests/blb/remove_machine_from_lb_backend.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



45
46
47
48
49
50
51
52
53
54
# File 'lib/fog/bluebox/blb.rb', line 45

def initialize(options={})
  @bluebox_api_key      = options[:bluebox_api_key]
  @bluebox_customer_id  = options[:bluebox_customer_id]
  @connection_options   = options[:connection_options] || {}
  @host       = options[:bluebox_host]    || "boxpanel.bluebox.net"
  @persistent = options[:persistent]      || false
  @port       = options[:bluebox_port]    || 443
  @scheme     = options[:bluebox_scheme]  || 'https'
  @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end

Instance Method Details

#add_machine_to_lb_application(lb_application_id, lb_machine_id, options = {}) ⇒ Object

Add machine to default lb_backend for each lb_service in the application.

Parameters

  • lb_application_id<~String> - ID of application

  • lb_machine_id<~String> - ID of machine

  • options<~Hash>:

    • port<~Integer> - port machine listens on; defaults to service listening port

    • maxconn<~Integer> - maximum number of connections server can be sent

    • backup<~Boolean> - only send traffic to machine if all others are down



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fog/bluebox/requests/blb/add_machine_to_lb_application.rb', line 16

def add_machine_to_lb_application(lb_application_id, lb_machine_id, options = {})
  # convert to CGI array args
  body = Hash[options.map {|k,v| ["lb_options[#{k}]", v] }]
  body['lb_machine'] = lb_machine_id
  request(
    :expects => 200,
    :method  => 'POST',
    :path    => "/api/lb_applications/add_machine/#{lb_application_id}.json",
    :body    => body.map {|k,v| "#{CGI.escape(k)}=#{CGI.escape(v.to_s)}"}.join('&')
  )
end

#add_machine_to_lb_backend(lb_backend_id, lb_machine_id, options = {}) ⇒ Object

Add machine to specified lb_backend

Parameters

  • lb_backend_id<~String> - ID of backend

  • lb_machine_id<~String> - ID of machine

  • options<~Hash>:

    • port<~Integer> - port machine listens on; defaults to service listening port

    • maxconn<~Integer> - maximum number of connections server can be sent

    • backup<~Boolean> - only send traffic to machine if all others are down



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fog/bluebox/requests/blb/add_machine_to_lb_backend.rb', line 14

def add_machine_to_lb_backend(lb_backend_id, lb_machine_id, options = {})
  # convert to CGI array args
  body = Hash[options.map {|k,v| ["lb_options[#{k}]", v] }]
  body['lb_machine'] = lb_machine_id
  request(
    :expects => 200,
    :method  => 'POST',
    :path    => "/api/lb_backends/#{lb_backend_id}/lb_machines.json",
    :body    => body.map {|k,v| "#{CGI.escape(k)}=#{CGI.escape(v.to_s)}"}.join('&')
  )
end

#get_lb_application(lb_application_id) ⇒ Object

Get details of an lb_application.

Parameters

  • lb_application_id<~Integer> - ID of application

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘id’<~String> - UUID of application

      • ‘ip_v4’<~Array> - IPv4 addresses

      • ‘ip_v6’<~String> - IPv6 address

      • ‘name’<~String> - The hostname

      • ‘lb_services’<~Array> - Listening services

      • ‘source_ip_v4’<~String> - address that application connects to pool members from (v1 only)



19
20
21
22
23
24
25
# File 'lib/fog/bluebox/requests/blb/get_lb_application.rb', line 19

def get_lb_application(lb_application_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :path     => "api/lb_applications/#{lb_application_id}.json"
  )
end

#get_lb_applicationsObject

Get list of applications

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • ‘application’<~Hash>:

        • ‘id’<~String> - UUID of application

        • ‘ip_v4’<~Array> - IPv4 addresses

        • ‘ip_v6’<~String> - IPv6 address

        • ‘name’<~String> - The hostname

        • ‘lb_services’<~Array> - Listening services

        • ‘source_ip_v4’<~String> - address that application connects to pool members from (v1 only)



17
18
19
20
21
22
23
# File 'lib/fog/bluebox/requests/blb/get_lb_applications.rb', line 17

def get_lb_applications
  request(
    :expects  => 200,
    :method   => 'GET',
    :path     => 'api/lb_applications.json'
  )
end

#get_lb_backend(lb_service_id, lb_backend_id) ⇒ Object

Get details of an lb_backend.

Parameters

  • lb_service_id<~String> - service backend belongs to

  • lb_backend_id<~String> - backend to look up

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • id<~String> - backend ID

      • backend_name<~String>

      • lb_machines<~Array> - array of backend members

      • acl_name<~String> - name of ACL for this backend

      • acl_rule<~String>

      • monitoring_url_hostname<~String> - HTTP host header for health check

      • monitoring_url<~String> - URL for health check

      • check_interval<~Integer> - time between checks, in milliseconds



22
23
24
25
26
27
28
# File 'lib/fog/bluebox/requests/blb/get_lb_backend.rb', line 22

def get_lb_backend(lb_service_id, lb_backend_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :path     => "api/lb_services/#{lb_service_id}/lb_backends/#{lb_backend_id}.json"
  )
end

#get_lb_backends(lb_service_id) ⇒ Object

Get list of backends

Parameters

  • lb_service_id<~String> - service containing backends

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • backend<~Hash>:

        • id<~String> - backend ID

        • backend_name<~String>

        • lb_machines<~Array> - array of backend members

        • acl_name<~String> - name of ACL for this backend

        • acl_rule<~String>

        • monitoring_url_hostname<~String> - HTTP host header for health check

        • monitoring_url<~String> - URL for health check

        • check_interval<~Integer> - time between checks, in milliseconds



22
23
24
25
26
27
28
# File 'lib/fog/bluebox/requests/blb/get_lb_backends.rb', line 22

def get_lb_backends(lb_service_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :path     => "api/lb_services/#{lb_service_id}/lb_backends.json"
  )
end

#get_lb_machine(lb_backend_id, lb_machine_id) ⇒ Object

Get details of an lb_machine.

Parameters

  • lb_backend_id<~String> - backend machine belongs to

  • lb_machine_id<~String> - machine to look up

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • id<~String> - machine ID

      • ip<~String> - machine IP address for this member (v4 or v6)

      • port<~Integer> - service port for this member

      • hostname<~String> - name as registered with Box Panel

      • acl_name<~String> - name of ACL for this machine

      • created<~DateTime> - when machine was added to load balancer backend

      • maxconn<~Integer> - maximum concurrent connections for this member (BLBv2 only)



21
22
23
24
25
26
27
# File 'lib/fog/bluebox/requests/blb/get_lb_machine.rb', line 21

def get_lb_machine(lb_backend_id, lb_machine_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :path     => "api/lb_backends/#{lb_backend_id}/lb_machines/#{lb_machine_id}.json"
  )
end

#get_lb_machines(lb_backend_id) ⇒ Object

Get list of machines

Parameters

  • lb_backend_id<~String> - backend containing machines

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • machine<~Hash>:

        • id<~String> - machine ID

        • ip<~String> - machine IP address for this member (v4 or v6)

        • port<~Integer> - service port for this member

        • hostname<~String> - name as registered with Box Panel

        • acl_name<~String> - name of ACL for this machine

        • created<~DateTime> - when machine was added to load balancer backend

        • maxconn<~Integer> - maximum concurrent connections for this member (BLBv2 only)



21
22
23
24
25
26
27
# File 'lib/fog/bluebox/requests/blb/get_lb_machines.rb', line 21

def get_lb_machines(lb_backend_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :path     => "api/lb_backends/#{lb_backend_id}/lb_machines.json"
  )
end

#get_lb_service(lb_application_id, lb_service_id) ⇒ Object

Get details of a lb_service.

Parameters

  • lb_application_id<~String> - ID of application the service belongs to

  • lb_service_id<~String> - ID of service to look up

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • name<~String> - service name

      • port<~Integer> - port of load balanced service

      • private<~Boolean> - whether service is only available internally

      • status_username<~String> - HTTP basic auth username

      • status_password<~String> - HTTP basic auth password

      • status_url<~String> - URL of stats page

      • service_type<~String> - proto being load balanced (e.g. ‘http’, ‘tcp’)

      • created<~DateTime> - when service was created



22
23
24
25
26
27
28
# File 'lib/fog/bluebox/requests/blb/get_lb_service.rb', line 22

def get_lb_service(lb_application_id, lb_service_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :path     => "api/lb_applications/#{lb_application_id}/lb_services/#{lb_service_id}.json",
  )
end

#get_lb_services(lb_application_id) ⇒ Object

Get list of load balancing services

Parameters

  • lb_application_id<~String> - Id of application services to list

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • backend<~Hash>:

        • name<~String> - service name

        • port<~Integer> - port of load balanced service

        • private<~Boolean> - whether service is only available internally

        • status_username<~String> - HTTP basic auth username

        • status_password<~String> - HTTP basic auth password

        • status_url<~String> - URL of stats page

        • service_type<~String> - proto being load balanced (e.g. ‘http’, ‘tcp’)

        • created<~DateTime> - when service was created



22
23
24
25
26
27
28
# File 'lib/fog/bluebox/requests/blb/get_lb_services.rb', line 22

def get_lb_services(lb_application_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :path     => "api/lb_applications/#{lb_application_id}/lb_services.json"
  )
end

#reloadObject



56
57
58
# File 'lib/fog/bluebox/blb.rb', line 56

def reload
  @connection.reset
end

#remove_machine_from_lb_backend(lb_backend_id, lb_machine_id) ⇒ Object

remove machine from single backend

Parameters

  • lb_backend_id<~String> - ID of backend

  • lb_machine_id<~String> - ID of machine

Returns

  • response<~Excon::Response>:

    • body<~String> - success or failure message



14
15
16
17
18
19
20
21
# File 'lib/fog/bluebox/requests/blb/remove_machine_from_lb_backend.rb', line 14

def remove_machine_from_lb_backend(lb_backend_id, lb_machine_id)
  request(
    :expects => 200,
    :method  => 'DELETE',
    :path    => "/api/lb_backends/#{lb_backend_id}/lb_machines/#{lb_machine_id}",
    :headers => {"Accept" => "text/plain"},
  )
end

#request(params) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/fog/bluebox/blb.rb', line 60

def request(params)
  params[:headers] ||= {}
  params[:headers].merge!({
    'Authorization' => "Basic #{Base64.encode64([@bluebox_customer_id, @bluebox_api_key].join(':')).delete("\r\n")}"
  })

  begin
    response = @connection.request(params)
  rescue Excon::Errors::HTTPStatusError => error
    raise case error
    when Excon::Errors::NotFound
      Fog::Compute::Bluebox::NotFound.slurp(error)
    else
      error
    end
  end
  unless response.body.empty? || params[:headers]['Accept'] == 'text/plain'
    response.body = Fog::JSON.decode(response.body)
  end
  response
end

#update_lb_backend_machine(lb_backend_id, lb_machine_id, options = {}) ⇒ Object

change machine attributes (port &c) in a single backend

Parameters

  • lb_backend_id<~String> - ID of backend

  • lb_machine_id<~String> - ID of machine

  • options<~Hash>:

    • port<~Integer> - port machine listens on

    • maxconn<~Integer> - maximum number of connections server can be sent

    • backup<~Boolean> - only send traffic to machine if all others are down



14
15
16
17
18
19
20
21
22
# File 'lib/fog/bluebox/requests/blb/update_lb_backend_machine.rb', line 14

def update_lb_backend_machine(lb_backend_id, lb_machine_id, options = {})
  # inconsistent, no?
  request(
    :expects => 202,
    :method  => 'PUT',
    :path    => "/api/lb_backends/#{lb_backend_id}/lb_machines/#{lb_machine_id}",
    :body    => options.map {|k,v| "#{CGI.escape(k)}=#{CGI.escape(v.to_s)}"}.join('&')
  )
end