Class: OVSImager::IPNetNS
- Inherits:
-
Object
- Object
- OVSImager::IPNetNS
- Defined in:
- lib/ovsimager/ipnetns.rb
Instance Method Summary collapse
- #exec_ip(args, root = false) ⇒ Object
- #ifaces_ary ⇒ Object
- #ifaces_hash ⇒ Object
- #ifname_ns(iface) ⇒ Object
-
#initialize ⇒ IPNetNS
constructor
A new instance of IPNetNS.
- #ns ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize ⇒ IPNetNS
Returns a new instance of IPNetNS.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ovsimager/ipnetns.rb', line 5 def initialize() @ns = exec_ip('netns').split(/\n/).map{|x| x.sub(/\s+\(id: \d+\)/, '')} @ifaces = {:root => parse_address(exec_ip('a'), :root)} links = parse_link(exec_ip('-d link'), :root) merge_link_type(@ifaces[:root], links) @ns.each {|ns| out = exec_ip("netns exec #{ns} ip a", true) @ifaces[ns] = parse_address(out, ns) out = exec_ip("netns exec #{ns} ip -d link", true) links = parse_link(out, ns) merge_link_type(@ifaces[ns], links) } find_veth_pair end |
Instance Method Details
#exec_ip(args, root = false) ⇒ Object
40 41 42 |
# File 'lib/ovsimager/ipnetns.rb', line 40 def exec_ip(args, root=false) Utils.execute("ip #{args}", root) end |
#ifaces_ary ⇒ Object
36 37 38 |
# File 'lib/ovsimager/ipnetns.rb', line 36 def ifaces_ary() @ifaces.inject([]) {|a, (ns, v)| v.each {|i| a[i[:id].to_i] = i}; a} end |
#ifaces_hash ⇒ Object
32 33 34 |
# File 'lib/ovsimager/ipnetns.rb', line 32 def ifaces_hash() @ifaces.inject({}) {|h, (ns, v)| v.each {|i| h[ifname_ns(i)] = i}; h} end |
#ifname_ns(iface) ⇒ Object
28 29 30 |
# File 'lib/ovsimager/ipnetns.rb', line 28 def ifname_ns(iface) iface[:name] + (iface[:ns] == :root ? "" : ":" + iface[:ns].to_s) end |
#ns ⇒ Object
20 21 22 |
# File 'lib/ovsimager/ipnetns.rb', line 20 def ns() @ns end |
#to_hash ⇒ Object
24 25 26 |
# File 'lib/ovsimager/ipnetns.rb', line 24 def to_hash() @ifaces end |