Class: Radfish::PowerInfo
- Inherits:
-
Object
- Object
- Radfish::PowerInfo
- Defined in:
- lib/radfish/power_info.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #allocated_watts ⇒ Object
- #capacity_watts ⇒ Object
- #cycle ⇒ Object
-
#initialize(client) ⇒ PowerInfo
constructor
A new instance of PowerInfo.
- #keys ⇒ Object
- #off(force: false) ⇒ Object
- #on ⇒ Object
- #psus ⇒ Object
- #reset_types_allowed ⇒ Object
- #restart(force: false) ⇒ Object
- #state ⇒ Object
- #to_h ⇒ Object
- #usage_watts ⇒ Object
Constructor Details
#initialize(client) ⇒ PowerInfo
Returns a new instance of PowerInfo.
7 8 9 10 |
# File 'lib/radfish/power_info.rb', line 7 def initialize(client) @client = client @cache = {} end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/radfish/power_info.rb', line 5 def client @client end |
Instance Method Details
#allocated_watts ⇒ Object
38 39 40 |
# File 'lib/radfish/power_info.rb', line 38 def allocated_watts fetch_power_consumption[:allocated_watts] || fetch_power_consumption[:power_allocated_watts] end |
#capacity_watts ⇒ Object
34 35 36 |
# File 'lib/radfish/power_info.rb', line 34 def capacity_watts fetch_power_consumption[:capacity_watts] || fetch_power_consumption[:power_capacity_watts] end |
#cycle ⇒ Object
54 55 56 |
# File 'lib/radfish/power_info.rb', line 54 def cycle @client.adapter.power_cycle end |
#keys ⇒ Object
12 13 14 |
# File 'lib/radfish/power_info.rb', line 12 def keys [:state, :usage_watts, :capacity_watts, :allocated_watts, :reset_types_allowed, :psus, :on, :off, :restart, :cycle] end |
#off(force: false) ⇒ Object
46 47 48 |
# File 'lib/radfish/power_info.rb', line 46 def off(force: false) @client.adapter.power_off(force: force) end |
#on ⇒ Object
42 43 44 |
# File 'lib/radfish/power_info.rb', line 42 def on @client.adapter.power_on end |
#psus ⇒ Object
62 63 64 |
# File 'lib/radfish/power_info.rb', line 62 def psus @cache[:psus] ||= @client.adapter.psus end |
#reset_types_allowed ⇒ Object
58 59 60 |
# File 'lib/radfish/power_info.rb', line 58 def reset_types_allowed @cache[:reset_types] ||= @client.adapter.reset_type_allowed if @client.adapter.respond_to?(:reset_type_allowed) end |
#restart(force: false) ⇒ Object
50 51 52 |
# File 'lib/radfish/power_info.rb', line 50 def restart(force: false) @client.adapter.power_restart(force: force) end |
#state ⇒ Object
24 25 26 |
# File 'lib/radfish/power_info.rb', line 24 def state fetch_power_status[:power_state] || fetch_power_status[:state] end |
#to_h ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/radfish/power_info.rb', line 16 def to_h # Only include data attributes, not methods data_keys = [:state, :usage_watts, :capacity_watts, :allocated_watts, :reset_types_allowed, :psus] data_keys.each_with_object({}) do |key, hash| hash[key] = send(key) rescue nil end end |
#usage_watts ⇒ Object
28 29 30 31 32 |
# File 'lib/radfish/power_info.rb', line 28 def usage_watts fetch_power_consumption[:consumed_watts] || fetch_power_consumption[:power_usage_watts] || fetch_power_consumption_watts end |