Class: OVSImager::OVSVS
- Inherits:
-
Object
- Object
- OVSImager::OVSVS
- Defined in:
- lib/ovsimager/ovsvs.rb
Instance Method Summary collapse
- #exec_vstcl ⇒ Object
-
#initialize ⇒ OVSVS
constructor
A new instance of OVSVS.
- #to_hash ⇒ Object
Constructor Details
#initialize ⇒ OVSVS
Returns a new instance of OVSVS.
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 |
# File 'lib/ovsimager/ovsvs.rb', line 5 def initialize() vsctl_out = exec_vstcl @vs = parse(vsctl_out, ['bridge', 'port', 'interface']) @vs[:bridges] ||= [] # Mark the peer port. @vs[:bridges].each do |br| br[:ports].each do |port| iface = port[:interfaces][0] if iface[:type] == 'patch' && iface[:options].match(/peer="?(\S+?)"?[,\}]/) port[:peer] = $1 end if iface[:type] == 'gre' || iface[:type] == 'vxlan' if iface[:options].match(/remote_ip="?(\S+?)"?[,\}]/) port[:remote_ip] = $1 end if iface[:options].match(/local_ip="?(\S+?)"?[,\}]/) port[:local_ip] = $1 end end end end # Move the port that has the same name with the interface to first. @vs[:bridges].each do |vs| vs[:ports].sort!{|a, b| vs[:name] == a[:name] ? -1 : vs[:name] == b[:name] ? 1 : a[:ns] == b[:ns] ? a[:name] <=> b[:name] : a[:ns] <=> b[:ns] } end end |
Instance Method Details
#exec_vstcl ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/ovsimager/ovsvs.rb', line 41 def exec_vstcl() begin Utils.execute('ovs-vsctl show', root=true) rescue '' end end |
#to_hash ⇒ Object
37 38 39 |
# File 'lib/ovsimager/ovsvs.rb', line 37 def to_hash() return @vs end |