Class: Boxcutter::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/boxcutter/api.rb

Instance Method Summary collapse

Constructor Details

#initialize(customer_id, api_key_secret) ⇒ Api

Returns a new instance of Api.



6
7
8
9
# File 'lib/boxcutter/api.rb', line 6

def initialize(customer_id, api_key_secret)
  @customer_id    = customer_id
  @api_key_secret = api_key_secret
end

Instance Method Details

#application(app_id) ⇒ Object



36
37
38
# File 'lib/boxcutter/api.rb', line 36

def application(app_id)
  get("lb_applications/#{app_id}")
end

#applicationsObject



32
33
34
# File 'lib/boxcutter/api.rb', line 32

def applications
  get('lb_applications')
end

#backend(service_id, backend_id) ⇒ Object



52
53
54
# File 'lib/boxcutter/api.rb', line 52

def backend(service_id, backend_id)
  get("lb_services/#{service_id}/lb_backends/#{backend_id}")
end

#backends(service_id) ⇒ Object



48
49
50
# File 'lib/boxcutter/api.rb', line 48

def backends(service_id)
  get("lb_services/#{service_id}/lb_backends")
end

#connObject



24
25
26
27
28
29
30
# File 'lib/boxcutter/api.rb', line 24

def conn
  @conn ||= Faraday.new(:url => "https://boxpanel.bluebox.net/api") do |conn|
    conn.request :url_encoded
    conn.adapter Faraday.default_adapter
    conn.basic_auth(@customer_id, @api_key_secret)
  end
end

#create_machine(backend_id, machine_id, options = {}) ⇒ Object

Options are: port - The port the machine is serving http or https on. Defaults to the

port the service is listening on.

weight - The multiplier for what portion of the incoming traffic should be

routed to this machine.

maxconn - The maximum number of simultaneous connections allowed for this

machine.

backup - Only direct traffic to this node if all the other nodes are down.



76
77
78
79
80
# File 'lib/boxcutter/api.rb', line 76

def create_machine(backend_id, machine_id, options = {})
  data = { 'lb_machine' => machine_id }
  data['lb_options'] = options unless options.empty?
  conn.post("lb_backends/#{backend_id}/lb_machines", data)
end

#delete_machine(backend_id, machine_id) ⇒ Object



64
65
66
# File 'lib/boxcutter/api.rb', line 64

def delete_machine(backend_id, machine_id)
  conn.delete("lb_backends/#{backend_id}/lb_machines/#{machine_id}")
end

#get(path) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/boxcutter/api.rb', line 15

def get(path)
  response = conn.get(path)
  begin
    Yajl::Parser.new.parse(response.body)
  rescue Yajl::ParseError
    {:message => response.body}
  end
end

#machine(backend_id, machine_id) ⇒ Object



60
61
62
# File 'lib/boxcutter/api.rb', line 60

def machine(backend_id, machine_id)
  get("lb_backends/#{backend_id}/lb_machines/#{machine_id}")
end

#machines(backend_id) ⇒ Object



56
57
58
# File 'lib/boxcutter/api.rb', line 56

def machines(backend_id)
  get("lb_backends/#{backend_id}/lb_machines")
end

#serversObject



82
83
84
# File 'lib/boxcutter/api.rb', line 82

def servers
  get("servers")
end

#service(app_id, service_id) ⇒ Object



44
45
46
# File 'lib/boxcutter/api.rb', line 44

def service(app_id, service_id)
  get("lb_applications/#{app_id}/lb_services/#{service_id}")
end

#services(app_id) ⇒ Object



40
41
42
# File 'lib/boxcutter/api.rb', line 40

def services(app_id)
  get("lb_applications/#{app_id}/lb_services")
end

#to_sObject



11
12
13
# File 'lib/boxcutter/api.rb', line 11

def to_s
  "#<Api customer_id:'#{@customer_id}' api_key_secret:'***'>"
end