Class: Puppet::Provider::SnmpCommunity::CiscoNexus

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

Overview

Implementation for the snmp_community type using the Resource API.

Instance Method Summary collapse

Instance Method Details

#canonicalize(_context, resources) ⇒ Object



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

def canonicalize(_context, resources)
  resources
end

#create(context, name, should) ⇒ Object



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

def create(context, name, should)
  context.notice("Creating '#{name}' with #{should.inspect}")
  snmp_community = Cisco::SnmpCommunity.new(name, should[:group])
  should_apply(snmp_community, should)
end

#delete(context, name) ⇒ Object



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

def delete(context, name)
  context.notice("Destroying '#{name}'")
  @snmp_communities = Cisco::SnmpCommunity.communities
  @snmp_communities[name].destroy
end

#get(_context, communities = nil) ⇒ Object



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

def get(_context, communities=nil)
  require 'cisco_node_utils'
  current_states = []
  if communities.nil? || communities.empty?
    @snmp_communities = Cisco::SnmpCommunity.communities
    @snmp_communities.each do |community, instance|
      current_states << get_current_state(community, instance)
    end
  else
    communities.each do |community|
      @snmp_communities = Cisco::SnmpCommunity.communities
      individual_community = @snmp_communities[community]
      next if individual_community.nil?
      current_states << get_current_state(community, individual_community)
    end
  end
  current_states
end

#get_current_state(name, instance) ⇒ Object



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

def get_current_state(name, instance)
  {
    name:   name,
    ensure: 'present',
    acl:    instance.acl,
    group:  instance.group,
  }
end

#should_apply(snmp_community, should) ⇒ Object



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

def should_apply(snmp_community, should)
  [:acl, :group].each do |property|
    snmp_community.send("#{property}=", should[property]) if should[property] && snmp_community.respond_to?("#{property}=")
  end
end

#update(context, name, should) ⇒ Object



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

def update(context, name, should)
  context.notice("Updating '#{name}' with #{should.inspect}")
  @snmp_communities = Cisco::SnmpCommunity.communities
  snmp_community = @snmp_communities[name]
  should_apply(snmp_community, should)
end