Class: Cisco::Pim

Inherits:
NodeUtil show all
Defined in:
lib/cisco_node_utils/pim.rb

Overview

node_utils class for Pim

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NodeUtil

config_get, #config_get, config_get_default, #config_get_default, #config_set, config_set, #node, node, #show

Constructor Details

#initialize(afi, vrf, instantiate = true) ⇒ Pim

Constructor with vrf




29
30
31
32
33
34
35
36
# File 'lib/cisco_node_utils/pim.rb', line 29

def initialize(afi, vrf, instantiate=true)
  fail ArgumentError unless vrf.is_a?(String) || vrf.length > 0
  @vrf = vrf
  @afi = Pim.afi_cli(afi)
  set_args_keys_default

  Pim.feature_enable if instantiate
end

Instance Attribute Details

#afiObject (readonly)

Returns the value of attribute afi.



25
26
27
# File 'lib/cisco_node_utils/pim.rb', line 25

def afi
  @afi
end

#vrfObject (readonly)

Returns the value of attribute vrf.



25
26
27
# File 'lib/cisco_node_utils/pim.rb', line 25

def vrf
  @vrf
end

Class Method Details

.afi_cli(afi) ⇒ Object



79
80
81
82
83
84
# File 'lib/cisco_node_utils/pim.rb', line 79

def self.afi_cli(afi)
  # Add ipv6 support later
  fail ArgumentError, "Argument afi must be 'ipv4'" unless
    afi[/(ipv4)/]
  afi[/ipv4/] ? 'ip' : afi
end

.feature_enableObject



46
47
48
# File 'lib/cisco_node_utils/pim.rb', line 46

def self.feature_enable
  config_set('pim', 'feature')
end

.feature_enabledObject



38
39
40
41
42
43
44
# File 'lib/cisco_node_utils/pim.rb', line 38

def self.feature_enabled
  config_get('pim', 'feature')
rescue Cisco::CliError => e
  # cmd will syntax reject when feature is not enabled
  raise unless e.clierror =~ /Syntax error/
  return false
end

.pimsObject

self.pims returns a hash of all current pim objects. There will be one object for each vrf. This method has slightly different behavior than most of the other “get all objects” methods because the pim properties are standalone and do not reside in a “pim” container; therefore, this method simply returns a pim object for each vrf regardless of whether there are any specific pim properties currently defined for the context.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cisco_node_utils/pim.rb', line 57

def self.pims
  afis = %w(ipv4) # TBD: No support for ipv6 at this time
  hash_final = {}
  afis.each do |afi|
    hash_final[afi] = {}
    default_vrf = 'default'
    hash_final[afi][default_vrf] = Pim.new(afi, default_vrf, false)

    # Now the vrf's
    vrf_ids = config_get('vrf', 'all_vrfs')
    vrf_ids.delete_if { |vrf_id| vrf_id == 'management' }
    vrf_ids.each do |vrf|
      hash_final[afi][vrf] = Pim.new(afi, vrf, false)
    end
  end
  hash_final
rescue Cisco::CliError => e
  # cmd will syntax reject when feature is not enabled
  raise unless e.clierror =~ /Syntax error/
  return {}
end

Instance Method Details

#destroyObject

This destroy method is different than most because pim does not have a “container” for properties, they simply exist in a given vrf context. For that reason destroy needs to explicitly set each property to its default state.



101
102
103
# File 'lib/cisco_node_utils/pim.rb', line 101

def destroy
  self.ssm_range = ''
end

#set_args_keys(hash = {}) ⇒ Object

rubocop:disable Style/AccessorMethodName



92
93
94
95
# File 'lib/cisco_node_utils/pim.rb', line 92

def set_args_keys(hash={}) # rubocop:disable Style/AccessorMethodName
  set_args_keys_default
  @set_args = @get_args.merge!(hash) unless hash.empty?
end

#set_args_keys_defaultObject



86
87
88
89
90
# File 'lib/cisco_node_utils/pim.rb', line 86

def set_args_keys_default
  keys = { afi: @afi }
  keys[:vrf] = @vrf unless @vrf == 'default'
  @get_args = @set_args = keys
end

#ssm_rangeObject


Properties




108
109
110
# File 'lib/cisco_node_utils/pim.rb', line 108

def ssm_range
  config_get('pim', 'ssm_range', @get_args)
end

#ssm_range=(range) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/cisco_node_utils/pim.rb', line 112

def ssm_range=(range)
  if range.empty?
    state = 'no'
    range = ssm_range
    return if range.nil?
  else
    state = ''
  end
  set_args_keys(state: state, ssm_range: range)
  config_set('pim', 'ssm_range', @set_args)
end