Class: Puppet::Provider::IosAccessList::CiscoIos

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/provider/ios_access_list/cisco_ios.rb

Overview

Configure Access List on the device

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.commands_from_instance(instance) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/puppet/provider/ios_access_list/cisco_ios.rb', line 22

def self.commands_from_instance(instance)
  commands = []
  if instance[:access_list_type].casecmp('none').zero?
    instance[:access_list_type] = nil
  end
  command = PuppetX::CiscoIOS::Utility.set_values(instance, commands_hash)
  if instance[:ensure].to_s == 'absent'
    command = 'no ' + command
  end
  commands << command
  commands
end

.commands_hashObject



6
7
8
# File 'lib/puppet/provider/ios_access_list/cisco_ios.rb', line 6

def self.commands_hash
  @commands_hash ||= PuppetX::CiscoIOS::Utility.load_yaml(File.expand_path(__dir__) + '/command.yaml')
end

.instances_from_cli(output) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/puppet/provider/ios_access_list/cisco_ios.rb', line 10

def self.instances_from_cli(output)
  new_instance_fields = []

  output.scan(%r{#{PuppetX::CiscoIOS::Utility.get_instances(commands_hash)}}).each do |raw_instance_fields|
    new_instance = PuppetX::CiscoIOS::Utility.parse_resource(raw_instance_fields, commands_hash)
    new_instance[:ensure] = 'present'
    new_instance.delete_if { |_k, v| v.nil? }
    new_instance_fields << new_instance
  end
  new_instance_fields
end

Instance Method Details

#commands_hashObject



35
36
37
# File 'lib/puppet/provider/ios_access_list/cisco_ios.rb', line 35

def commands_hash
  self.class.commands_hash
end

#delete(context, _name, is) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/puppet/provider/ios_access_list/cisco_ios.rb', line 69

def delete(context, _name, is)
  is[:ensure] = 'absent'
  array_of_commands_to_run = self.class.commands_from_instance(is)
  array_of_commands_to_run.each do |command|
    context.transport.run_command_conf_t_mode(command)
  end
end

#get(context) ⇒ Object



39
40
41
42
43
44
# File 'lib/puppet/provider/ios_access_list/cisco_ios.rb', line 39

def get(context)
  context.warning('The ios_access_list type is deprecated, due to unreconcilable implementation issues. Use the ios_acl type instead.')
  output = context.transport.run_command_enable_mode(PuppetX::CiscoIOS::Utility.get_values(commands_hash))
  return [] if output.nil?
  self.class.instances_from_cli(output)
end

#set(context, changes) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/puppet/provider/ios_access_list/cisco_ios.rb', line 46

def set(context, changes)
  changes.each do |name, change|
    is = change.key?(:is) ? change[:is] : (get(context) || []).find { |key| key[:name] == name }
    should = change[:should]
    if should[:ensure].to_s == 'absent'
      context.deleting(name) do
        delete(context, name, is)
      end
    else
      context.updating(name) do
        update(context, name, should)
      end
    end
  end
end

#update(context, _name, should) ⇒ Object



62
63
64
65
66
67
# File 'lib/puppet/provider/ios_access_list/cisco_ios.rb', line 62

def update(context, _name, should)
  array_of_commands_to_run = self.class.commands_from_instance(should)
  array_of_commands_to_run.each do |command|
    context.transport.run_command_conf_t_mode(command)
  end
end