Class: Rbeapi::Api::Staticroutes

Inherits:
Entity
  • Object
show all
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

#config, #error, #node

Instance Method Summary collapse

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.

Parameters:

  • :destination (String)

    The destination and prefix matching the route(s). Ex ‘192.168.0.2/24’.

  • :nexthop (String)

    The nexthop for this entry, which may an IP address or interface name.

  • :opts (Hash)

    Additional options for the route entry.

Returns:

  • (Boolean)

    returns true on success



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.

Parameters:

  • :destination (String)

    The destination and prefix matching the route(s). Ex ‘192.168.0.2/24’.

  • :nexthop (String)

    The nexthop for this entry, which may an IP address or interface name.

Returns:

  • (Boolean)

    returns true on success



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

#getallObject

Returns the static routes configured on the node

Examples:

{
  [
    {
      destination: <route_dest/masklen>,
      nexthop: next_hop>,
      distance: <integer>,
      tag: <integer, nil>,
      name: <string, nil>
    },
    ...
  ]
}


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