Class: Cisco::Acl

Inherits:
NodeUtil show all
Defined in:
lib/cisco_node_utils/acl.rb

Overview

Acl - node utility class for ACL configuration

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NodeUtil

client, #client, config_get, #config_get, #config_get_default, config_get_default, config_set, #config_set, #get, #ios_xr?, #nexus?, #node, node, platform, #platform, supports?, #supports?

Constructor Details

#initialize(afi, acl_name, instantiate = true) ⇒ Acl

Returns a new instance of Acl.



22
23
24
25
# File 'lib/cisco_node_utils/acl.rb', line 22

def initialize(afi, acl_name, instantiate=true)
  @set_args = @get_args = { afi: Acl.afi_cli(afi), acl_name: acl_name.to_s }
  create if instantiate
end

Instance Attribute Details

#acl_nameObject (readonly)

Returns the value of attribute acl_name.



20
21
22
# File 'lib/cisco_node_utils/acl.rb', line 20

def acl_name
  @acl_name
end

#afiObject (readonly)

Returns the value of attribute afi.



20
21
22
# File 'lib/cisco_node_utils/acl.rb', line 20

def afi
  @afi
end

Class Method Details

.aclsObject

Return all acls currently on the switch



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cisco_node_utils/acl.rb', line 28

def self.acls
  afis = %w(ipv4 ipv6)
  acl_hash = {}
  afis.each do |afi|
    acl_hash[afi] = {}
    afi_cli = Acl.afi_cli(afi)
    instances = config_get('acl', 'all_acls', afi: afi_cli)

    next if instances.nil?
    instances.each do |acl_name|
      acl_hash[afi][acl_name] = Acl.new(afi, acl_name, false)
    end
  end
  acl_hash
end

.afi_cli(afi) ⇒ Object

Platform-specific afi cli string



45
46
47
48
49
50
# File 'lib/cisco_node_utils/acl.rb', line 45

def self.afi_cli(afi)
  fail ArgumentError, "Argument afi must be 'ipv4' or 'ipv6'" unless
    afi[/(ipv4|ipv6)/]
  afi = 'ip' if platform == :nexus && afi[/ipv4/]
  afi
end

Instance Method Details

#==(other) ⇒ Object

acl == overide func



97
98
99
# File 'lib/cisco_node_utils/acl.rb', line 97

def ==(other)
  acl_name == other.acl_name && afi == other.afi
end

#config_acl(state) ⇒ Object



60
61
62
63
# File 'lib/cisco_node_utils/acl.rb', line 60

def config_acl(state)
  @set_args[:state] = state
  config_set('acl', 'acl', @set_args)
end

#createObject



52
53
54
# File 'lib/cisco_node_utils/acl.rb', line 52

def create
  config_acl('')
end

#default_fragmentsObject



92
93
94
# File 'lib/cisco_node_utils/acl.rb', line 92

def default_fragments
  config_get_default('acl', 'fragments')
end

#default_stats_per_entryObject



77
78
79
# File 'lib/cisco_node_utils/acl.rb', line 77

def default_stats_per_entry
  config_get_default('acl', 'stats_per_entry')
end

#destroyObject



56
57
58
# File 'lib/cisco_node_utils/acl.rb', line 56

def destroy
  config_acl('no')
end

#fragmentsObject



81
82
83
# File 'lib/cisco_node_utils/acl.rb', line 81

def fragments
  config_get('acl', 'fragments', @get_args)
end

#fragments=(action) ⇒ Object



85
86
87
88
89
90
# File 'lib/cisco_node_utils/acl.rb', line 85

def fragments=(action)
  @set_args[:state] = (action ? '' : 'no')
  action = fragments unless action
  @set_args[:action] = action
  config_set('acl', 'fragments', @set_args) if action
end

#stats_per_entryObject


PROPERTIES




68
69
70
# File 'lib/cisco_node_utils/acl.rb', line 68

def stats_per_entry
  config_get('acl', 'stats_per_entry', @get_args)
end

#stats_per_entry=(state) ⇒ Object



72
73
74
75
# File 'lib/cisco_node_utils/acl.rb', line 72

def stats_per_entry=(state)
  @set_args[:state] = (state ? '' : 'no')
  config_set('acl', 'stats_per_entry', @set_args)
end