Class: Puppet::Provider::IosIp::CiscoIos

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

Overview

Utility functions to parse out the Interface

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.commands_from_instance(instance) ⇒ Object



26
27
28
29
30
# File 'lib/puppet/provider/ios_ip/cisco_ios.rb', line 26

def self.commands_from_instance(instance)
  instance[:routing] = 'unset' unless instance[:routing]
  array_of_commands = PuppetX::CiscoIOS::Utility.build_commmands_from_attribute_set_values(instance, commands_hash)
  array_of_commands
end

.commands_hashObject



8
9
10
# File 'lib/puppet/provider/ios_ip/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/ios_ip/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[:routing] = if ['4503', '4507', '4948'].include?(PuppetX::CiscoIOS::Utility.ios_device_type)
                             (new_instance[:routing]) ? false : true
                           else
                             (new_instance[:routing]) ? true : false
                           end
  new_instance.delete_if { |_k, v| v.nil? }
  new_instance_fields << new_instance
  new_instance_fields
end

Instance Method Details

#canonicalize(_context, resources) ⇒ Object



65
66
67
# File 'lib/puppet/provider/ios_ip/cisco_ios.rb', line 65

def canonicalize(_context, resources)
  resources
end

#commands_hashObject



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

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

#create(context, _name, _should) ⇒ Object



61
# File 'lib/puppet/provider/ios_ip/cisco_ios.rb', line 61

def create(context, _name, _should); end

#delete(context, _name) ⇒ Object



63
# File 'lib/puppet/provider/ios_ip/cisco_ios.rb', line 63

def delete(context, _name); end

#get(context, _names = nil) ⇒ Object



36
37
38
39
40
41
# File 'lib/puppet/provider/ios_ip/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::IosIp::CiscoIos.instances_from_cli(output)
  PuppetX::CiscoIOS::Utility.enforce_simple_types(context, return_value)
end

#set(context, changes) ⇒ Object



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

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



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

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