Class: Puppet::Util::NetworkDevice::Cisco_ios::Fact
- Inherits:
-
Object
- Object
- Puppet::Util::NetworkDevice::Cisco_ios::Fact
- Extended by:
- ValueHelper
- Defined in:
- lib/puppet/util/network_device/cisco_ios/fact.rb
Instance Attribute Summary collapse
-
#evaluated ⇒ Object
Returns the value of attribute evaluated.
-
#idx ⇒ Object
Returns the value of attribute idx.
-
#name ⇒ Object
Returns the value of attribute name.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #canonicalize_hardwaremodel(hardwaremodel) ⇒ Object
-
#initialize(name, transport, facts = nil, idx = 0, &block) ⇒ Fact
constructor
A new instance of Fact.
- #ios_major_version(version) ⇒ Object
- #parse(txt) ⇒ Object
- #uptime_to_seconds(uptime) ⇒ Object
Constructor Details
#initialize(name, transport, facts = nil, idx = 0, &block) ⇒ Fact
Returns a new instance of Fact.
8 9 10 11 12 13 14 |
# File 'lib/puppet/util/network_device/cisco_ios/fact.rb', line 8 def initialize(name, transport, facts = nil, idx = 0, &block) @name = name @idx = idx @evaluated = false @downcase = false self.instance_eval(&block) end |
Instance Attribute Details
#evaluated ⇒ Object
Returns the value of attribute evaluated.
5 6 7 |
# File 'lib/puppet/util/network_device/cisco_ios/fact.rb', line 5 def evaluated @evaluated end |
#idx ⇒ Object
Returns the value of attribute idx.
5 6 7 |
# File 'lib/puppet/util/network_device/cisco_ios/fact.rb', line 5 def idx @idx end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/puppet/util/network_device/cisco_ios/fact.rb', line 5 def name @name end |
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'lib/puppet/util/network_device/cisco_ios/fact.rb', line 5 def value @value end |
Instance Method Details
#canonicalize_hardwaremodel(hardwaremodel) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/puppet/util/network_device/cisco_ios/fact.rb', line 44 def canonicalize_hardwaremodel(hardwaremodel) hardwaremodels = { 'c4500' => %w{WS-C4506-E WS-C4507R+E}, 'c3750' => %w{WS-C3750-24TS WS-C3750-24PS WS-C3750G-24TS-1U WS-C3750G-24PS WS-C3750-24TS-S WS-C3750-24P WS-C3750-48TS WS-C3750G-24PS-S WS-C3750E-24PD}, 'c3560' => %w{WS-C3560-12PC-S}, 'c2960' => %w{WS-C2960G-48TC-L WS-C2960-24TC-L WS-C2960G-24TC-L}, 'c2950' => %w{WS-C2950T-24}, 'c2924' => %w{WS-C2924C-XL}, 'c6509' => %w{WS-C6509-E}, 'c1841' => %w{1841}, 'c877' => %w{877} } hardwaremodels.each do |k,v| return k if v.find {|model| hardwaremodel == model} end hardwaremodel end |
#ios_major_version(version) ⇒ Object
29 30 31 32 33 |
# File 'lib/puppet/util/network_device/cisco_ios/fact.rb', line 29 def ios_major_version(version) # TODO: Review return if version.nil? version.gsub(/^(\d+)\.(\d+)\(.+\)([A-Z]+)([\da-z]+)?/, '\1.\2\3') end |
#parse(txt) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/puppet/util/network_device/cisco_ios/fact.rb', line 18 def parse(txt) if self.match.is_a?(Proc) self.value = self.match.call(txt) else self.value = txt.scan(self.match).flatten[self.idx] end self.evaluated = true self.value = self.value.downcase if downcase and self.value raise Puppet::Error, "Fact: #{self.name} is required but didn't evaluate to a proper Value" if self.required == true && (self.value.nil? || self.value.to_s.empty?) end |
#uptime_to_seconds(uptime) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/puppet/util/network_device/cisco_ios/fact.rb', line 35 def uptime_to_seconds(uptime) # TODO: Review return if uptime.nil? captures = (uptime.match /^(?:(\d+) years?,)?\s*(?:(\d+) weeks?,)?\s*(?:(\d+) days?,)?\s*(?:(\d+) hours?,)?\s*(\d+) minutes?$/).captures seconds = captures.zip([31536000, 604800, 86400, 3600, 60]).inject(0) do |total, (x,y)| total + (x.nil? ? 0 : x.to_i * y) end end |