Class: Rbeapi::Api::Prefixlists

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

Overview

The Prefixlists 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

#add_rule(name, action, prefix, seq = nil) ⇒ Boolean

add_rule will create an ip prefix-list with the designated name,

seqno, action and prefix.

Parameters:

  • :name (String)

    The name of the ip prefix-list

  • :seq (String)

    The seq value

  • :action (String)

    The action value

  • :prefix (String)

    The prefix value

Returns:

  • (Boolean)

    returns true if the command completed successfully



119
120
121
122
123
124
# File 'lib/rbeapi/api/prefixlists.rb', line 119

def add_rule(name, action, prefix, seq = nil)
  cmd = "ip prefix-list #{name}"
  cmd << " seq #{seq}" if seq
  cmd << " #{action} #{prefix}"
  configure cmd
end

#create(name) ⇒ Boolean

create will create a new ip prefix-list with designated name.

Parameters:

  • :name (String)

    The name of the ip prefix-list

Returns:

  • (Boolean)

    returns true if the command completed successfully



102
103
104
# File 'lib/rbeapi/api/prefixlists.rb', line 102

def create(name)
  configure "ip prefix-list #{name}"
end

#delete(name, seq = nil) ⇒ Boolean

delete will remove the designated prefix-list

Parameters:

  • :name (String)

    The name of the ip prefix-list

  • :seq (String)

    The seq value

Returns:

  • (Boolean)

    returns true if the command completed successfully



134
135
136
137
138
# File 'lib/rbeapi/api/prefixlists.rb', line 134

def delete(name, seq = nil)
  cmd = "no ip prefix-list #{name}"
  cmd << " seq #{seq}" if seq
  configure cmd
end

#get(name) ⇒ Object

Returns the static routes configured on the node

Examples:

{
  <route>: {
    next_hop: <string>,
    name: <string, nil>
  }
}

Parameters:

  • :name (String)

    The name of the prefix-list to return



62
63
64
65
66
67
68
69
70
71
# File 'lib/rbeapi/api/prefixlists.rb', line 62

def get(name)
  config = get_block("ip prefix-list #{name}")
  return nil unless config

  entries = config.scan(/^\s{3}(?:seq\s)(\d+)\s(permit|deny)\s(.+)$/)
  entries.each_with_object([]) do |entry, arry|
    arry << { 'seq' => entry[0], 'action' => entry[1],
              'prefex' => entry[2] }
  end
end

#getallObject

Returns the static routes configured on the node

Examples:

{
  <route>: {
    next_hop: <string>,
    name: <string, nil>
  }
}


88
89
90
91
92
93
94
# File 'lib/rbeapi/api/prefixlists.rb', line 88

def getall
  lists = config.scan(/(?<=^ip\sprefix-list\s).+/)
  lists.each_with_object({}) do |name, hsh|
    values = get name
    hsh[name] = values if values
  end
end