Class: Cisco::ItdDeviceGroupNode

Inherits:
ItdDeviceGroup show all
Defined in:
lib/cisco_node_utils/itd_device_group_node.rb

Overview

node_utils class for itd_device_group_node

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ItdDeviceGroup

#create, #default_probe_control, #default_probe_frequency, #default_probe_retry_down, #default_probe_retry_up, #default_probe_timeout, #default_probe_type, itds, #probe_control, #probe_control=, #probe_dns_host, #probe_dns_host=, #probe_frequency, #probe_frequency=, #probe_get, #probe_port, #probe_port=, #probe_retry_down, #probe_retry_down=, #probe_retry_up, #probe_retry_up=, #probe_set, #probe_timeout, #probe_timeout=, #probe_type, #probe_type=, #set_args_keys

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(itd_dg_name, node_name, node_type, instantiate = true) ⇒ ItdDeviceGroupNode


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cisco_node_utils/itd_device_group_node.rb', line 25

def initialize(itd_dg_name, node_name, node_type, instantiate=true)
  fail TypeError unless itd_dg_name.is_a?(String)
  fail TypeError unless node_name.is_a?(String)
  fail ArgumentError unless itd_dg_name.length > 0
  fail ArgumentError unless node_name.length > 0

  @itd_device_group_name = itd_dg_name
  @itddg = ItdDeviceGroup.itds[itd_dg_name]
  fail "itd device-group #{itd_dg_name} does not exist" if
  @itddg.nil?
  @name = node_name
  @node_type = node_type

  set_args_keys_default
  create_node if instantiate
end

Instance Attribute Details

#itd_device_group_nameObject (readonly)

Returns the value of attribute itd_device_group_name


23
24
25
# File 'lib/cisco_node_utils/itd_device_group_node.rb', line 23

def itd_device_group_name
  @itd_device_group_name
end

#nameObject (readonly)

Returns the value of attribute name


23
24
25
# File 'lib/cisco_node_utils/itd_device_group_node.rb', line 23

def name
  @name
end

#node_typeObject (readonly)

Returns the value of attribute node_type


23
24
25
# File 'lib/cisco_node_utils/itd_device_group_node.rb', line 23

def node_type
  @node_type
end

Class Method Details

.itd_nodes(node_name = nil) ⇒ Object

itd_device_group_nodes have the name form as node ip 1.1.1.1 node IPv6 2000::1 and they depdend on the device_group


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

def self.itd_nodes(node_name=nil)
  fail TypeError unless node_name.is_a?(String) || node_name.nil?
  itd_nodes = {}
  itd_list = ItdDeviceGroup.itds
  return itd_nodes if itd_list.nil?
  itd_list.keys.each do |name|
    itd_nodes[name] = {}
    match = config_get('itd_device_group',
                       'all_itd_device_group_nodes', name: name)
    next if match.nil?
    match.each do |vars|
      ntype = vars[0]
      nname = vars[1].strip
      next unless node_name.nil? || nname == node_name
      itd_nodes[name][nname] =
          ItdDeviceGroupNode.new(name, nname, ntype, false)
    end
  end
  itd_nodes
end

Instance Method Details

#==(other) ⇒ Object

PROPERTIES #


71
72
73
74
# File 'lib/cisco_node_utils/itd_device_group_node.rb', line 71

def ==(other)
  (itd_device_group_name == other.itd_device_group_name) &&
    (name == other.name) && (node_type == other.node_type)
end

#create_nodeObject


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

def create_node
  config_set('itd_device_group', 'create_node',
             name: @itddg.name, ntype: @node_type, nname: @name)
end

#default_hot_standbyObject


106
107
108
# File 'lib/cisco_node_utils/itd_device_group_node.rb', line 106

def default_hot_standby
  config_get_default('itd_device_group', 'hot_standby')
end

#default_weightObject


140
141
142
# File 'lib/cisco_node_utils/itd_device_group_node.rb', line 140

def default_weight
  config_get_default('itd_device_group', 'weight')
end

#destroyObject


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

def destroy
  config_set('itd_device_group', 'destroy_node', name: @itddg.name,
            ntype: @node_type, nname: @name)
end

#hot_standbyObject


94
95
96
# File 'lib/cisco_node_utils/itd_device_group_node.rb', line 94

def hot_standby
  config_get('itd_device_group', 'hot_standby', @get_args)
end

#hs_weight(hs, wt) ⇒ Object

Call this for setting hot_standby and weight together because the CLI is pretty weird and it accepts these params in a very particular way and they cannot even be reset unless proper order is followed


125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/cisco_node_utils/itd_device_group_node.rb', line 125

def hs_weight(hs, wt)
  if hs != hot_standby && hot_standby == default_hot_standby
    self.lweight = wt unless weight == wt
    self.lhot_standby = hs
  elsif hs != hot_standby && hot_standby != default_hot_standby
    self.lhot_standby = hs
    self.lweight = wt unless weight == wt
  elsif wt != weight && weight == default_weight
    self.lweight = wt
  elsif wt != weight && weight != default_weight
    self.lweight = wt
  end
  set_args_keys_default
end

#lhot_standby=(state) ⇒ Object

DO NOT call this directly


99
100
101
102
103
104
# File 'lib/cisco_node_utils/itd_device_group_node.rb', line 99

def lhot_standby=(state)
  no_cmd = (state ? '' : 'no')
  @set_args[:state] = no_cmd
  config_set('itd_device_group', 'hot_standby', @set_args)
  set_args_keys_default
end

#lweight=(val) ⇒ Object

DO NOT call this directly


115
116
117
118
119
# File 'lib/cisco_node_utils/itd_device_group_node.rb', line 115

def lweight=(val)
  @set_args[:state] = val == default_weight ? 'no' : ''
  @set_args[:weight] = val
  config_set('itd_device_group', 'weight', @set_args)
end

#set_args_keys_defaultObject

Helper method to delete @set_args hash keys


87
88
89
90
91
92
# File 'lib/cisco_node_utils/itd_device_group_node.rb', line 87

def set_args_keys_default
  @set_args = { name: @itddg.name }
  @set_args[:ntype] = @node_type
  @set_args[:nname] = @name
  @get_args = @set_args
end

#weightObject


110
111
112
# File 'lib/cisco_node_utils/itd_device_group_node.rb', line 110

def weight
  config_get('itd_device_group', 'weight', @get_args)
end