Class: Brightbox::CloudIP
- Inherits:
-
Api
- Object
- Api
- Brightbox::CloudIP
show all
- Defined in:
- lib/brightbox-cli/cloud_ips.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, #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
9
10
11
|
# File 'lib/brightbox-cli/cloud_ips.rb', line 9
def self.all
conn.cloud_ips
end
|
.create(options = {}) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/brightbox-cli/cloud_ips.rb', line 13
def self.create(options = {})
create_options = {}
if options[:t]
create_options[:port_translators] = format_translators_for_api(options[:t])
end
if options[:n] && !options[:name].empty?
create_options[:name] = options[:n]
end
r = conn.create_cloud_ip(create_options)
new(r["id"])
end
|
.default_field_order ⇒ Object
60
61
62
|
# File 'lib/brightbox-cli/cloud_ips.rb', line 60
def self.default_field_order
%i[id status public_ip destination reverse_dns name]
end
|
26
27
28
29
30
31
32
33
|
# File 'lib/brightbox-cli/cloud_ips.rb', line 26
def self.format_translators_for_api(translators)
translators.split(",").map do |t|
incoming, outgoing, protocol = t.split(":")
raise "translator #{t} is invalid" if incoming.nil? || outgoing.nil? || protocol.nil?
{ :incoming => incoming, :outgoing => outgoing, :protocol => protocol }
end
end
|
.get(id) ⇒ Object
5
6
7
|
# File 'lib/brightbox-cli/cloud_ips.rb', line 5
def self.get(id)
conn.cloud_ips.get id
end
|
.require_account? ⇒ Boolean
3
|
# File 'lib/brightbox-cli/cloud_ips.rb', line 3
def self.require_account?; true; end
|
Instance Method Details
#<=>(other) ⇒ Object
64
65
66
|
# File 'lib/brightbox-cli/cloud_ips.rb', line 64
def <=>(other)
status <=> other.status
end
|
#attributes ⇒ Object
35
36
37
38
39
|
# File 'lib/brightbox-cli/cloud_ips.rb', line 35
def attributes
fog_attributes.tap do |attrs|
attrs[:destination] = destination_id
end
end
|
#mapped? ⇒ Boolean
47
48
49
|
# File 'lib/brightbox-cli/cloud_ips.rb', line 47
def mapped?
status == "mapped"
end
|
#to_row ⇒ Object
41
42
43
44
45
|
# File 'lib/brightbox-cli/cloud_ips.rb', line 41
def to_row
attributes.merge(
port_translators: translators(attributes),
).to_h
end
|
#translators(raw_attributes) ⇒ Object
51
52
53
54
55
56
57
58
|
# File 'lib/brightbox-cli/cloud_ips.rb', line 51
def translators(raw_attributes)
translators = (raw_attributes[:port_translators] || raw_attributes["port_translators"])
return unless translators
translators.map do |t|
[t["incoming"], t["outgoing"], t["protocol"]].join(":")
end
end
|
#update(options) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/brightbox-cli/cloud_ips.rb', line 68
def update(options)
params = {}
if options[:r]
params[:reverse_dns] = options[:r]
end
if options[:"delete-reverse-dns"]
params[:reverse_dns] = ""
end
if options[:n] && !options[:n].nil?
params[:name] = options[:n]
end
if options[:t]
params[:port_translators] = CloudIP.format_translators_for_api(options[:t])
end
self.class.conn.update_cloud_ip(id, params)
reload
self
end
|