Class: Cisco::RadiusGlobal

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

Overview

RadiusGlobal - node utility class for Radius Global configuration management

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(name) ⇒ RadiusGlobal


27
28
29
30
31
32
33
# File 'lib/cisco_node_utils/radius_global.rb', line 27

def initialize(name)
  fail TypeError unless name.is_a?(String)
  fail ArgumentError,
       "This provider only accepts an id of 'default'" \
       unless name.eql?('default')
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


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

def name
  @name
end

Class Method Details

.radius_globalObject


35
36
37
38
39
# File 'lib/cisco_node_utils/radius_global.rb', line 35

def self.radius_global
  hash = {}
  hash['default'] = RadiusGlobal.new('default')
  hash
end

Instance Method Details

#==(other) ⇒ Object


41
42
43
# File 'lib/cisco_node_utils/radius_global.rb', line 41

def ==(other)
  name == other.name
end

#default_retransmit_countObject


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

def default_retransmit_count
  config_get_default('radius_global', 'retransmit').to_i
end

#default_source_interfaceObject

Get default source interface


142
143
144
# File 'lib/cisco_node_utils/radius_global.rb', line 142

def default_source_interface
  config_get_default('radius_global', 'source_interface')
end

#default_timeoutObject


49
50
51
# File 'lib/cisco_node_utils/radius_global.rb', line 49

def default_timeout
  config_get_default('radius_global', 'timeout')
end

#keyObject


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

def key
  str = config_get('radius_global', 'key')
  return if str.nil?
  str.strip
end

#key_formatObject


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

def key_format
  config_get('radius_global', 'key_format')
end

#key_set(value, format) ⇒ Object


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/cisco_node_utils/radius_global.rb', line 109

def key_set(value, format)
  unless value.nil?
    fail ArgumentError, 'value must be a String' \
      unless value.is_a?(String)
  end

  unless format.nil?
    fail ArgumentError, 'format must be an Integer' \
      unless format.is_a?(Integer)
  end

  if value.nil? && !key.nil?
    value = Utils.add_quotes(key)
    config_set('radius_global',
               'key',
               state: 'no',
               key:   "#{key_format} #{value}")
  elsif !format.nil?
    value = Utils.add_quotes(value)
    config_set('radius_global',
               'key',
               state: '',
               key:   "#{format} #{value}")
  else
    value = Utils.add_quotes(value)
    config_set('radius_global',
               'key',
               state: '',
               key:   "#{value}")
  end
end

#retransmit_countObject


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

def retransmit_count
  config_get('radius_global', 'retransmit')
end

#retransmit_count=(val) ⇒ Object


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/cisco_node_utils/radius_global.rb', line 80

def retransmit_count=(val)
  unless val.nil?
    fail ArgumentError, 'retransmit_count must be an Integer' \
      unless val.is_a?(Integer)
  end

  if val.nil?
    config_set('radius_global',
               'retransmit',
               state: 'no',
               count: retransmit_count)
  else
    config_set('radius_global',
               'retransmit',
               state: '',
               count: val)
  end
end

#source_interfaceObject

Get source interface


160
161
162
163
# File 'lib/cisco_node_utils/radius_global.rb', line 160

def source_interface
  i = config_get('radius_global', 'source_interface')
  i.nil? ? default_source_interface : i.downcase
end

#source_interface=(name) ⇒ Object

Set source interface


147
148
149
150
151
152
153
154
155
156
157
# File 'lib/cisco_node_utils/radius_global.rb', line 147

def source_interface=(name)
  if name
    config_set(
      'radius_global', 'source_interface',
      state: '', source_interface: name)
  else
    config_set(
      'radius_global', 'source_interface',
      state: 'no', source_interface: '')
  end
end

#timeoutObject


45
46
47
# File 'lib/cisco_node_utils/radius_global.rb', line 45

def timeout
  config_get('radius_global', 'timeout')
end

#timeout=(val) ⇒ Object


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/cisco_node_utils/radius_global.rb', line 53

def timeout=(val)
  unless val.nil?
    fail ArgumentError, 'timeout must be an Integer' \
      unless val.is_a?(Integer)
  end

  if val.nil?
    config_set('radius_global',
               'timeout',
               state:   'no',
               timeout: timeout)
  else
    config_set('radius_global',
               'timeout',
               state:   '',
               timeout: val)
  end
end