Class: Rbeapi::Api::Prefixlists
- 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
Instance Method Summary collapse
-
#add_rule(name, action, prefix, seq = nil) ⇒ Boolean
Creates an ip prefix-list with the designated name, seqno, action and prefix.
-
#create(name) ⇒ Boolean
Creates a new ip prefix-list with the designated name.
-
#delete(name, seq = nil) ⇒ Boolean
Removes the designated prefix-list.
-
#get(name) ⇒ Array<Hash>
Returns the prefix list configured on the node.
-
#getall ⇒ Hash<String, Array>
Returns all prefix lists configured on the node.
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
Creates an ip prefix-list with the designated name,
seqno, action and prefix.
159 160 161 162 163 164 |
# 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 |
#create(name) ⇒ Boolean
Creates a new ip prefix-list with the designated name.
142 143 144 |
# File 'lib/rbeapi/api/prefixlists.rb', line 142 def create(name) configure("ip prefix-list #{name}") end |
#delete(name, seq = nil) ⇒ Boolean
Removes the designated prefix-list.
174 175 176 177 178 |
# 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 |
#get(name) ⇒ Array<Hash>
Returns the prefix list configured on the node.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# 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 |
#getall ⇒ Hash<String, Array>
Returns all prefix lists configured on the node.
128 129 130 131 132 133 134 |
# 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 |