Class: Y2Network::Routing
- Inherits:
-
Object
- Object
- Y2Network::Routing
- Defined in:
- src/lib/y2network/routing.rb
Overview
General routing configuration storage (routing tables, forwarding setup, …)
Instance Attribute Summary collapse
-
#forward_ipv4 ⇒ Boolean
Whether IPv4 forwarding is enabled.
-
#forward_ipv6 ⇒ Boolean
Whether IPv6 forwarding is enabled.
- #tables ⇒ Array<RoutingTable> readonly
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Determines whether two set of routing settings are equal.
-
#default_route ⇒ Route
Returns the default route.
-
#default_routes ⇒ Array<Route>
Returns the default routes.
-
#initialize(tables: [], forward_ipv4: false, forward_ipv6: false) ⇒ Routing
constructor
A new instance of Routing.
-
#remove_default_routes ⇒ Object
Remove default routes from routing tables.
-
#routes ⇒ Array<Route>
Routes in the configuration.
Constructor Details
#initialize(tables: [], forward_ipv4: false, forward_ipv6: false) ⇒ Routing
Returns a new instance of Routing.
30 31 32 33 34 |
# File 'src/lib/y2network/routing.rb', line 30 def initialize(tables: [], forward_ipv4: false, forward_ipv6: false) @tables = tables @forward_ipv4 = forward_ipv4 @forward_ipv6 = forward_ipv6 end |
Instance Attribute Details
#forward_ipv4 ⇒ Boolean
Returns whether IPv4 forwarding is enabled.
26 27 28 |
# File 'src/lib/y2network/routing.rb', line 26 def forward_ipv4 @forward_ipv4 end |
#forward_ipv6 ⇒ Boolean
Returns whether IPv6 forwarding is enabled.
28 29 30 |
# File 'src/lib/y2network/routing.rb', line 28 def forward_ipv6 @forward_ipv6 end |
#tables ⇒ Array<RoutingTable> (readonly)
24 25 26 |
# File 'src/lib/y2network/routing.rb', line 24 def tables @tables end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Determines whether two set of routing settings are equal
70 71 72 73 |
# File 'src/lib/y2network/routing.rb', line 70 def ==(other) forward_ipv4 == other.forward_ipv4 && forward_ipv6 == other.forward_ipv6 && ((tables - other.tables) | (other.tables - tables)).empty? end |
#default_route ⇒ Route
Should we implement a `default_routes` which returns an array instead?
Returns the default route
50 51 52 |
# File 'src/lib/y2network/routing.rb', line 50 def default_route routes.find(&:default?) end |
#default_routes ⇒ Array<Route>
Returns the default routes
57 58 59 |
# File 'src/lib/y2network/routing.rb', line 57 def default_routes routes.select(&:default?) end |
#remove_default_routes ⇒ Object
Remove default routes from routing tables
62 63 64 |
# File 'src/lib/y2network/routing.rb', line 62 def remove_default_routes tables.each(&:remove_default_routes) end |
#routes ⇒ Array<Route>
Routes in the configuration
Convenience method to iterate through the routes in all routing tables.
41 42 43 |
# File 'src/lib/y2network/routing.rb', line 41 def routes tables.flat_map(&:to_a) end |