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.
- checksums.yaml +4 -4
- data/bin/oneacct +2 -1
- data/bin/oneacl +2 -1
- data/bin/onecluster +2 -1
- data/bin/onedatastore +2 -1
- data/bin/oneflow +149 -551
- data/bin/oneflow-template +171 -292
- data/bin/onegroup +2 -1
- data/bin/onehook +2 -1
- data/bin/onehost +76 -9
- data/bin/oneimage +2 -1
- data/bin/onemarket +2 -1
- data/bin/onemarketapp +15 -3
- data/bin/onesecgroup +2 -1
- data/bin/oneshowback +2 -1
- data/bin/onetemplate +2 -1
- data/bin/oneuser +2 -1
- data/bin/onevcenter +2 -1
- data/bin/onevdc +2 -1
- data/bin/onevm +88 -16
- data/bin/onevmgroup +2 -1
- data/bin/onevnet +11 -3
- data/bin/onevntemplate +2 -1
- data/bin/onevrouter +2 -1
- data/bin/onezone +5 -1
- 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 +8 -6
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -63,15 +63,15 @@ class OneClusterHelper < OpenNebulaHelper::OneHelper
|
|
63
63
|
end
|
64
64
|
|
65
65
|
column :HOSTS, "Number of Hosts", :size=>5 do |d|
|
66
|
-
@ext.element_size(d,"HOSTS")
|
66
|
+
@ext.element_size(d,"HOSTS") rescue 0
|
67
67
|
end
|
68
68
|
|
69
69
|
column :VNETS, "Number of Networks", :size=>5 do |d|
|
70
|
-
@ext.element_size(d,"VNETS")
|
70
|
+
@ext.element_size(d,"VNETS") rescue 0
|
71
71
|
end
|
72
72
|
|
73
73
|
column :DATASTORES, "Number of Datastores", :size=>10 do |d|
|
74
|
-
@ext.element_size(d,"DATASTORES")
|
74
|
+
@ext.element_size(d,"DATASTORES") rescue 0
|
75
75
|
end
|
76
76
|
|
77
77
|
default :ID, :NAME, :HOSTS, :VNETS, :DATASTORES
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -0,0 +1,419 @@
|
|
1
|
+
# -------------------------------------------------------------------------- #
|
2
|
+
# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
|
3
|
+
# #
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
|
+
# not use this file except in compliance with the License. You may obtain #
|
6
|
+
# a copy of the License at #
|
7
|
+
# #
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0 #
|
9
|
+
# #
|
10
|
+
# Unless required by applicable law or agreed to in writing, software #
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, #
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
13
|
+
# See the License for the specific language governing permissions and #
|
14
|
+
# limitations under the License. #
|
15
|
+
#--------------------------------------------------------------------------- #
|
16
|
+
|
17
|
+
require 'one_helper'
|
18
|
+
|
19
|
+
# Oneflow command helper
|
20
|
+
class OneFlowHelper < OpenNebulaHelper::OneHelper
|
21
|
+
|
22
|
+
# Configuration file
|
23
|
+
def self.conf_file
|
24
|
+
'oneflow.yaml'
|
25
|
+
end
|
26
|
+
|
27
|
+
# Get client to make request
|
28
|
+
#
|
29
|
+
# @options [Hash] CLI options
|
30
|
+
def client(options)
|
31
|
+
Service::Client.new(
|
32
|
+
:username => options[:username],
|
33
|
+
:password => options[:password],
|
34
|
+
:url => options[:server],
|
35
|
+
:user_agent => USER_AGENT
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Get service pool table
|
40
|
+
def format_service_pool
|
41
|
+
config_file = self.class.table_conf
|
42
|
+
|
43
|
+
CLIHelper::ShowTable.new(config_file, self) do
|
44
|
+
column :ID, 'ID', :size => 10 do |d|
|
45
|
+
d['ID']
|
46
|
+
end
|
47
|
+
|
48
|
+
column :USER, 'Username', :left, :size => 15 do |d|
|
49
|
+
d['UNAME']
|
50
|
+
end
|
51
|
+
|
52
|
+
column :GROUP, 'Group', :left, :size => 15 do |d|
|
53
|
+
d['GNAME']
|
54
|
+
end
|
55
|
+
|
56
|
+
column :NAME, 'Name', :expand => true, :left => true do |d|
|
57
|
+
d['NAME']
|
58
|
+
end
|
59
|
+
|
60
|
+
column :STAT, 'State', :size => 11, :left => true do |d|
|
61
|
+
Service.state_str(d['TEMPLATE']['BODY']['state'])
|
62
|
+
end
|
63
|
+
|
64
|
+
default :ID, :USER, :GROUP, :NAME, :STAT
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# List service pool
|
69
|
+
#
|
70
|
+
# @param client [Service::Client] Petition client
|
71
|
+
# @param options [Hash] CLI options
|
72
|
+
def list_service_pool(client, options)
|
73
|
+
response = client.get(RESOURCE_PATH)
|
74
|
+
|
75
|
+
if CloudClient.is_error?(response)
|
76
|
+
[response.code.to_i, response.to_s]
|
77
|
+
else
|
78
|
+
array_list = JSON.parse(response.body)
|
79
|
+
array_list = array_list['DOCUMENT_POOL']['DOCUMENT']
|
80
|
+
|
81
|
+
array_list = [] if array_list.nil?
|
82
|
+
|
83
|
+
unless options.key? :done
|
84
|
+
# remove from list flows in DONE state
|
85
|
+
array_list.reject! do |value|
|
86
|
+
value['TEMPLATE']['BODY']['state'] == 5
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
if options[:json]
|
91
|
+
if array_list.empty?
|
92
|
+
0
|
93
|
+
else
|
94
|
+
[0, JSON.pretty_generate(array_list)]
|
95
|
+
end
|
96
|
+
else
|
97
|
+
format_service_pool.show(array_list)
|
98
|
+
|
99
|
+
0
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# List service pool continiously
|
105
|
+
#
|
106
|
+
# @param client [Service::Client] Petition client
|
107
|
+
# @param options [Hash] CLI options
|
108
|
+
def top_service_pool(client, options)
|
109
|
+
# TODO: make default delay configurable
|
110
|
+
options[:delay] ? delay = options[:delay] : delay = 4
|
111
|
+
|
112
|
+
begin
|
113
|
+
loop do
|
114
|
+
CLIHelper.scr_cls
|
115
|
+
CLIHelper.scr_move(0, 0)
|
116
|
+
|
117
|
+
list_service_pool(client, options)
|
118
|
+
|
119
|
+
sleep delay
|
120
|
+
end
|
121
|
+
rescue StandardError => e
|
122
|
+
STDERR.puts e.message
|
123
|
+
exit(-1)
|
124
|
+
end
|
125
|
+
|
126
|
+
0
|
127
|
+
end
|
128
|
+
|
129
|
+
# Show service detailed information
|
130
|
+
#
|
131
|
+
# @param client [Service::Client] Petition client
|
132
|
+
# @param service [Integer] Service ID
|
133
|
+
# @param options [Hash] CLI options
|
134
|
+
def format_resource(client, service, options)
|
135
|
+
response = client.get("#{RESOURCE_PATH}/#{service}")
|
136
|
+
|
137
|
+
if CloudClient.is_error?(response)
|
138
|
+
[response.code.to_i, response.to_s]
|
139
|
+
else
|
140
|
+
if options[:json]
|
141
|
+
[0, response.body]
|
142
|
+
else
|
143
|
+
str_h1 = '%-80s'
|
144
|
+
document = JSON.parse(response.body)['DOCUMENT']
|
145
|
+
template = document['TEMPLATE']['BODY']
|
146
|
+
|
147
|
+
CLIHelper.print_header(
|
148
|
+
str_h1 % "SERVICE #{document['ID']} INFORMATION"
|
149
|
+
)
|
150
|
+
|
151
|
+
print_service_info(document)
|
152
|
+
|
153
|
+
print_roles_info(template['roles'])
|
154
|
+
|
155
|
+
return 0 unless template['log']
|
156
|
+
|
157
|
+
CLIHelper.print_header(str_h1 % 'LOG MESSAGES', false)
|
158
|
+
|
159
|
+
template['log'].each do |log|
|
160
|
+
t = Time.at(log['timestamp']).strftime('%m/%d/%y %H:%M')
|
161
|
+
puts "#{t} [#{log['severity']}] #{log['message']}"
|
162
|
+
end
|
163
|
+
|
164
|
+
0
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# Get policy adjust information in str format
|
170
|
+
#
|
171
|
+
# @param policy [Hash] Policy information
|
172
|
+
def self.adjust_str(policy)
|
173
|
+
policy['adjust'].to_i >= 0 ? sign = '+' : sign = '-'
|
174
|
+
adjust = policy['adjust'].to_i.abs
|
175
|
+
|
176
|
+
case policy['type']
|
177
|
+
when 'CARDINALITY'
|
178
|
+
"= #{adjust}"
|
179
|
+
when 'PERCENTAGE_CHANGE'
|
180
|
+
st = "#{sign} #{adjust} %"
|
181
|
+
|
182
|
+
if policy['min_adjust_step']
|
183
|
+
st << " (#{policy['min_adjust_step']})"
|
184
|
+
end
|
185
|
+
|
186
|
+
st
|
187
|
+
else
|
188
|
+
"#{sign} #{adjust}"
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
private
|
193
|
+
|
194
|
+
# Get nodes pool table
|
195
|
+
def format_node_pool
|
196
|
+
# TODO: config file
|
197
|
+
CLIHelper::ShowTable.new(nil, self) do
|
198
|
+
column :VM_ID,
|
199
|
+
'ONE identifier for Virtual Machine',
|
200
|
+
:size => 6 do |d|
|
201
|
+
st = ''
|
202
|
+
|
203
|
+
if d['scale_up']
|
204
|
+
st << '\u2191 '
|
205
|
+
elsif d['disposed']
|
206
|
+
st << '\u2193 '
|
207
|
+
end
|
208
|
+
|
209
|
+
if d['vm_info'].nil?
|
210
|
+
st << d['deploy_id'].to_s
|
211
|
+
else
|
212
|
+
st << d['vm_info']['VM']['ID']
|
213
|
+
end
|
214
|
+
|
215
|
+
st
|
216
|
+
end
|
217
|
+
|
218
|
+
column :NAME,
|
219
|
+
'Name of the Virtual Machine',
|
220
|
+
:left,
|
221
|
+
:size => 24 do |d|
|
222
|
+
if !d['vm_info'].nil?
|
223
|
+
if d['vm_info']['VM']['RESCHED'] == '1'
|
224
|
+
"*#{d['NAME']}"
|
225
|
+
else
|
226
|
+
d['vm_info']['VM']['NAME']
|
227
|
+
end
|
228
|
+
else
|
229
|
+
''
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
column :USER,
|
234
|
+
'Username of the Virtual Machine owner',
|
235
|
+
:left,
|
236
|
+
:size => 15 do |d|
|
237
|
+
if !d['vm_info'].nil?
|
238
|
+
d['vm_info']['VM']['UNAME']
|
239
|
+
else
|
240
|
+
''
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
column :GROUP,
|
245
|
+
'Group of the Virtual Machine',
|
246
|
+
:left,
|
247
|
+
:size => 15 do |d|
|
248
|
+
if !d['vm_info'].nil?
|
249
|
+
d['vm_info']['VM']['GNAME']
|
250
|
+
else
|
251
|
+
''
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
default :VM_ID, :NAME, :USER, :GROUP
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
# Print service information
|
260
|
+
#
|
261
|
+
# @param document [Hash] Service document information
|
262
|
+
def print_service_info(document)
|
263
|
+
str = '%-20s: %-20s'
|
264
|
+
str_h1 = '%-80s'
|
265
|
+
template = document['TEMPLATE']['BODY']
|
266
|
+
|
267
|
+
puts Kernel.format(str, 'ID', document['ID'])
|
268
|
+
puts Kernel.format(str, 'NAME', document['NAME'])
|
269
|
+
puts Kernel.format(str, 'USER', document['UNAME'])
|
270
|
+
puts Kernel.format(str, 'GROUP', document['GNAME'])
|
271
|
+
|
272
|
+
puts Kernel.format(str, 'STRATEGY', template['deployment'])
|
273
|
+
puts Kernel.format(str,
|
274
|
+
'SERVICE STATE',
|
275
|
+
Service.state_str(template['state']))
|
276
|
+
|
277
|
+
if template['shutdown_action']
|
278
|
+
puts Kernel.format(str, 'SHUTDOWN', template['shutdown_action'])
|
279
|
+
end
|
280
|
+
|
281
|
+
puts
|
282
|
+
|
283
|
+
CLIHelper.print_header(str_h1 % 'PERMISSIONS', false)
|
284
|
+
|
285
|
+
%w[OWNER GROUP OTHER].each do |e|
|
286
|
+
mask = '---'
|
287
|
+
permissions_hash = document['PERMISSIONS']
|
288
|
+
mask[0] = 'u' if permissions_hash["#{e}_U"] == '1'
|
289
|
+
mask[1] = 'm' if permissions_hash["#{e}_M"] == '1'
|
290
|
+
mask[2] = 'a' if permissions_hash["#{e}_A"] == '1'
|
291
|
+
|
292
|
+
puts Kernel.format(str, e, mask)
|
293
|
+
end
|
294
|
+
|
295
|
+
puts
|
296
|
+
end
|
297
|
+
|
298
|
+
# Print service roles information
|
299
|
+
#
|
300
|
+
# @param roles [Array] Service roles information
|
301
|
+
def print_roles_info(roles)
|
302
|
+
str = '%-20s: %-20s'
|
303
|
+
|
304
|
+
roles.each do |role|
|
305
|
+
CLIHelper.print_header("ROLE #{role['name']}", false)
|
306
|
+
|
307
|
+
puts Kernel.format(str,
|
308
|
+
'ROLE STATE',
|
309
|
+
Role.state_str(role['state']))
|
310
|
+
|
311
|
+
if role['parents']
|
312
|
+
puts Kernel.format(str,
|
313
|
+
'PARENTS',
|
314
|
+
role['parents'].join(', '))
|
315
|
+
end
|
316
|
+
|
317
|
+
puts Kernel.format(str, 'VM TEMPLATE', role['vm_template'])
|
318
|
+
puts Kernel.format(str, 'CARDINALITY', role['cardinality'])
|
319
|
+
|
320
|
+
if role['min_vms']
|
321
|
+
puts Kernel.format(str, 'MIN VMS', role['min_vms'])
|
322
|
+
end
|
323
|
+
|
324
|
+
if role['max_vms']
|
325
|
+
puts Kernel.format(str, 'MAX VMS', role['max_vms'])
|
326
|
+
end
|
327
|
+
|
328
|
+
if role['coolddown']
|
329
|
+
puts Kernel.format(str, 'COOLDOWN', "#{role['cooldown']}s")
|
330
|
+
end
|
331
|
+
|
332
|
+
if role['shutdown_action']
|
333
|
+
puts Kernel.format(str, 'SHUTDOWN', role['shutdown_action'])
|
334
|
+
end
|
335
|
+
|
336
|
+
if role['elasticity_policies'] &&
|
337
|
+
!role['elasticity_policies'].empty?
|
338
|
+
print_elasticity_info(role)
|
339
|
+
end
|
340
|
+
|
341
|
+
if role['scheduled_policies'] &&
|
342
|
+
!role['scheduled_policies'].empty?
|
343
|
+
print_scheduled_info(role)
|
344
|
+
end
|
345
|
+
|
346
|
+
puts
|
347
|
+
CLIHelper.print_header('NODES INFORMATION', false)
|
348
|
+
|
349
|
+
format_node_pool.show(role['nodes'])
|
350
|
+
puts
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
# Print role elasticity info
|
355
|
+
#
|
356
|
+
# @param role [OpenNebula::Role] Role information
|
357
|
+
def print_elasticity_info(role)
|
358
|
+
puts
|
359
|
+
CLIHelper.print_header('ROLE ELASTICITY', false)
|
360
|
+
|
361
|
+
CLIHelper::ShowTable.new(nil, self) do
|
362
|
+
column :ADJUST, '', :left, :size => 12 do |d|
|
363
|
+
OneFlowHelper.adjust_str(d)
|
364
|
+
end
|
365
|
+
|
366
|
+
column :EXPRESSION, '', :left, :size => 48 do |d|
|
367
|
+
if !d['expression_evaluated'].nil?
|
368
|
+
d['expression_evaluated']
|
369
|
+
else
|
370
|
+
d['expression']
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
column :EVALS, '', :right, :size => 5 do |d|
|
375
|
+
if d['period_number']
|
376
|
+
"#{d['true_evals'].to_i}/"\
|
377
|
+
"#{d['period_number']}"
|
378
|
+
else
|
379
|
+
'-'
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
column :PERIOD, '', :size => 6 do |d|
|
384
|
+
d['period'] ? "#{d['period']}s" : '-'
|
385
|
+
end
|
386
|
+
|
387
|
+
column :COOL, '', :size => 5 do |d|
|
388
|
+
d['cooldown'] ? "#{d['cooldown']}s" : '-'
|
389
|
+
end
|
390
|
+
|
391
|
+
default :ADJUST, :EXPRESSION, :EVALS, :PERIOD, :COOL
|
392
|
+
end.show([role['elasticity_policies']].flatten, {})
|
393
|
+
end
|
394
|
+
|
395
|
+
# Print role schedule info
|
396
|
+
#
|
397
|
+
# @param role [OpenNebula::Role] Role information
|
398
|
+
def print_scheduled_info(role)
|
399
|
+
puts
|
400
|
+
CLIHelper.print_header('ROLE ELASTICITY SCHEDULE', false)
|
401
|
+
|
402
|
+
CLIHelper::ShowTable.new(nil, self) do
|
403
|
+
column :ADJUST, '', :left, :size => 12 do |d|
|
404
|
+
OneFlowHelper.adjust_str(d)
|
405
|
+
end
|
406
|
+
|
407
|
+
column :TIME, '', :left, :size => 67 do |d|
|
408
|
+
if d['start_time']
|
409
|
+
Time.parse(d['start_time']).to_s
|
410
|
+
else
|
411
|
+
d['recurrence']
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
default :ADJUST, :TIME
|
416
|
+
end.show([role['scheduled_policies']].flatten, {})
|
417
|
+
end
|
418
|
+
|
419
|
+
end
|