Class: Phut::Netns
Overview
‘ip netns …` command runner
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#network_device ⇒ Object
Returns the value of attribute network_device.
Instance Method Summary collapse
-
#initialize(options, name, logger = NullLogger.new) ⇒ Netns
constructor
A new instance of Netns.
-
#maybe_stop ⇒ Object
rubocop:enable AbcSize.
- #method_missing(message, *_args) ⇒ Object
-
#run ⇒ Object
rubocop:disable AbcSize.
Methods included from ShellRunner
Constructor Details
#initialize(options, name, logger = NullLogger.new) ⇒ Netns
Returns a new instance of Netns.
12 13 14 15 16 |
# File 'lib/phut/netns.rb', line 12 def initialize(, name, logger = NullLogger.new) @name = name @options = @logger = logger end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(message, *_args) ⇒ Object
33 34 35 |
# File 'lib/phut/netns.rb', line 33 def method_missing(, *_args) @options.__send__ :[], end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/phut/netns.rb', line 9 def name @name end |
#network_device ⇒ Object
Returns the value of attribute network_device.
10 11 12 |
# File 'lib/phut/netns.rb', line 10 def network_device @network_device end |
Instance Method Details
#maybe_stop ⇒ Object
rubocop:enable AbcSize
29 30 31 |
# File 'lib/phut/netns.rb', line 29 def maybe_stop sh "sudo ip netns delete #{name}" end |
#run ⇒ Object
rubocop:disable AbcSize
19 20 21 22 23 24 25 26 |
# File 'lib/phut/netns.rb', line 19 def run sh "sudo ip netns add #{name}" sh "sudo ip link set dev #{network_device} netns #{name}" sh "sudo ip netns exec #{name} ifconfig lo 127.0.0.1" sh "sudo ip netns exec #{name}"\ " ifconfig #{network_device} #{ip} netmask #{netmask}" sh "sudo ip netns exec #{name} route add -net #{net} gw #{gateway}" end |