rbeapi 1.2 → 1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77f57dffb48069339da41ad9ccbacb58f0ba721c
4
- data.tar.gz: 01a8466b66a59fba98f05b90951e3dbec95cb403
3
+ metadata.gz: 110cd5fb3e11a5fec2598d63ed79db2c3b092ce7
4
+ data.tar.gz: 7e7d89671f76f5875980d0320cdee5fa93d2333b
5
5
  SHA512:
6
- metadata.gz: 376ea7873d47cc61f196aaae4efcfa68127b0146f64b8a265f680d6ab2e2ee7dffaa3f09df21b6d2a8e4a963bd78b7fc606fed96ca87dcb4912a8b2beee43dfa
7
- data.tar.gz: b848cbd0cd4c76935fa9e9e542f25eb94738a16ddad6862ceb9aea5b97030e653484b53ce55bec9a88ffac6ff045d61c098ca9779747caff957539b9f6ca908f
6
+ metadata.gz: 2f36371a3497d8e4af54803b64385cf787e530bbb6eb65fad541f1e378986f6c1e81df7dc25cbf72a5d932d15a5d3ad44e6decc4eaeecf5261664883056cb7bb
7
+ data.tar.gz: c2f98dd638875fabe9183ffdd308c9d1f6c245d3f9e1d2e267b05850b7d9a4e514c27a3b2bf747ada68b84573426d870d23bbfa24a1ce8b954980d85188305ec
@@ -1,7 +1,21 @@
1
- # Change Log
1
+ # Changelog
2
2
 
3
- ## [1.2](https://github.com/arista-eosplus/rbeapi/tree/1.2) (2017-06-02)
4
- [Full Changelog](https://github.com/arista-eosplus/rbeapi/compare/v1.1...1.2)
3
+ ## [1.3.0](https://github.com/arista-eosplus/rbeapi/tree/1.3.0) (2018-04-03)
4
+
5
+ [Full Changelog](https://github.com/arista-eosplus/rbeapi/compare/v1.2...1.3.0)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - logging: support vrf, port, and protocol options [\#173](https://github.com/arista-eosplus/rbeapi/issues/173)
10
+ - \(NETDEV-30\) Support new properties in Types [\#174](https://github.com/arista-eosplus/rbeapi/pull/174) ([jerearista](https://github.com/jerearista))
11
+
12
+ **Merged pull requests:**
13
+
14
+ - Release 1.2.0 [\#170](https://github.com/arista-eosplus/rbeapi/pull/170) ([jerearista](https://github.com/jerearista))
15
+
16
+ ## [v1.2](https://github.com/arista-eosplus/rbeapi/tree/v1.2) (2017-06-03)
17
+
18
+ [Full Changelog](https://github.com/arista-eosplus/rbeapi/compare/v1.1...v1.2)
5
19
 
6
20
  **Implemented enhancements:**
7
21
 
@@ -13,6 +27,7 @@
13
27
  - \(NETDEV-29\) Enhance netdev NTP api [\#169](https://github.com/arista-eosplus/rbeapi/pull/169) ([shermdog](https://github.com/shermdog))
14
28
 
15
29
  ## [v1.1](https://github.com/arista-eosplus/rbeapi/tree/v1.1) (2016-12-06)
30
+
16
31
  [Full Changelog](https://github.com/arista-eosplus/rbeapi/compare/v1.0...v1.1)
17
32
 
18
33
  **Implemented enhancements:**
@@ -31,6 +46,7 @@
31
46
  - extend and fix ospf features [\#156](https://github.com/arista-eosplus/rbeapi/pull/156) ([rknaus](https://github.com/rknaus))
32
47
 
33
48
  ## [v1.0](https://github.com/arista-eosplus/rbeapi/tree/v1.0) (2016-09-26)
49
+
34
50
  [Full Changelog](https://github.com/arista-eosplus/rbeapi/compare/v0.5.1...v1.0)
35
51
 
36
52
  **Implemented enhancements:**
@@ -75,6 +91,7 @@
75
91
  - Created vlans set\_trunk\_groups method. [\#119](https://github.com/arista-eosplus/rbeapi/pull/119) ([devrobo](https://github.com/devrobo))
76
92
 
77
93
  ## [v0.5.1](https://github.com/arista-eosplus/rbeapi/tree/v0.5.1) (2016-02-16)
94
+
78
95
  [Full Changelog](https://github.com/arista-eosplus/rbeapi/compare/v0.5.0...v0.5.1)
79
96
 
80
97
  **Implemented enhancements:**
@@ -104,6 +121,7 @@
104
121
  - Added support for setting system banners. [\#104](https://github.com/arista-eosplus/rbeapi/pull/104) ([devrobo](https://github.com/devrobo))
105
122
 
106
123
  ## [v0.5.0](https://github.com/arista-eosplus/rbeapi/tree/v0.5.0) (2016-01-12)
124
+
107
125
  [Full Changelog](https://github.com/arista-eosplus/rbeapi/compare/v0.4.0...v0.5.0)
108
126
 
109
127
  **Implemented enhancements:**
@@ -140,6 +158,7 @@
140
158
  - Update documentation [\#97](https://github.com/arista-eosplus/rbeapi/pull/97) ([HuntBurdick](https://github.com/HuntBurdick))
141
159
 
142
160
  ## [v0.4.0](https://github.com/arista-eosplus/rbeapi/tree/v0.4.0) (2015-11-21)
161
+
143
162
  [Full Changelog](https://github.com/arista-eosplus/rbeapi/compare/v0.3.0...v0.4.0)
144
163
 
145
164
  **Implemented enhancements:**
@@ -177,6 +196,7 @@
177
196
  - add dry-run mode [\#42](https://github.com/arista-eosplus/rbeapi/pull/42) ([kakkotetsu](https://github.com/kakkotetsu))
178
197
 
179
198
  ## [v0.3.0](https://github.com/arista-eosplus/rbeapi/tree/v0.3.0) (2015-08-24)
199
+
180
200
  [Full Changelog](https://github.com/arista-eosplus/rbeapi/compare/v0.2.0...v0.3.0)
181
201
 
182
202
  **Fixed bugs:**
@@ -196,6 +216,7 @@
196
216
  - Eliminate overloading value option in command\_builder. [\#39](https://github.com/arista-eosplus/rbeapi/pull/39) ([devrobo](https://github.com/devrobo))
197
217
 
198
218
  ## [v0.2.0](https://github.com/arista-eosplus/rbeapi/tree/v0.2.0) (2015-07-08)
219
+
199
220
  [Full Changelog](https://github.com/arista-eosplus/rbeapi/compare/v0.1.0...v0.2.0)
200
221
 
201
222
  **Implemented enhancements:**
@@ -239,5 +260,8 @@
239
260
 
240
261
  ## [v0.1.0](https://github.com/arista-eosplus/rbeapi/tree/v0.1.0) (2015-02-25)
241
262
 
263
+ [Full Changelog](https://github.com/arista-eosplus/rbeapi/compare/63b0bf8c005b4eab53036556d7becf9b1a7f4bb4...v0.1.0)
264
+
265
+
242
266
 
243
- \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
267
+ \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
data/Gemfile CHANGED
@@ -17,6 +17,7 @@ end
17
17
 
18
18
  group :development, :test do
19
19
  gem 'ci_reporter_rspec', require: false
20
+ gem 'github_changelog_generator', :git => 'https://github.com/skywinder/github-changelog-generator.git'
20
21
  gem 'listen', '<=3.0.3'
21
22
  gem 'pry', require: false
22
23
  gem 'pry-doc', require: false
data/README.md CHANGED
@@ -250,29 +250,29 @@ omnibus installation package in /opt/chef/bin/. For Chef, use the
250
250
  Examples:
251
251
  Puppet Open Source:
252
252
  cd /mnt/flash; \
253
- swix create rbeapi-1.2-1.swix \
254
- rubygem-rbeapi-1.2-1.eos4.noarch.rpm \
253
+ swix create rbeapi-1.3-1.swix \
254
+ rubygem-rbeapi-1.3-1.eos4.noarch.rpm \
255
255
  rubygem-inifile-3.0.0-3.eos4.noarch.rpm \
256
256
  rubygem-netaddr-1.5.0-2.eos4.noarch.rpm \
257
257
  rubygem-net_http_unix-0.2.1-3.eos4.noarch.rpm
258
258
  Puppet-enterprise agent (3.x):
259
259
  cd/mnt/flash; \
260
- swix create rbeapi-puppet3-1.2-1.swix \
261
- rubygem-rbeapi-puppet3-1.2-1.eos4.noarch.rpm \
260
+ swix create rbeapi-puppet3-1.3-1.swix \
261
+ rubygem-rbeapi-puppet3-1.3-1.eos4.noarch.rpm \
262
262
  rubygem-inifile-puppet3-3.0.0-3.eos4.noarch.rpm \
263
263
  rubygem-netaddr-puppet3-1.5.0-2.eos4.noarch.rpm
264
264
  Puppet-All-in-one agent (2015.x/4.x):
265
265
  cd/mnt/flash; \
266
- swix create rbeapi-puppet-aio-1.2-1.swix \
267
- rubygem-rbeapi-puppet-aio-1.2-1.eos4.noarch.rpm \
266
+ swix create rbeapi-puppet-aio-1.3-1.swix \
267
+ rubygem-rbeapi-puppet-aio-1.3-1.eos4.noarch.rpm \
268
268
  rubygem-inifile-puppet-aio-3.0.0-3.eos4.noarch.rpm \
269
269
  rubygem-netaddr-puppet-aio-1.5.0-2.eos4.noarch.rpm \
270
270
  rubygem-net_http_unix-puppet-aio-0.2.1-3.eos4.noarch.rpm
271
271
 
272
272
  Chef client:
273
273
  cd /mnt/flash; \
274
- swix create rbeapi-chef-1.2-1.swix \
275
- rubygem-rbeapi-chef-1.2-1.eos4.noarch.rpm \
274
+ swix create rbeapi-chef-1.3-1.swix \
275
+ rubygem-rbeapi-chef-1.3-1.eos4.noarch.rpm \
276
276
  rubygem-inifile-chef-3.0.0-5.eos4.noarch.rpm \
277
277
  rubygem-netaddr-chef-1.5.1-4.eos4.noarch.rpm \
278
278
  rubygem-net_http_unix-chef-0.2.2-5.eos4.noarch.rpm
@@ -283,13 +283,13 @@ omnibus installation package in /opt/chef/bin/. For Chef, use the
283
283
  Arista# copy <URI-to-RPMs> flash:
284
284
  Arista# bash
285
285
  -bash-4.1# cd /mnt/flash/
286
- -bash-4.1# swix create rbeapi-puppet3-1.2-1.swix \
287
- rubygem-rbeapi-puppet3-1.2-1.eos4.noarch.rpm \
286
+ -bash-4.1# swix create rbeapi-puppet3-1.3-1.swix \
287
+ rubygem-rbeapi-puppet3-1.3-1.eos4.noarch.rpm \
288
288
  rubygem-inifile-puppet3-3.0.0-1.eos4.noarch.rpm \
289
289
  rubygem-netaddr-puppet3-1.5.0-1.eos4.noarch.rpm
290
290
  -bash-4.1# exit
291
- Arista# copy flash:rbeapi-puppet3-1.2-1.swix extension:
292
- Arista# extension rbeapi-puppet3-1.2-1.swix
291
+ Arista# copy flash:rbeapi-puppet3-1.3-1.swix extension:
292
+ Arista# extension rbeapi-puppet3-1.3-1.swix
293
293
  Arista# copy installed-extensions boot-extensions
294
294
  ```
295
295
 
@@ -298,7 +298,7 @@ omnibus installation package in /opt/chef/bin/. For Chef, use the
298
298
  On EOS:
299
299
  ```
300
300
  Arista# no extension pe-rbeapi-1.1.0-1.swix
301
- Arista# extension rbeapi-puppet3-1.2-1.swix
301
+ Arista# extension rbeapi-puppet3-1.3-1.swix
302
302
  Arista# copy installed-extensions boot-extensions
303
303
  ```
304
304
 
@@ -40,6 +40,16 @@ module Rbeapi
40
40
  ##
41
41
  # The Logging class manages logging settings on an EOS node.
42
42
  class Logging < Entity
43
+ SEV_NUM = {
44
+ 'emergencies' => 0,
45
+ 'alerts' => 1,
46
+ 'critical' => 2,
47
+ 'errors' => 3,
48
+ 'warnings' => 4,
49
+ 'notifications' => 5,
50
+ 'informational' => 6,
51
+ 'debugging' => 7
52
+ }.freeze
43
53
  ##
44
54
  # get returns the current logging configuration hash extracted from the
45
55
  # nodes running configuration.
@@ -55,6 +65,10 @@ module Rbeapi
55
65
  def get
56
66
  response = {}
57
67
  response.merge!(parse_enable)
68
+ response.merge!(parse_console_level)
69
+ response.merge!(parse_monitor_level)
70
+ response.merge!(parse_timestamp_units)
71
+ response.merge!(parse_source)
58
72
  response.merge!(parse_hosts)
59
73
  response
60
74
  end
@@ -73,6 +87,79 @@ module Rbeapi
73
87
  value = /no logging on/ !~ config
74
88
  { enable: value }
75
89
  end
90
+ private :parse_enable
91
+
92
+ ##
93
+ # parse_console_level scans the nodes current running configuration and
94
+ # extracts the current enabled state of the logging facility. The logging
95
+ # enable command is expected to always be in the node's configuration.
96
+ # This methods return value is intended to be merged into the logging
97
+ # resource hash.
98
+ #
99
+ # @api private
100
+ #
101
+ # @return [Hash<Symbol, Object>] Returns the resource hash attribute.
102
+ def parse_console_level
103
+ level = config.scan(/^logging console ([^\s]+)/).first
104
+ { console: SEV_NUM[level[0]] }
105
+ end
106
+ private :parse_console_level
107
+
108
+ ##
109
+ # parse_monitor_level scans the nodes current running configuration and
110
+ # extracts the current enabled state of the logging facility. The
111
+ # logging enable command is expected to always be in the node's
112
+ # configuration. This methods return value is intended to be merged into
113
+ # the logging resource hash.
114
+ #
115
+ # @api private
116
+ #
117
+ # @return [Hash<Symbol, Object>] Returns the resource hash attribute.
118
+ def parse_monitor_level
119
+ level = config.scan(/^logging monitor ([^\s]+)/).first
120
+ { monitor: SEV_NUM[level[0]] }
121
+ end
122
+ private :parse_monitor_level
123
+
124
+ ##
125
+ # parse_timestamp_units scans the nodes current running configuration
126
+ # and extracts the current configured value of the logging timestamps.
127
+ # The logging timestamps command is expected to always be in the node's
128
+ # configuration. This methods return value is intended to be merged into
129
+ # the logging resource hash.
130
+ #
131
+ # @api private
132
+ #
133
+ # @return [Hash<Symbol, Object>] Returns the resource hash attribute.
134
+ def parse_timestamp_units
135
+ value = config.scan(/^logging format timestamp ([^\s]+)/).first
136
+ units = value[0] == 'traditional' ? 'seconds' : 'milliseconds'
137
+ { time_stamp_units: units }
138
+ end
139
+ private :parse_timestamp_units
140
+
141
+ ##
142
+ # parse_source scans the nodes' current running configuration and extracts
143
+ # the configured logging source interfaces if any are configured. If no
144
+ # logging sources are configured, then the value will be an empty
145
+ # array. The return value requires conversion from a hash to a pair of
146
+ # ordered arrays to be merged into the logging resource hash.
147
+ #
148
+ # @api private
149
+ #
150
+ # @return [Hash<Symbol, Object>] Returns the resource hash attribute.
151
+ def parse_source
152
+ entries = config.scan(
153
+ /^logging(?:\svrf\s([^\s]+))?\ssource-interface\s([^\s]+)/
154
+ )
155
+ sources = {}
156
+ entries.each do |vrf, intf|
157
+ vrf = vrf.nil? ? 'default' : vrf
158
+ sources[vrf.to_s] = intf
159
+ end
160
+ { source: sources }
161
+ end
162
+ private :parse_source
76
163
 
77
164
  ##
78
165
  # parse_hosts scans the nodes current running configuration and extracts
@@ -85,7 +172,17 @@ module Rbeapi
85
172
  #
86
173
  # @return [Hash<Symbol, Object>] Returns the resource hash attribute.
87
174
  def parse_hosts
88
- hosts = config.scan(/(?<=^logging\shost\s)[^\s]+/)
175
+ entries = config.scan(
176
+ /^logging(?:\svrf\s([^\s]+))?\shost\s([^\s]+)\s(\d+)
177
+ \sprotocol\s([^\s]+)/x
178
+ )
179
+ hosts = []
180
+ entries.each do |vrf, address, port, proto|
181
+ hosts << { address: address,
182
+ vrf: vrf.nil? ? 'default' : vrf,
183
+ port: port,
184
+ protocol: proto }
185
+ end
89
186
  { hosts: hosts }
90
187
  end
91
188
  private :parse_hosts
@@ -119,6 +216,104 @@ module Rbeapi
119
216
  configure cmd
120
217
  end
121
218
 
219
+ ##
220
+ # set_console configures the global logging level for the console.
221
+ # If the default keyword is specified and set to true, then the
222
+ # configuration is defaulted using the default keyword. The default
223
+ # keyword option takes precedence over the enable keyword if both
224
+ # options are specified.
225
+ #
226
+ # @since eos_version 4.13.7M
227
+ #
228
+ # ===Commands
229
+ # logging console <level>
230
+ # no logging console <level>
231
+ # default logging console
232
+ #
233
+ # @param opts [Hash] Optional keyword arguments
234
+ #
235
+ # @option opts level [Int|String] Enables logging at the specified
236
+ # level. Accepts <0-7> and logging level keywords.
237
+ #
238
+ # @option opts default [Boolean] Resets the monitor level to the
239
+ # default.
240
+ #
241
+ # @return [Boolean] Returns true if the command completed successfully.
242
+ def set_console(opts = {})
243
+ cmd = 'logging console'
244
+ cmd += " #{opts[:level]}" if opts[:level]
245
+ cmd = command_builder(cmd, opts)
246
+ configure cmd
247
+ end
248
+
249
+ ##
250
+ # set_monitor configures the global logging level for terminals
251
+ # If the default keyword is specified and set to true, then the
252
+ # configuration is defaulted using the default keyword. The default
253
+ # keyword option takes precedence over the enable keyword if both
254
+ # options are specified.
255
+ #
256
+ # @since eos_version 4.13.7M
257
+ #
258
+ # ===Commands
259
+ # logging monitor <level>
260
+ # no logging monitor <level>
261
+ # default logging monitor
262
+ #
263
+ # @param opts [Hash] Optional keyword arguments
264
+ #
265
+ # @option opts level [Int|String] Enables logging at the specified
266
+ # level. Accepts <0-7> and logging level keywords.
267
+ #
268
+ # @option opts default [Boolean] Resets the monitor level to the
269
+ # default.
270
+ #
271
+ # @return [Boolean] Returns true if the command completed successfully.
272
+ def set_monitor(opts = {})
273
+ cmd = 'logging monitor'
274
+ cmd += " #{opts[:level]}" if opts[:level]
275
+ cmd = command_builder(cmd, opts)
276
+ configure cmd
277
+ end
278
+
279
+ ##
280
+ # set_time_stamp_units configures the global logging time_stamp_units
281
+ # If the default keyword is specified and set to true, then the
282
+ # configuration is defaulted using the default keyword. The default
283
+ # keyword option takes precedence over the enable keyword if both
284
+ # options are specified.
285
+ #
286
+ # @since eos_version 4.13.7M
287
+ #
288
+ # ===Commands
289
+ # logging format timestamp <traditional|high-resolution>
290
+ # no logging format timestamp <level>
291
+ # default logging format timestamp
292
+ #
293
+ # @param opts [Hash] Optional keyword arguments
294
+ #
295
+ # @option opts units [String] Enables logging timestamps with the
296
+ # specified units. One of 'traditional' | 'seconds' or
297
+ # 'high-resolution' | 'milliseconds'
298
+ #
299
+ # @option opts default [Boolean] Resets the logging timestamp level to
300
+ # the default.
301
+ #
302
+ # @return [Boolean] Returns true if the command completed successfully.
303
+ def set_time_stamp_units(opts = {})
304
+ unit_map = {
305
+ 'traditional' => ' traditional',
306
+ 'seconds' => ' traditional',
307
+ 'high-resolution' => ' high-resolution',
308
+ 'milliseconds' => ' high-resolution'
309
+ }
310
+ units = ''
311
+ units = unit_map[opts[:units]] if opts[:units]
312
+ cmd = "logging format timestamp#{units}"
313
+ cmd = command_builder(cmd, opts)
314
+ configure cmd
315
+ end
316
+
122
317
  ##
123
318
  # add_host configures a new logging destination host address or hostname
124
319
  # to the list of logging destinations. If the host is already configured
@@ -133,8 +328,12 @@ module Rbeapi
133
328
  # node to send logging information to.
134
329
  #
135
330
  # @return [Boolean] Returns true if the command completed successfully.
136
- def add_host(name)
137
- configure "logging host #{name}"
331
+ def add_host(name, opts = {})
332
+ vrf = opts[:vrf] ? "vrf #{opts[:vrf]} " : ''
333
+ cmd = "logging #{vrf}host #{name}"
334
+ cmd += " #{opts[:port]}" if opts[:port]
335
+ cmd += " protocol #{opts[:protocol]}" if opts[:protocol]
336
+ configure cmd
138
337
  end
139
338
 
140
339
  ##
@@ -151,8 +350,11 @@ module Rbeapi
151
350
  # host to remove from the nodes current configuration.
152
351
  #
153
352
  # @return [Boolean] Returns true if the commands completed successfully.
154
- def remove_host(name)
155
- configure "no logging host #{name}"
353
+ def remove_host(name, opts = {})
354
+ vrf = opts[:vrf] ? "vrf #{opts[:vrf]} " : ''
355
+ # Hosts are uniquely identified by vrf and address, alone.
356
+ cmd = "no logging #{vrf}host #{name}"
357
+ configure cmd
156
358
  end
157
359
  end
158
360
  end
@@ -76,6 +76,7 @@ module Rbeapi
76
76
  global.merge!(parse_global_timeout)
77
77
  global.merge!(parse_global_retransmit)
78
78
  global.merge!(parse_global_key)
79
+ global.merge!(parse_global_source)
79
80
  resource = { global: global, servers: parse_servers }
80
81
  resource
81
82
  end
@@ -126,6 +127,29 @@ module Rbeapi
126
127
  end
127
128
  private :parse_global_key
128
129
 
130
+ ##
131
+ # parse_global_source takes a running configuration as a string
132
+ # and parses out the radius global source-interface per VRF if it exists
133
+ # in the configuration. An empty Hash is returned if there is no global
134
+ # setting configured. The Hash needs to be converted to ordered lists
135
+ # for vrf and source_interface before being merged into a property hash.
136
+ #
137
+ # @api private
138
+ #
139
+ # @return [Hash<Symbol, Object>] Returns the resource hash attribute.
140
+ def parse_global_source
141
+ src = config.scan(/ip radius(?:\svrf\s(\w+))?\ssource-interface\s(\w+)/)
142
+ sources = {}
143
+ src.each do |vrf, intf|
144
+ vrf = vrf.nil? ? 'default' : vrf
145
+ sources[vrf] = intf
146
+ end
147
+ { source_interface: sources }
148
+ end
149
+ private :parse_global_source
150
+
151
+ ##
152
+
129
153
  ##
130
154
  # parse_servers returns an Array of radius server resource hashes. Each
131
155
  # hash describes the current state of the radius server and is intended
@@ -335,6 +359,32 @@ module Rbeapi
335
359
  cmd << " acct-port #{opts[:acct_port]}" if opts[:acct_port]
336
360
  configure cmd
337
361
  end
362
+
363
+ ##
364
+ # set_source_interface takes a dictionary mapping the VRF to the desired
365
+ # source interface. Any radius source-interface lines in the
366
+ # running-config that are not defined in the hash will be removed, then
367
+ # lines generated from the hash will be applied. This is NOT idempotent,
368
+ # however, it is explicit.
369
+ #
370
+ # @api public
371
+ #
372
+ # @param sources [Hash] A hash mapping the vrf name to the source
373
+ # interface.
374
+ #
375
+ # @return [Boolean] Returns true if there are no errors.
376
+ def set_source_interface(sources)
377
+ existing = config.scan(/ip radius.* source-interface.*/)
378
+ desired = []
379
+ sources.each do |vrf, intf|
380
+ vrf_str = vrf == 'default' ? '' : " vrf #{vrf}"
381
+ desired << "ip radius#{vrf_str} source-interface #{intf}"
382
+ end
383
+ remove = existing - desired
384
+ cmds = remove.map { |line| "no #{line}" }
385
+ cmds.concat(desired)
386
+ configure cmds
387
+ end
338
388
  end
339
389
  end
340
390
  end
@@ -77,6 +77,7 @@ module Rbeapi
77
77
  global = {}
78
78
  global.merge!(parse_global_timeout)
79
79
  global.merge!(parse_global_key)
80
+ global.merge!(parse_global_source)
80
81
  resource = { global: global, servers: servers }
81
82
  resource
82
83
  end
@@ -116,6 +117,27 @@ module Rbeapi
116
117
  end
117
118
  private :parse_global_timeout
118
119
 
120
+ ##
121
+ # parse_global_source takes a running configuration as a string
122
+ # and parses out the tacacs global source-interface per VRF if it exists
123
+ # in the configuration. An empty Hash is returned if there is no global
124
+ # setting configured. The Hash needs to be converted to ordered lists
125
+ # for vrf and source_interface before being merged into a property hash.
126
+ #
127
+ # @api private
128
+ #
129
+ # @return [Hash<Symbol,Object>] Returns the resource hash attributes.
130
+ def parse_global_source
131
+ src = config.scan(/ip tacacs(?:\svrf\s(\w+))?\ssource-interface\s(\w+)/)
132
+ sources = {}
133
+ src.each do |vrf, intf|
134
+ vrf = vrf.nil? ? 'default' : vrf
135
+ sources[vrf] = intf
136
+ end
137
+ { source_interface: sources }
138
+ end
139
+ private :parse_global_source
140
+
119
141
  ##
120
142
  # servers returns an Array of tacacs server resource hashes. Each hash
121
143
  # describes the current state of the tacacs server and is suitable for
@@ -243,6 +265,32 @@ module Rbeapi
243
265
  cmd << " port #{opts[:port]}" if opts[:port]
244
266
  configure cmd
245
267
  end
268
+
269
+ ##
270
+ # set_source_interface takes a dictionary mapping the VRF to the desired
271
+ # source interface. Any tacacs source-interface lines in the
272
+ # running-config that are not defined in the hash will be removed, then
273
+ # lines generated from the hash will be applied. This is NOT idempotent,
274
+ # however, it is explicit.
275
+ #
276
+ # @api public
277
+ #
278
+ # @param sources [Hash] A hash mapping the vrf name to the source
279
+ # interface.
280
+ #
281
+ # @return [Boolean] Returns true if there are no errors.
282
+ def set_source_interface(sources)
283
+ existing = config.scan(/ip tacacs.* source-interface.*/)
284
+ desired = []
285
+ sources.each do |vrf, intf|
286
+ vrf_str = vrf == 'default' ? '' : " vrf #{vrf}"
287
+ desired << "ip tacacs#{vrf_str} source-interface #{intf}"
288
+ end
289
+ remove = existing - desired
290
+ cmds = remove.map { |line| "no #{line}" }
291
+ cmds.concat(desired)
292
+ configure cmds
293
+ end
246
294
  end
247
295
  end
248
296
  end
@@ -33,5 +33,5 @@
33
33
  # #
34
34
  # Rbeapi toplevel namespace.
35
35
  module Rbeapi
36
- VERSION = '1.2'.freeze
36
+ VERSION = '1.3'.freeze
37
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbeapi
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: '1.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Sprygada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-03 00:00:00.000000000 Z
11
+ date: 2018-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inifile
@@ -350,7 +350,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
350
350
  version: '0'
351
351
  requirements: []
352
352
  rubyforge_project:
353
- rubygems_version: 2.6.6
353
+ rubygems_version: 2.6.14
354
354
  signing_key:
355
355
  specification_version: 4
356
356
  summary: This Gem library provides a Ruby interface to the Arista EOS command API
@@ -444,4 +444,3 @@ test_files:
444
444
  - spec/unit/rbeapi/switchconfig2_spec.rb
445
445
  - spec/unit/rbeapi/switchconfig3_spec.rb
446
446
  - spec/unit/rbeapi/switchconfig_spec.rb
447
- has_rdoc: