mu 5.7.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Mu_Gem.html +1591 -0
- data/bin/mu +11 -0
- data/lib/mu.rb +65 -0
- data/lib/mu/api/ddt.rb +233 -0
- data/lib/mu/api/homepage.rb +54 -0
- data/lib/mu/api/muapi.rb +231 -0
- data/lib/mu/api/netconfig.rb +233 -0
- data/lib/mu/api/scale.rb +199 -0
- data/lib/mu/api/system.rb +40 -0
- data/lib/mu/client.rb +31 -0
- data/lib/mu/command.rb +28 -0
- data/lib/mu/command/api.rb +95 -0
- data/lib/mu/command/cmd_appid.rb +486 -0
- data/lib/mu/command/cmd_cli.rb +151 -0
- data/lib/mu/command/cmd_ddt.rb +449 -0
- data/lib/mu/command/cmd_homepage.rb +146 -0
- data/lib/mu/command/cmd_muapi.rb +361 -0
- data/lib/mu/command/cmd_netconfig.rb +262 -0
- data/lib/mu/command/cmd_runscale.rb +533 -0
- data/lib/mu/command/cmd_runscenario.rb +258 -0
- data/lib/mu/command/cmd_runverify.rb +336 -0
- data/lib/mu/command/cmd_scale.rb +333 -0
- data/lib/mu/command/cmd_system.rb +127 -0
- data/lib/mu/command/curl.rb +246 -0
- data/lib/mu/command/help.rb +29 -0
- data/lib/mu/curl/error.rb +54 -0
- data/lib/mu/curl/verify.rb +137 -0
- data/lib/mu/helper.rb +55 -0
- data/lib/mu/http_helper.rb +232 -0
- data/rdoc/classes/Mu.html +305 -0
- data/rdoc/classes/Mu/Client.html +265 -0
- data/rdoc/classes/Mu/Command.html +208 -0
- data/rdoc/classes/Mu/Command/API.html +524 -0
- data/rdoc/classes/Mu/Command/Cmd_appid.html +934 -0
- data/rdoc/classes/Mu/Command/Cmd_cli.html +515 -0
- data/rdoc/classes/Mu/Command/Cmd_ddt.html +1169 -0
- data/rdoc/classes/Mu/Command/Cmd_homepage.html +489 -0
- data/rdoc/classes/Mu/Command/Cmd_muapi.html +968 -0
- data/rdoc/classes/Mu/Command/Cmd_netconfig.html +743 -0
- data/rdoc/classes/Mu/Command/Cmd_runscale.html +970 -0
- data/rdoc/classes/Mu/Command/Cmd_runscenario.html +530 -0
- data/rdoc/classes/Mu/Command/Cmd_runverify.html +621 -0
- data/rdoc/classes/Mu/Command/Cmd_scale.html +939 -0
- data/rdoc/classes/Mu/Command/Cmd_system.html +426 -0
- data/rdoc/classes/Mu/Command/Curl.html +524 -0
- data/rdoc/classes/Mu/Command/Help.html +166 -0
- data/rdoc/classes/Mu/Curl.html +116 -0
- data/rdoc/classes/Mu/Curl/Error.html +157 -0
- data/rdoc/classes/Mu/Curl/Error/Authorize.html +178 -0
- data/rdoc/classes/Mu/Curl/Error/Connect.html +149 -0
- data/rdoc/classes/Mu/Curl/Error/DNS.html +113 -0
- data/rdoc/classes/Mu/Curl/Error/Region.html +160 -0
- data/rdoc/classes/Mu/Curl/Error/Status.html +149 -0
- data/rdoc/classes/Mu/Curl/Error/Timeout.html +149 -0
- data/rdoc/classes/Mu/Curl/Verify.html +282 -0
- data/rdoc/classes/Mu/Curl/Verify/Request.html +227 -0
- data/rdoc/classes/Mu/Curl/Verify/Response.html +187 -0
- data/rdoc/classes/Mu/Curl/Verify/Result.html +188 -0
- data/rdoc/classes/Mu/Ddt.html +914 -0
- data/rdoc/classes/Mu/Helper.html +308 -0
- data/rdoc/classes/Mu/Homepage.html +377 -0
- data/rdoc/classes/Mu/HttpHelper.html +639 -0
- data/rdoc/classes/Mu/Muapi.html +816 -0
- data/rdoc/classes/Mu/Netconfig.html +781 -0
- data/rdoc/classes/Mu/Scale.html +832 -0
- data/rdoc/classes/Mu/System.html +281 -0
- data/rdoc/classes/Object.html +148 -0
- data/rdoc/classes/TCTestMu.html +1793 -0
- data/rdoc/classes/Test.html +107 -0
- data/rdoc/classes/Test/Unit.html +107 -0
- data/rdoc/classes/Test/Unit/TestCase.html +113 -0
- data/rdoc/created.rid +1 -0
- data/rdoc/files/lib/mu/api/ddt_rb.html +101 -0
- data/rdoc/files/lib/mu/api/homepage_rb.html +101 -0
- data/rdoc/files/lib/mu/api/muapi_rb.html +101 -0
- data/rdoc/files/lib/mu/api/netconfig_rb.html +101 -0
- data/rdoc/files/lib/mu/api/scale_rb.html +101 -0
- data/rdoc/files/lib/mu/api/system_rb.html +101 -0
- data/rdoc/files/lib/mu/client_rb.html +101 -0
- data/rdoc/files/lib/mu/command/api_rb.html +101 -0
- data/rdoc/files/lib/mu/command/cmd_appid_rb.html +119 -0
- data/rdoc/files/lib/mu/command/cmd_cli_rb.html +108 -0
- data/rdoc/files/lib/mu/command/cmd_ddt_rb.html +117 -0
- data/rdoc/files/lib/mu/command/cmd_homepage_rb.html +115 -0
- data/rdoc/files/lib/mu/command/cmd_muapi_rb.html +116 -0
- data/rdoc/files/lib/mu/command/cmd_netconfig_rb.html +116 -0
- data/rdoc/files/lib/mu/command/cmd_runscale_rb.html +119 -0
- data/rdoc/files/lib/mu/command/cmd_runscenario_rb.html +115 -0
- data/rdoc/files/lib/mu/command/cmd_runverify_rb.html +117 -0
- data/rdoc/files/lib/mu/command/cmd_scale_rb.html +115 -0
- data/rdoc/files/lib/mu/command/cmd_system_rb.html +116 -0
- data/rdoc/files/lib/mu/command/curl_rb.html +101 -0
- data/rdoc/files/lib/mu/command/help_rb.html +101 -0
- data/rdoc/files/lib/mu/command_rb.html +107 -0
- data/rdoc/files/lib/mu/curl/error_rb.html +101 -0
- data/rdoc/files/lib/mu/curl/verify_rb.html +101 -0
- data/rdoc/files/lib/mu/helper_rb.html +101 -0
- data/rdoc/files/lib/mu/http_helper_rb.html +101 -0
- data/rdoc/files/lib/mu_rb.html +121 -0
- data/rdoc/files/test/helper_rb.html +112 -0
- data/rdoc/files/test/tc_test_mu_rb.html +111 -0
- data/rdoc/fr_class_index.html +68 -0
- data/rdoc/fr_file_index.html +55 -0
- data/rdoc/fr_method_index.html +374 -0
- data/rdoc/index.html +24 -0
- data/rdoc/rdoc-style.css +208 -0
- data/test/data/app_id_stats.csv +1 -0
- data/test/data/data_cgi.msl +94 -0
- data/test/data/data_cgi.xml +322 -0
- data/test/data/default_test.csv +3 -0
- data/test/data/ftp_with_channel.xml +1643 -0
- data/test/data/irc.xml +3837 -0
- data/test/data/scale_configuration.json +25 -0
- data/test/data/test_data_cgi_error.xml +35 -0
- data/test/helper.rb +18 -0
- data/test/tc_test_mu.rb +716 -0
- metadata +322 -0
@@ -0,0 +1,333 @@
|
|
1
|
+
# Use these commands to access the legacy REST API for Scale test (Studio Scale).
|
2
|
+
require 'mu/api/scale'
|
3
|
+
class Mu
|
4
|
+
class Command
|
5
|
+
class Cmd_scale < Command
|
6
|
+
|
7
|
+
attr_accessor :host, :username, :password, :api
|
8
|
+
|
9
|
+
# outputs help for this command
|
10
|
+
def cmd_help argv
|
11
|
+
help
|
12
|
+
end
|
13
|
+
|
14
|
+
# configures the scale json object
|
15
|
+
# * argv = command-line arguments, requires a params (-p) and params value (-pv) argument, such as -p volume -pv 100
|
16
|
+
def cmd_configure argv
|
17
|
+
setup argv
|
18
|
+
param = @hash['params']
|
19
|
+
value = @hash['param_value']
|
20
|
+
response = @api.configure(param, value)
|
21
|
+
msg response
|
22
|
+
return response
|
23
|
+
end
|
24
|
+
|
25
|
+
# starts a scale test
|
26
|
+
# * argv = command-line arguments, requires a scale json object to have been configured
|
27
|
+
def cmd_start argv
|
28
|
+
setup argv
|
29
|
+
response = @api.start
|
30
|
+
msg response
|
31
|
+
return response
|
32
|
+
end
|
33
|
+
|
34
|
+
# verifies a scale test
|
35
|
+
# * argv = command-line arguments, requires a scale json object to have been configured
|
36
|
+
def cmd_verify argv
|
37
|
+
setup argv
|
38
|
+
response = @api.verify
|
39
|
+
msg response
|
40
|
+
return response
|
41
|
+
end
|
42
|
+
|
43
|
+
# updates a running scale test (valid only if the test is running with no pattern)
|
44
|
+
# * argv = command-line arguments, requires a json params object (-p) such as '{ "volume": 100 }'
|
45
|
+
def cmd_update argv
|
46
|
+
setup argv
|
47
|
+
params = @hash['params']
|
48
|
+
response = @api.update(params)
|
49
|
+
msg response
|
50
|
+
return response
|
51
|
+
end
|
52
|
+
|
53
|
+
# returns status from a scale test
|
54
|
+
# * argv = command-line arguments
|
55
|
+
def cmd_status argv
|
56
|
+
setup argv
|
57
|
+
response = @api.status
|
58
|
+
msg response
|
59
|
+
return response
|
60
|
+
end
|
61
|
+
|
62
|
+
# returns an array of currently reserved scale engines
|
63
|
+
# * argv = command-line arguments
|
64
|
+
def cmd_list argv
|
65
|
+
setup argv
|
66
|
+
response = @api.list
|
67
|
+
msg response
|
68
|
+
return response
|
69
|
+
end
|
70
|
+
|
71
|
+
# returns scale engine configuration information
|
72
|
+
# * argv = command-line arguments
|
73
|
+
def cmd_about argv
|
74
|
+
setup argv
|
75
|
+
response = @api.about
|
76
|
+
msg response
|
77
|
+
return response
|
78
|
+
end
|
79
|
+
|
80
|
+
# returns a packet capture file from scale verify
|
81
|
+
# * argv = command-line arguments, requires a scale engine id (-b) and the pcap filename (-f) argument
|
82
|
+
def cmd_pcap argv
|
83
|
+
setup argv
|
84
|
+
bot_id = @hash['bot_id']
|
85
|
+
file = @hash['filename']
|
86
|
+
response = @api.pcap(bot_id, file)
|
87
|
+
msg response
|
88
|
+
return response
|
89
|
+
end
|
90
|
+
|
91
|
+
# returns the status of all reserved scale engines
|
92
|
+
# * argv = command-line arguments
|
93
|
+
def cmd_statuses argv
|
94
|
+
setup argv
|
95
|
+
response = @api.statuses
|
96
|
+
msg response
|
97
|
+
return response
|
98
|
+
end
|
99
|
+
|
100
|
+
# returns scale test data for charting
|
101
|
+
# * argv = command-line arguments, requires:
|
102
|
+
# * view (-w), which specifies the TIMELINE or CALLGRAPH chart.
|
103
|
+
# * zoom (-z), which specifies the zoom level (0 to 1). 1 returns data for 100% of the time range, 0.5 returns data for 50% of the time range, and 0 returns only the last minute of data
|
104
|
+
# * position (-p), which must be 0.
|
105
|
+
# * scale engine id (-b)
|
106
|
+
def cmd_data argv
|
107
|
+
setup argv
|
108
|
+
begin
|
109
|
+
view = @hash['view']
|
110
|
+
zoom = @hash['zoom']
|
111
|
+
position = @hash['view_position']
|
112
|
+
bot_id = @hash['bot_id']
|
113
|
+
response = @api.data(view, zoom, position, bot_id)
|
114
|
+
rescue => e
|
115
|
+
msg e
|
116
|
+
end
|
117
|
+
msg response
|
118
|
+
return response
|
119
|
+
end
|
120
|
+
|
121
|
+
# returns scale test data for charting
|
122
|
+
# * argv = command-line arguments, requires:
|
123
|
+
# * zoom (z) level
|
124
|
+
# * position(-p 0)
|
125
|
+
def cmd_pattern argv
|
126
|
+
setup argv
|
127
|
+
begin
|
128
|
+
zoom = @hash['zoom']
|
129
|
+
position = @hash['view_position']
|
130
|
+
response = @api.pattern(zoom, position)
|
131
|
+
rescue => e
|
132
|
+
msg e
|
133
|
+
end
|
134
|
+
msg response
|
135
|
+
return response
|
136
|
+
end
|
137
|
+
|
138
|
+
# stops a scale test
|
139
|
+
# * argv = command-line arguments
|
140
|
+
def cmd_stop argv
|
141
|
+
setup argv
|
142
|
+
response = @api.stop
|
143
|
+
msg response
|
144
|
+
return response
|
145
|
+
end
|
146
|
+
|
147
|
+
# releases the currently reserved scale engine
|
148
|
+
# * argv = command-line arguments
|
149
|
+
def cmd_release argv
|
150
|
+
setup argv
|
151
|
+
response = @api.release
|
152
|
+
msg response
|
153
|
+
return response
|
154
|
+
end
|
155
|
+
|
156
|
+
# reserves a scale engine
|
157
|
+
# * argv = command-line arguments, require a scale engine id (-b) argument
|
158
|
+
def cmd_reserve_scale_engine argv
|
159
|
+
setup argv
|
160
|
+
bot_id = @hash['bot_id']
|
161
|
+
response = @api.reserve_scale_engine(bot_id)
|
162
|
+
msg response
|
163
|
+
return response
|
164
|
+
end
|
165
|
+
|
166
|
+
# releases a scale engine
|
167
|
+
# * argv = command-line arguments, require a scale engine id (-b) argument
|
168
|
+
def cmd_release_scale_engine argv
|
169
|
+
setup argv
|
170
|
+
bot_id = @hash['bot_id']
|
171
|
+
response = @api.release_scale_engine(bot_id)
|
172
|
+
msg response
|
173
|
+
return response
|
174
|
+
end
|
175
|
+
|
176
|
+
# deletes a scale engine
|
177
|
+
# * argv = command-line arguments, require a scale engine id (-b) argument
|
178
|
+
def cmd_delete_scale_engine argv
|
179
|
+
setup argv
|
180
|
+
bot_id = @hash['bot_id']
|
181
|
+
response = @api.delete_scale_engine(bot_id)
|
182
|
+
msg response
|
183
|
+
return response
|
184
|
+
end
|
185
|
+
|
186
|
+
private
|
187
|
+
|
188
|
+
def setup argv
|
189
|
+
parse_cli argv
|
190
|
+
@host = (@@mu_ip.nil?) ? "127.0.0.1" : @@mu_ip
|
191
|
+
@username = (@@mu_admin_user.nil?) ? "admin" : @@mu_admin_user
|
192
|
+
@password = (@@mu_admin_pass.nil?) ? "admin" : @@mu_admin_pass
|
193
|
+
@api = Scale.new(@host, @username, @password)
|
194
|
+
response = @api.session
|
195
|
+
msg response
|
196
|
+
return response
|
197
|
+
end
|
198
|
+
|
199
|
+
def parse_cli argv
|
200
|
+
@hash = {}
|
201
|
+
args = Array.new
|
202
|
+
while not argv.empty?
|
203
|
+
args << argv.shift if argv.first[0,1] != '-'
|
204
|
+
|
205
|
+
k = argv.shift
|
206
|
+
|
207
|
+
if [ '-b', '--bot_id' ].member? k
|
208
|
+
@hash['bot_id'] = shift(k, argv)
|
209
|
+
next
|
210
|
+
end
|
211
|
+
|
212
|
+
if [ '-c', '--config_file' ].member? k
|
213
|
+
puts "process -c"
|
214
|
+
ENV['SCALE_CONFIG_FILE'] = shift(k, argv)
|
215
|
+
next
|
216
|
+
end
|
217
|
+
|
218
|
+
if [ '-f', '--filename' ].member? k
|
219
|
+
@hash['filename'] = shift(k, argv)
|
220
|
+
next
|
221
|
+
end
|
222
|
+
|
223
|
+
if [ '-h', '--help' ].member? k
|
224
|
+
help
|
225
|
+
exit
|
226
|
+
end
|
227
|
+
|
228
|
+
if [ '-m', '--mu_string' ].member? k
|
229
|
+
mu_string = shift(k, argv)
|
230
|
+
if mu_string =~ /(.+?):(.+?)@(.*)/
|
231
|
+
@@mu_admin_user = $1
|
232
|
+
@@mu_admin_pass = $2
|
233
|
+
@@mu_ip = $3
|
234
|
+
end
|
235
|
+
next
|
236
|
+
end
|
237
|
+
|
238
|
+
if [ '-o', '--output' ].member? k
|
239
|
+
$stdout.reopen(shift(k, argv), "w")
|
240
|
+
next
|
241
|
+
end
|
242
|
+
|
243
|
+
if [ '-p', '--params' ].member? k
|
244
|
+
@hash['params'] = shift(k, argv)
|
245
|
+
next
|
246
|
+
end
|
247
|
+
|
248
|
+
if [ '-ps', '--view_position' ].member? k
|
249
|
+
@hash['view_position'] = shift(k, argv)
|
250
|
+
next
|
251
|
+
end
|
252
|
+
|
253
|
+
if [ '-pv', '--param_value' ].member? k
|
254
|
+
@hash['param_value'] = shift(k, argv)
|
255
|
+
next
|
256
|
+
end
|
257
|
+
|
258
|
+
if [ '-v', '--verbose' ].member? k
|
259
|
+
$log.level = Logger::DEBUG
|
260
|
+
next
|
261
|
+
end
|
262
|
+
|
263
|
+
if [ '-w', '--view' ].member? k
|
264
|
+
@hash['view'] = shift(k, argv)
|
265
|
+
next
|
266
|
+
end
|
267
|
+
|
268
|
+
if [ '-z', '--zoom' ].member? k
|
269
|
+
@hash['zoom'] = shift(k, argv)
|
270
|
+
next
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
args
|
275
|
+
end
|
276
|
+
|
277
|
+
def help
|
278
|
+
helps = [
|
279
|
+
{ :short => '-b', :long => '--bot_id', :value => '<string>', :help => 'scale engine identifier' },
|
280
|
+
{ :short => '-c', :long => '--config_file', :value => '<string>', :help => 'change json config_file' },
|
281
|
+
{ :short => '-f', :long => '--filename', :value => '<string>', :help => 'pcap filename' },
|
282
|
+
{ :short => '-h', :long => '--help', :value => '', :help => 'help on command line options' },
|
283
|
+
{ :short => '-m', :long => '--mu_string', :value => '<string>', :help => 'user, password, mu_ip in the form of admin:admin@10.9.8.7' },
|
284
|
+
{ :short => '-o', :long => '--output', :value => '<string>', :help => 'output logging to this file' },
|
285
|
+
{ :short => '-p', :long => '--params', :value => '<string>', :help => 'param(s) for configure or update' },
|
286
|
+
{ :short => '-ps', :long => '--view_position', :value => '<string>', :help => 'view position for data calls' },
|
287
|
+
{ :short => '-pv', :long => '--param_value', :value => '<string>', :help => 'param value for configure' },
|
288
|
+
{ :short => '-v', :long => '--verbose', :value => '', :help => 'set Logger::DEBUG level' },
|
289
|
+
{ :short => '-w', :long => '--view', :value => '<string>', :help => 'view (RUNTIME|CALLGRAPH) for data calls' },
|
290
|
+
{ :short => '-z', :long => '--zoom', :value => '<string>', :help => 'zoom value for data calls' }
|
291
|
+
]
|
292
|
+
|
293
|
+
cmds = [
|
294
|
+
"mu cmd_scale:about",
|
295
|
+
"mu cmd_scale:configure -p <param> -pv <value>",
|
296
|
+
"mu cmd_scale:data -w <view> -z <zoom> -ps <position> -b <bot_id>",
|
297
|
+
"mu cmd_scale:delete_scale_engine -b <bot_id>",
|
298
|
+
"mu cmd_scale:help",
|
299
|
+
"mu cmd_scale:list",
|
300
|
+
"mu cmd_scale:pattern -z <zoom> -ps <position> ",
|
301
|
+
"mu cmd_scale:pcap -b <bot_id> -f <filename>",
|
302
|
+
"mu cmd_scale:release",
|
303
|
+
"mu cmd_scale:release_scale_engine -b <bot_id>",
|
304
|
+
"mu cmd_scale:reserve_scale_engine -b <bot_id>",
|
305
|
+
"mu cmd_scale:session (a.k.a. /new)", # new
|
306
|
+
"mu cmd_scale:start",
|
307
|
+
"mu cmd_scale:status",
|
308
|
+
"mu cmd_scale:statuses",
|
309
|
+
"mu cmd_scale:stop",
|
310
|
+
"mu cmd_scale:update -p <params>",
|
311
|
+
"mu cmd_scale:verify"
|
312
|
+
]
|
313
|
+
|
314
|
+
max_long_size = helps.inject(0) { |memo, obj| [ obj[:long].size, memo ].max }
|
315
|
+
max_value_size = helps.inject(0) { |memo, obj| [ obj[:value].size, memo ].max }
|
316
|
+
puts
|
317
|
+
puts "Usage: mu cmd_scale <options>"
|
318
|
+
puts
|
319
|
+
helps.each do |h|
|
320
|
+
puts "%-*s %*s %-*s %s" % [max_long_size, h[:long], 2, h[:short], max_value_size, h[:value], h[:help]]
|
321
|
+
end
|
322
|
+
puts
|
323
|
+
puts "Available Commands"
|
324
|
+
puts
|
325
|
+
cmds.each do | c |
|
326
|
+
puts c
|
327
|
+
end
|
328
|
+
puts
|
329
|
+
end
|
330
|
+
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# Api methods to access the Mu System System page
|
2
|
+
# Use these commands to restart system services or to get status details for the Mu system
|
3
|
+
require 'mu/api/system'
|
4
|
+
class Mu
|
5
|
+
class Command
|
6
|
+
class Cmd_system < Command
|
7
|
+
|
8
|
+
attr_accessor :host, :username, :password, :api
|
9
|
+
|
10
|
+
# outputs help for this command
|
11
|
+
# * argv = command-line arguments
|
12
|
+
def cmd_help argv
|
13
|
+
help
|
14
|
+
end
|
15
|
+
|
16
|
+
# restarts the Mu system services (this does not reboot the appliance)
|
17
|
+
# * argv = command-line arguments
|
18
|
+
def cmd_restart argv
|
19
|
+
setup argv
|
20
|
+
response = @api.restart
|
21
|
+
msg response
|
22
|
+
return response
|
23
|
+
end
|
24
|
+
|
25
|
+
# gets the complete System status page
|
26
|
+
# * argv = command-line arguments
|
27
|
+
def cmd_status argv
|
28
|
+
setup argv
|
29
|
+
response = @api.status
|
30
|
+
msg response
|
31
|
+
return response
|
32
|
+
end
|
33
|
+
|
34
|
+
# gets additional system status information, imncluding hard drive, model and serial data
|
35
|
+
# * argv = command-line arguments
|
36
|
+
def cmd_status2 argv
|
37
|
+
setup argv
|
38
|
+
response = @api.status2
|
39
|
+
msg response
|
40
|
+
return response
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def setup argv
|
46
|
+
parse_cli argv
|
47
|
+
@host = (@@mu_ip.nil?) ? "127.0.0.1" : @@mu_ip
|
48
|
+
@username = (@@mu_admin_user.nil?) ? "admin" : @@mu_admin_user
|
49
|
+
@password = (@@mu_admin_pass.nil?) ? "admin" : @@mu_admin_pass
|
50
|
+
@api = System.new(@host, @username, @password)
|
51
|
+
msg "Created System Api object to :#{@host}", Logger::DEBUG
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
# parses command-line arguments
|
56
|
+
def parse_cli argv
|
57
|
+
args = Array.new
|
58
|
+
while not argv.empty?
|
59
|
+
args << argv.shift if argv.first[0,1] != '-'
|
60
|
+
|
61
|
+
k = argv.shift
|
62
|
+
|
63
|
+
if [ '-h', '--help' ].member? k
|
64
|
+
help
|
65
|
+
exit
|
66
|
+
end
|
67
|
+
|
68
|
+
if [ '-m', '--mu_string' ].member? k
|
69
|
+
mu_string = shift(k, argv)
|
70
|
+
if mu_string =~ /(.+?):(.+?)@(.*)/
|
71
|
+
@@mu_admin_user = $1
|
72
|
+
@@mu_admin_pass = $2
|
73
|
+
@@mu_ip = $3
|
74
|
+
end
|
75
|
+
next
|
76
|
+
end
|
77
|
+
|
78
|
+
if [ '-o', '--output' ].member? k
|
79
|
+
$stdout.reopen(shift(k, argv), "w")
|
80
|
+
next
|
81
|
+
end
|
82
|
+
|
83
|
+
if [ '-v', '--verbose' ].member? k
|
84
|
+
$log.level = Logger::DEBUG
|
85
|
+
next
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
args
|
91
|
+
end
|
92
|
+
|
93
|
+
# displays command-line help
|
94
|
+
def help
|
95
|
+
helps = [
|
96
|
+
{ :short => '-h', :long => '--help', :value => '', :help => 'help on command line options' },
|
97
|
+
{ :short => '-m', :long => '--mu_string', :value => '<string>', :help => 'user, password, mu_ip in the form of admin:admin@10.9.8.7' },
|
98
|
+
{ :short => '-o', :long => '--output', :value => '<string>', :help => 'output logging to this file' },
|
99
|
+
{ :short => '-v', :long => '--verbose', :value => '', :help => 'set Logger::DEBUG level' }
|
100
|
+
]
|
101
|
+
|
102
|
+
cmds = [
|
103
|
+
"mu cmd_system:restart",
|
104
|
+
"mu cmd_system:status",
|
105
|
+
"mu cmd_system:status2"
|
106
|
+
]
|
107
|
+
|
108
|
+
max_long_size = helps.inject(0) { |memo, obj| [ obj[:long].size, memo ].max }
|
109
|
+
max_value_size = helps.inject(0) { |memo, obj| [ obj[:value].size, memo ].max }
|
110
|
+
puts
|
111
|
+
puts "Usage: mu cmd_system <options>"
|
112
|
+
puts
|
113
|
+
helps.each do |h|
|
114
|
+
puts "%-*s %*s %-*s %s" % [max_long_size, h[:long], 2, h[:short], max_value_size, h[:value], h[:help]]
|
115
|
+
end
|
116
|
+
puts
|
117
|
+
puts "Available Commands"
|
118
|
+
puts
|
119
|
+
cmds.each do | c |
|
120
|
+
puts c
|
121
|
+
end
|
122
|
+
puts
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
end # Command
|
127
|
+
end # Mu
|