opennebula-cli 5.6.2 → 5.7.80.pre

Sign up to get free protection for your applications and to get access to all the features.
data/bin/oneflow CHANGED
@@ -16,16 +16,16 @@
16
16
  # limitations under the License. #
17
17
  #--------------------------------------------------------------------------- #
18
18
 
19
- ONE_LOCATION=ENV["ONE_LOCATION"]
19
+ ONE_LOCATION = ENV['ONE_LOCATION']
20
20
 
21
21
  if !ONE_LOCATION
22
- RUBY_LIB_LOCATION="/usr/lib/one/ruby"
22
+ RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
23
23
  else
24
- RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
24
+ RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
25
25
  end
26
26
 
27
- $: << RUBY_LIB_LOCATION
28
- $: << RUBY_LIB_LOCATION+'/cli'
27
+ $LOAD_PATH << RUBY_LIB_LOCATION
28
+ $LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
29
29
 
30
30
  require 'command_parser'
31
31
  require 'opennebula/oneflow_client'
@@ -35,139 +35,142 @@ require 'one_helper/onevm_helper'
35
35
 
36
36
  require 'json'
37
37
 
38
- USER_AGENT = "CLI"
38
+ USER_AGENT = 'CLI'
39
39
 
40
40
  # Base Path representing the resource to be used in the requests
41
- RESOURCE_PATH = "/service"
41
+ RESOURCE_PATH = '/service'
42
42
 
43
43
  #
44
44
  # Table
45
45
  #
46
46
 
47
47
  SERVICE_TABLE = CLIHelper::ShowTable.new(nil, self) do
48
- column :ID, "ID", :size=>10 do |d|
49
- d["ID"]
48
+ column :ID, 'ID', :size => 10 do |d|
49
+ d['ID']
50
50
  end
51
51
 
52
- column :USER, "Username", :left, :size=>15 do |d|
53
- d["UNAME"]
52
+ column :USER, 'Username', :left, :size => 15 do |d|
53
+ d['UNAME']
54
54
  end
55
55
 
56
- column :GROUP, "Group", :left, :size=>15 do |d|
57
- d["GNAME"]
56
+ column :GROUP, 'Group', :left, :size => 15 do |d|
57
+ d['GNAME']
58
58
  end
59
59
 
60
- column :NAME, "Name", :size=>25, :left=>true do |d|
61
- d["NAME"]
60
+ column :NAME, 'Name', :size => 25, :left => true do |d|
61
+ d['NAME']
62
62
  end
63
63
 
64
- column :STATE, "State", :size=>11, :left=>true do |d|
65
- Service.state_str(d["TEMPLATE"]["BODY"]['state'])
64
+ column :STATE, 'State', :size => 11, :left => true do |d|
65
+ Service.state_str(d['TEMPLATE']['BODY']['state'])
66
66
  end
67
67
 
68
68
  default :ID, :USER, :GROUP, :NAME, :STATE
69
69
  end
70
70
 
71
71
  NODE_TABLE = CLIHelper::ShowTable.new(nil, self) do
72
- column :VM_ID, "ONE identifier for Virtual Machine", :size=>6 do |d|
73
- st = ""
72
+ column :VM_ID, 'ONE identifier for Virtual Machine', :size => 6 do |d|
73
+ st = ''
74
74
  if d['scale_up']
75
- st << "\u2191 "
75
+ st << '\u2191 '
76
76
  elsif d['disposed']
77
- st << "\u2193 "
77
+ st << '\u2193 '
78
78
  end
79
79
 
80
80
  if d['vm_info'].nil?
81
81
  st << d['deploy_id'].to_s
82
82
  else
83
- st << d['vm_info']['VM']["ID"]
83
+ st << d['vm_info']['VM']['ID']
84
84
  end
85
85
 
86
86
  st
87
87
  end
88
88
 
89
- column :NAME, "Name of the Virtual Machine", :left,
90
- :size=>23 do |d|
89
+ column :NAME, 'Name of the Virtual Machine', :left,
90
+ :size => 23 do |d|
91
91
  if !d['vm_info'].nil?
92
- if d['vm_info']['VM']["RESCHED"] == "1"
93
- "*#{d["NAME"]}"
92
+ if d['vm_info']['VM']['RESCHED'] == '1'
93
+ "*#{d['NAME']}"
94
94
  else
95
- d['vm_info']['VM']["NAME"]
95
+ d['vm_info']['VM']['NAME']
96
96
  end
97
97
  else
98
- ""
98
+ ''
99
99
  end
100
100
  end
101
101
 
102
- column :USER, "Username of the Virtual Machine owner", :left,
103
- :size=>8 do |d|
102
+ column :USER, 'Username of the Virtual Machine owner', :left,
103
+ :size => 8 do |d|
104
104
  if !d['vm_info'].nil?
105
- d['vm_info']['VM']["UNAME"]
105
+ d['vm_info']['VM']['UNAME']
106
106
  else
107
- ""
107
+ ''
108
108
  end
109
109
  end
110
110
 
111
- column :GROUP, "Group of the Virtual Machine", :left,
112
- :size=>8 do |d|
111
+ column :GROUP, 'Group of the Virtual Machine', :left,
112
+ :size => 8 do |d|
113
113
  if !d['vm_info'].nil?
114
- d['vm_info']['VM']["GNAME"]
114
+ d['vm_info']['VM']['GNAME']
115
115
  else
116
- ""
116
+ ''
117
117
  end
118
118
  end
119
119
 
120
- column :STAT, "Actual status", :size=>4 do |d,e|
120
+ column :STAT, 'Actual status', :size => 4 do |d, _|
121
121
  if !d['vm_info'].nil?
122
- OneVMHelper.state_to_str(d['vm_info']['VM']["STATE"], d['vm_info']['VM']["LCM_STATE"])
122
+ OneVMHelper.state_to_str(d['vm_info']['VM']['STATE'],
123
+ d['vm_info']['VM']['LCM_STATE'])
123
124
  else
124
- ""
125
+ ''
125
126
  end
126
127
  end
127
128
 
128
- column :UCPU, "CPU percentage used by the VM", :size=>4 do |d|
129
+ column :UCPU, 'CPU percentage used by the VM', :size => 4 do |d|
129
130
  if !d['vm_info'].nil?
130
- d['vm_info']['VM']["CPU"]
131
+ d['vm_info']['VM']['CPU']
131
132
  else
132
- ""
133
+ ''
133
134
  end
134
135
  end
135
136
 
136
- column :UMEM, "Memory used by the VM", :size=>7 do |d|
137
+ column :UMEM, 'Memory used by the VM', :size => 7 do |d|
137
138
  if !d['vm_info'].nil?
138
- OpenNebulaHelper.unit_to_str(d['vm_info']['VM']["MEMORY"].to_i, {})
139
+ OpenNebulaHelper.unit_to_str(d['vm_info']['VM']['MEMORY'].to_i, {})
139
140
  else
140
- ""
141
+ ''
141
142
  end
142
143
  end
143
144
 
144
- column :HOST, "Host where the VM is running", :left, :size=>20 do |d|
145
+ column :HOST, 'Host where the VM is running', :left, :size => 20 do |d|
145
146
  if !d['vm_info'].nil?
146
- if d['vm_info']['VM']['HISTORY_RECORDS'] && d['vm_info']['VM']['HISTORY_RECORDS']['HISTORY']
147
- state_str = VirtualMachine::VM_STATE[d['vm_info']['VM']['STATE'].to_i]
148
- if %w{ACTIVE SUSPENDED}.include? state_str
149
- history = if d['vm_info']['VM']['HISTORY_RECORDS']['HISTORY'].instance_of?(Array)
150
- d['vm_info']['VM']['HISTORY_RECORDS']['HISTORY'].last
151
- else
152
- d['vm_info']['VM']['HISTORY_RECORDS']['HISTORY']
153
- end
154
-
147
+ if d['vm_info']['VM']['HISTORY_RECORDS'] &&
148
+ d['vm_info']['VM']['HISTORY_RECORDS']['HISTORY']
149
+ state_str =
150
+ VirtualMachine::VM_STATE[d['vm_info']['VM']['STATE'].to_i]
151
+ history = d['vm_info']['VM']['HISTORY_RECORDS']['HISTORY']
152
+ if %w[ACTIVE SUSPENDED].include? state_str
153
+ history = history.last if history.instance_of?(Array)
155
154
  history['HOSTNAME']
156
155
  end
157
156
  end
158
157
  else
159
- ""
158
+ ''
160
159
  end
161
160
  end
162
161
 
163
- column :TIME, "Time since the VM was submitted", :size=>10 do |d|
162
+ column :TIME, 'Time since the VM was submitted', :size => 10 do |d|
164
163
  if !d['vm_info'].nil?
165
- stime = d['vm_info']['VM']["STIME"].to_i
166
- etime = d['vm_info']['VM']["ETIME"]=="0" ? Time.now.to_i : d['vm_info']['VM']["ETIME"].to_i
167
- dtime = etime-stime
164
+ stime = d['vm_info']['VM']['STIME'].to_i
165
+ if d['vm_info']['VM']['ETIME'] == '0'
166
+ etime = Time.now.to_i
167
+ else
168
+ etime = d['vm_info']['VM']['ETIME'].to_i
169
+ end
170
+ dtime = etime - stime
168
171
  OpenNebulaHelper.period_to_str(dtime, false)
169
172
  else
170
- ""
173
+ ''
171
174
  end
172
175
  end
173
176
 
@@ -176,19 +179,18 @@ end
176
179
 
177
180
  # List the services. This method is used in top and list commands
178
181
  # @param [Service::Client] client
179
- # @param [Array] args
180
182
  # @param [Hash] options
181
183
  # @return [[Integer, String], Integer] Returns the exit_code and optionally
182
184
  # a String to be printed
183
- def list_services(client, args, options)
185
+ def list_services(client, options)
184
186
  response = client.get(RESOURCE_PATH)
185
187
 
186
- if CloudClient::is_error?(response)
188
+ if CloudClient.is_error?(response)
187
189
  [response.code.to_i, response.to_s]
188
190
  else
189
- #[0,response.body]
191
+ # [0,response.body]
190
192
  if options[:json]
191
- [0,response.body]
193
+ [0, response.body]
192
194
  else
193
195
  array_list = JSON.parse(response.body)
194
196
  SERVICE_TABLE.show(array_list['DOCUMENT_POOL']['DOCUMENT'])
@@ -206,73 +208,92 @@ end
206
208
  def show_service(client, args, options)
207
209
  response = client.get("#{RESOURCE_PATH}/#{args[0]}")
208
210
 
209
- if CloudClient::is_error?(response)
211
+ if CloudClient.is_error?(response)
210
212
  [response.code.to_i, response.to_s]
211
213
  else
212
- #[0,response.body]
214
+ # [0,response.body]
213
215
  if options[:json]
214
- [0,response.body]
216
+ [0, response.body]
215
217
  else
216
- str="%-20s: %-20s"
217
- str_h1="%-80s"
218
+ str = '%-20s: %-20s'
219
+ str_h1 = '%-80s'
218
220
 
219
221
  document_hash = JSON.parse(response.body)
220
222
  template = document_hash['DOCUMENT']['TEMPLATE']['BODY']
221
-
222
- CLIHelper.print_header(str_h1 % "SERVICE #{document_hash['DOCUMENT']['ID']} INFORMATION")
223
-
224
- puts str % ["ID", document_hash['DOCUMENT']['ID']]
225
- puts str % ["NAME", document_hash['DOCUMENT']['NAME']]
226
- puts str % ["USER", document_hash['DOCUMENT']['UNAME']]
227
- puts str % ["GROUP",document_hash['DOCUMENT']['GNAME']]
228
-
229
- puts str % ["STRATEGY", template['deployment']]
230
- puts str % ["SERVICE STATE", Service.state_str(template['state'])]
231
- puts str % ["SHUTDOWN", template['shutdown_action']] if template['shutdown_action']
223
+ str_header = "SERVICE #{document_hash['DOCUMENT']['ID']} "\
224
+ 'INFORMATION'
225
+ CLIHelper.print_header(str_h1 % str_header)
226
+
227
+ puts format(str, ['ID', document_hash['DOCUMENT']['ID']])
228
+ puts format(str, ['NAME', document_hash['DOCUMENT']['NAME']])
229
+ puts format(str, ['USER', document_hash['DOCUMENT']['UNAME']])
230
+ puts format(str, ['GROUP', document_hash['DOCUMENT']['GNAME']])
231
+
232
+ puts format(str, ['STRATEGY', template['deployment']])
233
+ puts format(str,
234
+ ['SERVICE STATE', Service.state_str(template['state'])])
235
+ if template['shutdown_action']
236
+ puts format(str, ['SHUTDOWN', template['shutdown_action']])
237
+ end
232
238
 
233
239
  puts
234
240
 
235
- CLIHelper.print_header(str_h1 % "PERMISSIONS",false)
241
+ CLIHelper.print_header(str_h1 % 'PERMISSIONS', false)
236
242
 
237
- ["OWNER", "GROUP", "OTHER"].each { |e|
238
- mask = "---"
239
- mask[0] = "u" if document_hash['DOCUMENT']['PERMISSIONS']["#{e}_U"] == "1"
240
- mask[1] = "m" if document_hash['DOCUMENT']['PERMISSIONS']["#{e}_M"] == "1"
241
- mask[2] = "a" if document_hash['DOCUMENT']['PERMISSIONS']["#{e}_A"] == "1"
243
+ %w[OWNER GROUP OTHER].each do |e|
244
+ mask = '---'
245
+ permissions_hash = document_hash['DOCUMENT']['PERMISSIONS']
246
+ mask[0] = 'u' if permissions_hash["#{e}_U"] == '1'
247
+ mask[1] = 'm' if permissions_hash["#{e}_M"] == '1'
248
+ mask[2] = 'a' if permissions_hash["#{e}_A"] == '1'
242
249
 
243
- puts str % [e, mask]
244
- }
250
+ puts format(str, [e, mask])
251
+ end
245
252
 
246
253
  puts
247
254
 
248
- template['roles'].each {|role|
255
+ template['roles'].each do |role|
249
256
  CLIHelper.print_header("ROLE #{role['name']}", false)
250
257
 
251
- puts str % ["ROLE STATE", Role.state_str(role['state'])]
252
- puts str % ["PARENTS", role['parents'].join(', ')] if role['parents']
253
- puts str % ["VM TEMPLATE", role['vm_template']]
254
- puts str % ["CARDINALITY", role['cardinality']]
255
- puts str % ["MIN VMS", role['min_vms']] if role['min_vms']
256
- puts str % ["MAX VMS", role['max_vms']] if role['max_vms']
257
- puts str % ["COOLDOWN", "#{role['cooldown']}s"] if role['cooldown']
258
- puts str % ["SHUTDOWN", role['shutdown_action']] if role['shutdown_action']
258
+ puts format(str, ['ROLE STATE', Role.state_str(role['state'])])
259
+ if role['parents']
260
+ puts format(str, ['PARENTS', role['parents'].join(', ')])
261
+ end
262
+ puts format(str, ['VM TEMPLATE', role['vm_template']])
263
+ puts format(str, ['CARDINALITY', role['cardinality']])
264
+ if role['min_vms']
265
+ puts format(str, ['MIN VMS', role['min_vms']])
266
+ end
267
+ if role['max_vms']
268
+ puts format(str, ['MAX VMS', role['max_vms']])
269
+ end
270
+ if role['coolddown']
271
+ puts format(str, ['COOLDOWN', "#{role['cooldown']}s"])
272
+ end
273
+ if role['shutdown_action']
274
+ puts format(str, ['SHUTDOWN', role['shutdown_action']])
275
+ end
259
276
 
260
- puts "NODES INFORMATION"
277
+ puts 'NODES INFORMATION'
261
278
  NODE_TABLE.show(role['nodes'])
262
279
 
263
- if !role['elasticity_policies'].nil? && role['elasticity_policies'].size > 0 || !role['scheduled_policies'].nil? && role['scheduled_policies'].size > 0
280
+ if !role['elasticity_policies'].nil? &&
281
+ !role['elasticity_policies'].empty? ||
282
+ !role['scheduled_policies'].nil? &&
283
+ !role['scheduled_policies'].emtpty?
264
284
  puts
265
- puts "ELASTICITY RULES"
285
+ puts 'ELASTICITY RULES'
266
286
 
267
- if role['elasticity_policies'] && role['elasticity_policies'].size > 0
287
+ if role['elasticity_policies'] &&
288
+ !role['elasticity_policies'].emtpty?
268
289
  puts
269
- # puts "ELASTICITY POLICIES"
290
+ # puts 'ELASTICITY POLICIES'
270
291
  CLIHelper::ShowTable.new(nil, self) do
271
- column :ADJUST, "", :left, :size=>12 do |d|
292
+ column :ADJUST, '', :left, :size => 12 do |d|
272
293
  adjust_str(d)
273
294
  end
274
295
 
275
- column :EXPRESSION, "", :left, :size=>48 do |d|
296
+ column :EXPRESSION, '', :left, :size => 48 do |d|
276
297
  if !d['expression_evaluated'].nil?
277
298
  d['expression_evaluated']
278
299
  else
@@ -280,19 +301,20 @@ def show_service(client, args, options)
280
301
  end
281
302
  end
282
303
 
283
- column :'EVALS', "", :right, :size=>5 do |d|
304
+ column :EVALS, '', :right, :size => 5 do |d|
284
305
  if d['period_number']
285
- "#{d['true_evals'].to_i}/#{d['period_number']}"
306
+ "#{d['true_evals'].to_i}/"\
307
+ "#{d['period_number']}"
286
308
  else
287
- "-"
309
+ '-'
288
310
  end
289
311
  end
290
312
 
291
- column :PERIOD, "", :size=>6 do |d|
292
- d['period'] ? "#{d['period']}s" : '-'
313
+ column :PERIOD, '', :size => 6 do |d|
314
+ d['period'] ? "#{d['period']}s" : '-'
293
315
  end
294
316
 
295
- column :COOL, "", :size=>5 do |d|
317
+ column :COOL, '', :size => 5 do |d|
296
318
  d['cooldown'] ? "#{d['cooldown']}s" : '-'
297
319
  end
298
320
 
@@ -300,15 +322,16 @@ def show_service(client, args, options)
300
322
  end.show([role['elasticity_policies']].flatten, {})
301
323
  end
302
324
 
303
- if role['scheduled_policies'] && role['scheduled_policies'].size > 0
325
+ if role['scheduled_policies'] &&
326
+ !role['scheduled_policies'].empty?
304
327
  puts
305
- # puts "SCHEDULED POLICIES"
328
+ # puts 'SCHEDULED POLICIES'
306
329
  CLIHelper::ShowTable.new(nil, self) do
307
- column :ADJUST, "", :left, :size=>12 do |d|
330
+ column :ADJUST, '', :left, :size => 12 do |d|
308
331
  adjust_str(d)
309
332
  end
310
333
 
311
- column :TIME, "", :left, :size=>67 do |d|
334
+ column :TIME, '', :left, :size => 67 do |d|
312
335
  if d['start_time']
313
336
  Time.parse(d['start_time']).to_s
314
337
  else
@@ -322,17 +345,17 @@ def show_service(client, args, options)
322
345
  end
323
346
 
324
347
  puts
325
- }
348
+ end
326
349
 
327
350
  puts
328
351
 
329
- CLIHelper.print_header(str_h1 % "LOG MESSAGES",false)
352
+ CLIHelper.print_header(str_h1 % 'LOG MESSAGES', false)
330
353
 
331
354
  if template['log']
332
- template['log'].each { |log|
333
- t = Time.at(log['timestamp']).strftime("%m/%d/%y %H:%M")
355
+ template['log'].each do |log|
356
+ t = Time.at(log['timestamp']).strftime('%m/%d/%y %H:%M')
334
357
  puts "#{t} [#{log['severity']}] #{log['message']}"
335
- }
358
+ end
336
359
  end
337
360
 
338
361
  0
@@ -341,7 +364,7 @@ def show_service(client, args, options)
341
364
  end
342
365
 
343
366
  def adjust_str(policy)
344
- sign = policy['adjust'].to_i >= 0 ? "+" : "-"
367
+ policy['adjust'].to_i >= 0 ? sign = '+' : sign = '-'
345
368
  adjust = policy['adjust'].to_i.abs
346
369
 
347
370
  case policy['type']
@@ -363,8 +386,8 @@ end
363
386
  # Commands
364
387
  #
365
388
 
366
- cmd=CommandParser::CmdParser.new(ARGV) do
367
- usage "`oneflow` <command> [<args>] [<options>]"
389
+ CommandParser::CmdParser.new(ARGV) do
390
+ usage '`oneflow` <command> [<args>] [<options>]'
368
391
  version OpenNebulaHelper::ONE_VERSION
369
392
 
370
393
  set :option, Service::DEFAULT_OPTIONS
@@ -374,27 +397,29 @@ cmd=CommandParser::CmdParser.new(ARGV) do
374
397
  #
375
398
  # Formatters for arguments
376
399
  #
377
- set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
378
- OpenNebulaHelper.rname_to_id(arg, "GROUP")
400
+ set :format, :groupid, OpenNebulaHelper.rname_to_id_desc('GROUP') do |arg|
401
+ OpenNebulaHelper.rname_to_id(arg, 'GROUP')
379
402
  end
380
403
 
381
- set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg|
382
- OpenNebulaHelper.rname_to_id(arg, "USER")
404
+ set :format, :userid, OpenNebulaHelper.rname_to_id_desc('USER') do |arg|
405
+ OpenNebulaHelper.rname_to_id(arg, 'USER')
383
406
  end
384
407
 
385
- set :format, :service_id, Service.rname_to_id_desc("SERVICE") do |arg|
386
- Service.rname_to_id(arg, "SERVICE")
408
+ set :format, :service_id, Service.rname_to_id_desc('SERVICE') do |arg|
409
+ Service.rname_to_id(arg, 'SERVICE')
387
410
  end
388
411
 
389
- set :format, :service_id_list, Service.list_to_id_desc("SERVICE") do |arg|
390
- Service.list_to_id(arg, "SERVICE")
412
+ set :format, :service_id_list, Service.list_to_id_desc('SERVICE') do |arg|
413
+ Service.list_to_id(arg, 'SERVICE')
391
414
  end
392
415
 
393
- set :format, :vm_action, "Actions supported: #{Role::SCHEDULE_ACTIONS.join(', ')}" do |arg|
416
+ set :format, :vm_action,
417
+ 'Actions supported: #{Role::SCHEDULE_ACTIONS.join(', ')}' do |arg|
394
418
  if Role::SCHEDULE_ACTIONS.include?(arg)
395
419
  [0, arg]
396
420
  else
397
- [-1, "Action #{arg} is not supported. Actions supported: #{Role::SCHEDULE_ACTIONS.join(', ')}"]
421
+ [-1, "Action #{arg} is not supported. Actions supported: "\
422
+ "#{Role::SCHEDULE_ACTIONS.join(', ')}"]
398
423
  end
399
424
  end
400
425
 
@@ -408,12 +433,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
408
433
 
409
434
  command :list, list_desc, :options => Service::JSON_FORMAT do
410
435
  client = Service::Client.new(
411
- :username => options[:username],
412
- :password => options[:password],
413
- :url => options[:server],
414
- :user_agent => USER_AGENT)
436
+ :username => options[:username],
437
+ :password => options[:password],
438
+ :url => options[:server],
439
+ :user_agent => USER_AGENT
440
+ )
415
441
 
416
- list_services(client, args, options)
442
+ list_services(client, options)
417
443
  end
418
444
 
419
445
  #
@@ -426,10 +452,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do
426
452
 
427
453
  command :show, show_desc, :service_id, :options => Service::JSON_FORMAT do
428
454
  client = Service::Client.new(
429
- :username => options[:username],
430
- :password => options[:password],
431
- :url => options[:server],
432
- :user_agent => USER_AGENT)
455
+ :username => options[:username],
456
+ :password => options[:password],
457
+ :url => options[:server],
458
+ :user_agent => USER_AGENT
459
+ )
433
460
 
434
461
  show_service(client, args, options)
435
462
  end
@@ -444,37 +471,34 @@ cmd=CommandParser::CmdParser.new(ARGV) do
444
471
  EOT
445
472
 
446
473
  command :top, top_desc, [:service_id, nil],
447
- :options => [Service::JSON_FORMAT, Service::TOP, CLIHelper::DELAY] do
474
+ :options => [Service::JSON_FORMAT,
475
+ Service::TOP,
476
+ CLIHelper::DELAY] do
448
477
  client = Service::Client.new(
449
- :username => options[:username],
450
- :password => options[:password],
451
- :url => options[:server],
452
- :user_agent => USER_AGENT)
478
+ :username => options[:username],
479
+ :password => options[:password],
480
+ :url => options[:server],
481
+ :user_agent => USER_AGENT
482
+ )
453
483
 
454
- delay=options[:delay] ? options[:delay] : 3
484
+ options[:delay] ? delay = options[:delay] : delay = 3
455
485
 
456
486
  begin
457
- while true
487
+ loop do
458
488
  CLIHelper.scr_cls
459
- CLIHelper.scr_move(0,0)
489
+ CLIHelper.scr_move(0, 0)
460
490
 
461
491
  if args[0]
462
492
  rc, message = show_service(client, args, options)
463
-
464
- if rc != 0
465
- raise message
466
- end
467
493
  else
468
- rc, message = list_services(client, args, options)
469
-
470
- if rc != 0
471
- raise message
472
- end
494
+ rc, message = list_services(client, options)
473
495
  end
474
496
 
497
+ raise message if rc
498
+
475
499
  sleep delay
476
500
  end
477
- rescue Exception => e
501
+ rescue StandardError => e
478
502
  puts e.message
479
503
  -1
480
504
  end
@@ -490,14 +514,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do
490
514
 
491
515
  command :delete, delete_desc, [:range, :service_id_list] do
492
516
  client = Service::Client.new(
493
- :username => options[:username],
494
- :password => options[:password],
495
- :url => options[:server],
496
- :user_agent => USER_AGENT)
517
+ :username => options[:username],
518
+ :password => options[:password],
519
+ :url => options[:server],
520
+ :user_agent => USER_AGENT
521
+ )
497
522
 
498
- Service.perform_actions(args[0]) { |service_id|
523
+ Service.perform_actions(args[0]) do |service_id|
499
524
  client.delete("#{RESOURCE_PATH}/#{service_id}")
500
- }
525
+ end
501
526
  end
502
527
 
503
528
  #
@@ -511,16 +536,17 @@ cmd=CommandParser::CmdParser.new(ARGV) do
511
536
 
512
537
  command :shutdown, shutdown_desc, [:range, :service_id_list] do
513
538
  client = Service::Client.new(
514
- :username => options[:username],
515
- :password => options[:password],
516
- :url => options[:server],
517
- :user_agent => USER_AGENT)
539
+ :username => options[:username],
540
+ :password => options[:password],
541
+ :url => options[:server],
542
+ :user_agent => USER_AGENT
543
+ )
518
544
 
519
- Service.perform_actions(args[0]) { |service_id|
545
+ Service.perform_actions(args[0]) do |service_id|
520
546
  json_action = Service.build_json_action('shutdown')
521
547
 
522
548
  client.post("#{RESOURCE_PATH}/#{service_id}/action", json_action)
523
- }
549
+ end
524
550
  end
525
551
 
526
552
  #
@@ -538,16 +564,17 @@ cmd=CommandParser::CmdParser.new(ARGV) do
538
564
 
539
565
  command :recover, recover_desc, [:range, :service_id_list] do
540
566
  client = Service::Client.new(
541
- :username => options[:username],
542
- :password => options[:password],
543
- :url => options[:server],
544
- :user_agent => USER_AGENT)
567
+ :username => options[:username],
568
+ :password => options[:password],
569
+ :url => options[:server],
570
+ :user_agent => USER_AGENT
571
+ )
545
572
 
546
- Service.perform_actions(args[0]) { |service_id|
573
+ Service.perform_actions(args[0]) do |service_id|
547
574
  json_action = Service.build_json_action('recover')
548
575
 
549
576
  client.post("#{RESOURCE_PATH}/#{service_id}/action", json_action)
550
- }
577
+ end
551
578
  end
552
579
 
553
580
  #
@@ -558,27 +585,29 @@ cmd=CommandParser::CmdParser.new(ARGV) do
558
585
  Scale a role to the given cardinality
559
586
  EOT
560
587
 
561
- command :'scale', scale_desc, :service_id, :role_name,
562
- :cardinality, :options => [Service::FORCE] do
588
+ command :scale, scale_desc, :service_id, :role_name,
589
+ :cardinality, :options => [Service::FORCE] do
563
590
  client = Service::Client.new(
564
- :username => options[:username],
565
- :password => options[:password],
566
- :url => options[:server],
567
- :user_agent => USER_AGENT)
568
-
569
- if !(args[2] =~ /^\d+$/)
570
- puts "Cardinality must be an integer number"
571
- exit -1
591
+ :username => options[:username],
592
+ :password => options[:password],
593
+ :url => options[:server],
594
+ :user_agent => USER_AGENT
595
+ )
596
+
597
+ if args[2] !~ /^\d+$/
598
+ puts 'Cardinality must be an integer number'
599
+ exit(-1)
572
600
  end
573
601
 
574
602
  exit_code = 0
575
603
 
576
- json = "{ \"cardinality\" : #{args[2]},\n"<<
604
+ json = "{ \"cardinality\" : #{args[2]},\n" \
577
605
  " \"force\" : #{options[:force] == true} }"
578
606
 
579
- response = client.put("#{RESOURCE_PATH}/#{args[0]}/role/#{args[1]}", json)
607
+ response = client
608
+ .put("#{RESOURCE_PATH}/#{args[0]}/role/#{args[1]}", json)
580
609
 
581
- if CloudClient::is_error?(response)
610
+ if CloudClient.is_error?(response)
582
611
  puts response.to_s
583
612
  exit_code = response.code.to_i
584
613
  end
@@ -592,41 +621,44 @@ cmd=CommandParser::CmdParser.new(ARGV) do
592
621
 
593
622
  command :chgrp, chgrp_desc, [:range, :service_id_list], :groupid do
594
623
  client = Service::Client.new(
595
- :username => options[:username],
596
- :password => options[:password],
597
- :url => options[:server],
598
- :user_agent => USER_AGENT)
599
-
600
- Service.perform_actions(args[0]) { |service_id|
601
- params = Hash.new
624
+ :username => options[:username],
625
+ :password => options[:password],
626
+ :url => options[:server],
627
+ :user_agent => USER_AGENT
628
+ )
629
+
630
+ Service.perform_actions(args[0]) do |service_id|
631
+ params = {}
602
632
  params['group_id'] = args[1].to_i
603
633
 
604
634
  json_action = Service.build_json_action('chgrp', params)
605
635
 
606
636
  client.post("#{RESOURCE_PATH}/#{service_id}/action", json_action)
607
- }
637
+ end
608
638
  end
609
639
 
610
640
  chown_desc = <<-EOT.unindent
611
641
  Changes the service owner and group
612
642
  EOT
613
643
 
614
- command :chown, chown_desc, [:range, :service_id_list], :userid, [:groupid, nil] do
644
+ command :chown, chown_desc,
645
+ [:range, :service_id_list], :userid, [:groupid, nil] do
615
646
  client = Service::Client.new(
616
- :username => options[:username],
617
- :password => options[:password],
618
- :url => options[:server],
619
- :user_agent => USER_AGENT)
620
-
621
- Service.perform_actions(args[0]) { |service_id|
622
- params = Hash.new
647
+ :username => options[:username],
648
+ :password => options[:password],
649
+ :url => options[:server],
650
+ :user_agent => USER_AGENT
651
+ )
652
+
653
+ Service.perform_actions(args[0]) do |service_id|
654
+ params = {}
623
655
  params['owner_id'] = args[1]
624
656
  params['group_id'] = args[2] if args[2]
625
657
 
626
658
  json_action = Service.build_json_action('chown', params)
627
659
 
628
660
  client.post("#{RESOURCE_PATH}/#{service_id}/action", json_action)
629
- }
661
+ end
630
662
  end
631
663
 
632
664
  chmod_desc = <<-EOT.unindent
@@ -635,40 +667,43 @@ cmd=CommandParser::CmdParser.new(ARGV) do
635
667
 
636
668
  command :chmod, chmod_desc, [:range, :service_id_list], :octet do
637
669
  client = Service::Client.new(
638
- :username => options[:username],
639
- :password => options[:password],
640
- :url => options[:server],
641
- :user_agent => USER_AGENT)
642
-
643
- Service.perform_actions(args[0]) { |service_id|
644
- params = Hash.new
670
+ :username => options[:username],
671
+ :password => options[:password],
672
+ :url => options[:server],
673
+ :user_agent => USER_AGENT
674
+ )
675
+
676
+ Service.perform_actions(args[0]) do |service_id|
677
+ params = {}
645
678
  params['octet'] = args[1]
646
679
 
647
680
  json_action = Service.build_json_action('chmod', params)
648
681
 
649
682
  client.post("#{RESOURCE_PATH}/#{service_id}/action", json_action)
650
- }
683
+ end
651
684
  end
652
685
 
653
686
  rename_desc = <<-EOT.unindent
654
- Renames the Service
687
+ Renames the Service
655
688
  EOT
656
689
 
657
690
  command :rename, rename_desc, :service_id, :name do
658
691
  client = Service::Client.new(
659
- :username => options[:username],
660
- :password => options[:password],
661
- :url => options[:server],
662
- :user_agent => USER_AGENT)
692
+ :username => options[:username],
693
+ :password => options[:password],
694
+ :url => options[:server],
695
+ :user_agent => USER_AGENT
696
+ )
663
697
 
664
- params = Hash.new
698
+ params = {}
665
699
  params['name'] = args[1]
666
700
 
667
701
  json_action = Service.build_json_action('rename', params)
668
702
 
669
- response = client.post("#{RESOURCE_PATH}/#{args[0]}/action", json_action)
703
+ response = client
704
+ .post("#{RESOURCE_PATH}/#{args[0]}/action", json_action)
670
705
 
671
- if CloudClient::is_error?(response)
706
+ if CloudClient.is_error?(response)
672
707
  [response.code.to_i, response.to_s]
673
708
  else
674
709
  response.code.to_i
@@ -677,26 +712,28 @@ cmd=CommandParser::CmdParser.new(ARGV) do
677
712
 
678
713
  action_desc = <<-EOT.unindent
679
714
  Perform an action on all the Virtual Machines of a given role.
680
- Actions supported: #{Role::SCHEDULE_ACTIONS.join(",")}
715
+ Actions supported: #{Role::SCHEDULE_ACTIONS.join(',')}
681
716
  EOT
682
717
 
683
- command :"action", action_desc, :service_id, :role_name, :vm_action,
684
- :options => [Service::PERIOD, Service::NUMBER] do
718
+ command :action, action_desc, :service_id, :role_name, :vm_action,
719
+ :options => [Service::PERIOD, Service::NUMBER] do
685
720
 
686
721
  client = Service::Client.new(
687
- :username => options[:username],
688
- :password => options[:password],
689
- :url => options[:server],
690
- :user_agent => USER_AGENT)
691
-
692
- Service.perform_actions([args[0]]) { |service_id|
693
- params = Hash.new
722
+ :username => options[:username],
723
+ :password => options[:password],
724
+ :url => options[:server],
725
+ :user_agent => USER_AGENT
726
+ )
727
+
728
+ Service.perform_actions([args[0]]) do |service_id|
729
+ params = {}
694
730
  params[:period] = options[:period].to_i if options[:period]
695
731
  params[:number] = options[:number].to_i if options[:number]
696
732
 
697
733
  json_action = Service.build_json_action(args[2], params)
698
734
 
699
- client.post("#{RESOURCE_PATH}/#{service_id}/role/#{args[1]}/action", json_action)
700
- }
735
+ client.post("#{RESOURCE_PATH}/#{service_id}/role/#{args[1]}/action",
736
+ json_action)
737
+ end
701
738
  end
702
739
  end