Class: Brightbox::LoadBalancer
- Inherits:
-
Api
- Object
- Api
- Brightbox::LoadBalancer
show all
- Defined in:
- lib/bbcloud/load_balancers.rb
Instance Attribute Summary
Attributes inherited from Api
#id
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Api
cache_all!, cached_get, conn, #exists?, find, find_by_handle, find_or_call, #fog_model, #initialize, #method_missing, #to_s
Constructor Details
This class inherits a constructor from Brightbox::Api
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Brightbox::Api
Class Method Details
.all ⇒ Object
77
78
79
|
# File 'lib/bbcloud/load_balancers.rb', line 77
def self.all
conn.load_balancers
end
|
.create(options) ⇒ Object
4
5
6
|
# File 'lib/bbcloud/load_balancers.rb', line 4
def self.create(options)
new(conn.load_balancers.create(options))
end
|
.default_field_order ⇒ Object
81
82
83
|
# File 'lib/bbcloud/load_balancers.rb', line 81
def self.default_field_order
[:id, :status, :created_on, :cloud_ips, :nodes, :name]
end
|
.get(id) ⇒ Object
73
74
75
|
# File 'lib/bbcloud/load_balancers.rb', line 73
def self.get(id)
conn.load_balancers.get id
end
|
Instance Method Details
#add_nodes(nodes) ⇒ Object
50
51
52
53
54
55
|
# File 'lib/bbcloud/load_balancers.rb', line 50
def add_nodes(nodes)
node_hashes = nodes.collect { |n| { :node => n.id } }
LoadBalancer.conn.add_nodes_load_balancer(id, :nodes => node_hashes)
rescue Excon::Errors::BadRequest => e
raise Conflict, JSON.parse(e.response.body)['error']['details']
end
|
#attributes ⇒ Object
8
9
10
|
# File 'lib/bbcloud/load_balancers.rb', line 8
def attributes
fog_model.attributes
end
|
#cloud_ip_ids ⇒ Object
28
29
30
|
# File 'lib/bbcloud/load_balancers.rb', line 28
def cloud_ip_ids
@cloud_ip_ids ||= attributes["cloud_ips"].collect { |n| n["id"] } if attributes["cloud_ips"]
end
|
#cloud_ips ⇒ Object
32
33
34
|
# File 'lib/bbcloud/load_balancers.rb', line 32
def cloud_ips
@cloud_ips ||= attributes["cloud_ips"].collect { |n| n["public_ip"] } if attributes["cloud_ips"]
end
|
#created_on ⇒ Object
20
21
22
|
# File 'lib/bbcloud/load_balancers.rb', line 20
def created_on
attributes["created_at"].to_s.split('T').first
end
|
#destroy ⇒ Object
44
45
46
47
48
|
# File 'lib/bbcloud/load_balancers.rb', line 44
def destroy
fog_model.destroy
rescue Excon::Errors::Conflict => e
raise Conflict, "Cannot delete load balancer #{id}"
end
|
#listeners ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/bbcloud/load_balancers.rb', line 36
def listeners
if attributes[:listeners]
attributes[:listeners].collect { |l| [l["in"], l["out"], l["protocol"]].join(":") }
else
nil
end
end
|
#node_ids ⇒ Object
24
25
26
|
# File 'lib/bbcloud/load_balancers.rb', line 24
def node_ids
@node_ids ||= attributes[:nodes].collect { |n| n["id"] } if attributes[:nodes]
end
|
#remove_nodes(nodes) ⇒ Object
57
58
59
60
61
62
|
# File 'lib/bbcloud/load_balancers.rb', line 57
def remove_nodes(nodes)
node_hashes = nodes.collect { |n| { :node => n.id } }
LoadBalancer.conn.remove_nodes_load_balancer(id, :nodes => node_hashes)
rescue Excon::Errors::BadRequest => e
raise Conflict, JSON.parse(e.response.body)['error']['details']
end
|
#to_row ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/bbcloud/load_balancers.rb', line 12
def to_row
attributes.merge({ :nodes => node_ids,
:created_on => created_on,
:listeners => listeners,
:cloud_ips => cloud_ips
})
end
|
#update(options) ⇒ Object
64
65
66
67
68
69
70
71
|
# File 'lib/bbcloud/load_balancers.rb', line 64
def update(options)
debug options.inspect
LoadBalancer.conn.update_load_balancer(id, options)
self.reload
self
rescue Excon::Errors::BadRequest => e
raise Conflict, JSON.parse(e.response.body)['error']['details']
end
|