Class: Puppet::Provider::TacacsServerGroup::CiscoNexus

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

Overview

Implementation for the tacacs_server_group type using the Resource API.

Instance Method Summary collapse

Instance Method Details

#canonicalize(_context, resources) ⇒ Object



18
19
20
21
22
# File 'lib/puppet/provider/tacacs_server_group/cisco_nexus.rb', line 18

def canonicalize(_context, resources)
  resources.each do |resource|
    resource[:servers] = resource[:servers].sort_by(&:to_i) if resource[:servers]
  end
end

#create(context, name, should) ⇒ Object



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

def create(context, name, should)
  context.notice("Creating '#{name}' with #{should.inspect}")
  Cisco::TacacsServerGroup.new(name)
  handle_update(name, should)
end

#delete(context, name) ⇒ Object



76
77
78
79
80
# File 'lib/puppet/provider/tacacs_server_group/cisco_nexus.rb', line 76

def delete(context, name)
  context.notice("Destroying '#{name}'")
  @tacacs_servers = Cisco::TacacsServerGroup.tacacs_server_groups
  @tacacs_servers[name].destroy if @tacacs_servers[name]
end

#get(_context, servers = nil) ⇒ Object



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

def get(_context, servers=nil)
  require 'cisco_node_utils'
  current_states = []
  # using = instead of ||= due to creation behaviour and having
  # to reevaluate the hosts upon creation
  @tacacs_servers = Cisco::TacacsServerGroup.tacacs_server_groups
  if servers.nil? || servers.empty?
    @tacacs_servers.each do |server, instance|
      current_states << get_current_state(server, instance)
    end
  else
    servers.each do |server|
      individual_server = @tacacs_servers[server]
      next if individual_server.nil?
      current_states << get_current_state(server, individual_server)
    end
  end
  current_states
end

#get_current_state(server, instance) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/puppet/provider/tacacs_server_group/cisco_nexus.rb', line 44

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

#handle_update(name, should) ⇒ Object



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

def handle_update(name, should)
  @tacacs_servers = Cisco::TacacsServerGroup.tacacs_server_groups
  @tacacs_servers[name].servers = munge(should[:servers]) if should[:servers]
end

#munge(value) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/puppet/provider/tacacs_server_group/cisco_nexus.rb', line 68

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

#update(context, name, should) ⇒ Object



52
53
54
55
# File 'lib/puppet/provider/tacacs_server_group/cisco_nexus.rb', line 52

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