Class: Cisco::RadiusServerGroup

Inherits:
NodeUtil
  • Object
show all
Defined in:
lib/cisco_node_utils/radius_server_group.rb

Overview

RadiusServerGroup - node utility class for Raidus Server 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, instantiate = true) ⇒ RadiusServerGroup


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

def initialize(name, instantiate=true)
  unless name.is_a?(String)
    fail ArgumentError, 'Invalid value (Name is not a String)'
  end

  @name = name

  create if instantiate
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


26
27
28
# File 'lib/cisco_node_utils/radius_server_group.rb', line 26

def name
  @name
end

Class Method Details

.radius_server_groupsObject


38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cisco_node_utils/radius_server_group.rb', line 38

def self.radius_server_groups
  hash = {}
  group_list = config_get('radius_server_group', 'group')
  return hash if group_list.nil?

  group_list.each do |id|
    hash[id] = RadiusServerGroup.new(id, false)
  end

  hash
end

Instance Method Details

#==(other) ⇒ Object


64
65
66
# File 'lib/cisco_node_utils/radius_server_group.rb', line 64

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

#createObject


50
51
52
53
54
55
# File 'lib/cisco_node_utils/radius_server_group.rb', line 50

def create
  config_set('radius_server_group',
             'group',
             state: '',
             name:  @name)
end

#default_serversObject


68
69
70
# File 'lib/cisco_node_utils/radius_server_group.rb', line 68

def default_servers
  config_get_default('radius_server_group', 'servers')
end

#destroyObject


57
58
59
60
61
62
# File 'lib/cisco_node_utils/radius_server_group.rb', line 57

def destroy
  config_set('radius_server_group',
             'group',
             state: 'no',
             name:  @name)
end

#serversObject


72
73
74
75
76
# File 'lib/cisco_node_utils/radius_server_group.rb', line 72

def servers
  val = config_get('radius_server_group', 'servers', @name)
  val = default_servers if val.nil?
  val
end

#servers=(val) ⇒ Object


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/cisco_node_utils/radius_server_group.rb', line 78

def servers=(val)
  fail ArgumentError, 'Servers must be an array of valid IP addresses' \
    unless val.is_a?(Array)

  current = servers

  # Remove IPs that are no longer required
  current.each do |old_ip|
    next if val.include?(old_ip)
    config_set('radius_server_group',
               'servers',
               group: @name,
               state: 'no',
               ip:    old_ip)
  end

  # Add new IPs that aren't already on the device
  val.each do |new_ip|
    unless new_ip =~ /^[a-zA-Z0-9\.\:]*$/
      fail ArgumentError,
           'Servers must be an array of valid IPv4/IPv6 addresses'
    end

    begin
      IPAddr.new(new_ip)
    rescue
      raise ArgumentError,
            'Servers must be an array of valid IPv4/IPv6 addresses'
    end

    next unless current.nil? || !current.include?(new_ip)
    config_set('radius_server_group',
               'servers',
               group: @name,
               state: '',
               ip:    new_ip)
  end
end