Class: Puppet::Provider::IosNetworkDns::CiscoIos
- Inherits:
-
Object
- Object
- Puppet::Provider::IosNetworkDns::CiscoIos
- Defined in:
- lib/puppet/provider/ios_network_dns/cisco_ios.rb
Overview
Configure the domain name of the device
Class Method Summary collapse
- .commands_from_is_should(is, should) ⇒ Object
- .commands_hash ⇒ Object
- .convert_ip_domain_lookup(output) ⇒ Object
-
.false_to_unset(false_value) ⇒ Object
Returns ‘unset’ if the given calue is false.
- .instances_from_cli(output) ⇒ Object
Instance Method Summary collapse
- #canonicalize(_context, resources) ⇒ Object
- #commands_hash ⇒ Object
- #create(context, _name, _should) ⇒ Object
- #delete(context, name) ⇒ 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
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/puppet/provider/ios_network_dns/cisco_ios.rb', line 26 def self.commands_from_is_should(is, should) array_of_commands = [] array_of_commands += PuppetX::CiscoIOS::Utility.commands_from_diff_of_two_arrays(commands_hash, is[:search], should[:search], 'search') array_of_commands += PuppetX::CiscoIOS::Utility.commands_from_diff_of_two_arrays(commands_hash, is[:servers], should[:servers], 'servers') should.delete(:search) unless should.delete(:search).nil? should.delete(:servers) unless should.delete(:servers).nil? should.each do |key, _vlaue| should[key] = Puppet::Provider::IosNetworkDns::CiscoIos.false_to_unset(should[key]) end # this builds the command to set the domain-name commands = array_of_commands + PuppetX::CiscoIOS::Utility.build_commmands_from_attribute_set_values(should, commands_hash) commands end |
.commands_hash ⇒ Object
6 7 8 9 10 |
# File 'lib/puppet/provider/ios_network_dns/cisco_ios.rb', line 6 def self.commands_hash local_commands_hash = PuppetX::CiscoIOS::Utility.load_yaml(File.(__dir__) + '/command.yaml') network_dns_commands_hash = PuppetX::CiscoIOS::Utility.load_yaml(File.(__dir__) + '/../network_dns/command.yaml') @commands_hash = local_commands_hash.merge(network_dns_commands_hash) { |_key, oldval, newval| (oldval.to_a + newval.to_a).to_h } end |
.convert_ip_domain_lookup(output) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/puppet/provider/ios_network_dns/cisco_ios.rb', line 46 def self.convert_ip_domain_lookup(output) output_no_ip = output[:ip_domain_lookup] output[:ip_domain_lookup] = if output_no_ip false else true end output end |
.false_to_unset(false_value) ⇒ Object
Returns ‘unset’ if the given calue is false
41 42 43 44 |
# File 'lib/puppet/provider/ios_network_dns/cisco_ios.rb', line 41 def self.false_to_unset(false_value) return 'unset' if false_value == false false_value end |
.instances_from_cli(output) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/puppet/provider/ios_network_dns/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[:ensure] = 'present' new_instance[:search] = [].push(new_instance[:search]) if new_instance[:search].is_a?(String) new_instance[:servers] = [].push(new_instance[:servers]) if new_instance[:servers].is_a?(String) # servers can come as either a single value or space separated list - deal with it (-O_O) new_instance[:servers] = new_instance[:servers].flatten.map(&:split).flatten.sort if new_instance[:servers] new_instance.delete_if { |_k, v| v.nil? } new_instance_fields << Puppet::Provider::IosNetworkDns::CiscoIos.convert_ip_domain_lookup(new_instance) new_instance_fields end |
Instance Method Details
#canonicalize(_context, resources) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/puppet/provider/ios_network_dns/cisco_ios.rb', line 90 def canonicalize(_context, resources) resources.each do |resource| resource[:servers] = resource[:servers].sort if resource[:servers] end resources end |
#commands_hash ⇒ Object
56 57 58 |
# File 'lib/puppet/provider/ios_network_dns/cisco_ios.rb', line 56 def commands_hash Puppet::Provider::IosNetworkDns::CiscoIos.commands_hash end |
#create(context, _name, _should) ⇒ Object
86 |
# File 'lib/puppet/provider/ios_network_dns/cisco_ios.rb', line 86 def create(context, _name, _should); end |
#delete(context, name) ⇒ Object
88 |
# File 'lib/puppet/provider/ios_network_dns/cisco_ios.rb', line 88 def delete(context, name) end |
#get(context, _names = nil) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/puppet/provider/ios_network_dns/cisco_ios.rb', line 60 def get(context, _names = nil) values = PuppetX::CiscoIOS::Utility.get_values(commands_hash) output = context.transport.run_command_enable_mode(values) return [] if output.nil? return_value = Puppet::Provider::IosNetworkDns::CiscoIos.instances_from_cli(output) PuppetX::CiscoIOS::Utility.enforce_simple_types(context, return_value) end |
#set(context, changes) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/puppet/provider/ios_network_dns/cisco_ios.rb', line 68 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
79 80 81 82 83 84 |
# File 'lib/puppet/provider/ios_network_dns/cisco_ios.rb', line 79 def update(context, _name, is, should) array_of_commands_to_run = Puppet::Provider::IosNetworkDns::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 |