Class: Puppet::Provider::Banner::CiscoIos

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

Overview

Configure the device banners

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.commands_from_instance(instance) ⇒ Object



30
31
32
# File 'lib/puppet/provider/banner/cisco_ios.rb', line 30

def self.commands_from_instance(instance)
  PuppetX::CiscoIOS::Utility.build_commmands_from_attribute_set_values(instance, commands_hash)
end

.commands_hashObject



8
9
10
# File 'lib/puppet/provider/banner/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
25
26
27
28
# File 'lib/puppet/provider/banner/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'
  if new_instance[:motd].nil?
    new_instance[:motd] = 'unset'
  end
  if new_instance[:login].nil?
    new_instance[:login] = 'unset'
  end
  if new_instance[:exec].nil?
    new_instance[:exec] = 'unset'
  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



61
62
63
# File 'lib/puppet/provider/banner/cisco_ios.rb', line 61

def canonicalize(_context, resources)
  resources
end

#commands_hashObject



34
35
36
# File 'lib/puppet/provider/banner/cisco_ios.rb', line 34

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

#get(context, _names = nil) ⇒ Object



38
39
40
41
42
43
# File 'lib/puppet/provider/banner/cisco_ios.rb', line 38

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

#set(context, changes) ⇒ Object



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

def set(context, changes)
  changes.each do |name, change|
    should = change[:should]
    context.updating(name) do
      update(context, name, should)
    end
  end
end

#update(context, _name, should) ⇒ Object



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

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