Class: Puppet::Provider::RadiusServerGroup::CiscoNexus

Inherits:
ResourceApi::SimpleProvider
  • Object
show all
Defined in:
lib/puppet/provider/radius_server_group/cisco_nexus.rb

Overview

Implementation for the radius_server_group type using the Resource API.

Instance Method Summary collapse

Instance Method Details

#canonicalize(_context, resources) ⇒ Object



18
19
20
# File 'lib/puppet/provider/radius_server_group/cisco_nexus.rb', line 18

def canonicalize(_context, resources)
  resources
end

#create(context, name, should) ⇒ Object



63
64
65
66
# File 'lib/puppet/provider/radius_server_group/cisco_nexus.rb', line 63

def create(context, name, should)
  context.notice("Creating '#{name}' with #{should.inspect}")
  create_update(name, should, true)
end

#create_update(name, should, create_bool) ⇒ Object



58
59
60
61
# File 'lib/puppet/provider/radius_server_group/cisco_nexus.rb', line 58

def create_update(name, should, create_bool)
  radius_server_group = Cisco::RadiusServerGroup.new(name, create_bool)
  radius_server_group.servers = munge(should[:servers]) if should[:servers]
end

#delete(context, name) ⇒ Object



73
74
75
76
77
# File 'lib/puppet/provider/radius_server_group/cisco_nexus.rb', line 73

def delete(context, name)
  context.notice("Deleting '#{name}'")
  radius_server_group = Cisco::RadiusServerGroup.new(name, false)
  radius_server_group.destroy
end

#get(_context, groups = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/puppet/provider/radius_server_group/cisco_nexus.rb', line 22

def get(_context, groups=nil)
  require 'cisco_node_utils'

  radius_server_groups = []
  @radiusgroups = Cisco::RadiusServerGroup.radius_server_groups

  if groups.nil? || groups.empty?
    @radiusgroups.each_value do |v|
      radius_server_groups << get_current_state(v.name, v)
    end
  else
    groups.each do |group|
      individual_group = @radiusgroups[group]
      next if individual_group.nil?
      radius_server_groups << get_current_state(individual_group.name, individual_group)
    end
  end
  radius_server_groups
end

#get_current_state(name, instance) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/puppet/provider/radius_server_group/cisco_nexus.rb', line 42

def get_current_state(name, instance)
  {
    ensure:  'present',
    name:    name,
    servers: instance.servers.empty? ? ['unset'] : instance.servers,
  }
end

#munge(val) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/puppet/provider/radius_server_group/cisco_nexus.rb', line 50

def munge(val)
  if val.is_a?(Array) && val.length == 1 && val[0].eql?('unset')
    []
  else
    val
  end
end

#update(context, name, should) ⇒ Object



68
69
70
71
# File 'lib/puppet/provider/radius_server_group/cisco_nexus.rb', line 68

def update(context, name, should)
  context.notice("Updating '#{name}' with #{should.inspect}")
  create_update(name, should, false)
end