Class: ConfCtl::MachineStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/confctl/machine_status.rb

Defined Under Namespace

Classes: SwpinState

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(machine) ⇒ MachineStatus

Returns a new instance of MachineStatus.

Parameters:



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_toplevelString (readonly)

Returns:

  • (String)


61
62
63
# File 'lib/confctl/machine_status.rb', line 61

def current_toplevel
  @current_toplevel
end

#generationsGeneration::HostList (readonly)



70
71
72
# File 'lib/confctl/machine_status.rb', line 70

def generations
  @generations
end

#machineMachine (readonly)

Returns:



45
46
47
# File 'lib/confctl/machine_status.rb', line 45

def machine
  @machine
end

#onlineBoolean (readonly) Also known as: online?

Returns:

  • (Boolean)


51
52
53
# File 'lib/confctl/machine_status.rb', line 51

def online
  @online
end

#statusBoolean (readonly)

Returns:

  • (Boolean)


48
49
50
# File 'lib/confctl/machine_status.rb', line 48

def status
  @status
end

#swpins_infoHash (readonly)

Returns:

  • (Hash)


76
77
78
# File 'lib/confctl/machine_status.rb', line 76

def swpins_info
  @swpins_info
end

#swpins_stateHash (readonly)

Returns:

  • (Hash)


79
80
81
# File 'lib/confctl/machine_status.rb', line 79

def swpins_state
  @swpins_state
end

#target_swpin_specsHash

Returns:

  • (Hash)


73
74
75
# File 'lib/confctl/machine_status.rb', line 73

def target_swpin_specs
  @target_swpin_specs
end

#target_toplevelString

Returns:

  • (String)


58
59
60
# File 'lib/confctl/machine_status.rb', line 58

def target_toplevel
  @target_toplevel
end

#timezone_nameString (readonly)

Returns:

  • (String)


64
65
66
# File 'lib/confctl/machine_status.rb', line 64

def timezone_name
  @timezone_name
end

#timezone_offsetString (readonly)

Returns:

  • (String)


67
68
69
# File 'lib/confctl/machine_status.rb', line 67

def timezone_offset
  @timezone_offset
end

#uptimeFloat (readonly)

Returns:

  • (Float)


55
56
57
# File 'lib/confctl/machine_status.rb', line 55

def uptime
  @uptime
end

Instance Method Details

#evaluateObject



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