Class: Puppet::Provider::IosNtpAccessGroup::CiscoIos

Inherits:
ResourceApi::SimpleProvider
  • Object
show all
Defined in:
lib/puppet/provider/ios_ntp_access_group/cisco_ios.rb

Overview

NTP Access Group Puppet Provider for Cisco IOS devices

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
# File 'lib/puppet/provider/ios_ntp_access_group/cisco_ios.rb', line 22

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

.commands_hashObject



7
8
9
# File 'lib/puppet/provider/ios_ntp_access_group/cisco_ios.rb', line 7

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

.instances_from_cli(output) ⇒ Object



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

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[:ipv6_access_group] = (new_instance[:ipv6_access_group]) ? true : false
    new_instance[:ensure] = 'present'
    new_instance_fields << new_instance
  end
  new_instance_fields
end

Instance Method Details

#canonicalize(_context, resources) ⇒ Object



70
71
72
# File 'lib/puppet/provider/ios_ntp_access_group/cisco_ios.rb', line 70

def canonicalize(_context, resources)
  resources
end

#commands_hashObject



32
33
34
# File 'lib/puppet/provider/ios_ntp_access_group/cisco_ios.rb', line 32

def commands_hash
  Puppet::Provider::IosNtpAccessGroup::CiscoIos.commands_hash
end

#create(context, name, should) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/puppet/provider/ios_ntp_access_group/cisco_ios.rb', line 43

def create(context, name, should)
  create_hash = { name: name, ensure: 'present', access_group_type: should[:access_group_type], ipv6_access_group: should[:ipv6_access_group] }
  array_of_commands_to_run = Puppet::Provider::IosNtpAccessGroup::CiscoIos.commands_from_instance(create_hash)
  array_of_commands_to_run.each do |command|
    context.transport.run_command_conf_t_mode(command)
  end
  context.updating(name) do
    update(context, name, should)
  end
end

#delete(context, name) ⇒ Object



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

def delete(context, name)
  is = (get(context) || []).find { |key| key[:name] == name }
  clear_hash = { name: name, ensure: 'absent', access_group_type: is[:access_group_type], ipv6_access_group: is[:ipv6_access_group] }
  array_of_commands_to_run = Puppet::Provider::IosNtpAccessGroup::CiscoIos.commands_from_instance(clear_hash)
  array_of_commands_to_run.each do |command|
    context.transport.run_command_conf_t_mode(command)
  end
end

#get(context, _names = nil) ⇒ Object



36
37
38
39
40
41
# File 'lib/puppet/provider/ios_ntp_access_group/cisco_ios.rb', line 36

def get(context, _names = nil)
  output = context.transport.run_command_enable_mode(PuppetX::CiscoIOS::Utility.get_values(commands_hash))
  return [] if output.nil?
  return_value = Puppet::Provider::IosNtpAccessGroup::CiscoIos.instances_from_cli(output)
  PuppetX::CiscoIOS::Utility.enforce_simple_types(context, return_value)
end

#update(context, _name, should) ⇒ Object



54
55
56
57
58
59
# File 'lib/puppet/provider/ios_ntp_access_group/cisco_ios.rb', line 54

def update(context, _name, should)
  array_of_commands_to_run = Puppet::Provider::IosNtpAccessGroup::CiscoIos.commands_from_instance(should)
  array_of_commands_to_run.each do |command|
    context.transport.run_command_conf_t_mode(command)
  end
end