Class: PowerConnect

Inherits:
Oxidized::Model show all
Defined in:
lib/oxidized/model/powerconnect.rb

Constant Summary

Constants inherited from Oxidized::Model

Oxidized::Model::METADATA_DEFAULT

Constants included from Oxidized::Model::Macros

Oxidized::Model::Macros::VERBS

Instance Attribute Summary

Attributes inherited from Oxidized::Model

#input, #node

Attributes included from Oxidized::Model::DSLCommands

#procs

Instance Method Summary collapse

Methods inherited from Oxidized::Model

#cfg, #cmd, #comment, #expect, #expects, #get, inherited, #interpolate_string, #metadata, #output, #prompt, #screenscrape, #send, #significant_changes, #xmlcomment

Methods included from Oxidized::Model::DSLSetup

#cfg, #cfgs, #comment, #expect, #expects, #input_sequence, #inputs, #metadata, #prompt

Methods included from Oxidized::Model::DSLCommands

#cmd, #cmds, #post, #pre

Methods included from Oxidized::Config::Vars

#vars

Instance Method Details

#clean(cfg) ⇒ Object



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
# File 'lib/oxidized/model/powerconnect.rb', line 66

def clean(cfg)
  out = []
  len1 = len2 = skip_blocks = 0

  cfg.each_line do |line|
    # If this is a stackable switch we should skip this block of information
    if line.match(/Up\sTime|Temperature|Power Suppl(ies|y)|Fans/i) && (@stackable == true)
      skip_blocks = 1
      # Some switches have another empty line. This is identified by this line having a colon
      skip_blocks = 2 if line =~ /:/
    end
    # If we have lines to skip do this until we reach and empty line
    if skip_blocks.positive?
      skip_blocks -= 1 if /\S/ !~ line
      next
    end
    line = line.strip
    # If the temps were not removed by skipping blocks, then mask them out wih XXX
    # The most recent set of dashes has the spacing we want to match
    if (match = line.match(/^(---+ +)(---+ +)/))
      one, two = match.captures
      len1 = one.length
      len2 = two.length
    end
    # This can only be a temperature, right? ;-)
    if (match = line.match(/^(\d{1,2}) {3,}\d+ (.*)$/))
      one, two = match.captures
      line = one.to_s + (' ' * (len1 - one.length)) + "XXX" + (' ' * (len2 - 3)) + two.to_s
    end
    out << line
  end
  out = out.reject { |line| line[/Up\sTime/] } # Filter out Up Time
  out = comment out.join "\n"
  out << "\n"
end