Class: Rbeapi::Api::Routemaps

Inherits:
Entity
  • Object
show all
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/MethodLength

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, rule, seqno = nil) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/rbeapi/api/routemaps.rb', line 93

def add_rule(name, action, rule, seqno = nil)
  cmd = "route-map #{name} #{action}"
  cmd << " #{seqno}" if seqno
  cmds = [*cmds]
  cmds << rule
  configure cmds
end

#create(name) ⇒ Object



85
86
87
# File 'lib/rbeapi/api/routemaps.rb', line 85

def create(name)
  configure "route-map #{name}"
end

#delete(name) ⇒ Object



89
90
91
# File 'lib/rbeapi/api/routemaps.rb', line 89

def delete(name)
  configure "no route-map #{name}"
end

#get(name) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rbeapi/api/routemaps.rb', line 49

def get(name)
  entries = config.scan(/^route-map\s#{name}\s.+$/)

  entries.each_with_object([]) do |rm, arry|
    mdata = /route-map\s(.+)\s(.+)\s(\d+)$/.match(rm)
    rules = get_block(rm)
    rule_hsh = { 'action' => mdata[2], 'seqno' => mdata[3],
                 'match_rules' => [], 'set_rules' => [],
                 'continue_rules' => [] }

    parsed = rules.split("\n").each_with_object({}) do |rule, hsh|
      mdata = /\s{3}(\w+)\s/.match(rule)
      case mdata.nil? ? nil : mdata[1]
      when 'match'
        hsh['match_rules'] = [] unless hsh.include?('match')
        hsh['match_rules'] << rule.strip
      when 'set'
        hsh['set_rules'] = [] unless hsh.include?('set')
        hsh['set_rules'] << rule.strip
      when 'continue'
        hsh['continue_rules'] = [] unless hsh.include?('continue')
        hsh['continue_rules'] << rule.strip
      end
    end
    rule_hsh.update(parsed)
    arry << rule_hsh
  end
end

#getallObject



78
79
80
81
82
83
# File 'lib/rbeapi/api/routemaps.rb', line 78

def getall
  maps = config.scan(/(?<=^route-map\s)[^\s]+/)
  maps.each_with_object({}) do |name, hsh|
    hsh[name] = get name unless hsh.include?(name)
  end
end

#remove_rule(name, action, seqno) ⇒ Object



101
102
103
# File 'lib/rbeapi/api/routemaps.rb', line 101

def remove_rule(name, action, seqno)
  configure "no route-map #{name} #{action} #{seqno}"
end