Class: Net::IP::Route::Collection
- Inherits:
-
Object
- Object
- Net::IP::Route::Collection
- Includes:
- Enumerable
- Defined in:
- lib/net/ip/route/collection.rb
Instance Method Summary collapse
-
#add(route) ⇒ void
Add a route to the routing table.
-
#all ⇒ Array<Route>
Get a list of all routes.
-
#each {|Route| ... } ⇒ void
Enumerate all routes.
-
#flush(selector) ⇒ void
Flush the routing table based on a selector.
-
#gateways ⇒ Array<Route>
Get a list of all default gateway routes.
-
#initialize(table = "main") ⇒ Collection
constructor
A new instance of Collection.
-
#update_gateways(gateways) ⇒ void
Update the list of default gateways.
Constructor Details
#initialize(table = "main") ⇒ Collection
Returns a new instance of Collection.
10 11 12 |
# File 'lib/net/ip/route/collection.rb', line 10 def initialize(table = "main") @table = table end |
Instance Method Details
#add(route) ⇒ void
This method returns an undefined value.
Add a route to the routing table
51 52 53 54 |
# File 'lib/net/ip/route/collection.rb', line 51 def add(route) result = `ip route add #{route.to_params}` raise result unless $?.success? end |
#all ⇒ Array<Route>
Get a list of all routes
23 24 25 |
# File 'lib/net/ip/route/collection.rb', line 23 def all Parser.parse(`ip route show table #{@table}`).collect {|r| Route.new(r)} end |
#each {|Route| ... } ⇒ void
This method returns an undefined value.
Enumerate all routes
17 18 19 |
# File 'lib/net/ip/route/collection.rb', line 17 def each(&block) Parser.parse(`ip route show table #{@table}`).each {|r| yield(Route.new(r))} end |
#flush(selector) ⇒ void
This method returns an undefined value.
Flush the routing table based on a selector
61 62 63 64 |
# File 'lib/net/ip/route/collection.rb', line 61 def flush(selector) result = `ip route flush #{selector}` raise result unless $?.success? end |
#gateways ⇒ Array<Route>
Get a list of all default gateway routes
29 30 31 |
# File 'lib/net/ip/route/collection.rb', line 29 def gateways find_all {|r| r.prefix == "default"} end |
#update_gateways(gateways) ⇒ void
This method returns an undefined value.
Update the list of default gateways
39 40 41 42 43 |
# File 'lib/net/ip/route/collection.rb', line 39 def update_gateways(gateways) params = gateways.collect {|gateway| "nexthop " + gateway.to_params} result = `ip route replace default #{params.join(" ")}` raise result unless $?.success? end |