Class: Puppet::Provider::NtpConfig::CiscoIos
- Inherits:
-
Object
- Object
- Puppet::Provider::NtpConfig::CiscoIos
- Defined in:
- lib/puppet/provider/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
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/puppet/provider/ntp_config/cisco_ios.rb', line 29 def self.commands_from_is_should(is, should) array_of_commands = [] # build up the trusted keys commands array_of_commands += PuppetX::CiscoIOS::Utility.commands_from_diff_of_two_arrays(commands_hash, is[:trusted_key], should[:trusted_key], 'trusted_key') should.delete(:trusted_key) # build up the rest of the commands should.delete(:name) should[:authenticate] = 'unset' unless should[:authenticate] array_of_commands += PuppetX::CiscoIOS::Utility.build_commmands_from_attribute_set_values(should, commands_hash) array_of_commands end |
.commands_hash ⇒ Object
8 9 10 |
# File 'lib/puppet/provider/ntp_config/cisco_ios.rb', line 8 def self.commands_hash @commands_hash ||= PuppetX::CiscoIOS::Utility.load_yaml(File.(__dir__) + '/command.yaml') end |
.instances_from_cli(output) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/puppet/provider/ntp_config/cisco_ios.rb', line 12 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[:authenticate] = !new_instance[:authenticate].nil? unless new_instance[:trusted_key].nil? new_instance[:trusted_key] = [].push(new_instance[:trusted_key]) if new_instance[:trusted_key].is_a?(String) new_instance[:trusted_key] = new_instance[:trusted_key].map(&:to_i) new_instance[:trusted_key] = new_instance[:trusted_key].sort end new_instance[:trusted_key] = [] if new_instance[:trusted_key].nil? new_instance[:source_interface] = (new_instance[:source_interface]) ? new_instance[:source_interface] : 'unset' new_instance.delete_if { |_k, v| v.nil? } new_instance_fields << new_instance new_instance_fields end |
Instance Method Details
#canonicalize(_context, resources) ⇒ Object
70 71 72 73 74 |
# File 'lib/puppet/provider/ntp_config/cisco_ios.rb', line 70 def canonicalize(_context, resources) resources.each do |resource| resource[:trusted_keys] = resource[:trusted_keys].sort if resource[:trusted_keys] end end |
#commands_hash ⇒ Object
41 42 43 |
# File 'lib/puppet/provider/ntp_config/cisco_ios.rb', line 41 def commands_hash Puppet::Provider::NtpConfig::CiscoIos.commands_hash end |
#get(context, _names = nil) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/puppet/provider/ntp_config/cisco_ios.rb', line 45 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::NtpConfig::CiscoIos.instances_from_cli(output) PuppetX::CiscoIOS::Utility.enforce_simple_types(context, return_value) end |
#set(context, changes) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/puppet/provider/ntp_config/cisco_ios.rb', line 52 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
63 64 65 66 67 68 |
# File 'lib/puppet/provider/ntp_config/cisco_ios.rb', line 63 def update(context, _name, is, should) array_of_commands_to_run = Puppet::Provider::NtpConfig::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 |