Class: Rbeapi::Api::Routemaps
- 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
Instance Method Summary collapse
-
#create(name, action, seqno, opts = {}) ⇒ Boolean
create will create a new routemap with the specified name.
-
#default(name, action, seqno) ⇒ Boolean
This method will attempt to default the routemap from the nodes operational config.
-
#delete(name, action, seqno) ⇒ Boolean
delete will delete an existing routemap name from the nodes current running configuration.
-
#get(name) ⇒ nil, Hash<Symbol, Object>
get returns a hash of routemap configurations for the given name.
-
#getall ⇒ nil, Hash<Symbol, Object>
getall returns a collection of routemap resource hashes from the nodes running configuration.
-
#set_continue(name, action, seqno, value) ⇒ Boolean
set_continue will set the continue value for a specified routemap.
-
#set_description(name, action, seqno, value) ⇒ Boolean
set_description will set the description for a specified routemap.
-
#set_match_statements(name, action, seqno, value) ⇒ Boolean
set_match_statements will set the match values for a specified routemap.
-
#set_set_statements(name, action, seqno, value) ⇒ Boolean
set_set_statements will set the set values for a specified routemap.
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
Commands
route-map <name> action <value> seqno <value> description <value>
match <value> set <value> continue <value>
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/rbeapi/api/routemaps.rb', line 303 def create(name, action, seqno, opts = {}) if opts.empty? cmds = name_commands(name, action, seqno) else if opts[:match] && !opts[:match].is_a?(Array) raise ArgumentError, 'opts match must be an Array' end 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 || cmds << "match #{}" end end if opts[:set] remove_set_statements(name, action, seqno, cmds) opts[:set].each do || cmds << "set #{}" 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.
Commands
no route-map <name>
428 429 430 |
# File 'lib/rbeapi/api/routemaps.rb', line 428 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.
Commands
no route-map <name> <action> <seqno>
406 407 408 |
# File 'lib/rbeapi/api/routemaps.rb', line 406 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.
90 91 92 |
# File 'lib/rbeapi/api/routemaps.rb', line 90 def get(name) parse_entries(name) end |
#getall ⇒ nil, 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.
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.
Commands
route-map <name> action <value> seqno <value> continue <value>
502 503 504 505 506 507 |
# File 'lib/rbeapi/api/routemaps.rb', line 502 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.
Commands
route-map <name> action <value> seqno <value> description <value>
525 526 527 528 529 530 |
# File 'lib/rbeapi/api/routemaps.rb', line 525 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.
Commands
route-map <name> action <value> seqno <value> match <value>
448 449 450 451 452 453 454 455 456 457 |
# File 'lib/rbeapi/api/routemaps.rb', line 448 def set_match_statements(name, action, seqno, value) raise ArgumentError, 'value must be an Array' unless value.is_a?(Array) cmds = ["route-map #{name} #{action} #{seqno}"] remove_match_statements(name, action, seqno, cmds) Array(value).each do || cmds << "match #{}" 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.
Commands
route-map <name> action <value> seqno <value> set <value>
475 476 477 478 479 480 481 482 483 484 |
# File 'lib/rbeapi/api/routemaps.rb', line 475 def set_set_statements(name, action, seqno, value) raise ArgumentError, 'value must be an Array' unless value.is_a?(Array) cmds = ["route-map #{name} #{action} #{seqno}"] remove_set_statements(name, action, seqno, cmds) Array(value).each do || cmds << "set #{}" end configure(cmds) end |