Class: Cisco::PimRpAddress

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

Overview

node_utils class for pim_rp_address

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, rp_addr, instantiate = true) ⇒ PimRpAddress

Constructor with afi, rp_address and vrf




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

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

Instance Attribute Details

#afiObject (readonly)

Returns the value of attribute afi.



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

def afi
  @afi
end

#rp_addrObject (readonly)

Returns the value of attribute rp_addr.



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

def rp_addr
  @rp_addr
end

#vrfObject (readonly)

Returns the value of attribute vrf.



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

def vrf
  @vrf
end

Class Method Details

.rp_addressesObject

Create a hash of [afi][rp_address]




39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/cisco_node_utils/pim_rp_address.rb', line 39

def self.rp_addresses
  afis = %w(ipv4) # TBD ipv6
  hash = {}
  return hash unless Feature.pim_enabled?
  afis.each do |afi|
    hash[afi] = {}
    default_vrf = 'default'
    get_args = { afi: Pim.afi_cli(afi) }
    rp_addrs = config_get('pim', 'all_rp_addresses', get_args)
    unless rp_addrs.nil?
      rp_addrs.each do |addr|
        hash[afi][default_vrf] ||= {}
        hash[afi][default_vrf][addr] =
          PimRpAddress.new(afi, default_vrf, addr, false)
      end
    end
    vrf_ids = config_get('vrf', 'all_vrfs')
    vrf_ids.each do |vrf|
      get_args = { afi: Pim.afi_cli(afi), vrf: vrf }
      rp_addrs = config_get('pim', 'all_rp_addresses', get_args)
      next if rp_addrs.nil?
      rp_addrs.each do |addr|
        hash[afi][vrf] ||= {}
        hash[afi][vrf][addr] = PimRpAddress.new(afi, vrf, addr, false)
      end
    end
  end
  hash
rescue Cisco::CliError => e
  # cmd will syntax reject when feature is not enabled
  raise unless e.clierror =~ /Syntax error/
  return {}
end

Instance Method Details

#createObject

Create pim rp_addr instance




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

def create
  Feature.pim_enable
  set_args_keys(state: '')
  config_set('pim', 'rp_address', @set_args)
end

#destroyObject

Destroy pim rp_addr instance




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

def destroy
  set_args_keys(state: 'no')
  config_set('pim', 'rp_address', @set_args)
end

#set_args_keys(hash = {}) ⇒ Object

set_args_key




83
84
85
86
# File 'lib/cisco_node_utils/pim_rp_address.rb', line 83

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

set_args_keys_default




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

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