Class: Brightbox::ServerGroup

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

Direct Known Subclasses

DetailedServerGroup

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

.allObject



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

def self.all
  conn.server_groups
end

.create(options) ⇒ Object



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

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

.default_field_orderObject



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

def self.default_field_order
  %i[id server_count name]
end

.get(id) ⇒ Object



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

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

.require_account?Boolean

Returns:

  • (Boolean)


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

def self.require_account?; true; end

Instance Method Details

#destroyObject



33
34
35
# File 'lib/brightbox-cli/server_groups.rb', line 33

def destroy
  fog_model.destroy
end

#firewall_policyObject



21
22
23
24
25
# File 'lib/brightbox-cli/server_groups.rb', line 21

def firewall_policy
  FirewallPolicy.all.find do |policy|
    policy.server_group_id == id
  end
end

#server_countObject



48
49
50
# File 'lib/brightbox-cli/server_groups.rb', line 48

def server_count
  server_ids.respond_to?(:size) ? server_ids.size : 0
end

#server_idsObject



44
45
46
# File 'lib/brightbox-cli/server_groups.rb', line 44

def server_ids
  attributes[:server_ids].map { |id| id.is_a?(Hash) ? id["id"] : id }
end

#server_stringObject



52
53
54
# File 'lib/brightbox-cli/server_groups.rb', line 52

def server_string
  server_ids.respond_to?(:join) ? server_ids.join(" ") : ""
end

#to_rowObject



37
38
39
40
41
42
# File 'lib/brightbox-cli/server_groups.rb', line 37

def to_row
  super.merge(
    servers: server_string,
    server_count: server_count
  ).to_h
end

#update(options) ⇒ Object



27
28
29
30
31
# File 'lib/brightbox-cli/server_groups.rb', line 27

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