Class: Rbeapi::Api::Routemaps

Inherits:
Entity
  • Object
show all
Defined in:
lib/rbeapi/api/routemaps.rb

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


86
87
88
89
90
91
92
# File 'lib/rbeapi/api/routemaps.rb', line 86

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


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

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

#delete(name) ⇒ Object


82
83
84
# File 'lib/rbeapi/api/routemaps.rb', line 82

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

#get(name) ⇒ Object


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rbeapi/api/routemaps.rb', line 40

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


69
70
71
72
73
74
75
76
# File 'lib/rbeapi/api/routemaps.rb', line 69

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

#remove_rule(name, action, seqno) ⇒ Object


94
95
96
# File 'lib/rbeapi/api/routemaps.rb', line 94

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