Class: Havox::Topology
- Inherits:
-
Object
- Object
- Havox::Topology
- Defined in:
- lib/havox/classes/topology.rb
Constant Summary collapse
- NODE_REGEX =
/^\s*(?<name>\w+)\s?\[(?<attributes>.*)\];$/i
- EDGE_REGEX =
/^\s*(?<from>\w+)\s?->\s?(?<to>\w+)\s?\[(?<attributes>.*)\];$/i
Instance Attribute Summary collapse
-
#edges ⇒ Object
readonly
Returns the value of attribute edges.
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
Instance Method Summary collapse
- #host_names ⇒ Object
-
#initialize(file_path) ⇒ Topology
constructor
A new instance of Topology.
- #switch_hosts ⇒ Object
- #switch_ips ⇒ Object
Constructor Details
#initialize(file_path) ⇒ Topology
Returns a new instance of Topology.
8 9 10 11 12 13 |
# File 'lib/havox/classes/topology.rb', line 8 def initialize(file_path) @file_path = file_path @nodes = [] @edges = [] parse_dot_file end |
Instance Attribute Details
#edges ⇒ Object (readonly)
Returns the value of attribute edges.
3 4 5 |
# File 'lib/havox/classes/topology.rb', line 3 def edges @edges end |
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
3 4 5 |
# File 'lib/havox/classes/topology.rb', line 3 def nodes @nodes end |
Instance Method Details
#host_names ⇒ Object
15 16 17 |
# File 'lib/havox/classes/topology.rb', line 15 def host_names @nodes.select(&:host?).map(&:name) end |
#switch_hosts ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/havox/classes/topology.rb', line 26 def switch_hosts exit_edges = @edges.select { |e| e.from.switch? && e.to.host? } hash = {} exit_edges.each do |e| if hash[e.from.name].nil? hash[e.from.name] = [e.to.name] else hash[e.from.name] << e.to.name end end hash end |
#switch_ips ⇒ Object
19 20 21 22 23 24 |
# File 'lib/havox/classes/topology.rb', line 19 def switch_ips switches = @nodes.select(&:switch?) switch_ip_hash = {} switches.each { |s| switch_ip_hash[s.name] = s.attributes[:ip] } switch_ip_hash end |