Class: Cisco::PimGroupList

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

Overview

node_utils class for pim grouplist

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, group, instantiate = true) ⇒ PimGroupList

Constructor with grouplist and vrf



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

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

  create if instantiate
end

Instance Attribute Details

#afiObject (readonly)

Returns the value of attribute afi


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

def afi
  @afi
end

#groupObject (readonly)

Returns the value of attribute group


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

def group
  @group
end

#rp_addrObject (readonly)

Returns the value of attribute rp_addr


25
26
27
# File 'lib/cisco_node_utils/pim_group_list.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_group_list.rb', line 25

def vrf
  @vrf
end

Class Method Details

.group_listsObject

Create a hash of [afi][rp-addr,grouplist]



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
72
73
74
75
76
77
# File 'lib/cisco_node_utils/pim_group_list.rb', line 42

def self.group_lists
  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_group_lists', get_args)
    unless rp_addrs.nil?
      rp_addrs.each do |addr_and_group|
        addr, group = addr_and_group
        hash[afi][default_vrf] ||= {}
        hash[afi][default_vrf][addr_and_group] =
          PimGroupList.new(afi, default_vrf, addr, group, false)
      end
    end
    vrf_ids = config_get('vrf', 'all_vrfs')
    vrf_ids.each do |vrf|
      get_args = { vrf: vrf, afi: Pim.afi_cli(afi) }
      rp_addrs = config_get('pim', 'all_group_lists', get_args)
      next if rp_addrs.nil?
      rp_addrs.each do |addr_and_group|
        hash[afi][vrf] ||= {}
        addr, group = addr_and_group
        hash[afi][vrf][addr_and_group] =
          PimGroupList.new(afi, vrf, addr, group, 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 grouplist instance



96
97
98
99
100
# File 'lib/cisco_node_utils/pim_group_list.rb', line 96

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

#destroyObject

Destroy pim grouplist instance



104
105
106
107
# File 'lib/cisco_node_utils/pim_group_list.rb', line 104

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

#set_args_keys(hash = {}) ⇒ Object

set_args_key



89
90
91
92
# File 'lib/cisco_node_utils/pim_group_list.rb', line 89

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



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

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