Module: YML

Defined in:
generators/get_yml.rb

Overview

Encapsulates methods to generate YML from the Switch records.

Class Method Summary (collapse)

Class Method Details

+ (Object) gen(switches, target_file = 'iblinkinfo.yml')

Output Yaml file recording port status for a switch

Parameters:

  • switches (Hash)
  • target_file (String) (defaults to: 'iblinkinfo.yml')

    write output to this 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
# File 'generators/get_yml.rb', line 6

def self.gen(switches, target_file='iblinkinfo.yml')
  File.open(target_file, "w") do |fd|
    port_status = {}
    switches.switch_location.each do |k,loc|
      switch_ports = []
      v = ib.switches[k]
      if v != nil 
        (1..loc[4]).each do |i|
          row = []
          l = ib.location[v[i][9]] #Connected host / switch
          row[0] = v[i][9] #Remote host attached to port
          row[1] = v[i][7] #Remote Port Number
          if(l != nil && ib.switches[v[i][9]] != nil)
            row[2] = "" #Alternate name
            #fd.print "\t-"
          else
            row[2] = "#{l == nil ? v[i][9] : "#{l[2]}/P#{"%02d"%v[i][7]}"}" #Alternate name
          end
          switch_ports[i] = row
        end
        port_status[k] = switch_ports
      end
    end
    fd.write(port_status.to_yaml)
  end
end