Class: Puppet::Util::NetworkDevice::Cisco_ios::Model::Vlan

Inherits:
Base
  • Object
show all
Defined in:
lib/puppet/util/network_device/cisco_ios/model/vlan.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transport, facts, options) ⇒ Vlan

Returns a new instance of Vlan.



9
10
11
12
13
14
15
16
17
# File 'lib/puppet/util/network_device/cisco_ios/model/vlan.rb', line 9

def initialize(transport, facts, options)
  super(transport, facts)
  # Initialize some defaults
  @params         ||= {}
  @name           = options[:name] if options.key? :name

  # Register all needed Modules based on the availiable Facts
  register_modules
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/puppet/util/network_device/cisco_ios/model/vlan.rb', line 7

def name
  @name
end

#paramsObject (readonly)

Returns the value of attribute params.



7
8
9
# File 'lib/puppet/util/network_device/cisco_ios/model/vlan.rb', line 7

def params
  @params
end

Instance Method Details

#mod_const_baseObject



56
57
58
# File 'lib/puppet/util/network_device/cisco_ios/model/vlan.rb', line 56

def mod_const_base
  return Puppet::Util::NetworkDevice::Cisco_ios::Model::Vlan
end

#mod_path_baseObject



52
53
54
# File 'lib/puppet/util/network_device/cisco_ios/model/vlan.rb', line 52

def mod_path_base
  return 'puppet/util/network_device/cisco_ios/model/vlan'
end

#param_classObject



60
61
62
# File 'lib/puppet/util/network_device/cisco_ios/model/vlan.rb', line 60

def param_class
  return Puppet::Util::NetworkDevice::Cisco_ios::Model::ScopedValue
end

#perform_update(is, should) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/puppet/util/network_device/cisco_ios/model/vlan.rb', line 35

def perform_update(is, should)
  case @params[:ensure].value
  when :present
    transport.command("vlan #{name}", :prompt => /\(config-vlan\)#\s?\z/n)
    Puppet::Util::NetworkDevice::Sorter.new(@params).tsort.each do |param|
      # We dont want to change undefined values
      next if should[param.name] == :undef || should[param.name].nil?
      # Skip the ensure property
      next if param.name == :ensure
      param.update(@transport, is[param.name]) unless is[param.name] == should[param.name]
    end
    transport.command("exit")
  when :absent
    transport.command("no vlan #{name}")
  end
end

#register_modulesObject



64
65
66
# File 'lib/puppet/util/network_device/cisco_ios/model/vlan.rb', line 64

def register_modules
  register_new_module(:base)
end

#update(is = {}, should = {}) ⇒ Object

Raises:

  • (Puppet::Error)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/puppet/util/network_device/cisco_ios/model/vlan.rb', line 19

def update(is = {}, should = {})
  return unless configuration_changed?(is, should, :keep_ensure => true)
  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 == :acl_type
    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
  perform_update(is, should)
  after_update
end