Class: Konzertmeister::Host
- Inherits:
-
Object
- Object
- Konzertmeister::Host
- Defined in:
- lib/konzertmeister/host.rb
Constant Summary collapse
- FLAVORS =
%w[ 2x_small extra_small small medium large extra_large 2x_large ]- POSTGRES_KIND =
'postgres'- CODA_KIND =
'coda'- UTIL_KIND =
'util'
Instance Attribute Summary collapse
-
#backend_ip ⇒ Object
readonly
Returns the value of attribute backend_ip.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#flavor ⇒ Object
readonly
Returns the value of attribute flavor.
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#management_ip ⇒ Object
readonly
Returns the value of attribute management_ip.
-
#monthly_cost ⇒ Object
readonly
Returns the value of attribute monthly_cost.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
Class Method Summary collapse
Instance Method Summary collapse
- #backend ⇒ Object
-
#initialize(data) ⇒ Host
constructor
A new instance of Host.
- #name ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(data) ⇒ Host
Returns a new instance of Host.
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/konzertmeister/host.rb', line 31 def initialize(data) @data = data data.each do |k,value| next if %w[backend].include?(k) if m = k.match(/^host_(.*)$/) key = m[1] else key = k end instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#backend_ip ⇒ Object (readonly)
Returns the value of attribute backend_ip.
16 17 18 |
# File 'lib/konzertmeister/host.rb', line 16 def backend_ip @backend_ip end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
16 17 18 |
# File 'lib/konzertmeister/host.rb', line 16 def created_at @created_at end |
#flavor ⇒ Object (readonly)
Returns the value of attribute flavor.
16 17 18 |
# File 'lib/konzertmeister/host.rb', line 16 def flavor @flavor end |
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
16 17 18 |
# File 'lib/konzertmeister/host.rb', line 16 def hostname @hostname end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
16 17 18 |
# File 'lib/konzertmeister/host.rb', line 16 def id @id end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
16 17 18 |
# File 'lib/konzertmeister/host.rb', line 16 def kind @kind end |
#management_ip ⇒ Object (readonly)
Returns the value of attribute management_ip.
16 17 18 |
# File 'lib/konzertmeister/host.rb', line 16 def management_ip @management_ip end |
#monthly_cost ⇒ Object (readonly)
Returns the value of attribute monthly_cost.
16 17 18 |
# File 'lib/konzertmeister/host.rb', line 16 def monthly_cost @monthly_cost end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
16 17 18 |
# File 'lib/konzertmeister/host.rb', line 16 def status @status end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
16 17 18 |
# File 'lib/konzertmeister/host.rb', line 16 def token @token end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
16 17 18 |
# File 'lib/konzertmeister/host.rb', line 16 def updated_at @updated_at end |
Class Method Details
.all ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/konzertmeister/host.rb', line 18 def self.all response = Konzertmeister.session.get('/hosts') if response response.map do |data| Konzertmeister::Host.new(data) end.sort_by(&:hostname) end end |
.find_by(attr, value) ⇒ Object
27 28 29 |
# File 'lib/konzertmeister/host.rb', line 27 def self.find_by(attr, value) Host.new(Konzertmeister.session.get("/hosts/#{attr}/#{value}")) end |
Instance Method Details
#backend ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/konzertmeister/host.rb', line 45 def backend @backend ||= if @data.key?('backend') Konzertmeister::Backend.new(@data.fetch('backend')) else Host.find_by('id', self.id).backend end end |
#name ⇒ Object
53 54 55 |
# File 'lib/konzertmeister/host.rb', line 53 def name "#{kind}-#{token}" end |
#to_s ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/konzertmeister/host.rb', line 57 def to_s if status == "active" cost_string = "$%1.2f/month" % [monthly_cost] "%-14s %s" % [cost_string, name] else "%-14s %s" % ["(inactive)", name] end end |