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

Parameters:

  • :name (String)

    The name of the routemap to create

  • :action (String)

    Either permit or deny

  • :seqno (Integer)

    The sequence number

  • :opts (hash)

    Optional keyword arguments

Returns:

  • (Boolean)

    returns true if the command completed successfully



277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/rbeapi/api/routemaps.rb', line 277

def create(name, action, seqno, opts = {})
  if opts.empty?
    cmds = name_commands(name, action, seqno)
  else
    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

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



375
376
377
# File 'lib/rbeapi/api/routemaps.rb', line 375

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.

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



353
354
355
# File 'lib/rbeapi/api/routemaps.rb', line 353

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.

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



445
446
447
448
449
450
# File 'lib/rbeapi/api/routemaps.rb', line 445

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.

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



468
469
470
471
472
473
# File 'lib/rbeapi/api/routemaps.rb', line 468

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.

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



395
396
397
398
399
400
401
402
# File 'lib/rbeapi/api/routemaps.rb', line 395

def set_match_statements(name, action, seqno, value)
  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.

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



420
421
422
423
424
425
426
427
# File 'lib/rbeapi/api/routemaps.rb', line 420

def set_set_statements(name, action, seqno, value)
  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