Class: Puppet::Util::NetworkDevice::Cisco_ios::Model::Base
- Inherits:
-
Object
- Object
- Puppet::Util::NetworkDevice::Cisco_ios::Model::Base
show all
- Includes:
- Dsl
- Defined in:
- lib/puppet/util/network_device/cisco_ios/model/base.rb
Direct Known Subclasses
Aaa_group, Acl, Archive, Interface, Line, Radius_server, Snmp, Snmp_community, Snmp_host, Switch, User, Vlan
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(transport, facts) ⇒ Base
Returns a new instance of Base.
11
12
13
14
|
# File 'lib/puppet/util/network_device/cisco_ios/model/base.rb', line 11
def initialize(transport, facts)
@transport = transport
@facts = facts
end
|
Instance Attribute Details
#ensure ⇒ Object
Returns the value of attribute ensure.
9
10
11
|
# File 'lib/puppet/util/network_device/cisco_ios/model/base.rb', line 9
def ensure
@ensure
end
|
#facts ⇒ Object
Returns the value of attribute facts.
9
10
11
|
# File 'lib/puppet/util/network_device/cisco_ios/model/base.rb', line 9
def facts
@facts
end
|
#name ⇒ Object
Returns the value of attribute name.
9
10
11
|
# File 'lib/puppet/util/network_device/cisco_ios/model/base.rb', line 9
def name
@name
end
|
#transport ⇒ Object
Returns the value of attribute transport.
9
10
11
|
# File 'lib/puppet/util/network_device/cisco_ios/model/base.rb', line 9
def transport
@transport
end
|
Instance Method Details
#after_update ⇒ Object
61
62
63
|
# File 'lib/puppet/util/network_device/cisco_ios/model/base.rb', line 61
def after_update
transport.command("end")
end
|
#before_update ⇒ Object
57
58
59
|
# File 'lib/puppet/util/network_device/cisco_ios/model/base.rb', line 57
def before_update
transport.command("conf t", :prompt => /\(config\)#\s?\z/n)
end
|
#configuration_changed?(is, should, options = {}) ⇒ Boolean
36
37
38
39
40
41
42
43
|
# File 'lib/puppet/util/network_device/cisco_ios/model/base.rb', line 36
def configuration_changed?(is, should, options = {})
is = is.dup.delete_if {|k,v| v == :undef || should[k] == :undef}
is.delete_if {|k,v| k == :ensure} unless options[:keep_ensure]
should = should.dup.delete_if {|k,v| v == :undef}
should.delete_if {|k,v| k == :ensure} unless options[:keep_ensure]
is != should
end
|
#construct_cmd ⇒ Object
70
71
72
73
74
75
76
77
|
# File 'lib/puppet/util/network_device/cisco_ios/model/base.rb', line 70
def construct_cmd
base = get_base_cmd
Puppet::Util::NetworkDevice::Sorter.new(@params).tsort.each do |param|
fragment = param.get_fragment if param.fragment and param.value
base << " #{fragment}" if fragment and param.supported?
end
return base
end
|
#get_base_cmd ⇒ Object
65
66
67
68
|
# File 'lib/puppet/util/network_device/cisco_ios/model/base.rb', line 65
def get_base_cmd
raise ArgumentError, "Base Command not set for #{self.class}" if base_cmd.nil?
ERB.new(base_cmd).result(binding)
end
|
#mod_const_base ⇒ Object
49
50
51
|
# File 'lib/puppet/util/network_device/cisco_ios/model/base.rb', line 49
def mod_const_base
raise Puppet::Error, 'Override me'
end
|
#mod_path_base ⇒ Object
45
46
47
|
# File 'lib/puppet/util/network_device/cisco_ios/model/base.rb', line 45
def mod_path_base
raise Puppet::Error, 'Override me'
end
|
#param_class ⇒ Object
53
54
55
|
# File 'lib/puppet/util/network_device/cisco_ios/model/base.rb', line 53
def param_class
raise Puppet::Error, 'Override me'
end
|
79
80
81
82
83
84
85
86
|
# File 'lib/puppet/util/network_device/cisco_ios/model/base.rb', line 79
def perform_update
case @params[:ensure].value
when :present
transport.command(construct_cmd)
when :absent
transport.command("no " + construct_cmd)
end
end
|
#update(is = {}, should = {}) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/puppet/util/network_device/cisco_ios/model/base.rb', line 16
def update(is = {}, should = {})
return unless configuration_changed?(is, should)
missing_commands = [is.keys, should.keys].flatten.uniq.sort - @params.keys.flatten.uniq.sort
missing_commands.delete(:ensure)
raise Puppet::Error, "Undefined commands for #{missing_commands.join(', ')}" unless missing_commands.empty?
[is.keys, should.keys].flatten.uniq.sort.each do |property|
next if property == :ensure
next if should[property] == :undef
@params[property].value = :absent if should[property] == :absent || should[property].nil?
@params[property].value = should[property] unless should[property] == :absent || should[property].nil?
end
before_update
Puppet::Util::NetworkDevice::Sorter.new(@params).tsort.each do |param|
next if should[param.name] == :undef || should[param.name].nil?
param.update(@transport, is[param.name]) unless is[param.name] == should[param.name]
end
after_update
end
|