Class: JunosConfig::Config
- Inherits:
-
Object
- Object
- JunosConfig::Config
- Defined in:
- lib/junos-config/config.rb
Instance Attribute Summary collapse
-
#application_sets ⇒ Object
readonly
Returns the value of attribute application_sets.
-
#applications ⇒ Object
readonly
Returns the value of attribute applications.
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#interfaces ⇒ Object
readonly
Returns the value of attribute interfaces.
-
#last_changed ⇒ Object
readonly
Returns the value of attribute last_changed.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#security_policies ⇒ Object
readonly
Returns the value of attribute security_policies.
-
#security_zones ⇒ Object
readonly
Returns the value of attribute security_zones.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #application(name) ⇒ Object
-
#initialize(raw) ⇒ Config
constructor
A new instance of Config.
- #parse_applications(raw_section) ⇒ Object
- #parse_groups(raw_section) ⇒ Object
- #parse_interfaces(raw_section) ⇒ Object
- #parse_security(raw_section) ⇒ Object
Constructor Details
#initialize(raw) ⇒ Config
Returns a new instance of Config.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/junos-config/config.rb', line 13 def initialize(raw) @raw = raw m = raw.match(/Last\ changed:\ (.*?)\nversion\ (\S+);/m) @last_changed = m[1] if m @version = m[2] if m raw.scan(/^(\w+)\ \{$(.*?)^\}$/m).each do |section| method = "parse_#{section[0]}" send method, section[1] if respond_to?(method) end end |
Instance Attribute Details
#application_sets ⇒ Object (readonly)
Returns the value of attribute application_sets.
3 4 5 |
# File 'lib/junos-config/config.rb', line 3 def application_sets @application_sets end |
#applications ⇒ Object (readonly)
Returns the value of attribute applications.
3 4 5 |
# File 'lib/junos-config/config.rb', line 3 def applications @applications end |
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
3 4 5 |
# File 'lib/junos-config/config.rb', line 3 def hostname @hostname end |
#interfaces ⇒ Object (readonly)
Returns the value of attribute interfaces.
3 4 5 |
# File 'lib/junos-config/config.rb', line 3 def interfaces @interfaces end |
#last_changed ⇒ Object (readonly)
Returns the value of attribute last_changed.
3 4 5 |
# File 'lib/junos-config/config.rb', line 3 def last_changed @last_changed end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
3 4 5 |
# File 'lib/junos-config/config.rb', line 3 def raw @raw end |
#security_policies ⇒ Object (readonly)
Returns the value of attribute security_policies.
3 4 5 |
# File 'lib/junos-config/config.rb', line 3 def security_policies @security_policies end |
#security_zones ⇒ Object (readonly)
Returns the value of attribute security_zones.
3 4 5 |
# File 'lib/junos-config/config.rb', line 3 def security_zones @security_zones end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
3 4 5 |
# File 'lib/junos-config/config.rb', line 3 def version @version end |
Instance Method Details
#application(name) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/junos-config/config.rb', line 67 def application(name) if name =~ /any|ESP|esp|junos\-/ # junos internal applications return name end @application_lookup[name] end |
#parse_applications(raw_section) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/junos-config/config.rb', line 51 def parse_applications(raw_section) @applications = raw_section.scan(/^(\ {4}application\ \S+ \{$.*?^\ {4}\})$/m).collect do |x| Application.new self, x[0] end @application_lookup = {} @applications.each{|a| @application_lookup[a.name] = a } @application_sets = raw_section.scan(/^(\ {4}application\-set\ \S+ \{$.*?^\ {4}\})$/m).collect do |x| ApplicationSet.new self, x[0] end @application_sets.each{|a| @application_lookup[a.name] = a } @security_policies.each do |policy| policy.application.collect! {|name| application(name) } end end |
#parse_groups(raw_section) ⇒ Object
26 27 28 29 |
# File 'lib/junos-config/config.rb', line 26 def parse_groups(raw_section) m = raw_section.match(/host\-name\ (\S+)-\S;/m) @hostname = m[1] end |
#parse_interfaces(raw_section) ⇒ Object
31 32 33 34 35 |
# File 'lib/junos-config/config.rb', line 31 def parse_interfaces(raw_section) @interfaces = raw_section.scan(/^(\ {4}\S+\ \{$.*?^\ {4}\})$/m).collect do |x| Interface.new self, x[0] end end |
#parse_security(raw_section) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/junos-config/config.rb', line 37 def parse_security(raw_section) @security_zones = raw_section.scan(/^(\ {8}security\-zone\ \S+ \{$.*?^\ {8}\})$/m).collect do |x| Security::Zone.new self, x[0] end @security_policies = raw_section.scan(/^\ {8}from\-zone\ (\S+) to\-zone (\S+) \{$(.*?)^\ {8}\}$/m).collect do |x| from_zone = security_zones.find{ |zone| zone.name == x[0] } to_zone = security_zones.find{ |zone| zone.name == x[1] } x[2].scan(/(\ {12}policy \S+ \{$.*?^\ {12}\}$)/m).collect do |y| Security::Policy.new self, y[0], from_zone, to_zone end end @security_policies.flatten! end |