mtik 3.1.2 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +16 -1
- data/VERSION.txt +1 -1
- data/lib/mtik.rb +59 -17
- data/lib/mtik/request.rb +2 -2
- metadata +21 -38
data/CHANGELOG.txt
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
2011-03-25 (25 MAR 2011) VERSION 4.0.0 Aaron D. Gifford (http://www.aarongifford.com)
|
2
|
+
* Per user suggestion, added a new optional cancel parameter to the MTik#command()
|
3
|
+
method that will auto-cancel the supplied command after receiving the specified
|
4
|
+
number of '!re' reply sentences. This is usful for executing a command that otherwise
|
5
|
+
will not terminate, but will keep sending output perpetually if not canceled.
|
6
|
+
* Spelling changes: :cancelled updated to :canceled This means anyone who checked the
|
7
|
+
state of a request using :cancelled or 'cancelled' will need to update their code to
|
8
|
+
check for :canceled instead.
|
9
|
+
* Due to changing of spelling and adding a new parameter, I've bumped the major version
|
10
|
+
number to 4.x in case any users code might break. This in spite of the fact that
|
11
|
+
there are no major new features added.
|
12
|
+
* I found 2-3 tiny bugs left over from the past change of request state from string
|
13
|
+
to symbol and fixed those, updated error messages to reflect state as a symbol,
|
14
|
+
eliminated a few redundant key?() calls, and fixed a replycounter initialization
|
15
|
+
typo (had set it to 1 instead of 0).
|
1
16
|
2011-01-11 (11 JAN 2011) VERSION 3.1.2 Aaron D. Gifford (http://www.aarongifford.com)
|
2
17
|
* Added source file encoding comments and updated the copyright notices
|
3
18
|
* Fixed a tiny bug in lib/mtik/connection.rb
|
@@ -18,7 +33,7 @@
|
|
18
33
|
which should not affect the API and should be backward compatible. By default,
|
19
34
|
there is no inactivity timeout for downloads. But if you set the timeout parameter
|
20
35
|
to a positive number, when a reply arrives and no progress/activity has been
|
21
|
-
made for timeout seconds, the command will be
|
36
|
+
made for timeout seconds, the command will be canceled. This should help with
|
22
37
|
stalled downloads (i.e. the remote side has stopped sending but the TCP connection
|
23
38
|
remains open/active).
|
24
39
|
* Also add the MTik::Request object as a parameter to the MTik::Connection.fetch()
|
data/VERSION.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
4.0.0
|
data/lib/mtik.rb
CHANGED
@@ -53,6 +53,9 @@ module MTik
|
|
53
53
|
## API data when expecting one or more command responses.
|
54
54
|
CMD_TIMEOUT = 60
|
55
55
|
|
56
|
+
## Maximum number of replies before a command is auto-canceled:
|
57
|
+
MAXREPLIES = 1000
|
58
|
+
|
56
59
|
@verbose = false
|
57
60
|
@debug = false
|
58
61
|
|
@@ -120,8 +123,8 @@ module MTik
|
|
120
123
|
## Auto-cancel any '/tool/fetch' commands that have finished,
|
121
124
|
## or commands that have received the specified number of
|
122
125
|
## replies:
|
123
|
-
if req.state
|
124
|
-
cmd == '/tool/fetch' && sentence
|
126
|
+
if req.state == :sent && (
|
127
|
+
cmd == '/tool/fetch' && sentence['status'] == 'finished'
|
125
128
|
) || (maxreply > 0 && count == maxreply)
|
126
129
|
state = 2
|
127
130
|
req.cancel do |r, s|
|
@@ -190,12 +193,52 @@ module MTik
|
|
190
193
|
## more commands, retrieve the response(s), close the connection,
|
191
194
|
## and return the response(s).
|
192
195
|
##
|
193
|
-
##
|
194
|
-
##
|
195
|
-
##
|
196
|
-
##
|
197
|
-
##
|
198
|
-
##
|
196
|
+
## PARAMETERS:
|
197
|
+
## All parameters supplied to this method are contained in a
|
198
|
+
## single hash. Here are available hash keys:
|
199
|
+
##
|
200
|
+
## :host => the host name or IP to connect to
|
201
|
+
## :user => the API user ID to authenticate with
|
202
|
+
## :pass => the API password to authenticate with
|
203
|
+
## :command => one or more API commands to execute
|
204
|
+
## :limit => an OPTIONAL integer reply limit
|
205
|
+
##
|
206
|
+
## The :command parameter may be:
|
207
|
+
## * A single string representing a single API command to execute
|
208
|
+
## * An array of strings in which case the first string is the API
|
209
|
+
## command to execute and each subsequent array item is an API
|
210
|
+
## parameter or argument.
|
211
|
+
## * An array of arrays -- Multiple API command may be executed
|
212
|
+
## in sequence. Each subarray is an array of strings containing
|
213
|
+
## an API command and zero or more parameters.
|
214
|
+
##
|
215
|
+
## The :limit parameter if present specifies an integer. This parameter
|
216
|
+
## is to be used whenever executing one or more API commands that do
|
217
|
+
## not terminate with a '!done' response sentence, but instead keep
|
218
|
+
## sending '!re' reply sentences.
|
219
|
+
##
|
220
|
+
## An exception is the '/tools/fetch' API command, which this method
|
221
|
+
## will auto-cancel when it finishes.
|
222
|
+
##
|
223
|
+
## Regarding the :limit parameter:
|
224
|
+
## * If present and the integer is zero or negative, THERE WILL BE
|
225
|
+
## NO LIMIT ENFORCED on the number of replies from each API command.
|
226
|
+
## *WARNING:* If you do NOT limit the number of replies when
|
227
|
+
## executing an API command like <i>"/interface/montitor-traffic"</i>
|
228
|
+
## this method may not ever terminate and may consume memory
|
229
|
+
## buffering replies until resources are exhausted.
|
230
|
+
## * If present and a positive integer, each API command may at
|
231
|
+
## most receive the specified number of reply sentences, after which
|
232
|
+
## the command will automatically be canceled. This is useful
|
233
|
+
## to terminate commands that would otherwise keep sending output
|
234
|
+
## forever.
|
235
|
+
## * If NOT present, or if nil, the default reply limit as contained
|
236
|
+
## in the MAXREPLIES constant will be enforced. *WARNING:* This
|
237
|
+
## default limit could be so large that this method would not
|
238
|
+
## return for a long time, waiting for the number of replies.
|
239
|
+
##
|
240
|
+
## Remember that the limit applies separately to each API command
|
241
|
+
## executed.
|
199
242
|
def self.command(args)
|
200
243
|
tk = MTik::Connection.new(
|
201
244
|
:host => args[:host],
|
@@ -205,6 +248,7 @@ module MTik
|
|
205
248
|
:conn_timeout => args[:conn_timeout],
|
206
249
|
:cmd_timeout => args[:cmd_timeout]
|
207
250
|
)
|
251
|
+
limit = args[:limit] ## Optional reply limit
|
208
252
|
cmd = args[:command]
|
209
253
|
replies = Array.new
|
210
254
|
if cmd.is_a?(String)
|
@@ -217,20 +261,18 @@ module MTik
|
|
217
261
|
|
218
262
|
cmd.each_index do |i|
|
219
263
|
c = cmd[i]
|
220
|
-
replycount =
|
264
|
+
replycount = 0
|
221
265
|
tk.send_request(false, c[0], c[1,c.length-1]) do |req, sentence|
|
222
266
|
replycount += 1
|
223
267
|
if c[0] == '/tool/fetch'
|
224
|
-
if
|
225
|
-
sentence.key?('status') &&
|
226
|
-
sentence['status'] == 'finished' &&
|
227
|
-
req.state != 'cancelled'
|
228
|
-
)
|
268
|
+
if sentence['status'] == 'finished' && req.state == :sent
|
229
269
|
## Cancel 'finished' fetch commands
|
230
270
|
req.cancel
|
231
271
|
end
|
232
|
-
elsif
|
233
|
-
|
272
|
+
elsif req.state == :sent && (
|
273
|
+
limit.nil? ? (replycount >= MAXREPLIES) : (limit > 0 && replycount >= limit)
|
274
|
+
)
|
275
|
+
## Auto-cancel any command after the maximum number of replies:
|
234
276
|
req.cancel
|
235
277
|
end
|
236
278
|
if sentence.key?('!done')
|
@@ -239,7 +281,7 @@ module MTik
|
|
239
281
|
end
|
240
282
|
end
|
241
283
|
|
242
|
-
tk.wait_all ## Event loop -- wait for all commands
|
284
|
+
tk.wait_all ## Event loop -- wait for all commands to finish
|
243
285
|
tk.get_reply('/quit')
|
244
286
|
tk.close
|
245
287
|
return replies
|
data/lib/mtik/request.rb
CHANGED
@@ -242,7 +242,7 @@ class MTik::Request < Array
|
|
242
242
|
if @state != :sent
|
243
243
|
raise MTik::Error.new(
|
244
244
|
"Method MTik::Request#cancel() called with state '#{@state}' " +
|
245
|
-
"(should only call when state is
|
245
|
+
"(should only call when state is :sent)"
|
246
246
|
)
|
247
247
|
end
|
248
248
|
@conn.send_request(true, '/cancel', '=tag=' + @tag, &callback)
|
@@ -254,7 +254,7 @@ class MTik::Request < Array
|
|
254
254
|
if @state != :sent
|
255
255
|
raise MTik::Error.new(
|
256
256
|
"Method MTik::Request#cancel() called with state '#{@state}' " +
|
257
|
-
"(should only call when state is
|
257
|
+
"(should only call when state is :sent)"
|
258
258
|
)
|
259
259
|
end
|
260
260
|
@conn.send_request(false, '/cancel', '=tag=' + @tag, &callback)
|
metadata
CHANGED
@@ -1,34 +1,26 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: mtik
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 3
|
7
|
-
- 1
|
8
|
-
- 2
|
9
|
-
version: 3.1.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 4.0.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Aaron D. Gifford
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
date: 2011-01-11 00:00:00 -07:00
|
18
|
-
default_executable:
|
12
|
+
date: 2011-03-25 00:00:00.000000000Z
|
19
13
|
dependencies: []
|
20
|
-
|
21
14
|
description: MTik implements the MikroTik RouterOS API for use in Ruby.
|
22
15
|
email: email_not_accepted@aarongifford.com
|
23
|
-
executables:
|
16
|
+
executables:
|
24
17
|
- tikcli
|
25
18
|
- tikcommand
|
26
19
|
- tikfetch
|
27
20
|
extensions: []
|
28
|
-
|
29
|
-
extra_rdoc_files:
|
21
|
+
extra_rdoc_files:
|
30
22
|
- README.txt
|
31
|
-
files:
|
23
|
+
files:
|
32
24
|
- CHANGELOG.txt
|
33
25
|
- LICENSE.txt
|
34
26
|
- README.txt
|
@@ -45,37 +37,28 @@ files:
|
|
45
37
|
- lib/mtik/reply.rb
|
46
38
|
- lib/mtik/request.rb
|
47
39
|
- lib/mtik/timeouterror.rb
|
48
|
-
has_rdoc: true
|
49
40
|
homepage: http://www.aarongifford.com/computers/mtik/
|
50
41
|
licenses: []
|
51
|
-
|
52
42
|
post_install_message:
|
53
43
|
rdoc_options: []
|
54
|
-
|
55
|
-
require_paths:
|
44
|
+
require_paths:
|
56
45
|
- lib
|
57
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
47
|
none: false
|
59
|
-
requirements:
|
60
|
-
- -
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
|
63
|
-
|
64
|
-
version: "0"
|
65
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
53
|
none: false
|
67
|
-
requirements:
|
68
|
-
- -
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
|
71
|
-
- 0
|
72
|
-
version: "0"
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
73
58
|
requirements: []
|
74
|
-
|
75
59
|
rubyforge_project: mtik
|
76
|
-
rubygems_version: 1.
|
60
|
+
rubygems_version: 1.7.2
|
77
61
|
signing_key:
|
78
62
|
specification_version: 3
|
79
63
|
summary: MTik implements the MikroTik RouterOS API for use in Ruby.
|
80
64
|
test_files: []
|
81
|
-
|