Class: Aio::Module::OutputStyle::Cmds
- Inherits:
-
Aio::Module::OutputStyle
- Object
- Aio::Module::OutputStyle
- Aio::Module::OutputStyle::Cmds
- Defined in:
- lib/modules/output/style/cmds.rb
Instance Attribute Summary
Attributes inherited from Aio::Module::OutputStyle
#device_manager, #module_manager, #output_file, #output_info
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize ⇒ Cmds
constructor
A new instance of Cmds.
Methods inherited from Aio::Module::OutputStyle
#author, #description, #each_devices_with_useful, #file_suffix, #license, #platform, #set_defaults, #type
Constructor Details
#initialize ⇒ Cmds
Returns a new instance of Cmds.
8 9 10 11 12 13 14 |
# File 'lib/modules/output/style/cmds.rb', line 8 def initialize super({ :author => "Elin", :description => "这个模块将生成一个文件夹,其中每个文件为各种设备的巡检命令, 此模块不需要Input Module", :file_suffix => "txt" }) end |
Instance Method Details
#generate ⇒ Object
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 |
# File 'lib/modules/output/style/cmds.rb', line 16 def generate # 获得 cmds = {cmd_name => cmd_info} cmds = module_manager.get_modules_by_type("cmd") # 取得pf = {device => [cmd, ...]} pf = {} cmds.each_pair do |cmd, info| device = info[:module_layer_2] pf[device] = [] unless pf.has_key?(device) pf[device] << info[:klass].cmd_full end # 各种设备的修改方法 terminal = { "cisco" => ["ter leng 0", "ter leng 24"], "h3c" => ["screen-length 0", "screen-length 24"], "maipu" => ["more off", "more on"], "juniper" => [" | no-more"], } text = {} # 生成Terminal格式 pf.each_pair do |device, arr| name = device + "_terminal" text[name] = [] # 当是cisco, h3c, maipu 的时候使用一种方式 if device == "cisco" or device == "h3c" or device == "maipu" text[name] << terminal[device][0] arr.each do |cmd| text[name] << cmd end text[name] << terminal[device][1] # 当是 juniper 的时候使用cmd后面跟参数 elsif device == "juniper" arr.each do |cmd| text[name] << cmd + terminal[device][0] end end # 最后将数组改为文本 text[name] = text[name].join("\r\n!\r\n") end # 生成空格的格式 pf.each_pair do |device, arr| name = device + "_blank" text[name] = arr.join("\r\n#{' '*10}\r\n!\r\n") text[name] << "\r\n#{' '*10}\r\n!\r\n" end pn = Pathname.new(output_file) Dir.mkdir(output_file) unless pn.directory? text.each_pair do |name, content| file = File.new(File.join(output_file, name), "w+") file.write(content) end end |