Module: Excel_XML
- Defined in:
- generators/gen_excel_xml.rb
Overview
Generate an Excel XML file from the IBLinkInfo data. Switches and their ports are shown.
Class Method Summary (collapse)
-
+ (Object) excel_xml_footer(fd)
Generates closing XML.
-
+ (Object) excel_xml_header(fd, switch_count)
Excel XML file lead in.
-
+ (Object) excel_xml_last_row(fd)
Generates the xml table's last row's formatting for the switch.
-
+ (Object) excel_xml_row(fd, start, end_val, v, location, inc)
Generates the xml table's last row's formatting for the switch.
-
+ (Object) excel_xml_table_header(fd, start, end_val, inc)
Generates the table header for a switch.
-
+ (Object) excel_xml_table_start(fd, switch_name)
Generates the xml table's first row's XML formatting for the switch.
-
+ (Object) gen(ib, file = "iblinkinfo.xml")
Generate a XML formated Excel file from the IBLinkinfo data.
Class Method Details
+ (Object) excel_xml_footer(fd)
Generates closing XML
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'generators/gen_excel_xml.rb', line 329 def self.(fd) fd.puts <<-EOF </Table> <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel"> <PageLayoutZoom>0</PageLayoutZoom> <Selected/> <Panes> <Pane> <Number>3</Number> <ActiveRow>10</ActiveRow> <ActiveCol>11</ActiveCol> </Pane> </Panes> <ProtectObjects>False</ProtectObjects> <ProtectScenarios>False</ProtectScenarios> </WorksheetOptions> </Worksheet> </Workbook> EOF end |
+ (Object) excel_xml_header(fd, switch_count)
Excel XML file lead in
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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'generators/gen_excel_xml.rb', line 91 def self.excel_xml_header(fd, switch_count) fd.puts <<-EOF <?xml version="1.0"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40"> <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"> <Author>rbur004</Author> <LastAuthor>rbur004</LastAuthor> <Created>2015-01-12T23:01:09Z</Created> <LastSaved>2015-01-12T22:56:15Z</LastSaved> <Company>UoA</Company> <Version>14.0</Version> </DocumentProperties> <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office"> <AllowPNG/> </OfficeDocumentSettings> <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"> <WindowHeight>23900</WindowHeight> <WindowWidth>39720</WindowWidth> <WindowTopX>4960</WindowTopX> <WindowTopY>140</WindowTopY> <ProtectStructure>False</ProtectStructure> <ProtectWindows>False</ProtectWindows> </ExcelWorkbook> <Styles> <Style ss:ID="Default" ss:Name="Normal"> <Alignment ss:Vertical="Bottom"/> <Borders/> <Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="12" ss:Color="#000000"/> <Interior/> <NumberFormat/> <Protection/> </Style> <Style ss:ID="s63"> <Borders> <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="2"/> <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="2"/> <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="2"/> </Borders> </Style> <Style ss:ID="s64"> <Borders> <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="2"/> <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="2"/> <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="2"/> </Borders> </Style> <Style ss:ID="s65"> <Borders> <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="2"/> <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="2"/> </Borders> <Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="12" ss:Color="#000000" ss:Bold="1"/> </Style> <Style ss:ID="s66"> <Borders> <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="2"/> </Borders> </Style> <Style ss:ID="s67"> <Borders> <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="2"/> <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="2"/> </Borders> </Style> <Style ss:ID="s68"> <Borders> <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="2"/> </Borders> </Style> <Style ss:ID="s69"> <Borders/> <Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="12" ss:Color="#000000" ss:Bold="1"/> </Style> <Style ss:ID="s70"> <Borders> <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="2"/> </Borders> </Style> <Style ss:ID="s71"> <Borders/> </Style> <Style ss:ID="s72"> <Borders> <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="2"/> <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="2"/> </Borders> </Style> <Style ss:ID="s73"> <Borders> <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="2"/> </Borders> </Style> <Style ss:ID="s74"> <Borders> <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="2"/> <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="2"/> </Borders> </Style> </Styles> <Worksheet ss:Name="iblinkinfo_excel.txt"> <Table ss:ExpandedColumnCount="21" ss:ExpandedRowCount="#{switch_count*8}" x:FullColumns="1" x:FullRows="1" ss:DefaultColumnWidth="65" ss:DefaultRowHeight="15"> <Column ss:AutoFitWidth="0" ss:Width="22"/> <Column ss:AutoFitWidth="0" ss:Width="88" ss:Span="8"/> <Column ss:Index="11" ss:AutoFitWidth="0" ss:Width="12"/> <Column ss:AutoFitWidth="0" ss:Width="88" ss:Span="8"/> <Column ss:Index="21" ss:AutoFitWidth="0" ss:Width="19"/> EOF end |
+ (Object) excel_xml_last_row(fd)
Generates the xml table's last row's formatting for the switch
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'generators/gen_excel_xml.rb', line 261 def self.excel_xml_last_row(fd) fd.puts <<-EOF <Row ss:Height="16"> <Cell ss:StyleID="s72"/> <Cell ss:StyleID="s73"/> <Cell ss:StyleID="s73"/> <Cell ss:StyleID="s73"/> <Cell ss:StyleID="s73"/> <Cell ss:StyleID="s73"/> <Cell ss:StyleID="s73"/> <Cell ss:StyleID="s73"/> <Cell ss:StyleID="s73"/> <Cell ss:StyleID="s73"/> <Cell ss:StyleID="s73"/> <Cell ss:StyleID="s73"/> <Cell ss:StyleID="s73"/> <Cell ss:StyleID="s73"/> <Cell ss:StyleID="s73"/> <Cell ss:StyleID="s73"/> <Cell ss:StyleID="s73"/> <Cell ss:StyleID="s73"/> <Cell ss:StyleID="s73"/> <Cell ss:StyleID="s73"/> <Cell ss:StyleID="s74"/> </Row> EOF end |
+ (Object) excel_xml_row(fd, start, end_val, v, location, inc)
Generates the xml table's last row's formatting for the switch
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'generators/gen_excel_xml.rb', line 296 def self.excel_xml_row(fd, start, end_val, v, location, inc ) fd.puts <<-EOF <Row ss:Height="16"> <Cell ss:StyleID="s68"/> EOF gap = start + 9 * inc #Output the location (start..end_val).step(inc) do |i| l = location[v[i][9]] fd.print " <Cell ss:StyleID=\"s71\"/>\n" if i == gap fd.print " <Cell ss:StyleID=\"s63\"><Data ss:Type=\"String\">" fd.print l == nil ? " " : "#{l[0]}/P#{"%02d"%v[i][7]}" fd.print "</Data></Cell>\n" end fd.print " <Cell ss:StyleID=\"s70\"/>\n </Row>\n" fd.puts <<-EOF <Row ss:Height="16"> <Cell ss:StyleID="s68"/> EOF #Output the name of the client node (start..end_val).step(inc) do |i| l = location[v[i][9]] fd.print " <Cell ss:StyleID=\"s71\"/>\n" if i == gap fd.print " <Cell ss:StyleID=\"s64\"><Data ss:Type=\"String\">" fd.print "#{l == nil ? v[i][9] : "#{l[2]}/P#{"%02d"%v[i][7]}"}" # Don't have a location : do have a location fd.print "</Data></Cell>\n" end fd.print " <Cell ss:StyleID=\"s70\"/>\n </Row>\n" end |
+ (Object) excel_xml_table_header(fd, start, end_val, inc)
Generates the table header for a switch
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'generators/gen_excel_xml.rb', line 212 def self.excel_xml_table_header(fd, start, end_val, inc ) fd.puts <<-EOF <Row ss:Height="16"> <Cell ss:StyleID="s68"/> EOF gap = start + 9 * inc (start..end_val).step(inc) do |i| fd.puts " <Cell ss:StyleID=\"s69\"/>" if i == gap fd.puts " <Cell ss:StyleID=\"s69\"><Data ss:Type=\"Number\">#{i}</Data></Cell>" end fd.puts <<-EOF <Cell ss:StyleID="s70"/> </Row> EOF end |
+ (Object) excel_xml_table_start(fd, switch_name)
Generates the xml table's first row's XML formatting for the switch
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'generators/gen_excel_xml.rb', line 231 def self.excel_xml_table_start(fd,switch_name) fd.puts <<-EOF <Row> <Cell ss:StyleID="s65"><Data ss:Type="String">#{switch_name}</Data></Cell> <Cell ss:StyleID="s66"/> <Cell ss:StyleID="s66"/> <Cell ss:StyleID="s66"/> <Cell ss:StyleID="s66"/> <Cell ss:StyleID="s66"/> <Cell ss:StyleID="s66"/> <Cell ss:StyleID="s66"/> <Cell ss:StyleID="s66"/> <Cell ss:StyleID="s66"/> <Cell ss:StyleID="s66"/> <Cell ss:StyleID="s66"/> <Cell ss:StyleID="s66"/> <Cell ss:StyleID="s66"/> <Cell ss:StyleID="s66"/> <Cell ss:StyleID="s66"/> <Cell ss:StyleID="s66"/> <Cell ss:StyleID="s66"/> <Cell ss:StyleID="s66"/> <Cell ss:StyleID="s66"/> <Cell ss:StyleID="s67"/> </Row> EOF end |
+ (Object) gen(ib, file = "iblinkinfo.xml")
Generate a XML formated Excel file from the IBLinkinfo data.
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'generators/gen_excel_xml.rb', line 8 def self.gen(ib, file="iblinkinfo.xml") #Output Excel XML file File.open(file, "w") do |fd| excel_xml_header(fd, ib.switches.length) ib.switch_location.each do |k,loc| if loc[1] == :leaf || loc[1] == :ex_spine excel_xml_table_start(fd, k) v = ib.switches[k] #puts v.class if v != nil #excel_xml_table_1st_header(fd) if k =~ /Mellanox 4036E.*/ excel_xml_table_header(fd, 18, 34, 1 ) excel_xml_row(fd, 18, 34, v, ib.location, 1) #excel_xml_table_2nd_header(fd) excel_xml_table_header(fd, 1, 17, 1 ) excel_xml_row(fd, 1, 17, v, ib.location, 1) else excel_xml_table_header(fd, 1, 36, 2 ) excel_xml_row(fd, 1, 36, v, ib.location, 2) #excel_xml_table_2nd_header(fd) excel_xml_table_header(fd, 2, 36, 2 ) excel_xml_row(fd, 2, 36, v, ib.location, 2) end excel_xml_last_row(fd) else v_nil = [ #hack to make code simpler. 36 empty ports, so we don't have to special case this. ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ["","","","","","","","","",""], ] excel_xml_table_1st_header(fd) excel_xml_row(fd, 1, 19, v_nil, ib.location, loc) excel_xml_table_2nd_header(fd) excel_xml_row(fd, 2, 20, v_nil, ib.location, loc) excel_xml_last_row(fd) end end end (fd) end end |