Class: Brightbox::Server
- Inherits:
-
Api
- Object
- Api
- Brightbox::Server
show all
- Defined in:
- lib/bbcloud/servers.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, #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
49
50
51
|
# File 'lib/bbcloud/servers.rb', line 49
def self.all
conn.servers
end
|
.create(options) ⇒ Object
4
5
6
|
# File 'lib/bbcloud/servers.rb', line 4
def self.create(options)
new(conn.servers.create(options))
end
|
.default_field_order ⇒ Object
53
54
55
|
# File 'lib/bbcloud/servers.rb', line 53
def self.default_field_order
[:id, :status, :type, :zone, :created_on, :image_id, :cloud_ips, :name]
end
|
.get(id) ⇒ Object
45
46
47
|
# File 'lib/bbcloud/servers.rb', line 45
def self.get(id)
conn.servers.get id
end
|
Instance Method Details
#attributes ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/bbcloud/servers.rb', line 16
def attributes
a = fog_model.attributes
a[:image] = image
a[:created_at] = created_at
a[:created_on] = fog_model.created_at.strftime("%Y-%m-%d")
a[:type] = server_type
a[:zone] = Zone.new(zone_id)
a[:hostname] = hostname
a[:public_hostname] = public_hostname unless cloud_ips.empty?
a
end
|
#deleted? ⇒ Boolean
35
36
37
|
# File 'lib/bbcloud/servers.rb', line 35
def deleted?
fog_model.status == "deleted"
end
|
#destroy ⇒ Object
39
40
41
42
43
|
# File 'lib/bbcloud/servers.rb', line 39
def destroy
fog_model.destroy
rescue Excon::Errors::Conflict => e
raise Conflict, "Cannot delete server #{id}"
end
|
#hostname ⇒ Object
57
58
59
|
# File 'lib/bbcloud/servers.rb', line 57
def hostname
"#{id}.gb1.brightbox.com"
end
|
#image ⇒ Object
12
13
14
|
# File 'lib/bbcloud/servers.rb', line 12
def image
@image ||= Image.new(image_id)
end
|
#public_hostname ⇒ Object
61
62
63
|
# File 'lib/bbcloud/servers.rb', line 61
def public_hostname
"public.#{hostname}"
end
|
#server_type ⇒ Object
8
9
10
|
# File 'lib/bbcloud/servers.rb', line 8
def server_type
@server_type ||= Type.new(flavor_id)
end
|
#to_row ⇒ Object
28
29
30
31
32
33
|
# File 'lib/bbcloud/servers.rb', line 28
def to_row
o = attributes
o[:cloud_ips] = cloud_ips.collect { |i| i['public_ip'] }
o[:ips] = interfaces.collect { |i| i['ipv4_address'] }.join(', ')
o
end
|