Class: ConfCtl::MachineStatus
- Inherits:
-
Object
- Object
- ConfCtl::MachineStatus
- Defined in:
- lib/confctl/machine_status.rb
Defined Under Namespace
Classes: SwpinState
Instance Attribute Summary collapse
- #current_toplevel ⇒ String readonly
- #generations ⇒ Generation::HostList readonly
- #machine ⇒ Machine readonly
- #online ⇒ Boolean (also: #online?) readonly
- #status ⇒ Boolean readonly
- #swpins_info ⇒ Hash readonly
- #swpins_state ⇒ Hash readonly
- #target_swpin_specs ⇒ Hash
- #target_toplevel ⇒ String
- #timezone_name ⇒ String readonly
- #timezone_offset ⇒ String readonly
- #uptime ⇒ Float readonly
Instance Method Summary collapse
- #evaluate ⇒ Object
-
#initialize(machine) ⇒ MachineStatus
constructor
A new instance of MachineStatus.
-
#query(toplevel: true, generations: true) ⇒ Object
Connect to the machine and query its state.
Constructor Details
#initialize(machine) ⇒ MachineStatus
Returns a new instance of MachineStatus.
83 84 85 86 |
# File 'lib/confctl/machine_status.rb', line 83 def initialize(machine) @machine = machine @mc = MachineControl.new(machine.carried? ? machine.carrier_machine : machine) end |
Instance Attribute Details
#current_toplevel ⇒ String (readonly)
62 63 64 |
# File 'lib/confctl/machine_status.rb', line 62 def current_toplevel @current_toplevel end |
#generations ⇒ Generation::HostList (readonly)
71 72 73 |
# File 'lib/confctl/machine_status.rb', line 71 def generations @generations end |
#machine ⇒ Machine (readonly)
46 47 48 |
# File 'lib/confctl/machine_status.rb', line 46 def machine @machine end |
#online ⇒ Boolean (readonly) Also known as: online?
52 53 54 |
# File 'lib/confctl/machine_status.rb', line 52 def online @online end |
#status ⇒ Boolean (readonly)
49 50 51 |
# File 'lib/confctl/machine_status.rb', line 49 def status @status end |
#swpins_info ⇒ Hash (readonly)
77 78 79 |
# File 'lib/confctl/machine_status.rb', line 77 def swpins_info @swpins_info end |
#swpins_state ⇒ Hash (readonly)
80 81 82 |
# File 'lib/confctl/machine_status.rb', line 80 def swpins_state @swpins_state end |
#target_swpin_specs ⇒ Hash
74 75 76 |
# File 'lib/confctl/machine_status.rb', line 74 def target_swpin_specs @target_swpin_specs end |
#target_toplevel ⇒ String
59 60 61 |
# File 'lib/confctl/machine_status.rb', line 59 def target_toplevel @target_toplevel end |
#timezone_name ⇒ String (readonly)
65 66 67 |
# File 'lib/confctl/machine_status.rb', line 65 def timezone_name @timezone_name end |
#timezone_offset ⇒ String (readonly)
68 69 70 |
# File 'lib/confctl/machine_status.rb', line 68 def timezone_offset @timezone_offset end |
#uptime ⇒ Float (readonly)
56 57 58 |
# File 'lib/confctl/machine_status.rb', line 56 def uptime @uptime end |
Instance Method Details
#evaluate ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/confctl/machine_status.rb', line 119 def evaluate @swpins_state = {} target_swpin_specs.each do |name, spec| swpins_state[name] = SwpinState.new(spec, swpins_info && swpins_info[name]) end outdated_swpins = swpins_state.detect { |_k, v| v.outdated? } @online = uptime ? true : false @status = online? && !outdated_swpins @status = false if target_toplevel && target_toplevel != current_toplevel end |
#query(toplevel: true, generations: true) ⇒ Object
Connect to the machine and query its state
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/confctl/machine_status.rb', line 89 def query(toplevel: true, generations: true) begin @uptime = mc.uptime rescue TTY::Command::ExitError return end if toplevel begin @current_toplevel = query_toplevel rescue TTY::Command::ExitError return end end if generations begin @generations = Generation::HostList.fetch(mc, profile: machine.profile) rescue TTY::Command::ExitError return end end begin @swpins_info = query_swpins rescue Error nil end end |