Module: TSV

Defined in:
generators/gen_tsv.rb

Overview

output TSV Excel file from IBLinkinfo as tab seperated file

Class Method Summary (collapse)

Class Method Details

+ (Object) gen(ib, file = 'iblinkinfo.tsv')

Generate a Tab separated (.tsv) formated file from the IBLinkinfo data.

Parameters:

  • ib (IBLinkInfo)

    The data derived from an iblinkinfo command, and parsed by the IBLinkInfo class parser

  • file (String) (defaults to: 'iblinkinfo.tsv')

    The name of the output file.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'generators/gen_tsv.rb', line 6

def self.gen(ib, file='iblinkinfo.tsv')
  #Output Excel tab separated fields for current switch port to rack mappings
  #@switches.each do |k,v|
  File.open(file, "w") do |fd|
    ib.switch_location.each do |k,loc|
      if loc[1] == :leaf || loc[1] == :ex_spine
        fd.puts k
        v = ib.switches[k]
        #puts v.class
        if v != nil 
          (1..loc[4]).step(2) do |i|
            fd.print "\t" if i == 19 
            fd.print"\t#{i}"
          end
          fd.print "\n"
          (1..loc[4]).step(2) do |i|
            l = ib.location[v[i][9]]
            fd.print "\t" if i == 19 
            fd.print l == nil ? "\t " : "\t#{l[0]}/P#{"%02d"%v[i][7]}"
          end
          fd.print "\n"
          (1..loc[4]).step(2) do |i|
            l = ib.location[v[i][9]]
            fd.print "\t" if i == 19 
              fd.print "\t#{l == nil ? v[i][9] : "#{l[2]}/P#{"%02d"%v[i][7]}"}" # Don't have a location : do have a location
            #end
          end
          fd.print "\n"

          (2..loc[4]).step(2) do |i|
            fd.print "\t" if i == 20
            fd.print "\t#{i}" 
          end
          fd.print "\n"
          (2..loc[4]).step(2) do |i|
            l = ib.location[v[i][9]]
            fd.print "\t" if i == 20
            fd.print l == nil ? "\t " : "\t#{l[0]}/P#{"%02d"%v[i][7]}"
          end
          fd.print "\n"
          (2..loc[4]).step(2) do |i|
            l = ib.location[v[i][9]]
            fd.print "\t" if i == 20
            fd.print "\t#{l == nil ? v[i][9] : "#{l[2]}/P#{"%02d"%v[i][7]}"}"
          end
          fd.print "\n"
        end
      end
    end
  end
end