Class: Brightbox::Account

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

Direct Known Subclasses

CollaboratingAccount

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, require_account?, #respond_to_missing?

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



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

def self.all
  if Brightbox.config.using_application?
    conn.accounts.all
  else
    [conn.]
  end
end

.default_field_orderObject



43
44
45
# File 'lib/brightbox-cli/accounts.rb', line 43

def self.default_field_order
  %i[id name cloud_ips_limit lb_limit ram_limit ram_used ram_free]
end

.get(id) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/brightbox-cli/accounts.rb', line 31

def self.get(id)
  acc = if Brightbox.config.using_application?
          conn.accounts.get(id)
        else
          conn.
        end

  return unless acc && acc.id == id

  acc
end

Instance Method Details

#cloud_ip_limitObject



7
8
9
# File 'lib/brightbox-cli/accounts.rb', line 7

def cloud_ip_limit
  attributes[:cloud_ips_limit]
end

#lb_limitObject



11
12
13
# File 'lib/brightbox-cli/accounts.rb', line 11

def lb_limit
  attributes[:load_balancers_limit]
end

#ram_freeObject



3
4
5
# File 'lib/brightbox-cli/accounts.rb', line 3

def ram_free
  [ram_limit.to_i - ram_used.to_i, 0].max
end

#to_rowObject



15
16
17
18
19
20
21
# File 'lib/brightbox-cli/accounts.rb', line 15

def to_row
  attributes.to_h.merge(
    :ram_free => ram_free,
    :cloud_ip_limit => cloud_ip_limit,
    :lb_limit => lb_limit
  )
end

#to_sObject



47
48
49
# File 'lib/brightbox-cli/accounts.rb', line 47

def to_s
  @id
end