Class: Brightbox::LoadBalancer
- Inherits:
-
Api
- Object
- Api
- Brightbox::LoadBalancer
show all
- Defined in:
- lib/brightbox-cli/load_balancers.rb
Instance Attribute Summary
Attributes inherited from Api
#id
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Api
#attributes, cache_all!, cached_get, conn, #created_on, #exists?, find, find_all_or_warn, find_by_handle, find_or_call, #fog_attributes, #fog_model, #initialize, klass_name, #method_missing, #respond_to_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
109
110
111
|
# File 'lib/brightbox-cli/load_balancers.rb', line 109
def self.all
conn.load_balancers
end
|
.create(options) ⇒ Object
5
6
7
8
9
10
|
# File 'lib/brightbox-cli/load_balancers.rb', line 5
def self.create(options)
options.delete(:buffer_size) if options[:buffer_size].nil?
options[:buffer_size] = options[:buffer_size].to_i if options[:buffer_size]
new(conn.load_balancers.create(options))
end
|
.default_field_order ⇒ Object
113
114
115
|
# File 'lib/brightbox-cli/load_balancers.rb', line 113
def self.default_field_order
i[id status created_on cloud_ips nodes name]
end
|
.get(id) ⇒ Object
105
106
107
|
# File 'lib/brightbox-cli/load_balancers.rb', line 105
def self.get(id)
conn.load_balancers.get id
end
|
.require_account? ⇒ Boolean
3
|
# File 'lib/brightbox-cli/load_balancers.rb', line 3
def self.require_account?; true; end
|
Instance Method Details
#acme_cert ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/brightbox-cli/load_balancers.rb', line 12
def acme_cert
if attributes[:acme] && attributes[:acme][:certificate]
OpenStruct.new(
:expires_at => attributes[:acme][:certificate][:expires_at],
:fingerprint => attributes[:acme][:certificate][:fingerprint],
:issued_at => attributes[:acme][:certificate][:issued_at],
:subjects => attributes[:acme][:certificate][:domains].join(",")
)
else
OpenStruct.new(
:expires_at => "",
:fingerprint => "",
:issued_at => "",
:subjects => ""
)
end
end
|
#add_nodes(nodes) ⇒ Object
89
90
91
92
|
# File 'lib/brightbox-cli/load_balancers.rb', line 89
def add_nodes(nodes)
node_hashes = nodes.map { |n| { :node => n.id } }
LoadBalancer.conn.add_nodes_load_balancer(id, :nodes => node_hashes)
end
|
#buffer_size ⇒ Object
79
80
81
|
# File 'lib/brightbox-cli/load_balancers.rb', line 79
def buffer_size
attributes[:buffer_size]
end
|
#cloud_ip_ids ⇒ Object
65
66
67
68
|
# File 'lib/brightbox-cli/load_balancers.rb', line 65
def cloud_ip_ids
cips = attributes["cloud_ips"] || attributes[:cloud_ips]
@cloud_ip_ids ||= cips.map { |n| n["id"] } if cips
end
|
#cloud_ips ⇒ Object
70
71
72
73
|
# File 'lib/brightbox-cli/load_balancers.rb', line 70
def cloud_ips
cips = attributes["cloud_ips"] || attributes[:cloud_ips]
@cloud_ips ||= cips.map { |n| n["public_ip"] } if cips
end
|
#destroy ⇒ Object
83
84
85
86
87
|
# File 'lib/brightbox-cli/load_balancers.rb', line 83
def destroy
fog_model.destroy
rescue Excon::Errors::Conflict
raise Conflict, "Cannot delete load balancer #{id}"
end
|
#formatted_acme_domains ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/brightbox-cli/load_balancers.rb', line 30
def formatted_acme_domains
return "" unless attributes[:acme]
attributes[:acme][:domains].map do |domain|
[domain[:identifier], domain[:status]].join(":")
end.join(",")
rescue StandardError
""
end
|
#listeners ⇒ Object
75
76
77
|
# File 'lib/brightbox-cli/load_balancers.rb', line 75
def listeners
attributes[:listeners]&.map { |l| [l["in"], l["out"], l["protocol"], l["timeout"]].join(":") }
end
|
#node_ids ⇒ Object
61
62
63
|
# File 'lib/brightbox-cli/load_balancers.rb', line 61
def node_ids
@node_ids ||= attributes[:nodes].map { |n| n["id"] } if attributes[:nodes]
end
|
#remove_nodes(nodes) ⇒ Object
94
95
96
97
|
# File 'lib/brightbox-cli/load_balancers.rb', line 94
def remove_nodes(nodes)
node_hashes = nodes.map { |n| { :node => n.id } }
LoadBalancer.conn.remove_nodes_load_balancer(id, :nodes => node_hashes)
end
|
#to_row ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/brightbox-cli/load_balancers.rb', line 40
def to_row
attributes.merge(
:locked => locked?,
:acme_domains => formatted_acme_domains,
:acme_cert_expires_at => acme_cert.expires_at,
:acme_cert_fingerprint => acme_cert.fingerprint,
:acme_cert_issued_at => acme_cert.issued_at,
:acme_cert_subjects => acme_cert.subjects,
:ssl_minimum_version => ssl_minimum_version,
:ssl_issuer => certificate_issuer,
:ssl_subject => certificate_subject,
:ssl_valid_from => certificate_valid_from,
:ssl_expires_at => certificate_expires_at,
:ssl_v3_enabled => certificate_enable_ssl3,
:nodes => node_ids,
:created_on => created_on,
:listeners => listeners,
:cloud_ips => cloud_ip_ids
)
end
|
#update(options) ⇒ Object
99
100
101
102
103
|
# File 'lib/brightbox-cli/load_balancers.rb', line 99
def update(options)
LoadBalancer.conn.update_load_balancer(id, options)
reload
self
end
|