Class: Puppet::Provider::IosNtpConfig::CiscoIos
- Inherits:
-
Object
- Object
- Puppet::Provider::IosNtpConfig::CiscoIos
- Defined in:
- lib/puppet/provider/ios_ntp_config/cisco_ios.rb
Overview
NTP Config Puppet Provider for Cisco IOS devices
Class Method Summary collapse
- .commands_from_is_should(is, should) ⇒ Object
- .commands_hash ⇒ Object
- .instances_from_cli(output) ⇒ Object
Instance Method Summary collapse
- #canonicalize(_context, resources) ⇒ Object
- #commands_hash ⇒ Object
- #get(context, _names = nil) ⇒ Object
- #set(context, changes) ⇒ Object
- #update(context, _name, is, should) ⇒ Object
Class Method Details
.commands_from_is_should(is, should) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/puppet/provider/ios_ntp_config/cisco_ios.rb', line 30 def self.commands_from_is_should(is, should) array_of_commands = [] should.delete(:name) should[:update_calendar] = 'unset' unless should[:update_calendar] should[:logging] = 'unset' unless should[:logging] array_of_commands += Puppet::Provider::NtpConfig::CiscoIos.commands_from_is_should(is, should) # build up the rest of the commands should.delete(:authenticate) should.delete(:source_interface) array_of_commands.concat(PuppetX::CiscoIOS::Utility.build_commmands_from_attribute_set_values(should, commands_hash)) array_of_commands end |
.commands_hash ⇒ Object
11 12 13 14 15 16 |
# File 'lib/puppet/provider/ios_ntp_config/cisco_ios.rb', line 11 def self.commands_hash local_commands_hash = PuppetX::CiscoIOS::Utility.load_yaml(File.(__dir__) + '/command.yaml') ntp_config_commands_hash = PuppetX::CiscoIOS::Utility.load_yaml(File.(__dir__) + '/../ntp_config/command.yaml') @commands_hash = local_commands_hash.merge(ntp_config_commands_hash) { |_key, oldval, newval| (oldval.to_a + newval.to_a).to_h } @commands_hash end |
.instances_from_cli(output) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/puppet/provider/ios_ntp_config/cisco_ios.rb', line 18 def self.instances_from_cli(output) new_instance_fields = [] new_instance = PuppetX::CiscoIOS::Utility.parse_resource(output, commands_hash) new_instance[:name] = 'default' new_instance[:update_calendar] = (new_instance[:update_calendar]) ? true : false new_instance[:logging] = (new_instance[:logging]) ? true : false new_instance = new_instance.merge(Puppet::Provider::NtpConfig::CiscoIos.instances_from_cli(output).first) new_instance.delete_if { |_k, v| v.nil? } new_instance_fields << new_instance new_instance_fields end |
Instance Method Details
#canonicalize(_context, resources) ⇒ Object
72 73 74 75 76 |
# File 'lib/puppet/provider/ios_ntp_config/cisco_ios.rb', line 72 def canonicalize(_context, resources) resources.each do |resource| resource[:trusted_keys] = resource[:trusted_keys].sort if resource[:trusted_keys] end end |
#commands_hash ⇒ Object
43 44 45 |
# File 'lib/puppet/provider/ios_ntp_config/cisco_ios.rb', line 43 def commands_hash Puppet::Provider::IosNtpConfig::CiscoIos.commands_hash end |
#get(context, _names = nil) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/puppet/provider/ios_ntp_config/cisco_ios.rb', line 47 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::IosNtpConfig::CiscoIos.instances_from_cli(output) PuppetX::CiscoIOS::Utility.enforce_simple_types(context, return_value) end |
#set(context, changes) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/puppet/provider/ios_ntp_config/cisco_ios.rb', line 54 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] context.updating(name) do update(context, name, is, should) end end end |
#update(context, _name, is, should) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/puppet/provider/ios_ntp_config/cisco_ios.rb', line 65 def update(context, _name, is, should) array_of_commands_to_run = Puppet::Provider::IosNtpConfig::CiscoIos.commands_from_is_should(is, should) array_of_commands_to_run.each do |command| context.transport.run_command_conf_t_mode(command) end end |