Class: Adapter_fc

Inherits:
Object
  • Object
show all
Defined in:
lib/AIX/adapter_fc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAdapter_fc

Returns a new instance of Adapter_fc.



9
10
11
12
13
# File 'lib/AIX/adapter_fc.rb', line 9

def initialize

  @fcstats = Hash.new
  @serial_number = nil
end

Instance Attribute Details

#fcstatsObject (readonly)

Returns the value of attribute fcstats.



5
6
7
# File 'lib/AIX/adapter_fc.rb', line 5

def fcstats
  @fcstats
end

#serial_numberObject

Returns the value of attribute serial_number.



7
8
9
# File 'lib/AIX/adapter_fc.rb', line 7

def serial_number
  @serial_number
end

Instance Method Details

#analyzeObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/AIX/adapter_fc.rb', line 34

def analyze

  verbose = 1

  if @fcstats.count == 2
    puts 'Will analyze data'

    keys = @fcstats.keys

    fcs_1 = @fcstats[keys[0]]
    fcs_2 = @fcstats[keys[1]]

    if keys[0] < keys[1]
      puts "Test of timestamps -  [passed] " if verbose > 0
    else
      raise 'Wrong timestamps order in object, this version can work in this case (wrong data file?)'
    end

    if  fcs_1.data["Seconds Since Last Reset"] < fcs_2.data["Seconds Since Last Reset"]
      puts "Seconds from liast Reset are increasing, it means adapter stats weren't reset and we can compare both states [passed]"
    else
      raise 'data statistics were reset, cannot compare data'
    end


  else
    puts 'I cannot find 2 fcstats entries'
  end
end

#diffsObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/AIX/adapter_fc.rb', line 64

def diffs

  diffs = Hash.new

  timestamps = @fcstats.keys
  fcs_1 = @fcstats[timestamps[0]]
  fcs_2 = @fcstats[timestamps[1]]

  fcs_1.data.each_pair { |key, value|

    diff = Hash.new

    if value.class == Hash
        value.each_pair { |key2, value2|
            puts "key: #{key}, key2: #{key2}, value2 type: #{value2.class}"

            if fcs_1.data[key][key2] != fcs_2.data[key][key2]
              diff[timestamps[0]] = fcs_1.data[key][key2]
              diff[timestamps[1]] = fcs_2.data[key][key2]
              diffs["#{key}-#{key2}"] = diff
            end

        }
    elsif   value.class == String or value.class == Integer
      #puts "key: #{key}, value type: #{value.class}"

      if fcs_1.data[key] != fcs_2.data[key]
        diff[timestamps[0]] = fcs_1.data[key]
        diff[timestamps[1]] = fcs_2.data[key]
        diffs[key] = diff
      end

    else
      puts "Unknown type: #{value.class}"
    end
  }

  diffs
end

#fcstat_add(timestamp, string) ⇒ Object



15
16
17
18
19
20
# File 'lib/AIX/adapter_fc.rb', line 15

def fcstat_add(timestamp, string)

  @fcstats[timestamp] = Fcstat.new(string)
  self.validate_new_fcstat_data(timestamp)

end

#validate_new_fcstat_data(timestamp) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/AIX/adapter_fc.rb', line 22

def validate_new_fcstat_data(timestamp)

  if @fcstats.count == 1
    @serial_number = @fcstats[timestamp].data['Serial Number']
  else
    pp @serial_number
    pp @fcstats[timestamp].data['Serial Number']
    raise 'wrong serial number' if @fcstats[timestamp].data['Serial Number'] != @serial_number

  end
end