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

#configure, #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) ⇒ Object


83
84
85
86
87
88
# File 'lib/rbeapi/api/prefixlists.rb', line 83

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) ⇒ Object


79
80
81
# File 'lib/rbeapi/api/prefixlists.rb', line 79

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

#delete(name, seq = nil) ⇒ Object


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

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>
  }
}

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

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


71
72
73
74
75
76
77
# File 'lib/rbeapi/api/prefixlists.rb', line 71

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