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.
82 83 84 85 |
# File 'lib/confctl/machine_status.rb', line 82 def initialize(machine) @machine = machine @mc = MachineControl.new(machine) end |
Instance Attribute Details
#current_toplevel ⇒ String (readonly)
61 62 63 |
# File 'lib/confctl/machine_status.rb', line 61 def current_toplevel @current_toplevel end |
#generations ⇒ Generation::HostList (readonly)
70 71 72 |
# File 'lib/confctl/machine_status.rb', line 70 def generations @generations end |
#machine ⇒ Machine (readonly)
45 46 47 |
# File 'lib/confctl/machine_status.rb', line 45 def machine @machine end |
#online ⇒ Boolean (readonly) Also known as: online?
51 52 53 |
# File 'lib/confctl/machine_status.rb', line 51 def online @online end |
#status ⇒ Boolean (readonly)
48 49 50 |
# File 'lib/confctl/machine_status.rb', line 48 def status @status end |
#swpins_info ⇒ Hash (readonly)
76 77 78 |
# File 'lib/confctl/machine_status.rb', line 76 def swpins_info @swpins_info end |
#swpins_state ⇒ Hash (readonly)
79 80 81 |
# File 'lib/confctl/machine_status.rb', line 79 def swpins_state @swpins_state end |
#target_swpin_specs ⇒ Hash
73 74 75 |
# File 'lib/confctl/machine_status.rb', line 73 def target_swpin_specs @target_swpin_specs end |
#target_toplevel ⇒ String
58 59 60 |
# File 'lib/confctl/machine_status.rb', line 58 def target_toplevel @target_toplevel end |
#timezone_name ⇒ String (readonly)
64 65 66 |
# File 'lib/confctl/machine_status.rb', line 64 def timezone_name @timezone_name end |
#timezone_offset ⇒ String (readonly)
67 68 69 |
# File 'lib/confctl/machine_status.rb', line 67 def timezone_offset @timezone_offset end |
#uptime ⇒ Float (readonly)
55 56 57 |
# File 'lib/confctl/machine_status.rb', line 55 def uptime @uptime end |
Instance Method Details
#evaluate ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/confctl/machine_status.rb', line 118 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
88 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 |
# File 'lib/confctl/machine_status.rb', line 88 def query(toplevel: true, generations: true) begin @uptime = mc.uptime rescue TTY::Command::ExitError return end if toplevel begin @current_toplevel = mc.read_symlink('/run/current-system') rescue TTY::Command::ExitError return end end if generations begin @generations = Generation::HostList.fetch(mc) rescue TTY::Command::ExitError return end end begin @swpins_info = Swpins::DeployedInfo.parse!(mc.read_file('/etc/confctl/swpins-info.json')) rescue Error nil end end |