Class: Rbeapi::Api::Routemaps

Inherits:
Entity
  • Object
show all
Defined in:
lib/rbeapi/api/routemaps.rb

Overview

The Routemaps class manages routemaps. A route map is a list of rules that control the redistribution of IP routes into a protocol domain on the basis of such criteria as route metrics, access control lists, next hop addresses, and route tags.

rubocop:disable Metrics/ClassLength

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(name, action, seqno, opts = {}) ⇒ Boolean

create will create a new routemap with the specified name.

rubocop:disable Metrics/MethodLength

Commands

route-map <name> action <value> seqno <value> description <value>
match <value> set <value> continue <value>

Parameters:

  • name (String)

    The name of the routemap to create.

  • action (String)

    Either permit or deny.

  • seqno (Integer)

    The sequence number value.

  • opts (hash) (defaults to: {})

    Optional keyword arguments.

Options Hash (opts):

  • default (Boolean)

    Set routemap to default.

  • description (String)

    A description for the routemap.

  • match (Array)

    routemap match rule.

  • set (String)

    Sets route attribute.

  • continue (String)

    The routemap sequence number to continue on.

  • enable (Boolean)

    If false then the command is negated. Default is true.

  • default (Boolean)

    Configure the routemap to default.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/rbeapi/api/routemaps.rb', line 303

def create(name, action, seqno, opts = {})
  if opts.empty?
    cmds = name_commands(name, action, seqno)
  else
    if opts[:match] && !opts[:match].is_a?(Array)
      raise ArgumentError, 'opts match must be an Array'
    end
    cmds = name_commands(name, action, seqno, opts)
    if opts[:description]
      cmds << 'no description'
      cmds << "description #{opts[:description]}"
    end
    if opts[:continue]
      cmds << 'no continue'
      cmds << "continue #{opts[:continue]}"
    end
    if opts[:match]
      remove_match_statements(name, action, seqno, cmds)
      opts[:match].each do |options|
        cmds << "match #{options}"
      end
    end
    if opts[:set]
      remove_set_statements(name, action, seqno, cmds)
      opts[:set].each do |options|
        cmds << "set #{options}"
      end
    end
  end
  configure(cmds)
end

#default(name, action, seqno) ⇒ Boolean

This method will attempt to default the routemap from the nodes operational config. Since routemaps do not exist by default, the default action is essentially a negation and the result will be the removal of the routemap clause. If the routemap does not exist then this method will not perform any changes but still return True.

Commands

no route-map <name>

Parameters:

  • name (String)

    The routemap name to set to default.

  • action (String)

    Either permit or deny.

  • seqno (Integer)

    The sequence number.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.



428
429
430
# File 'lib/rbeapi/api/routemaps.rb', line 428

def default(name, action, seqno)
  configure(["default route-map #{name} #{action} #{seqno}"])
end

#delete(name, action, seqno) ⇒ Boolean

delete will delete an existing routemap name from the nodes current running configuration. If the delete method is called and the routemap name does not exist, this method will succeed.

Commands

no route-map <name> <action> <seqno>

Parameters:

  • name (String)

    The routemap name to delete from the node.

  • action (String)

    Either permit or deny.

  • seqno (Integer)

    The sequence number.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.



406
407
408
# File 'lib/rbeapi/api/routemaps.rb', line 406

def delete(name, action, seqno)
  configure(["no route-map #{name} #{action} #{seqno}"])
end

#get(name) ⇒ nil, Hash<Symbol, Object>

get returns a hash of routemap configurations for the given name.

Examples:

{
  <action>: {
    <seqno>: {
      match: <array>,
      set: <array>,
      continue: <integer>,
      description: <string>
    },
    <seqno>: {
      match: <array>,
      set: <array>,
      continue: <integer>,
      description: <string>
    }
  },
  <action>: {
    <seqno>: {
      match: <array>,
      set: <array>,
      continue: <integer>,
      description: <string>
    },
    <seqno>: {
      match: <array>,
      set: <array>,
      continue: <integer>,
      description: <string>
    }
  }
}

Parameters:

  • name (String)

    The routemap name to return a resource for from the nodes configuration.

Returns:

  • (nil, Hash<Symbol, Object>)

    Returns the routemap resource as a Hash. If the specified name is not found in the nodes current configuration a nil object is returned.



90
91
92
# File 'lib/rbeapi/api/routemaps.rb', line 90

def get(name)
  parse_entries(name)
end

#getallnil, Hash<Symbol, Object>

getall returns a collection of routemap resource hashes from the nodes running configuration. The routemap resource collection hash is keyed by the unique routemap name.

Examples:

{
  <name>: {
    <action>: {
      <seqno>: {
        match: <array>,
        set: <array>,
        continue: <integer>,
        description: <string>
      },
      <seqno>: {
        match: <array>,
        set: <array>,
        continue: <integer>,
        description: <string>
      }
    },
    <action>: {
      <seqno>: {
        match: <array>,
        set: <array>,
        continue: <integer>,
        description: <string>
      },
      <seqno>: {
        match: <array>,
        set: <array>,
        continue: <integer>,
        description: <string>
      }
    }
  },
  <name>: {
    <action>: {
      <seqno>: {
        match: <array>,
        set: <array>,
        continue: <integer>,
        description: <string>
      },
      <seqno>: {
        match: <array>,
        set: <array>,
        continue: <integer>,
        description: <string>
      }
    },
    <action>: {
      <seqno>: {
        match: <array>,
        set: <array>,
        continue: <integer>,
        description: <string>
      },
      <seqno>: {
        match: <array>,
        set: <array>,
        continue: <integer>,
        description: <string>
      }
    }
  }
}

Returns:

  • (nil, Hash<Symbol, Object>)

    Returns a hash that represents the entire routemap collection from the nodes running configuration. If there are no routemap names configured, this method will return nil.



166
167
168
169
170
171
172
# File 'lib/rbeapi/api/routemaps.rb', line 166

def getall
  routemaps = config.scan(/(?<=^route-map\s)[^\s]+/)
  return nil if routemaps.empty?
  routemaps.each_with_object({}) do |name, response|
    response[name] = parse_entries(name)
  end
end

#set_continue(name, action, seqno, value) ⇒ Boolean

set_continue will set the continue value for a specified routemap. If the specified routemap does not exist, it will be created.

Commands

route-map <name> action <value> seqno <value> continue <value>

Parameters:

  • name (String)

    The name of the routemap to create.

  • action (String)

    Either permit or deny.

  • seqno (Integer)

    The sequence number.

  • value (Integer)

    The continue value.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.



502
503
504
505
506
507
# File 'lib/rbeapi/api/routemaps.rb', line 502

def set_continue(name, action, seqno, value)
  cmds = ["route-map #{name} #{action} #{seqno}"]
  cmds << 'no continue'
  cmds << "continue #{value}"
  configure(cmds)
end

#set_description(name, action, seqno, value) ⇒ Boolean

set_description will set the description for a specified routemap. If the specified routemap does not exist, it will be created.

Commands

route-map <name> action <value> seqno <value> description <value>

Parameters:

  • name (String)

    The name of the routemap to create.

  • action (String)

    Either permit or deny.

  • seqno (Integer)

    The sequence number.

  • value (String)

    The description value.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.



525
526
527
528
529
530
# File 'lib/rbeapi/api/routemaps.rb', line 525

def set_description(name, action, seqno, value)
  cmds = ["route-map #{name} #{action} #{seqno}"]
  cmds << 'no description'
  cmds << "description #{value}"
  configure(cmds)
end

#set_match_statements(name, action, seqno, value) ⇒ Boolean

set_match_statements will set the match values for a specified routemap. If the specified routemap does not exist, it will be created.

Commands

route-map <name> action <value> seqno <value> match <value>

Parameters:

  • name (String)

    The name of the routemap to create.

  • action (String)

    Either permit or deny.

  • seqno (Integer)

    The sequence number.

  • value (Array)

    The routemap match rules.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Raises:

  • (ArgumentError)


448
449
450
451
452
453
454
455
456
457
# File 'lib/rbeapi/api/routemaps.rb', line 448

def set_match_statements(name, action, seqno, value)
  raise ArgumentError, 'value must be an Array' unless value.is_a?(Array)

  cmds = ["route-map #{name} #{action} #{seqno}"]
  remove_match_statements(name, action, seqno, cmds)
  Array(value).each do |options|
    cmds << "match #{options}"
  end
  configure(cmds)
end

#set_set_statements(name, action, seqno, value) ⇒ Boolean

set_set_statements will set the set values for a specified routemap. If the specified routemap does not exist, it will be created.

Commands

route-map <name> action <value> seqno <value> set <value>

Parameters:

  • name (String)

    The name of the routemap to create.

  • action (String)

    Either permit or deny.

  • seqno (Integer)

    The sequence number.

  • value (Array)

    The routemap set rules.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Raises:

  • (ArgumentError)


475
476
477
478
479
480
481
482
483
484
# File 'lib/rbeapi/api/routemaps.rb', line 475

def set_set_statements(name, action, seqno, value)
  raise ArgumentError, 'value must be an Array' unless value.is_a?(Array)

  cmds = ["route-map #{name} #{action} #{seqno}"]
  remove_set_statements(name, action, seqno, cmds)
  Array(value).each do |options|
    cmds << "set #{options}"
  end
  configure(cmds)
end