iosparse 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +8 -2
  2. data/iosparse.gemspec +1 -1
  3. data/lib/iosparse.rb +25 -47
  4. metadata +1 -1
data/README.md CHANGED
@@ -5,7 +5,7 @@ Good question. First install it using `gem install iosparse`. Then use it. Cr
5
5
 
6
6
  ````
7
7
  config = IOSParse.new('path/to/ios.conf')
8
- puts config.interfaces
8
+ puts config.find_all('interface')
9
9
  ````
10
10
  ````
11
11
  Output:
@@ -19,4 +19,10 @@ Output:
19
19
 
20
20
  All objects returned are arrays that can be further manipulated and parsed. "Human readable" format coming soon, maybe even a CLI. Please note the mock Cisco ASA config file in the spec test is completely fabricated and is not intended to be a correct configuration, it is only to be used for it's syntax.
21
21
 
22
- All '\n' are inject to show where children lines separate from the parent and allowed for easy String#gsub to parse and print in other formats. There is also a find() method that allows you to customize searches, feel free to look at the documentation link on the <a href="http://rubygems.org/gems/iosparse">rubygems</a> site.
22
+ All '\n' are injected as delimiters to show where children lines separate from the parent and inteded to be used for easy String#gsub to parse and print in other formats. Feel free to look at the documentation link on the <a href="http://rubygems.org/gems/iosparse">rubygems</a> site.
23
+
24
+ Current methods:
25
+
26
+ `find_all` used to find all specific rules, interface, object-group, route, name, etc.
27
+ `has` used to find any rule that includes a specific string.
28
+ `group_has_ip` returns group(s) that include a specific IP.
data/iosparse.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "iosparse"
5
- s.version = "0.0.7"
5
+ s.version = "0.0.8"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ari Mizrahi"]
data/lib/iosparse.rb CHANGED
@@ -9,7 +9,7 @@ class IOSParse
9
9
  end
10
10
 
11
11
  # Custom filter
12
- def find(custom_filter)
12
+ def find_all(custom_filter)
13
13
  options = {
14
14
  filter: /^#{custom_filter}.+/,
15
15
  parent: "#{custom_filter}"
@@ -17,58 +17,22 @@ class IOSParse
17
17
  find_blocks(options)
18
18
  end
19
19
 
20
- # Find all interfaces
21
- def interfaces
20
+ # Custom seek
21
+ def has(custom_seek)
22
22
  options = {
23
- filter: /^interface.+/,
24
- parent: "interface"
23
+ filter: /.+#{custom_seek}.+/,
24
+ parent: "#{custom_seek}"
25
25
  }
26
26
  find_blocks(options)
27
27
  end
28
28
 
29
- # Find all monitor-interfaces
30
- def monitor_interfaces
29
+ # What group is an IP in?
30
+ def group_has_ip(ip)
31
31
  options = {
32
- filter: /^monitor-interface.+/,
33
- parent: "monitor-interface"
32
+ filter: /^object-group.+#{ip}.+/,
33
+ parent: "#{ip}"
34
34
  }
35
- find_blocks(options)
36
- end
37
-
38
- # Find all access-lists
39
- def access_lists
40
- options = {
41
- filter: /^access-list.+/,
42
- parent: "access-list"
43
- }
44
- find_blocks(options)
45
- end
46
-
47
- # Find all names
48
- def names
49
- options = {
50
- filter: /^name.+/,
51
- parent: "name"
52
- }
53
- find_blocks(options)
54
- end
55
-
56
- # Find all routes
57
- def routes
58
- options = {
59
- filter: /^route[^r].+/,
60
- parent: "route"
61
- }
62
- find_blocks(options)
63
- end
64
-
65
- # Find all object-groups
66
- def object_groups
67
- options = {
68
- filter: /^object-group.+/,
69
- parent: "object-group"
70
- }
71
- find_blocks(options)
35
+ find_object_group(options)
72
36
  end
73
37
 
74
38
  private
@@ -81,6 +45,16 @@ class IOSParse
81
45
  normalize(output)
82
46
  end
83
47
 
48
+ def find_object_group(options)
49
+ input = Array.new
50
+ output = Array.new
51
+ @yaml.each do |line|
52
+ input << line.match(options[:filter]) if line.match(options[:filter])
53
+ end
54
+ input.each { |rule| output << rule.to_s.split("\s-\s")[0] }
55
+ normalize(output)
56
+ end
57
+
84
58
  # Load Cisco 'show all' dump
85
59
  def load_config(filename)
86
60
  @config = File.open(filename, 'r')
@@ -126,4 +100,8 @@ class IOSParse
126
100
  end
127
101
  end
128
102
  end
129
- end
103
+ end
104
+
105
+ config = IOSParse.new('../spec/etc/cisco_asa.config')
106
+
107
+ puts config.group_has_ip('10.10.15.100').class
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iosparse
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: