opennebula-cli 5.10.5 → 5.12.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/oneacct +4 -2
- data/bin/oneacl +4 -2
- data/bin/onecluster +4 -2
- data/bin/onedatastore +4 -2
- data/bin/oneflow +151 -552
- data/bin/oneflow-template +173 -293
- data/bin/onegroup +4 -2
- data/bin/onehook +4 -2
- data/bin/onehost +78 -10
- data/bin/oneimage +4 -2
- data/bin/onemarket +4 -2
- data/bin/onemarketapp +17 -4
- data/bin/onesecgroup +4 -2
- data/bin/oneshowback +4 -2
- data/bin/onetemplate +4 -2
- data/bin/oneuser +4 -2
- data/bin/onevcenter +4 -2
- data/bin/onevdc +4 -2
- data/bin/onevm +90 -17
- data/bin/onevmgroup +4 -2
- data/bin/onevnet +13 -4
- data/bin/onevntemplate +4 -2
- data/bin/onevrouter +4 -2
- data/bin/onezone +7 -2
- data/lib/cli_helper.rb +54 -30
- data/lib/command_parser.rb +33 -14
- data/lib/one_helper.rb +258 -6
- data/lib/one_helper/oneacct_helper.rb +1 -1
- data/lib/one_helper/oneacl_helper.rb +1 -1
- data/lib/one_helper/onecluster_helper.rb +4 -4
- data/lib/one_helper/onedatastore_helper.rb +1 -1
- data/lib/one_helper/oneflow_helper.rb +419 -0
- data/lib/one_helper/oneflowtemplate_helper.rb +312 -0
- data/lib/one_helper/onegroup_helper.rb +1 -1
- data/lib/one_helper/onehook_helper.rb +1 -1
- data/lib/one_helper/onehost_helper.rb +148 -68
- data/lib/one_helper/oneimage_helper.rb +2 -2
- data/lib/one_helper/onemarket_helper.rb +1 -1
- data/lib/one_helper/onemarketapp_helper.rb +1 -1
- data/lib/one_helper/oneprovision_helper.rb +104 -60
- data/lib/one_helper/onequota_helper.rb +1 -1
- data/lib/one_helper/onesecgroup_helper.rb +1 -1
- data/lib/one_helper/onetemplate_helper.rb +9 -180
- data/lib/one_helper/oneuser_helper.rb +1 -1
- data/lib/one_helper/onevcenter_helper.rb +2 -1
- data/lib/one_helper/onevdc_helper.rb +1 -1
- data/lib/one_helper/onevm_helper.rb +11 -6
- data/lib/one_helper/onevmgroup_helper.rb +1 -1
- data/lib/one_helper/onevnet_helper.rb +1 -1
- data/lib/one_helper/onevntemplate_helper.rb +1 -1
- data/lib/one_helper/onevrouter_helper.rb +1 -1
- data/lib/one_helper/onezone_helper.rb +3 -1
- metadata +15 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf03af73280a7f88580018b9dc1bcd1edb12975a
|
4
|
+
data.tar.gz: b55f9fb61f690572670d6b9a029bd9f3c543acac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e72d448c240092614852b8adbca32b535ec7b855d785bcc3e79109d317460d43aa86e79bac367e6d73e83d38e54b11e2a9ee20081a740c66e5b09eca746890f9
|
7
|
+
data.tar.gz: 2889b20a9bb830381c58af98f8e98be9442d13d829da84419505c3efc84f36dd50cc4266f018f3c785732a726340a74f5c71758847691b31c03a6a62a3e26ff7
|
data/bin/oneacct
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# -------------------------------------------------------------------------- #
|
4
|
-
# Copyright 2002-
|
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 #
|
@@ -27,7 +27,9 @@ else
|
|
27
27
|
end
|
28
28
|
|
29
29
|
if File.directory?(GEMS_LOCATION)
|
30
|
-
|
30
|
+
$LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
|
31
|
+
require 'rubygems'
|
32
|
+
Gem.use_paths(File.realpath(GEMS_LOCATION))
|
31
33
|
end
|
32
34
|
|
33
35
|
$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-
|
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 #
|
@@ -27,7 +27,9 @@ else
|
|
27
27
|
end
|
28
28
|
|
29
29
|
if File.directory?(GEMS_LOCATION)
|
30
|
-
|
30
|
+
$LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
|
31
|
+
require 'rubygems'
|
32
|
+
Gem.use_paths(File.realpath(GEMS_LOCATION))
|
31
33
|
end
|
32
34
|
|
33
35
|
$LOAD_PATH << RUBY_LIB_LOCATION
|
data/bin/onecluster
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# -------------------------------------------------------------------------- #
|
4
|
-
# Copyright 2002-
|
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 #
|
@@ -27,7 +27,9 @@ else
|
|
27
27
|
end
|
28
28
|
|
29
29
|
if File.directory?(GEMS_LOCATION)
|
30
|
-
|
30
|
+
$LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
|
31
|
+
require 'rubygems'
|
32
|
+
Gem.use_paths(File.realpath(GEMS_LOCATION))
|
31
33
|
end
|
32
34
|
|
33
35
|
$LOAD_PATH << RUBY_LIB_LOCATION
|
data/bin/onedatastore
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# -------------------------------------------------------------------------- #
|
4
|
-
# Copyright 2002-
|
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 #
|
@@ -27,7 +27,9 @@ else
|
|
27
27
|
end
|
28
28
|
|
29
29
|
if File.directory?(GEMS_LOCATION)
|
30
|
-
|
30
|
+
$LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
|
31
|
+
require 'rubygems'
|
32
|
+
Gem.use_paths(File.realpath(GEMS_LOCATION))
|
31
33
|
end
|
32
34
|
|
33
35
|
$LOAD_PATH << RUBY_LIB_LOCATION
|
data/bin/oneflow
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# -------------------------------------------------------------------------- #
|
4
|
-
# Copyright 2002-
|
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 #
|
@@ -27,376 +27,25 @@ else
|
|
27
27
|
end
|
28
28
|
|
29
29
|
if File.directory?(GEMS_LOCATION)
|
30
|
-
|
30
|
+
$LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
|
31
|
+
require 'rubygems'
|
32
|
+
Gem.use_paths(File.realpath(GEMS_LOCATION))
|
31
33
|
end
|
32
34
|
|
33
35
|
$LOAD_PATH << RUBY_LIB_LOCATION
|
34
36
|
$LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
|
35
37
|
|
38
|
+
require 'json'
|
39
|
+
|
36
40
|
require 'command_parser'
|
37
41
|
require 'opennebula/oneflow_client'
|
38
|
-
|
39
|
-
require 'cli_helper'
|
40
|
-
require 'one_helper/onevm_helper'
|
41
|
-
|
42
|
-
require 'json'
|
42
|
+
require 'one_helper/oneflow_helper'
|
43
43
|
|
44
44
|
USER_AGENT = 'CLI'
|
45
45
|
|
46
46
|
# Base Path representing the resource to be used in the requests
|
47
47
|
RESOURCE_PATH = '/service'
|
48
48
|
|
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
49
|
CommandParser::CmdParser.new(ARGV) do
|
401
50
|
usage '`oneflow` <command> [<args>] [<options>]'
|
402
51
|
version OpenNebulaHelper::ONE_VERSION
|
@@ -405,9 +54,32 @@ CommandParser::CmdParser.new(ARGV) do
|
|
405
54
|
set :option, CommandParser::VERSION
|
406
55
|
set :option, CommandParser::HELP
|
407
56
|
|
408
|
-
|
57
|
+
DONE = {
|
58
|
+
:name => 'done',
|
59
|
+
:large => '--done',
|
60
|
+
:description => 'Show services in DONE state'
|
61
|
+
}
|
62
|
+
|
63
|
+
ARGS = {
|
64
|
+
:name => 'args',
|
65
|
+
:large => '--args arg1,arg2',
|
66
|
+
:description => 'Schedule action arguments',
|
67
|
+
:format => String
|
68
|
+
}
|
69
|
+
|
70
|
+
DELETE = {
|
71
|
+
:name => 'delete',
|
72
|
+
:large => '--delete',
|
73
|
+
:description => 'Force flow necover delete'
|
74
|
+
}
|
75
|
+
|
76
|
+
# create helper object
|
77
|
+
helper = OneFlowHelper.new
|
78
|
+
|
79
|
+
############################################################################
|
409
80
|
# Formatters for arguments
|
410
|
-
|
81
|
+
############################################################################
|
82
|
+
|
411
83
|
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc('GROUP') do |arg|
|
412
84
|
OpenNebulaHelper.rname_to_id(arg, 'GROUP')
|
413
85
|
end
|
@@ -424,326 +96,253 @@ CommandParser::CmdParser.new(ARGV) do
|
|
424
96
|
Service.list_to_id(arg, 'SERVICE')
|
425
97
|
end
|
426
98
|
|
427
|
-
set :format,
|
99
|
+
set :format,
|
100
|
+
:vm_action,
|
428
101
|
'Actions supported: #{Role::SCHEDULE_ACTIONS.join(', ')}' do |arg|
|
429
102
|
if Role::SCHEDULE_ACTIONS.include?(arg)
|
430
103
|
[0, arg]
|
431
104
|
else
|
432
|
-
[-1, "Action #{arg} is not supported.
|
105
|
+
[-1, "Action '#{arg}' is not supported. Supported actions: " \
|
433
106
|
"#{Role::SCHEDULE_ACTIONS.join(', ')}"]
|
434
107
|
end
|
435
108
|
end
|
436
109
|
|
437
|
-
|
438
|
-
# List
|
439
|
-
#
|
110
|
+
###
|
440
111
|
|
441
112
|
list_desc = <<-EOT.unindent
|
442
113
|
List the available services
|
443
114
|
EOT
|
444
115
|
|
445
|
-
command :list, list_desc, :options => Service::JSON_FORMAT do
|
446
|
-
client
|
447
|
-
:username => options[:username],
|
448
|
-
:password => options[:password],
|
449
|
-
:url => options[:server],
|
450
|
-
:user_agent => USER_AGENT
|
451
|
-
)
|
452
|
-
|
453
|
-
list_services(client, options)
|
116
|
+
command :list, list_desc, :options => [Service::JSON_FORMAT, DONE] do
|
117
|
+
helper.list_service_pool(helper.client(options), options)
|
454
118
|
end
|
455
119
|
|
456
|
-
|
457
|
-
# Show
|
458
|
-
#
|
120
|
+
###
|
459
121
|
|
460
|
-
|
461
|
-
|
122
|
+
top_desc = <<-EOT.unindent
|
123
|
+
Top the available services
|
462
124
|
EOT
|
463
125
|
|
464
|
-
command :
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
)
|
471
|
-
|
472
|
-
show_service(client, args, options)
|
126
|
+
command :top, top_desc, :options => [CLIHelper::DELAY, DONE] do
|
127
|
+
Signal.trap('INT') { exit(-1) }
|
128
|
+
|
129
|
+
helper.top_service_pool(helper.client(options), options)
|
130
|
+
|
131
|
+
0
|
473
132
|
end
|
474
133
|
|
475
|
-
|
476
|
-
# Top
|
477
|
-
#
|
134
|
+
###
|
478
135
|
|
479
|
-
|
480
|
-
|
481
|
-
id is specified
|
136
|
+
show_desc = <<-EOT.unindent
|
137
|
+
Show detailed information of a given service
|
482
138
|
EOT
|
483
139
|
|
484
|
-
command :
|
485
|
-
|
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
|
140
|
+
command :show, show_desc, :service_id, :options => Service::JSON_FORMAT do
|
141
|
+
helper.format_resource(helper.client(options), args[0], options)
|
516
142
|
end
|
517
143
|
|
518
|
-
|
519
|
-
# Delete
|
520
|
-
#
|
144
|
+
###
|
521
145
|
|
522
146
|
delete_desc = <<-EOT.unindent
|
523
147
|
Delete a given service
|
524
148
|
EOT
|
525
149
|
|
526
150
|
command :delete, delete_desc, [:range, :service_id_list] do
|
527
|
-
client =
|
528
|
-
:username => options[:username],
|
529
|
-
:password => options[:password],
|
530
|
-
:url => options[:server],
|
531
|
-
:user_agent => USER_AGENT
|
532
|
-
)
|
151
|
+
client = helper.client(options)
|
533
152
|
|
534
153
|
Service.perform_actions(args[0]) do |service_id|
|
535
154
|
client.delete("#{RESOURCE_PATH}/#{service_id}")
|
536
155
|
end
|
537
156
|
end
|
538
157
|
|
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
|
-
#
|
158
|
+
###
|
566
159
|
|
567
160
|
recover_desc = <<-EOT.unindent
|
568
161
|
Recover a failed service, cleaning the failed VMs.
|
569
162
|
From FAILED_DEPLOYING continues deploying the Service
|
570
163
|
From FAILED_SCALING continues scaling the Service
|
571
164
|
From FAILED_UNDEPLOYING continues shutting down the Service
|
572
|
-
From COOLDOWN the Service is set to running ignoring the cooldown
|
165
|
+
From COOLDOWN the Service is set to running ignoring the cooldown
|
573
166
|
From WARNING failed VMs are deleted, and new VMs are instantiated
|
574
167
|
EOT
|
575
168
|
|
576
|
-
command :recover,
|
577
|
-
|
578
|
-
:
|
579
|
-
:
|
580
|
-
|
581
|
-
:user_agent => USER_AGENT
|
582
|
-
)
|
169
|
+
command :recover,
|
170
|
+
recover_desc,
|
171
|
+
[:range, :service_id_list],
|
172
|
+
:options => DELETE do
|
173
|
+
client = helper.client(options)
|
583
174
|
|
584
175
|
Service.perform_actions(args[0]) do |service_id|
|
585
|
-
|
176
|
+
params = {}
|
177
|
+
params['delete'] = options.key?(:delete)
|
178
|
+
|
179
|
+
json = Service.build_json_action('recover', params)
|
586
180
|
|
587
|
-
client.post("#{RESOURCE_PATH}/#{service_id}/action",
|
181
|
+
client.post("#{RESOURCE_PATH}/#{service_id}/action", json)
|
588
182
|
end
|
589
183
|
end
|
590
184
|
|
591
|
-
|
592
|
-
# Scale
|
593
|
-
#
|
185
|
+
###
|
594
186
|
|
595
187
|
scale_desc = <<-EOT.unindent
|
596
188
|
Scale a role to the given cardinality
|
597
189
|
EOT
|
598
190
|
|
599
|
-
command :scale,
|
600
|
-
|
601
|
-
|
602
|
-
:
|
603
|
-
:
|
604
|
-
:
|
605
|
-
:user_agent => USER_AGENT
|
606
|
-
)
|
607
|
-
|
191
|
+
command :scale,
|
192
|
+
scale_desc,
|
193
|
+
:service_id,
|
194
|
+
:role_name,
|
195
|
+
:cardinality,
|
196
|
+
:options => [Service::FORCE] do
|
608
197
|
if args[2] !~ /^\d+$/
|
609
|
-
puts 'Cardinality must be an integer number'
|
198
|
+
STDERR.puts 'Cardinality must be an integer number'
|
610
199
|
exit(-1)
|
611
200
|
end
|
612
201
|
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
" \"force\" : #{options[:force] == true} }"
|
202
|
+
json = "{ \"cardinality\" : #{args[2]},\n" \
|
203
|
+
" \"force\" : #{options[:force] == true}, " \
|
204
|
+
" \"role_name\" : \"#{args[1]}\"}"
|
617
205
|
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
if CloudClient.is_error?(response)
|
622
|
-
puts response.to_s
|
623
|
-
exit_code = response.code.to_i
|
206
|
+
Service.perform_action(args[0]) do |service_id|
|
207
|
+
helper.client(options).post("#{RESOURCE_PATH}/#{service_id}/scale",
|
208
|
+
json)
|
624
209
|
end
|
625
|
-
|
626
|
-
exit_code
|
627
210
|
end
|
628
211
|
|
212
|
+
###
|
213
|
+
|
629
214
|
chgrp_desc = <<-EOT.unindent
|
630
215
|
Changes the service group
|
631
216
|
EOT
|
632
217
|
|
633
218
|
command :chgrp, chgrp_desc, [:range, :service_id_list], :groupid do
|
634
|
-
client =
|
635
|
-
:username => options[:username],
|
636
|
-
:password => options[:password],
|
637
|
-
:url => options[:server],
|
638
|
-
:user_agent => USER_AGENT
|
639
|
-
)
|
219
|
+
client = helper.client(options)
|
640
220
|
|
641
221
|
Service.perform_actions(args[0]) do |service_id|
|
642
222
|
params = {}
|
643
223
|
params['group_id'] = args[1].to_i
|
644
224
|
|
645
|
-
|
225
|
+
json = Service.build_json_action('chgrp', params)
|
646
226
|
|
647
|
-
client.post("#{RESOURCE_PATH}/#{service_id}/action",
|
227
|
+
client.post("#{RESOURCE_PATH}/#{service_id}/action", json)
|
648
228
|
end
|
649
229
|
end
|
650
230
|
|
231
|
+
###
|
232
|
+
|
651
233
|
chown_desc = <<-EOT.unindent
|
652
234
|
Changes the service owner and group
|
653
235
|
EOT
|
654
236
|
|
655
|
-
command :chown,
|
656
|
-
|
657
|
-
|
658
|
-
:
|
659
|
-
:
|
660
|
-
|
661
|
-
:user_agent => USER_AGENT
|
662
|
-
)
|
237
|
+
command :chown,
|
238
|
+
chown_desc,
|
239
|
+
[:range, :service_id_list],
|
240
|
+
:userid,
|
241
|
+
[:groupid, nil] do
|
242
|
+
client = helper.client(options)
|
663
243
|
|
664
244
|
Service.perform_actions(args[0]) do |service_id|
|
665
245
|
params = {}
|
666
246
|
params['owner_id'] = args[1]
|
667
247
|
params['group_id'] = args[2] if args[2]
|
668
248
|
|
669
|
-
|
249
|
+
json = Service.build_json_action('chown', params)
|
670
250
|
|
671
|
-
client.post("#{RESOURCE_PATH}/#{service_id}/action",
|
251
|
+
client.post("#{RESOURCE_PATH}/#{service_id}/action", json)
|
672
252
|
end
|
673
253
|
end
|
674
254
|
|
255
|
+
###
|
256
|
+
|
675
257
|
chmod_desc = <<-EOT.unindent
|
676
258
|
Changes the service permissions
|
677
259
|
EOT
|
678
260
|
|
679
261
|
command :chmod, chmod_desc, [:range, :service_id_list], :octet do
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
)
|
262
|
+
if !/\A\d+\z/.match(args[1])
|
263
|
+
STDERR.puts "Invalid '#{args[1]}' octed permissions"
|
264
|
+
exit(-1)
|
265
|
+
end
|
266
|
+
|
267
|
+
client = helper.client(options)
|
686
268
|
|
687
269
|
Service.perform_actions(args[0]) do |service_id|
|
688
270
|
params = {}
|
689
271
|
params['octet'] = args[1]
|
690
272
|
|
691
|
-
|
273
|
+
json = Service.build_json_action('chmod', params)
|
692
274
|
|
693
|
-
client.post("#{RESOURCE_PATH}/#{service_id}/action",
|
275
|
+
client.post("#{RESOURCE_PATH}/#{service_id}/action", json)
|
694
276
|
end
|
695
277
|
end
|
696
278
|
|
279
|
+
###
|
280
|
+
|
697
281
|
rename_desc = <<-EOT.unindent
|
698
282
|
Renames the Service
|
699
283
|
EOT
|
700
284
|
|
701
285
|
command :rename, rename_desc, :service_id, :name do
|
702
|
-
|
703
|
-
|
704
|
-
|
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)
|
286
|
+
Service.perform_action(args[0]) do |service_id|
|
287
|
+
params = {}
|
288
|
+
params['name'] = args[1]
|
713
289
|
|
714
|
-
|
715
|
-
.post("#{RESOURCE_PATH}/#{args[0]}/action", json_action)
|
290
|
+
json = Service.build_json_action('rename', params)
|
716
291
|
|
717
|
-
|
718
|
-
|
719
|
-
else
|
720
|
-
response.code.to_i
|
292
|
+
helper.client(options).post("#{RESOURCE_PATH}/#{service_id}/action",
|
293
|
+
json)
|
721
294
|
end
|
722
295
|
end
|
723
296
|
|
297
|
+
###
|
298
|
+
|
724
299
|
action_desc = <<-EOT.unindent
|
725
300
|
Perform an action on all the Virtual Machines of a given role.
|
726
301
|
Actions supported: #{Role::SCHEDULE_ACTIONS.join(',')}
|
727
302
|
EOT
|
728
303
|
|
729
|
-
command :action,
|
730
|
-
|
731
|
-
|
732
|
-
:
|
733
|
-
:
|
734
|
-
:
|
735
|
-
|
736
|
-
)
|
737
|
-
|
738
|
-
Service.perform_actions([args[0]]) do |service_id|
|
304
|
+
command :action,
|
305
|
+
action_desc,
|
306
|
+
:service_id,
|
307
|
+
:role_name,
|
308
|
+
:vm_action,
|
309
|
+
:options => [Service::PERIOD, Service::NUMBER, ARGS] do
|
310
|
+
Service.perform_action(args[0]) do |service_id|
|
739
311
|
params = {}
|
740
312
|
params[:period] = options[:period].to_i if options[:period]
|
741
313
|
params[:number] = options[:number].to_i if options[:number]
|
314
|
+
params[:args] = options[:args] if options[:args]
|
742
315
|
|
743
|
-
|
316
|
+
json = Service.build_json_action(args[2], params)
|
317
|
+
client = helper.client(options)
|
744
318
|
|
745
319
|
client.post("#{RESOURCE_PATH}/#{service_id}/role/#{args[1]}/action",
|
746
|
-
|
320
|
+
json)
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
###
|
325
|
+
|
326
|
+
action_desc = <<-EOT.unindent
|
327
|
+
Perform an action on all the Virtual Machines of a given service.
|
328
|
+
Actions supported: #{Role::SCHEDULE_ACTIONS.join(',')}
|
329
|
+
EOT
|
330
|
+
|
331
|
+
command [:service, :action],
|
332
|
+
action_desc,
|
333
|
+
:service_id,
|
334
|
+
:vm_action,
|
335
|
+
:options => [Service::PERIOD, Service::NUMBER, ARGS] do
|
336
|
+
Service.perform_action(args[0]) do |service_id|
|
337
|
+
params = {}
|
338
|
+
params[:period] = options[:period].to_i if options[:period]
|
339
|
+
params[:number] = options[:number].to_i if options[:number]
|
340
|
+
params[:args] = options[:args] if options[:args]
|
341
|
+
|
342
|
+
json = Service.build_json_action(args[1], params)
|
343
|
+
client = helper.client(options)
|
344
|
+
|
345
|
+
client.post("#{RESOURCE_PATH}/#{service_id}/action", json)
|
747
346
|
end
|
748
347
|
end
|
749
348
|
end
|