class Rbeapi::Api::Staticroutes
The Staticroutes
class provides a configuration instance for working with static routes in EOS.
Public Instance Methods
Creates a static route in EOS. May add or overwrite an existing route.
Commands¶ ↑
ip route <destination> <nexthop> [router_ip] [distance] [tag <tag>] [name <name>]
@param destination [String] The destination and prefix matching the
route(s). Ex '192.168.0.2/24'.
@param nexthop [String] The nexthop for this entry, which may an IP
address or interface name.
@param opts [Hash] Additional options for the route entry.
@option opts router_ip [String] If nexthop is an egress interface,
router_ip specifies the router to which traffic will be forwarded.
@option opts distance [String] The administrative distance (metric).
@option opts tag [String] The route tag.
@option opts name [String] A route name.
@return [Boolean] Returns True on success, otherwise False.
# File lib/rbeapi/api/staticroutes.rb, line 113 def create(destination, nexthop, opts = {}) cmd = "ip route #{destination} #{nexthop}" cmd << " #{opts[:router_ip]}" if opts[:router_ip] cmd << " #{opts[:distance]}" if opts[:distance] cmd << " tag #{opts[:tag]}" if opts[:tag] cmd << " name #{opts[:name]}" if opts[:name] configure cmd end
Removes a given route from EOS. May remove multiple routes if nexthop is not specified.
Commands¶ ↑
no ip route <destination> [nexthop]
@param destination [String] The destination and prefix matching the
route(s). Ex '192.168.0.2/24'.
@param nexthop [String] The nexthop for this entry, which may an IP
address or interface name.
@return [Boolean] Returns True on success, otherwise False.
# File lib/rbeapi/api/staticroutes.rb, line 136 def delete(destination, nexthop = nil) cmd = "no ip route #{destination}" cmd << " #{nexthop}" if nexthop configure cmd end
Returns the static routes configured on the node.
@example
{ [ { destination: <route_dest/masklen>, nexthop: next_hop>, distance: <integer>, tag: <integer, nil>, name: <string, nil> }, ... ] }
@return [Array<Hash, Hash>] The method will return all of the
configured static routes on the node as a Ruby array object containing a list of hashes with each hash describing a route. If there are no static routes configured, this method will return an empty array.
# File lib/rbeapi/api/staticroutes.rb, line 67 def getall regex = / (?<=^ip\sroute\s) ([^\s]+)\s # capture destination ([^\s$]+) # capture next hop IP or egress interface [\s|$](\d+) # capture metric (distance) [\s|$]{1}(?:tag\s(\d+))? # catpure route tag [\s|$]{1}(?:name\s(.+))? # capture route name /x routes = config.scan(regex) routes.each_with_object([]) do |route, arry| arry << { destination: route[0], nexthop: route[1], distance: route[2], tag: route[3], name: route[4] } end end