cisco_node_utils 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/CHANGELOG.md +126 -1
  4. data/README.md +19 -12
  5. data/Rakefile +1 -0
  6. data/bin/git/hooks/commit-msg/enforce_style +8 -0
  7. data/cisco_node_utils.gemspec +4 -3
  8. data/docs/README-develop-best-practices.md +127 -109
  9. data/docs/README-develop-node-utils-APIs.md +47 -39
  10. data/docs/template-router.rb +3 -7
  11. data/lib/.rubocop.yml +4 -4
  12. data/lib/cisco_node_utils.rb +1 -1
  13. data/lib/cisco_node_utils/aaa_authentication_login.rb +96 -0
  14. data/lib/cisco_node_utils/aaa_authentication_login_service.rb +133 -0
  15. data/lib/cisco_node_utils/aaa_authorization_service.rb +150 -0
  16. data/lib/cisco_node_utils/ace.rb +196 -0
  17. data/lib/cisco_node_utils/acl.rb +100 -0
  18. data/lib/cisco_node_utils/bgp.rb +301 -163
  19. data/lib/cisco_node_utils/bgp_af.rb +187 -19
  20. data/lib/cisco_node_utils/bgp_neighbor.rb +18 -33
  21. data/lib/cisco_node_utils/bgp_neighbor_af.rb +25 -48
  22. data/lib/cisco_node_utils/cisco_cmn_utils.rb +23 -4
  23. data/lib/cisco_node_utils/cmd_ref/README_YAML.md +593 -0
  24. data/lib/cisco_node_utils/cmd_ref/aaa_auth_login_service.yaml +22 -0
  25. data/lib/cisco_node_utils/cmd_ref/aaa_authentication_login.yaml +31 -0
  26. data/lib/cisco_node_utils/cmd_ref/aaa_authorization_service.yaml +22 -0
  27. data/lib/cisco_node_utils/cmd_ref/acl.yaml +43 -0
  28. data/lib/cisco_node_utils/cmd_ref/bgp.yaml +242 -0
  29. data/lib/cisco_node_utils/cmd_ref/bgp_af.yaml +164 -0
  30. data/lib/cisco_node_utils/cmd_ref/bgp_neighbor.yaml +131 -0
  31. data/lib/cisco_node_utils/cmd_ref/bgp_neighbor_af.yaml +179 -0
  32. data/lib/cisco_node_utils/cmd_ref/dnsclient.yaml +34 -0
  33. data/lib/cisco_node_utils/cmd_ref/evpn_vni.yaml +42 -0
  34. data/lib/cisco_node_utils/cmd_ref/fabricpath.yaml +172 -0
  35. data/lib/cisco_node_utils/cmd_ref/fabricpath_topology.yaml +35 -0
  36. data/lib/cisco_node_utils/cmd_ref/feature.yaml +42 -0
  37. data/lib/cisco_node_utils/cmd_ref/fex.yaml +9 -0
  38. data/lib/cisco_node_utils/cmd_ref/images.yaml +7 -0
  39. data/lib/cisco_node_utils/cmd_ref/interface.yaml +339 -0
  40. data/lib/cisco_node_utils/cmd_ref/interface_channel_group.yaml +28 -0
  41. data/lib/cisco_node_utils/cmd_ref/interface_ospf.yaml +61 -0
  42. data/lib/cisco_node_utils/cmd_ref/interface_portchannel.yaml +54 -0
  43. data/lib/cisco_node_utils/cmd_ref/interface_service_vni.yaml +32 -0
  44. data/lib/cisco_node_utils/cmd_ref/inventory.yaml +45 -0
  45. data/lib/cisco_node_utils/cmd_ref/memory.yaml +13 -0
  46. data/lib/cisco_node_utils/cmd_ref/ntp_config.yaml +7 -0
  47. data/lib/cisco_node_utils/cmd_ref/ntp_server.yaml +14 -0
  48. data/lib/cisco_node_utils/cmd_ref/ospf.yaml +74 -0
  49. data/lib/cisco_node_utils/cmd_ref/overlay_global.yaml +33 -0
  50. data/lib/cisco_node_utils/cmd_ref/pim.yaml +40 -0
  51. data/lib/cisco_node_utils/cmd_ref/portchannel_global.yaml +69 -0
  52. data/lib/cisco_node_utils/cmd_ref/radius_global.yaml +25 -0
  53. data/lib/cisco_node_utils/cmd_ref/radius_server.yaml +64 -0
  54. data/lib/cisco_node_utils/cmd_ref/radius_server_group.yaml +14 -0
  55. data/lib/cisco_node_utils/cmd_ref/show_system.yaml +5 -0
  56. data/lib/cisco_node_utils/cmd_ref/show_version.yaml +72 -0
  57. data/lib/cisco_node_utils/cmd_ref/snmp_community.yaml +23 -0
  58. data/lib/cisco_node_utils/cmd_ref/snmp_group.yaml +7 -0
  59. data/lib/cisco_node_utils/cmd_ref/snmp_notification_receiver.yaml +50 -0
  60. data/lib/cisco_node_utils/cmd_ref/snmp_server.yaml +51 -0
  61. data/lib/cisco_node_utils/cmd_ref/snmp_user.yaml +55 -0
  62. data/lib/cisco_node_utils/cmd_ref/snmpnotification.yaml +11 -0
  63. data/lib/cisco_node_utils/cmd_ref/syslog_server.yaml +18 -0
  64. data/lib/cisco_node_utils/cmd_ref/syslog_settings.yaml +7 -0
  65. data/lib/cisco_node_utils/cmd_ref/system.yaml +6 -0
  66. data/lib/cisco_node_utils/cmd_ref/tacacs_server.yaml +49 -0
  67. data/lib/cisco_node_utils/cmd_ref/tacacs_server_group.yaml +33 -0
  68. data/lib/cisco_node_utils/cmd_ref/tacacs_server_host.yaml +35 -0
  69. data/lib/cisco_node_utils/cmd_ref/vdc.yaml +38 -0
  70. data/lib/cisco_node_utils/cmd_ref/virtual_service.yaml +6 -0
  71. data/lib/cisco_node_utils/cmd_ref/vlan.yaml +56 -0
  72. data/lib/cisco_node_utils/cmd_ref/vni.yaml +76 -0
  73. data/lib/cisco_node_utils/cmd_ref/vpc.yaml +197 -0
  74. data/lib/cisco_node_utils/cmd_ref/vrf.yaml +88 -0
  75. data/lib/cisco_node_utils/cmd_ref/vtp.yaml +38 -0
  76. data/lib/cisco_node_utils/cmd_ref/vxlan_vtep.yaml +60 -0
  77. data/lib/cisco_node_utils/cmd_ref/vxlan_vtep_vni.yaml +39 -0
  78. data/lib/cisco_node_utils/cmd_ref/yum.yaml +13 -0
  79. data/lib/cisco_node_utils/command_reference.rb +359 -187
  80. data/lib/cisco_node_utils/configparser_lib.rb +1 -1
  81. data/lib/cisco_node_utils/dns_domain.rb +19 -5
  82. data/lib/cisco_node_utils/domain_name.rb +4 -8
  83. data/lib/cisco_node_utils/evpn_vni.rb +157 -0
  84. data/lib/cisco_node_utils/fabricpath_global.rb +388 -0
  85. data/lib/cisco_node_utils/fabricpath_topology.rb +150 -0
  86. data/lib/cisco_node_utils/feature.rb +111 -0
  87. data/lib/cisco_node_utils/interface.rb +390 -97
  88. data/lib/cisco_node_utils/interface_channel_group.rb +124 -0
  89. data/lib/cisco_node_utils/interface_ospf.rb +11 -34
  90. data/lib/cisco_node_utils/interface_portchannel.rb +157 -0
  91. data/lib/cisco_node_utils/interface_service_vni.rb +132 -0
  92. data/lib/cisco_node_utils/name_server.rb +1 -1
  93. data/lib/cisco_node_utils/node.rb +55 -249
  94. data/lib/cisco_node_utils/node_util.rb +5 -1
  95. data/lib/cisco_node_utils/ntp_config.rb +2 -2
  96. data/lib/cisco_node_utils/ntp_server.rb +14 -5
  97. data/lib/cisco_node_utils/overlay_global.rb +153 -0
  98. data/lib/cisco_node_utils/pim.rb +124 -0
  99. data/lib/cisco_node_utils/pim_group_list.rb +108 -0
  100. data/lib/cisco_node_utils/pim_rp_address.rb +102 -0
  101. data/lib/cisco_node_utils/platform.rb +8 -9
  102. data/lib/cisco_node_utils/portchannel_global.rb +277 -0
  103. data/lib/cisco_node_utils/radius_global.rb +9 -19
  104. data/lib/cisco_node_utils/radius_server.rb +31 -41
  105. data/lib/cisco_node_utils/radius_server_group.rb +117 -0
  106. data/lib/cisco_node_utils/router_ospf.rb +1 -1
  107. data/lib/cisco_node_utils/router_ospf_vrf.rb +14 -19
  108. data/lib/cisco_node_utils/snmp_notification_receiver.rb +158 -0
  109. data/lib/cisco_node_utils/snmpcommunity.rb +3 -5
  110. data/lib/cisco_node_utils/snmpgroup.rb +1 -1
  111. data/lib/cisco_node_utils/snmpnotification.rb +57 -0
  112. data/lib/cisco_node_utils/snmpserver.rb +8 -17
  113. data/lib/cisco_node_utils/snmpuser.rb +67 -28
  114. data/lib/cisco_node_utils/syslog_server.rb +3 -9
  115. data/lib/cisco_node_utils/syslog_settings.rb +2 -10
  116. data/lib/cisco_node_utils/tacacs_server.rb +9 -14
  117. data/lib/cisco_node_utils/tacacs_server_group.rb +145 -0
  118. data/lib/cisco_node_utils/tacacs_server_host.rb +5 -9
  119. data/lib/cisco_node_utils/vdc.rb +88 -0
  120. data/lib/cisco_node_utils/version.rb +5 -2
  121. data/lib/cisco_node_utils/vlan.rb +71 -8
  122. data/lib/cisco_node_utils/vni.rb +227 -0
  123. data/lib/cisco_node_utils/vpc.rb +377 -0
  124. data/lib/cisco_node_utils/vrf.rb +60 -9
  125. data/lib/cisco_node_utils/vrf_af.rb +191 -0
  126. data/lib/cisco_node_utils/vtp.rb +8 -6
  127. data/lib/cisco_node_utils/vxlan_vtep.rb +151 -0
  128. data/lib/cisco_node_utils/vxlan_vtep_vni.rb +234 -0
  129. data/lib/cisco_node_utils/yum.rb +1 -1
  130. data/tests/.rubocop.yml +1 -1
  131. data/tests/basetest.rb +16 -7
  132. data/tests/ciscotest.rb +55 -13
  133. data/tests/cmd_config.yaml +2 -2
  134. data/tests/platform_info.rb +3 -2
  135. data/tests/test_aaa_authentication_login.rb +219 -0
  136. data/tests/test_aaa_authentication_login_service.rb +759 -0
  137. data/tests/test_aaa_authorization_service.rb +1041 -0
  138. data/tests/test_ace.rb +160 -0
  139. data/tests/test_acl.rb +176 -0
  140. data/tests/test_bgp_af.rb +269 -13
  141. data/tests/test_bgp_neighbor.rb +38 -40
  142. data/tests/test_bgp_neighbor_af.rb +92 -32
  143. data/tests/test_command_config.rb +5 -5
  144. data/tests/test_command_reference.rb +284 -101
  145. data/tests/test_dns_domain.rb +1 -1
  146. data/tests/test_domain_name.rb +1 -1
  147. data/tests/test_evpn_vni.rb +106 -0
  148. data/tests/test_fabricpath_global.rb +243 -0
  149. data/tests/test_fabricpath_topology.rb +98 -0
  150. data/tests/test_interface.rb +292 -74
  151. data/tests/test_interface_channel_group.rb +74 -0
  152. data/tests/test_interface_ospf.rb +9 -4
  153. data/tests/test_interface_portchannel.rb +105 -0
  154. data/tests/test_interface_service_vni.rb +232 -0
  155. data/tests/test_interface_svi.rb +77 -62
  156. data/tests/test_interface_switchport.rb +17 -5
  157. data/tests/test_name_server.rb +1 -1
  158. data/tests/test_node.rb +1 -1
  159. data/tests/test_node_ext.rb +10 -20
  160. data/tests/test_ntp_config.rb +1 -1
  161. data/tests/test_ntp_server.rb +18 -6
  162. data/tests/test_overlay_global.rb +102 -0
  163. data/tests/test_pim.rb +177 -0
  164. data/tests/test_pim_group_list.rb +181 -0
  165. data/tests/test_pim_rp_address.rb +153 -0
  166. data/tests/test_platform.rb +3 -3
  167. data/tests/test_portchannel_global.rb +202 -0
  168. data/tests/test_radius_global.rb +1 -1
  169. data/tests/test_radius_server.rb +92 -57
  170. data/tests/test_radius_server_group.rb +149 -0
  171. data/tests/test_router_bgp.rb +283 -112
  172. data/tests/test_router_ospf.rb +2 -2
  173. data/tests/test_router_ospf_vrf.rb +4 -4
  174. data/tests/test_snmp_notification_receiver.rb +167 -0
  175. data/tests/test_snmpcommunity.rb +1 -1
  176. data/tests/test_snmpgroup.rb +1 -1
  177. data/tests/test_snmpnotification.rb +72 -0
  178. data/tests/test_snmpserver.rb +29 -105
  179. data/tests/test_snmpuser.rb +32 -30
  180. data/tests/test_syslog_server.rb +36 -10
  181. data/tests/test_syslog_settings.rb +1 -1
  182. data/tests/test_tacacs_server.rb +1 -1
  183. data/tests/test_tacacs_server_group.rb +405 -0
  184. data/tests/test_tacacs_server_host.rb +1 -1
  185. data/tests/test_vdc.rb +78 -0
  186. data/tests/test_vlan.rb +74 -19
  187. data/tests/test_vlan_mt_full.rb +95 -0
  188. data/tests/test_vni.rb +106 -0
  189. data/tests/test_vpc.rb +361 -0
  190. data/tests/test_vrf.rb +172 -29
  191. data/tests/test_vtp.rb +1 -1
  192. data/tests/test_vxlan_vtep.rb +214 -0
  193. data/tests/test_vxlan_vtep_vni.rb +201 -0
  194. data/tests/test_yum.rb +1 -1
  195. metadata +120 -11
  196. data/lib/cisco_node_utils/README_YAML.md +0 -325
  197. data/lib/cisco_node_utils/command_reference_common.yaml +0 -1051
  198. data/lib/cisco_node_utils/command_reference_common_bgp.yaml +0 -535
  199. data/lib/cisco_node_utils/command_reference_n3064.yaml +0 -13
  200. data/lib/cisco_node_utils/command_reference_n7k.yaml +0 -52
  201. data/lib/cisco_node_utils/command_reference_n9k.yaml +0 -26
  202. data/tests/platform_info.yaml +0 -10
@@ -0,0 +1,117 @@
1
+ # Radius Server Group provider class
2
+
3
+ # Jonathan Tripathy et al., October 2015
4
+
5
+ # Copyright (c) 2014-2016 Cisco and/or its affiliates.
6
+
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require_relative 'node_util'
20
+ require 'ipaddr'
21
+
22
+ module Cisco
23
+ # RadiusServerGroup - node utility class for
24
+ # Raidus Server configuration management
25
+ class RadiusServerGroup < NodeUtil
26
+ attr_reader :name
27
+
28
+ def initialize(name, instantiate=true)
29
+ unless name.is_a?(String)
30
+ fail ArgumentError, 'Invalid value (Name is not a String)'
31
+ end
32
+
33
+ @name = name
34
+
35
+ create if instantiate
36
+ end
37
+
38
+ def self.radius_server_groups
39
+ hash = {}
40
+ group_list = config_get('radius_server_group', 'group')
41
+ return hash if group_list.nil?
42
+
43
+ group_list.each do |id|
44
+ hash[id] = RadiusServerGroup.new(id, false)
45
+ end
46
+
47
+ hash
48
+ end
49
+
50
+ def create
51
+ config_set('radius_server_group',
52
+ 'group',
53
+ state: '',
54
+ name: @name)
55
+ end
56
+
57
+ def destroy
58
+ config_set('radius_server_group',
59
+ 'group',
60
+ state: 'no',
61
+ name: @name)
62
+ end
63
+
64
+ def ==(other)
65
+ name == other.name
66
+ end
67
+
68
+ def default_servers
69
+ config_get_default('radius_server_group', 'servers')
70
+ end
71
+
72
+ def servers
73
+ val = config_get('radius_server_group', 'servers', @name)
74
+ val = default_servers if val.nil?
75
+ val
76
+ end
77
+
78
+ def servers=(val)
79
+ fail ArgumentError, 'Servers must be an array of valid IP addresses' \
80
+ unless val.is_a?(Array)
81
+
82
+ current = servers
83
+
84
+ # Remove IPs that are no longer required
85
+ current.each do |old_ip|
86
+ next if val.include?(old_ip)
87
+ config_set('radius_server_group',
88
+ 'servers',
89
+ group: @name,
90
+ state: 'no',
91
+ ip: old_ip)
92
+ end
93
+
94
+ # Add new IPs that aren't already on the device
95
+ val.each do |new_ip|
96
+ unless new_ip =~ /^[a-zA-Z0-9\.\:]*$/
97
+ fail ArgumentError,
98
+ 'Servers must be an array of valid IPv4/IPv6 addresses'
99
+ end
100
+
101
+ begin
102
+ IPAddr.new(new_ip)
103
+ rescue
104
+ raise ArgumentError,
105
+ 'Servers must be an array of valid IPv4/IPv6 addresses'
106
+ end
107
+
108
+ next unless current.nil? || !current.include?(new_ip)
109
+ config_set('radius_server_group',
110
+ 'servers',
111
+ group: @name,
112
+ state: '',
113
+ ip: new_ip)
114
+ end
115
+ end
116
+ end # class
117
+ end # module
@@ -1,6 +1,6 @@
1
1
  # November 2014, Chris Van Heuveln
2
2
  #
3
- # Copyright (c) 2014-2015 Cisco and/or its affiliates.
3
+ # Copyright (c) 2014-2016 Cisco and/or its affiliates.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  # Mike Wiebe, March 2015
2
2
  #
3
- # Copyright (c) 2015 Cisco and/or its affiliates.
3
+ # Copyright (c) 2015-2016 Cisco and/or its affiliates.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -56,8 +56,9 @@ module Cisco
56
56
  RouterOspf.routers.each do |instance|
57
57
  name = instance[0]
58
58
  vrf_ids = config_get('ospf', 'vrf', name: name)
59
- hash_tmp = { name =>
60
- { 'default' => RouterOspfVrf.new(name, 'default', false) } }
59
+ hash_tmp = {
60
+ name => { 'default' => RouterOspfVrf.new(name, 'default', false) }
61
+ }
61
62
  unless vrf_ids.nil?
62
63
  vrf_ids.each do |vrf|
63
64
  hash_tmp[name][vrf] = RouterOspfVrf.new(name, vrf, false)
@@ -89,12 +90,10 @@ module Cisco
89
90
  def auto_cost
90
91
  match = config_get('ospf', 'auto_cost', @get_args)
91
92
  return default_auto_cost if match.nil?
92
- # Multiple matches are possible but the first match is used.
93
- # This can be removed when rally defect DE3614 is resolved.
94
- if match[0].last.nil?
95
- [match[0].first.to_i, OSPF_AUTO_COST[:mbps]]
93
+ if match.last.nil?
94
+ [match.first.to_i, OSPF_AUTO_COST[:mbps]]
96
95
  else
97
- [match[0].first.to_i, match[0].last]
96
+ [match.first.to_i, match.last]
98
97
  end
99
98
  end
100
99
 
@@ -110,8 +109,7 @@ module Cisco
110
109
  end
111
110
 
112
111
  def default_metric
113
- match = config_get('ospf', 'default_metric', @get_args)
114
- match.nil? ? default_default_metric : match.first.to_i
112
+ config_get('ospf', 'default_metric', @get_args)
115
113
  end
116
114
 
117
115
  def default_metric=(metric)
@@ -133,9 +131,7 @@ module Cisco
133
131
  def log_adjacency
134
132
  match = config_get('ospf', 'log_adjacency', @get_args)
135
133
  return default_log_adjacency if match.nil?
136
- # Multiple matches are possible but the first match is used.
137
- # This can be removed when rally defect DE3614 is resolved.
138
- match[0].flatten.last.nil? ? :log : :detail
134
+ match.flatten.last.nil? ? :log : :detail
139
135
  end
140
136
 
141
137
  def log_adjacency=(type)
@@ -156,8 +152,7 @@ module Cisco
156
152
  end
157
153
 
158
154
  def router_id
159
- match = config_get('ospf', 'router_id', @get_args)
160
- match.nil? ? default_router_id : match.first
155
+ config_get('ospf', 'router_id', @get_args)
161
156
  end
162
157
 
163
158
  def router_id=(router_id)
@@ -179,10 +174,10 @@ module Cisco
179
174
 
180
175
  def timer_throttle_lsa
181
176
  match = config_get('ospf', 'timer_throttle_lsa', @get_args)
182
- if match.nil? || match.first.nil?
177
+ if match.nil?
183
178
  default_timer_throttle_lsa
184
179
  else
185
- match.first.collect(&:to_i)
180
+ match.collect(&:to_i)
186
181
  end
187
182
  end
188
183
 
@@ -232,10 +227,10 @@ module Cisco
232
227
 
233
228
  def timer_throttle_spf
234
229
  match = config_get('ospf', 'timer_throttle_spf', @get_args)
235
- if match.nil? || match.first.nil?
230
+ if match.nil?
236
231
  default_timer_throttle_spf
237
232
  else
238
- match.first.collect(&:to_i)
233
+ match.collect(&:to_i)
239
234
  end
240
235
  end
241
236
 
@@ -0,0 +1,158 @@
1
+ # November 2015, Jonathan Tripathy
2
+ #
3
+ # Copyright (c) 2014-2016 Cisco and/or its affiliates.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require_relative 'node_util'
18
+
19
+ module Cisco
20
+ # SnmpNotificationReceiver - node utility class for SNMP server management
21
+ class SnmpNotificationReceiver < NodeUtil
22
+ attr_reader :name
23
+
24
+ def initialize(name,
25
+ instantiate: true,
26
+ type: '',
27
+ version: '',
28
+ security: '',
29
+ username: '',
30
+ port: '',
31
+ vrf: '',
32
+ source_interface: '')
33
+
34
+ fail TypeError unless name.is_a?(String)
35
+ @name = name
36
+
37
+ fail TypeError unless type.is_a?(String)
38
+
39
+ fail TypeError unless version.is_a?(String) || version.is_a?(Integer)
40
+
41
+ fail TypeError unless security.is_a?(String)
42
+
43
+ fail TypeError unless username.is_a?(String)
44
+
45
+ fail TypeError unless port.is_a?(String) || port.is_a?(Integer)
46
+
47
+ fail TypeError unless vrf.is_a?(String)
48
+
49
+ fail TypeError unless source_interface.is_a?(String)
50
+
51
+ return unless instantiate
52
+
53
+ # Mandatory Properties
54
+ fail TypeError unless name.length > 0
55
+ fail TypeError unless type.length > 0
56
+
57
+ if version.is_a?(Integer)
58
+ fail TypeError if version <= 0
59
+ else
60
+ fail TypeError if version.length <= 0
61
+ end
62
+
63
+ fail TypeError unless username.length > 0
64
+
65
+ config_set('snmp_notification_receiver',
66
+ 'receivers',
67
+ state: '',
68
+ ip: name,
69
+ type: type,
70
+ version: version,
71
+ security: security,
72
+ username: username,
73
+ udp_port: port.empty? ? '' : "udp-port #{port}")
74
+
75
+ unless source_interface.empty?
76
+ config_set('snmp_notification_receiver',
77
+ 'source_interface',
78
+ ip: name,
79
+ source_interface: source_interface,
80
+ port: port.empty? ? '' : "udp-port #{port}")
81
+ end
82
+
83
+ return if vrf.empty?
84
+ config_set('snmp_notification_receiver',
85
+ 'vrf',
86
+ ip: name,
87
+ vrf: vrf,
88
+ port: port.empty? ? '' : "udp-port #{port}")
89
+ end
90
+
91
+ def self.receivers
92
+ hash = {}
93
+
94
+ receivers_list = config_get('snmp_notification_receiver', 'receivers')
95
+ return hash if receivers_list.nil?
96
+
97
+ receivers_list.each do |arr|
98
+ next if !arr.is_a?(Array) || arr.empty?
99
+ id = arr[0]
100
+ hash[id] = SnmpNotificationReceiver.new(id, instantiate: false)
101
+ end
102
+
103
+ hash
104
+ end
105
+
106
+ def ==(other)
107
+ name == other.name
108
+ end
109
+
110
+ def destroy
111
+ config_set('snmp_notification_receiver',
112
+ 'receivers',
113
+ state: 'no',
114
+ ip: name,
115
+ type: type,
116
+ version: version,
117
+ security: security.nil? ? '' : "#{security}",
118
+ username: username,
119
+ udp_port: port.nil? ? '' : "udp-port #{port}")
120
+ end
121
+
122
+ def port
123
+ config_get('snmp_notification_receiver', 'port', @name)
124
+ end
125
+
126
+ def username
127
+ if !port.nil?
128
+ endpoint = 'username_with_port'
129
+ else
130
+ endpoint = 'username'
131
+ end
132
+
133
+ config_get('snmp_notification_receiver', endpoint, @name)
134
+ end
135
+
136
+ def version
137
+ config_get('snmp_notification_receiver', 'version', @name)
138
+ end
139
+
140
+ def type
141
+ config_get('snmp_notification_receiver', 'type', @name)
142
+ end
143
+
144
+ def security
145
+ config_get('snmp_notification_receiver', 'security', @name)
146
+ end
147
+
148
+ def vrf
149
+ config_get('snmp_notification_receiver', 'vrf', @name)
150
+ end
151
+
152
+ def source_interface
153
+ val = config_get('snmp_notification_receiver', 'source_interface', @name)
154
+ val = val.downcase unless val.nil?
155
+ val
156
+ end
157
+ end
158
+ end
@@ -1,6 +1,6 @@
1
1
  # December 2014, Alex Hunsberger
2
2
  #
3
- # Copyright (c) 2014-2015 Cisco and/or its affiliates.
3
+ # Copyright (c) 2014-2016 Cisco and/or its affiliates.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -50,8 +50,7 @@ module Cisco
50
50
  # end
51
51
 
52
52
  def group
53
- result = config_get('snmp_community', 'group', @name)
54
- result.nil? ? SnmpCommunity.default_group : result.first
53
+ config_get('snmp_community', 'group', @name)
55
54
  end
56
55
 
57
56
  def group=(group)
@@ -64,8 +63,7 @@ module Cisco
64
63
  end
65
64
 
66
65
  def acl
67
- result = config_get('snmp_community', 'acl', @name)
68
- result.nil? ? SnmpCommunity.default_acl : result.first
66
+ config_get('snmp_community', 'acl', @name)
69
67
  end
70
68
 
71
69
  def acl=(acl)
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # February 2015, Chris Van Heuveln
5
5
  #
6
- # Copyright (c) 2015 Cisco and/or its affiliates.
6
+ # Copyright (c) 2015-2016 Cisco and/or its affiliates.
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
9
9
  # you may not use this file except in compliance with the License.
@@ -0,0 +1,57 @@
1
+ # December 2015
2
+ #
3
+ # Copyright (c) 2014-2016 Cisco and/or its affiliates.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require_relative 'node_util'
18
+
19
+ module Cisco
20
+ # SnmpNotification - node utility class for SNMP notification management
21
+ class SnmpNotification < NodeUtil
22
+ def initialize(name)
23
+ fail TypeError unless name.is_a?(String)
24
+ @name = name
25
+ end
26
+
27
+ def self.notifications
28
+ @notifications = {}
29
+ notifs = config_get('snmpnotification', 'notifications')
30
+ unless notifs.nil?
31
+ notifs.each do |notif|
32
+ @notifications[notif] = SnmpNotification.new(notif)
33
+ end
34
+ end
35
+ @notifications
36
+ end
37
+
38
+ def destroy
39
+ # not needed
40
+ end
41
+
42
+ # Set enable
43
+ def enable=(enable)
44
+ config_set('snmpnotification',
45
+ 'enable',
46
+ state: enable ? '' : 'no',
47
+ trap_name: @name)
48
+ end
49
+
50
+ # Get enable
51
+ def enable
52
+ value = config_get('snmpnotification', 'enable', trap_name: @name)
53
+ enabled = value.nil? ? false : true
54
+ enabled
55
+ end
56
+ end
57
+ end