Class: Rbeapi::Api::Staticroutes
- Defined in:
- lib/rbeapi/api/staticroutes.rb
Overview
The Staticroutes class provides a configuration instance for working with static routes in EOS.
Instance Attribute Summary
Attributes inherited from Entity
Instance Method Summary collapse
-
#create(destination, nexthop, opts = {}) ⇒ Boolean
Creates a static route in EOS.
-
#delete(destination, nexthop = nil) ⇒ Boolean
Removes a given route from EOS.
-
#getall ⇒ Object
Returns the static routes configured on the node.
Methods inherited from Entity
#command_builder, #configure, #configure_interface, #get_block, #initialize, instance
Constructor Details
This class inherits a constructor from Rbeapi::Api::Entity
Instance Method Details
#create(destination, nexthop, opts = {}) ⇒ Boolean
Creates a static route in EOS. May add or overwrite an existing route.
107 108 109 110 111 112 113 114 |
# File 'lib/rbeapi/api/staticroutes.rb', line 107 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 |
#delete(destination, nexthop = nil) ⇒ Boolean
Removes a given route from EOS. May remove multiple routes if nexthop is not specified.
129 130 131 132 133 |
# File 'lib/rbeapi/api/staticroutes.rb', line 129 def delete(destination, nexthop = nil) cmd = "no ip route #{destination}" cmd << " #{nexthop}" if nexthop configure cmd end |
#getall ⇒ Object
Returns the static routes configured on the node
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# 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 |