Class: Puppet::Provider::IosCef::CiscoIos
- Inherits:
-
Object
- Object
- Puppet::Provider::IosCef::CiscoIos
- Defined in:
- lib/puppet/provider/ios_cef/cisco_ios.rb
Overview
Utility functions to parse out the Interface
Class Method Summary collapse
- .commands_from_instance(instance) ⇒ Object
- .commands_hash ⇒ Object
- .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_instance(instance) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/puppet/provider/ios_cef/cisco_ios.rb', line 28 def self.commands_from_instance(instance) instance[:distributed] = 'unset' if instance[:distributed] == false instance[:optimize_resolution] = 'unset' if instance[:optimize_resolution] == false instance[:load_sharing] = instance[:load_sharing].join(' ') if instance[:load_sharing].class == Array array_of_commands = PuppetX::CiscoIOS::Utility.build_commmands_from_attribute_set_values(instance, commands_hash) array_of_commands end |
.commands_hash ⇒ Object
8 9 10 |
# File 'lib/puppet/provider/ios_cef/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 |
# File 'lib/puppet/provider/ios_cef/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[:distributed] = (new_instance[:distributed]) ? false : true new_instance[:optimize_resolution] = (new_instance[:optimize_resolution]) ? false : true if new_instance[:load_sharing] && new_instance[:load_sharing] =~ %r{ } new_instance[:load_sharing] = new_instance[:load_sharing].split(' ') elsif !new_instance[:load_sharing] new_instance[:load_sharing] = 'universal' 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
68 69 70 |
# File 'lib/puppet/provider/ios_cef/cisco_ios.rb', line 68 def canonicalize(_context, resources) resources end |
#commands_hash ⇒ Object
36 37 38 |
# File 'lib/puppet/provider/ios_cef/cisco_ios.rb', line 36 def commands_hash Puppet::Provider::IosCef::CiscoIos.commands_hash end |
#create(context, _name, _should) ⇒ Object
64 |
# File 'lib/puppet/provider/ios_cef/cisco_ios.rb', line 64 def create(context, _name, _should); end |
#delete(context, _name) ⇒ Object
66 |
# File 'lib/puppet/provider/ios_cef/cisco_ios.rb', line 66 def delete(context, _name); end |
#get(context, _names = nil) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/puppet/provider/ios_cef/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::IosCef::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 |
# File 'lib/puppet/provider/ios_cef/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
57 58 59 60 61 62 |
# File 'lib/puppet/provider/ios_cef/cisco_ios.rb', line 57 def update(context, _name, _is, should) array_of_commands_to_run = Puppet::Provider::IosCef::CiscoIos.commands_from_instance(should) array_of_commands_to_run.each do |command| context.transport.run_command_conf_t_mode(command) end end |