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:



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

Returns:

  • (String)


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

def current_toplevel
  @current_toplevel
end

#generationsGeneration::HostList (readonly)



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

def generations
  @generations
end

#machineMachine (readonly)

Returns:



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

def machine
  @machine
end

#onlineBoolean (readonly) Also known as: online?

Returns:

  • (Boolean)


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

def online
  @online
end

#statusBoolean (readonly)

Returns:

  • (Boolean)


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

def status
  @status
end

#swpins_infoHash (readonly)

Returns:

  • (Hash)


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

def swpins_info
  @swpins_info
end

#swpins_stateHash (readonly)

Returns:

  • (Hash)


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

def swpins_state
  @swpins_state
end

#target_swpin_specsHash

Returns:

  • (Hash)


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

def target_swpin_specs
  @target_swpin_specs
end

#target_toplevelString

Returns:

  • (String)


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

def target_toplevel
  @target_toplevel
end

#timezone_nameString (readonly)

Returns:

  • (String)


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

def timezone_name
  @timezone_name
end

#timezone_offsetString (readonly)

Returns:

  • (String)


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

def timezone_offset
  @timezone_offset
end

#uptimeFloat (readonly)

Returns:

  • (Float)


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

def uptime
  @uptime
end

Instance Method Details

#evaluateObject



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