Class: StarosParser_2
- Inherits:
-
Object
- Object
- StarosParser_2
- Defined in:
- lib/imperituroard/platforms/staros/staros_parser.rb
Instance Method Summary collapse
-
#ecs_config_parser(config_string_array) ⇒ Object
parser for staros ECS configuration.
Instance Method Details
#ecs_config_parser(config_string_array) ⇒ Object
parser for staros ECS configuration
5 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 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 87 88 89 90 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 |
# File 'lib/imperituroard/platforms/staros/staros_parser.rb', line 5 def ecs_config_parser(config_string_array) out_ans = {} parsed_config = {"config" => {"active-charging service" => []}} config_string_array.shift # {"config" => {"active-charging service" => [{"ECS-SVC" => {"root" => [], "host-pool"=>{"1b1.nekurims.top"=>["ip 185.59.101.182/32"]}, "ruledef"=>{"VKONTAKTE_CDN_b"=>[]}}}}]} flag_inter_ecs_name = 0 current_ecs_name = "" current_section = "root" current_section_name = "" section_flag = 0 section_deep = 0 ecs_number = 0 for aaa in config_string_array if section_deep == 0 && aaa[0..22] == "active-charging service" #&& flag_inter_ecs_name == 0 ecs_name_regexp = /active-charging service (\S+)/ current_ecs_name = aaa.match(ecs_name_regexp)[1] #p current_ecs_name parsed_config["config"]["active-charging service"].push({current_ecs_name => {"root" => [], "host-pool" => {}, "port-map" => {}, "ruledef" => {}, "access-ruledef" => {}, "group-of-ruledefs" => {}, "packet-filter" => {}, "edr-format" => {}, "xheader-format" => {}, "charging-action" => {}, "rulebase" => {}, "fw-and-nat policy" => {} }}) flag_inter_ecs_name = 1 section_deep = 1 current_section = "root" else if aaa == "exit" && section_deep == 2 section_flag = 0 section_deep = section_deep - 1 current_section = "root" elsif aaa[0..9] == "host-pool " && section_flag == 0 && section_deep == 1 current_section = "host-pool" ecs_hostpool_regexp = /host-pool\s+(.+)/ current_section_name = aaa.match(ecs_hostpool_regexp)[1] parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = [] section_flag = 1 section_deep = section_deep + 1 elsif aaa[0..8] == "port-map " && section_flag == 0 && section_deep == 1 current_section = "port-map" ecs_portmap_regexp = /port-map\s+(.+)/ current_section_name = aaa.match(ecs_portmap_regexp)[1] parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = [] section_flag = 1 section_deep = section_deep + 1 elsif aaa[0..7] == "ruledef " && section_flag == 0 && section_deep == 1 current_section = "ruledef" ecs_ruldef_regexp = /ruledef\s+(.+)/ current_section_name = aaa.match(ecs_ruldef_regexp)[1] parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = [] section_flag = 1 section_deep = section_deep + 1 elsif aaa[0..14] == "access-ruledef " && section_flag == 0 && section_deep == 1 current_section = "access-ruledef" ecs_accruldef_regexp = /access-ruledef\s+(.+)/ current_section_name = aaa.match(ecs_accruldef_regexp)[1] parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = [] section_flag = 1 section_deep = section_deep + 1 elsif aaa[0..17] == "group-of-ruledefs " && section_flag == 0 && section_deep == 1 current_section = "group-of-ruledefs" ecs_grruldef_regexp = /group-of-ruledefs\s+(.+)/ current_section_name = aaa.match(ecs_grruldef_regexp)[1] parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = [] section_flag = 1 section_deep = section_deep + 1 elsif aaa[0..13] == "packet-filter " && section_flag == 0 && section_deep == 1 current_section = "packet-filter" ecs_packfil_regexp = /packet-filter\s+(.+)/ current_section_name = aaa.match(ecs_packfil_regexp)[1] parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = [] section_flag = 1 section_deep = section_deep + 1 elsif aaa[0..10] == "edr-format " && section_flag == 0 && section_deep == 1 current_section = "edr-format" ecs_edrformat_regexp = /edr-format\s+(.+)/ current_section_name = aaa.match(ecs_edrformat_regexp)[1] parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = [] section_flag = 1 section_deep = section_deep + 1 elsif aaa[0..14] == "xheader-format " && section_flag == 0 && section_deep == 1 current_section = "xheader-format" ecs_xheader_regexp = /xheader-format\s+(.+)/ current_section_name = aaa.match(ecs_xheader_regexp)[1] parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = [] section_flag = 1 section_deep = section_deep + 1 elsif aaa[0..15] == "charging-action " && section_flag == 0 && section_deep == 1 current_section = "charging-action" ecs_xheader_regexp = /charging-action\s+(.+)/ current_section_name = aaa.match(ecs_xheader_regexp)[1] parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = [] section_flag = 1 section_deep = section_deep + 1 elsif aaa[0..8] == "rulebase " && section_flag == 0 && section_deep == 1 current_section = "rulebase" ecs_xheader_regexp = /rulebase\s+(.+)/ current_section_name = aaa.match(ecs_xheader_regexp)[1] parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = [] section_flag = 1 section_deep = section_deep + 1 elsif aaa[0..17] == "fw-and-nat policy " && section_flag == 0 && section_deep == 1 current_section = "fw-and-nat policy" ecs_xheader_regexp = /fw-and-nat policy\s+(.+)/ current_section_name = aaa.match(ecs_xheader_regexp)[1] parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = [] section_flag = 1 section_deep = section_deep + 1 elsif section_flag == 1 && current_section != "root" && current_section != "end" && section_deep == 2 parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name].push(aaa) elsif current_section == "root" && section_deep == 1 && aaa != "end" parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name]["root"].push(aaa) elsif aaa == "end" section_flag = 0 section_deep = 0 current_section = "end" p "end" else p aaa end end end parsed_config end |