opennebula-cli 5.10.4 → 5.12.0

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