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

client, #client, config_get, #config_get, #config_get_default, config_get_default, config_set, #config_set, #get, #ios_xr?, #nexus?, #node, node, platform, #platform, supports?, #supports?

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

  Feature.pim_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



68
69
70
71
72
73
# File 'lib/cisco_node_utils/pim.rb', line 68

def self.afi_cli(afi)
  # Add ipv6 support later
  fail ArgumentError, "Argument afi must be 'ipv4'" unless
    afi[/(ipv4)/]
  afi[/ipv4/] ? 'ip' : afi
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.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/cisco_node_utils/pim.rb', line 45

def self.pims
  afis = %w(ipv4) # TBD: No support for ipv6 at this time
  hash_final = {}
  return hash_final unless Feature.pim_enabled?
  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

#bfdObject



115
116
117
# File 'lib/cisco_node_utils/pim.rb', line 115

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

#bfd=(val) ⇒ Object



119
120
121
122
123
124
125
# File 'lib/cisco_node_utils/pim.rb', line 119

def bfd=(val)
  return if val == bfd
  state = val ? '' : 'no'
  set_args_keys(state: state)
  Feature.bfd_enable if val
  config_set('pim', 'bfd', @set_args)
end

#default_bfdObject



127
128
129
# File 'lib/cisco_node_utils/pim.rb', line 127

def default_bfd
  config_get_default('pim', 'bfd')
end

#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.



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

def destroy
  return unless Feature.pim_enabled?
  self.ssm_range = ''
  self.bfd = false
end

#set_args_keys(hash = {}) ⇒ Object

rubocop:disable Style/AccessorMethodName



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

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



75
76
77
78
79
# File 'lib/cisco_node_utils/pim.rb', line 75

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

#ssm_rangeObject


Properties




99
100
101
# File 'lib/cisco_node_utils/pim.rb', line 99

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

#ssm_range=(range) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/cisco_node_utils/pim.rb', line 103

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