iosparse 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/iosparse.gemspec +1 -1
- data/lib/iosparse.rb +31 -21
- metadata +1 -1
data/iosparse.gemspec
CHANGED
data/lib/iosparse.rb
CHANGED
@@ -16,13 +16,13 @@ class IOSParse
|
|
16
16
|
end
|
17
17
|
|
18
18
|
#
|
19
|
-
# Find
|
19
|
+
# Find all interfaces in the configuration file
|
20
20
|
#
|
21
21
|
def interfaces
|
22
22
|
# Regex to parse out interfaces
|
23
23
|
interfaces = /\["interface[\s\S]+/
|
24
|
-
# Call findblocks() passing
|
25
|
-
findblocks(interfaces, "interface")
|
24
|
+
# Call findblocks() passing regex, parent name, and parse boolean
|
25
|
+
findblocks(interfaces, "interface", false)
|
26
26
|
end
|
27
27
|
|
28
28
|
#
|
@@ -31,8 +31,18 @@ class IOSParse
|
|
31
31
|
def names
|
32
32
|
# Regex to parse out names
|
33
33
|
names = /\["names[\s\S]+/
|
34
|
-
# Call findblocks() passing regex and
|
35
|
-
findblocks(names, "names")
|
34
|
+
# Call findblocks() passing regex, parent name, and parse boolean
|
35
|
+
findblocks(names, "names", false)
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Find all routes
|
40
|
+
#
|
41
|
+
def routes
|
42
|
+
# Regex to parse out routes
|
43
|
+
routes = /\["route[\s\S]+/
|
44
|
+
# Call findblocks() passing regex, parent name, and parse boolean
|
45
|
+
findblocks(routes, "route", false)
|
36
46
|
end
|
37
47
|
|
38
48
|
#
|
@@ -40,19 +50,19 @@ class IOSParse
|
|
40
50
|
#
|
41
51
|
def access_list
|
42
52
|
# Regex to parse out acl
|
43
|
-
acl =
|
44
|
-
# Call findblocks() passing regex and
|
45
|
-
findblocks(acl, "access-list")
|
53
|
+
acl = /access-list[\s\S]+/
|
54
|
+
# Call findblocks() passing regex, parent name, and parse boolean
|
55
|
+
findblocks(acl, "access-list", true)
|
46
56
|
end
|
47
57
|
|
48
58
|
#
|
49
|
-
# Find all
|
59
|
+
# Find all object-groups
|
50
60
|
#
|
51
61
|
def object_group
|
52
62
|
# Regex to parse out object-groups
|
53
63
|
group = /object-group[\s\S]+/
|
54
|
-
# Call findblocks() passing regex and
|
55
|
-
findblocks(group, "object-group")
|
64
|
+
# Call findblocks() passing regex, parent name, and parse boolean
|
65
|
+
findblocks(group, "object-group", true)
|
56
66
|
end
|
57
67
|
|
58
68
|
private
|
@@ -60,16 +70,16 @@ class IOSParse
|
|
60
70
|
#
|
61
71
|
# Primary method to accept regex and parent, then use them to parse blocks and store them in an Array
|
62
72
|
#
|
63
|
-
def findblocks(filter, parent)
|
73
|
+
def findblocks(filter, parent, parse = true)
|
64
74
|
# Array to store parsed blocks
|
65
75
|
output = Array.new
|
66
76
|
@blocks.each do |block|
|
67
77
|
# Use regex to filter via scan() and flatten then push to array
|
68
78
|
output << block.to_s.scan(filter).flatten if block.to_s.include?(parent)
|
69
79
|
end
|
70
|
-
#
|
71
|
-
if
|
72
|
-
|
80
|
+
# Some parents are not within "!" blocks and require some extra work
|
81
|
+
if parse == true then
|
82
|
+
parse_parent(clean_object_group(output), parent)
|
73
83
|
else
|
74
84
|
# Return the parsed block as an array
|
75
85
|
output
|
@@ -91,20 +101,20 @@ class IOSParse
|
|
91
101
|
end
|
92
102
|
|
93
103
|
#
|
94
|
-
#
|
104
|
+
# Some parents come as a single string, we break each parents into a string and push into an array
|
95
105
|
#
|
96
|
-
def
|
106
|
+
def parse_parent(block, parent)
|
97
107
|
# Array to store parsed blocks
|
98
108
|
output = Array.new
|
99
109
|
block.each do |line|
|
100
|
-
# Split the line where each
|
101
|
-
line.to_s.split(
|
110
|
+
# Split the line where each parent begins
|
111
|
+
line.to_s.split(parent).each do |push|
|
102
112
|
# Skip empty lines
|
103
113
|
next if push.include?('["')
|
104
114
|
# Remove extra "] characters from each line
|
105
115
|
push = push.gsub('"]', '')
|
106
|
-
# Re-add
|
107
|
-
output << "[\"
|
116
|
+
# Re-add parent to the beginning of the line and push it into the array line-by-line
|
117
|
+
output << "[\"#{parent}#{push}\"]"
|
108
118
|
end
|
109
119
|
end
|
110
120
|
# Return the parsed block as an array
|