Class: Cisco::SnmpCommunity
Overview
SnmpCommunity - node utility class for SNMP community config management
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, group, instantiate = true) ⇒ SnmpCommunity
Returns a new instance of SnmpCommunity.
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/cisco_node_utils/snmpcommunity.rb', line 24
def initialize(name, group, instantiate=true)
fail TypeError unless name.is_a?(String)
fail TypeError unless group.is_a?(String)
@name = name
return unless instantiate
if platform == :nexus
config_set('snmp_community', 'community',
state: '',
name: @name,
group: group)
else
config_set('snmp_community', 'community',
state: '',
name: @name)
config_set('snmp_community', 'group_simple', state: '', group: group)
config_set('snmp_community', 'group_community_mapping', name: @name, group: group) end
end
|
Class Method Details
.communities ⇒ Object
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/cisco_node_utils/snmpcommunity.rb', line 44
def self.communities
@communities = {}
comms = config_get('snmp_community', 'all_communities')
unless comms.nil?
comms.each do |comm|
@communities[comm] = SnmpCommunity.new(comm, '', false)
end
end
@communities
end
|
.default_acl ⇒ Object
105
106
107
|
# File 'lib/cisco_node_utils/snmpcommunity.rb', line 105
def self.default_acl
config_get_default('snmp_community', 'acl')
end
|
.default_group ⇒ Object
87
88
89
|
# File 'lib/cisco_node_utils/snmpcommunity.rb', line 87
def self.default_group
config_get_default('snmp_community', 'group')
end
|
Instance Method Details
#acl ⇒ Object
91
92
93
|
# File 'lib/cisco_node_utils/snmpcommunity.rb', line 91
def acl
config_get('snmp_community', 'acl', name: @name)
end
|
#acl=(acl) ⇒ Object
95
96
97
98
99
100
101
102
103
|
# File 'lib/cisco_node_utils/snmpcommunity.rb', line 95
def acl=(acl)
fail TypeError unless acl.is_a?(String)
if acl.empty?
acl = self.acl
config_set('snmp_community', 'acl', state: 'no', name: @name, acl: acl) unless acl.empty? else
config_set('snmp_community', 'acl', state: '', name: @name, acl: acl)
end
end
|
#destroy ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/cisco_node_utils/snmpcommunity.rb', line 55
def destroy
config_set('snmp_community', 'community',
state: 'no',
name: @name,
group: 'null')
end
|
#group ⇒ Object
name is read only
def name
@name
end
68
69
70
71
72
73
74
|
# File 'lib/cisco_node_utils/snmpcommunity.rb', line 68
def group
if platform == :nexus
config_get('snmp_community', 'group', name: @name)
else
config_get('snmp_community', 'group_community_mapping', name: @name)
end
end
|
#group=(group) ⇒ Object
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/cisco_node_utils/snmpcommunity.rb', line 76
def group=(group)
fail TypeError unless group.is_a?(String)
if platform == :nexus
config_set('snmp_community', 'group', name: @name, group: group)
else
config_set('snmp_community', 'group_simple', group: group)
config_set('snmp_community', 'group_community_mapping', name: @name, group: group) end
end
|