Class: Net::IP::Route
- Inherits:
-
Object
- Object
- Net::IP::Route
- Extended by:
- Enumerable
- Defined in:
- lib/net/ip/route.rb
Overview
Class for working with routing table entries.
Instance Attribute Summary collapse
-
#dev ⇒ Object
Returns the value of attribute dev.
-
#error ⇒ Object
Returns the value of attribute error.
-
#metric ⇒ Object
Returns the value of attribute metric.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#proto ⇒ Object
Returns the value of attribute proto.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#src ⇒ Object
Returns the value of attribute src.
-
#table ⇒ Object
Returns the value of attribute table.
-
#type ⇒ Object
Returns the value of attribute type.
-
#via ⇒ Object
Returns the value of attribute via.
-
#weight ⇒ Object
Returns the value of attribute weight.
Class Method Summary collapse
-
.add_route(route) ⇒ void
Add a route to the routing table.
-
.all ⇒ Array<Route>
Get a list of all routes.
-
.each {|Route| ... } ⇒ void
Enumerate all routes.
-
.find_gateways ⇒ Array<Route>
Get a list of all default gateway routes.
-
.flush(selector) ⇒ void
Flush the routing table based on a selector.
-
.update_gateways(gateways) ⇒ void
Update the list of default gateways.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Route
constructor
Create a new route object.
Constructor Details
#initialize(params = {}) ⇒ Route
This does NOT add the entry to the routing table. See add_route for creating new routes in the routing table.
Create a new route object
17 18 19 20 21 |
# File 'lib/net/ip/route.rb', line 17 def initialize(params = {}) params.each do |k,v| send("#{k}=", v) end end |
Instance Attribute Details
#dev ⇒ Object
Returns the value of attribute dev.
5 6 7 |
# File 'lib/net/ip/route.rb', line 5 def dev @dev end |
#error ⇒ Object
Returns the value of attribute error.
5 6 7 |
# File 'lib/net/ip/route.rb', line 5 def error @error end |
#metric ⇒ Object
Returns the value of attribute metric.
5 6 7 |
# File 'lib/net/ip/route.rb', line 5 def metric @metric end |
#prefix ⇒ Object
Returns the value of attribute prefix.
5 6 7 |
# File 'lib/net/ip/route.rb', line 5 def prefix @prefix end |
#proto ⇒ Object
Returns the value of attribute proto.
5 6 7 |
# File 'lib/net/ip/route.rb', line 5 def proto @proto end |
#scope ⇒ Object
Returns the value of attribute scope.
5 6 7 |
# File 'lib/net/ip/route.rb', line 5 def scope @scope end |
#src ⇒ Object
Returns the value of attribute src.
5 6 7 |
# File 'lib/net/ip/route.rb', line 5 def src @src end |
#table ⇒ Object
Returns the value of attribute table.
5 6 7 |
# File 'lib/net/ip/route.rb', line 5 def table @table end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/net/ip/route.rb', line 5 def type @type end |
#via ⇒ Object
Returns the value of attribute via.
5 6 7 |
# File 'lib/net/ip/route.rb', line 5 def via @via end |
#weight ⇒ Object
Returns the value of attribute weight.
5 6 7 |
# File 'lib/net/ip/route.rb', line 5 def weight @weight end |
Class Method Details
.add_route(route) ⇒ void
This method returns an undefined value.
Add a route to the routing table
60 61 62 63 |
# File 'lib/net/ip/route.rb', line 60 def self.add_route(route) result = `ip route add #{route.build_param_string}` raise result unless $?.success? end |
.all ⇒ Array<Route>
Get a list of all routes
32 33 34 |
# File 'lib/net/ip/route.rb', line 32 def self.all RouteParser.parse(`ip route`).collect {|r| new(r)} end |
.each {|Route| ... } ⇒ void
This method returns an undefined value.
Enumerate all routes
26 27 28 |
# File 'lib/net/ip/route.rb', line 26 def self.each(&block) RouteParser.parse(`ip route`).each {|r| yield(new(r))} end |
.find_gateways ⇒ Array<Route>
Get a list of all default gateway routes
38 39 40 |
# File 'lib/net/ip/route.rb', line 38 def self.find_gateways find_all {|r| r.prefix == "default"} end |
.flush(selector) ⇒ void
This method returns an undefined value.
Flush the routing table based on a selector
70 71 72 73 |
# File 'lib/net/ip/route.rb', line 70 def self.flush(selector) result = `ip route flush #{selector}` raise result unless $?.success? end |
.update_gateways(gateways) ⇒ void
This method returns an undefined value.
Update the list of default gateways
48 49 50 51 52 |
# File 'lib/net/ip/route.rb', line 48 def self.update_gateways(gateways) params = gateways.collect {|gateway| "nexthop " + gateway.build_param_string} result = `ip route replace default #{params.join(" ")}` raise result unless $?.success? end |