Class: Brightbox::Server

Inherits:
Api
  • Object
show all
Defined in:
lib/brightbox-cli/servers.rb

Direct Known Subclasses

DetailedServer

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

.allObject



13
14
15
# File 'lib/brightbox-cli/servers.rb', line 13

def self.all
  conn.servers
end

.create(options) ⇒ Object



9
10
11
# File 'lib/brightbox-cli/servers.rb', line 9

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

.create_servers(count, options) ⇒ Object



5
6
7
# File 'lib/brightbox-cli/servers.rb', line 5

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

.default_field_orderObject



21
22
23
# File 'lib/brightbox-cli/servers.rb', line 21

def self.default_field_order
  %i[id status type zone created_on image_id cloud_ip_ids name]
end

.get(id) ⇒ Object



17
18
19
# File 'lib/brightbox-cli/servers.rb', line 17

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

.require_account?Boolean

Returns:

  • (Boolean)


3
# File 'lib/brightbox-cli/servers.rb', line 3

def self.require_account?; true; end

Instance Method Details

#activate_consoleObject



35
36
37
# File 'lib/brightbox-cli/servers.rb', line 35

def activate_console
  self.class.conn.activate_console_server id
end

#attributesObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/brightbox-cli/servers.rb', line 39

def attributes
  fog_attributes.tap do |attrs|
    attrs[:created_at] = created_at
    attrs[:created_on] = created_on
    attrs[:hostname] = hostname
    attrs[:image] = image_id
    attrs[:locked] = locked?
    attrs[:status] = fog_model.state
    attrs[:type] = server_type["handle"]
    attrs[:zone] = zone && zone["handle"]

    unless cloud_ips.empty?
      attrs[:public_hostname] = "public.#{fqdn}"
    end

    if interfaces.any? { |i| i["ipv6_address"] }
      attrs[:ipv6_hostname] = ipv6_fqdn
    end
  end
end

#deleted?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/brightbox-cli/servers.rb', line 67

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

#destroyObject



31
32
33
# File 'lib/brightbox-cli/servers.rb', line 31

def destroy
  fog_model.destroy
end

#ipv6_fqdnObject



71
72
73
# File 'lib/brightbox-cli/servers.rb', line 71

def ipv6_fqdn
  "ipv6.#{fqdn}"
end

#to_rowObject



60
61
62
63
64
65
# File 'lib/brightbox-cli/servers.rb', line 60

def to_row
  attributes.merge(
    cloud_ips: cloud_ips.map { |i| i["public_ip"] }.join(", "),
    ips: interfaces.map { |i| i["ipv4_address"] }.join(", ")
  )
end

#update(options) ⇒ Object



25
26
27
28
29
# File 'lib/brightbox-cli/servers.rb', line 25

def update(options)
  self.class.conn.update_server id, options
  reload
  self
end