Class: Brightbox::Server

Inherits:
Api
  • Object
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, 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

.allObject



58
59
60
# File 'lib/bbcloud/servers.rb', line 58

def self.all
  conn.servers
end

.create(options) ⇒ Object



8
9
10
# File 'lib/bbcloud/servers.rb', line 8

def self.create(options)
  new(conn.servers.create(options))
end

.create_servers(count, options) ⇒ Object



4
5
6
# File 'lib/bbcloud/servers.rb', line 4

def self.create_servers(count,options)
  (0...count).map {|i| create(options) }
end

.default_field_orderObject



62
63
64
# File 'lib/bbcloud/servers.rb', line 62

def self.default_field_order
  [:id, :status, :type, :zone, :created_on, :image_id,:cloud_ip_ids,:name]
end

.get(id) ⇒ Object



54
55
56
# File 'lib/bbcloud/servers.rb', line 54

def self.get(id)
  conn.servers.get id
end

Instance Method Details

#activate_consoleObject



50
51
52
# File 'lib/bbcloud/servers.rb', line 50

def activate_console
  self.class.conn.activate_console_server id
end

#attributesObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bbcloud/servers.rb', line 20

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[:status] = fog_model.state
  a[:zone] = Zone.new(zone_id) if zone_id
  a[:hostname] = hostname
  a[:public_hostname] = public_hostname unless cloud_ips.empty?
  a
end

#deleted?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/bbcloud/servers.rb', line 40

def deleted?
  fog_model.status == "deleted"
end

#destroyObject



44
45
46
47
48
# File 'lib/bbcloud/servers.rb', line 44

def destroy
  fog_model.destroy
rescue Excon::Errors::Conflict => e
  raise Conflict, "Cannot delete server #{id}"
end

#hostnameObject



66
67
68
# File 'lib/bbcloud/servers.rb', line 66

def hostname
  "#{id}.gb1.brightbox.com"
end

#imageObject



16
17
18
# File 'lib/bbcloud/servers.rb', line 16

def image
  @image ||= (Image.new(image_id) if image_id)
end

#public_hostnameObject



70
71
72
# File 'lib/bbcloud/servers.rb', line 70

def public_hostname
  "public.#{hostname}"
end

#server_typeObject



12
13
14
# File 'lib/bbcloud/servers.rb', line 12

def server_type
  @server_type ||= (Type.new(flavor_id) if flavor_id)
end

#to_rowObject



33
34
35
36
37
38
# File 'lib/bbcloud/servers.rb', line 33

def to_row
  o = attributes
  o[:cloud_ip_ids] = cloud_ips.collect { |i| i['id'] }
  o[:ips] = interfaces.collect { |i| i['ipv4_address'] }.join(', ')
  o
end