class Rbeapi::Api::Prefixlists
The Prefixlists
class provides a configuration instance for working with static routes in EOS.
Public Instance Methods
Creates an ip prefix-list with the designated name,
seqno, action and prefix.
@param name [String] The name of the ip prefix-list.
@param seq [String] The seq value.
@param action [String] The action value.
@param prefix [String] The prefix value.
@return [Boolean] Returns true if the command completed successfully.
# File lib/rbeapi/api/prefixlists.rb, line 159 def add_rule(name, action, prefix, seq = nil) cmd = "ip prefix-list #{name}" cmd << " seq #{seq}" if seq cmd << " #{action} #{prefix}" configure(cmd) end
Creates a new ip prefix-list with the designated name.
@param name [String] The name of the ip prefix-list.
@return [Boolean] Returns true if the command completed successfully.
# File lib/rbeapi/api/prefixlists.rb, line 142 def create(name) configure("ip prefix-list #{name}") end
Removes the designated prefix-list.
@param name [String] The name of the ip prefix-list.
@param seq [String] The seq value.
@return [Boolean] Returns true if the command completed successfully.
# File lib/rbeapi/api/prefixlists.rb, line 174 def delete(name, seq = nil) cmd = "no ip prefix-list #{name}" cmd << " seq #{seq}" if seq configure(cmd) end
Returns the prefix list configured on the node.
@example
[ { seq: <string>, action: <string>, prefix: <string> }, ..., { seq: <string>, action: <string>, prefix: <string> } ]
@param name [String] The name of the prefix-list to return.
@return [Array<Hash>] The method will return the configured
prefix list on the node with all its sequences as a Ruby array of hashes, where each prefix is a hash object. If the prefix list is not found, a nil object is returned.
# File lib/rbeapi/api/prefixlists.rb, line 69 def get(name) return nil unless config =~ /ip prefix-list #{name}/ # single-line prefix list if config =~ /ip prefix-list #{name}\sseq/ entries = config.scan(/^(?:ip\sprefix-list\s#{name}\sseq\s)(\d+)\s (permit|deny)\s(.+)$/x) # or multi-line else prefix_list = get_block("ip prefix-list #{name}") entries = prefix_list.scan(/^\s+(?:seq\s)(\d+)\s (permit|deny)\s(.+)$/x) end entries.each_with_object([]) do |entry, arry| arry << { 'seq' => entry[0], 'action' => entry[1], 'prefix' => entry[2] } end end
Returns all prefix lists configured on the node.
@example
{ <name1>: [ { seq: <string>, action: <string>, prefix: <string> }, ... { seq: <string>, action: <string>, prefix: <string> } ], ..., <nameN>: [ { seq: <string>, action: <string>, prefix: <string> }, ... { seq: <string>, action: <string>, prefix: <string> } ] }
@return [Hash<String, Array>] The method will return all the
prefix lists configured on the node as a Ruby hash object. If there are no prefix lists configured, an empty hash will be returned.
# File lib/rbeapi/api/prefixlists.rb, line 128 def getall lists = config.scan(/(?<=^ip\sprefix-list\s)[^\s]+(?=\sseq.+)?/) lists.uniq.each_with_object({}) do |name, hsh| values = get name hsh[name] = values if values end end