Class: Phut::Route
- Inherits:
-
Object
- Object
- Phut::Route
- Extended by:
- ShellRunner
- Includes:
- ShellRunner
- Defined in:
- lib/phut/route.rb
Overview
routing table entry
Instance Attribute Summary collapse
-
#gateway ⇒ Object
readonly
Returns the value of attribute gateway.
-
#net ⇒ Object
readonly
Returns the value of attribute net.
Class Method Summary collapse
Instance Method Summary collapse
- #add(netns) ⇒ Object
-
#initialize(net:, gateway:) ⇒ Route
constructor
A new instance of Route.
Methods included from ShellRunner
Constructor Details
#initialize(net:, gateway:) ⇒ Route
Returns a new instance of Route.
22 23 24 25 |
# File 'lib/phut/route.rb', line 22 def initialize(net:, gateway:) @net = net @gateway = gateway end |
Instance Attribute Details
#gateway ⇒ Object (readonly)
Returns the value of attribute gateway.
20 21 22 |
# File 'lib/phut/route.rb', line 20 def gateway @gateway end |
#net ⇒ Object (readonly)
Returns the value of attribute net.
19 20 21 |
# File 'lib/phut/route.rb', line 19 def net @net end |
Class Method Details
.read(netns) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/phut/route.rb', line 10 def self.read(netns) sudo("ip netns exec #{netns} route -n").split("\n").each do |each| match = /^(\S+)\s+(\S+)\s+\S+\s+UG\s+/.match(each) next unless match return new(net: match[1], gateway: match[2]) end nil end |
Instance Method Details
#add(netns) ⇒ Object
29 30 31 32 |
# File 'lib/phut/route.rb', line 29 def add(netns) return unless @net && @gateway sudo "ip netns exec #{netns} route add -net #{@net} gw #{@gateway}" end |