Class: Puppet::Provider::NetworkDns::CiscoIos

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

Overview

Configure the domain name of the device

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.commands_from_is_should(is, should) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/puppet/provider/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?
  # this builds the command to set the domain-name
  array_of_commands + PuppetX::CiscoIOS::Utility.build_commmands_from_attribute_set_values(should, commands_hash)
end

.commands_hashObject



8
9
10
# File 'lib/puppet/provider/network_dns/cisco_ios.rb', line 8

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

.instances_from_cli(output) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/puppet/provider/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 << new_instance
  new_instance_fields
end

Instance Method Details

#canonicalize(_context, resources) ⇒ Object



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

def canonicalize(_context, resources)
  resources.each do |resource|
    resource[:servers] = resource[:servers].sort if resource[:servers]
  end
  resources
end

#commands_hashObject



36
37
38
# File 'lib/puppet/provider/network_dns/cisco_ios.rb', line 36

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

#create(context, _name, _should) ⇒ Object



65
# File 'lib/puppet/provider/network_dns/cisco_ios.rb', line 65

def create(context, _name, _should); end

#delete(context, name) ⇒ Object



67
# File 'lib/puppet/provider/network_dns/cisco_ios.rb', line 67

def delete(context, name) end

#get(context, _names = nil) ⇒ Object



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

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::NetworkDns::CiscoIos.instances_from_cli(output)
  PuppetX::CiscoIOS::Utility.enforce_simple_types(context, return_value)
end

#set(context, changes) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/puppet/provider/network_dns/cisco_ios.rb', line 47

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



58
59
60
61
62
63
# File 'lib/puppet/provider/network_dns/cisco_ios.rb', line 58

def update(context, _name, is, should)
  array_of_commands_to_run = Puppet::Provider::NetworkDns::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