opennebula-cli 5.10.3 → 5.11.90.pre

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 +9 -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 +32 -13
  27. data/lib/command_parser.rb +32 -13
  28. data/lib/one_helper.rb +193 -2
  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 +32 -30
  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 +10 -8
@@ -0,0 +1,312 @@
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 Template command helper
20
+ class OneFlowTemplateHelper < OpenNebulaHelper::OneHelper
21
+
22
+ # Configuration file
23
+ def self.conf_file
24
+ 'oneflowtemplate.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 template pool
40
+ def format_service_template_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', :left, :expand => true do |d|
57
+ d['NAME']
58
+ end
59
+
60
+ default :ID, :USER, :GROUP, :NAME
61
+ end
62
+ end
63
+
64
+ # List service template pool
65
+ #
66
+ # @param client [Service::Client] Petition client
67
+ # @param options [Hash] CLI options
68
+ def list_service_template_pool(client, options)
69
+ response = client.get(RESOURCE_PATH)
70
+
71
+ if CloudClient.is_error?(response)
72
+ [response.code.to_i, response.to_s]
73
+ else
74
+ if options[:json]
75
+ [0, response.body]
76
+ else
77
+ documents = JSON.parse(response.body)['DOCUMENT_POOL']
78
+ format_service_template_pool.show(documents['DOCUMENT'])
79
+
80
+ 0
81
+ end
82
+ end
83
+ end
84
+
85
+ # List service template pool continiously
86
+ #
87
+ # @param client [Service::Client] Petition client
88
+ # @param options [Hash] CLI options
89
+ def top_service_template_pool(client, options)
90
+ # TODO: make default delay configurable
91
+ options[:delay] ? delay = options[:delay] : delay = 4
92
+
93
+ begin
94
+ loop do
95
+ CLIHelper.scr_cls
96
+ CLIHelper.scr_move(0, 0)
97
+
98
+ list_service_template_pool(client, options)
99
+
100
+ sleep delay
101
+ end
102
+ rescue StandardError => e
103
+ STDERR.puts e.message
104
+ exit(-1)
105
+ end
106
+
107
+ 0
108
+ end
109
+
110
+ # Show service template detailed information
111
+ #
112
+ # @param client [Service::Client] Petition client
113
+ # @param service_template [Integer] Service template ID
114
+ # @param options [Hash] CLI options
115
+ def format_resource(client, service_template, options)
116
+ response = client.get("#{RESOURCE_PATH}/#{service_template}")
117
+
118
+ if CloudClient.is_error?(response)
119
+ [response.code.to_i, response.to_s]
120
+ else
121
+ if options[:json]
122
+ [0, response.body]
123
+ else
124
+ str = '%-20s: %-20s'
125
+ str_h1 = '%-80s'
126
+
127
+ document = JSON.parse(response.body)['DOCUMENT']
128
+ template = document['TEMPLATE']['BODY']
129
+
130
+ CLIHelper.print_header(
131
+ str_h1 % "SERVICE TEMPLATE #{document['ID']} INFORMATION"
132
+ )
133
+
134
+ puts Kernel.format str, 'ID', document['ID']
135
+ puts Kernel.format str, 'NAME', document['NAME']
136
+ puts Kernel.format str, 'USER', document['UNAME']
137
+ puts Kernel.format str, 'GROUP', document['GNAME']
138
+
139
+ puts
140
+
141
+ CLIHelper.print_header(str_h1 % 'PERMISSIONS', false)
142
+
143
+ %w[OWNER GROUP OTHER].each do |e|
144
+ mask = '---'
145
+ permissions_hash = document['PERMISSIONS']
146
+ mask[0] = 'u' if permissions_hash["#{e}_U"] == '1'
147
+ mask[1] = 'm' if permissions_hash["#{e}_M"] == '1'
148
+ mask[2] = 'a' if permissions_hash["#{e}_A"] == '1'
149
+
150
+ puts Kernel.format str, e, mask
151
+ end
152
+
153
+ puts
154
+
155
+ CLIHelper.print_header(str_h1 % 'TEMPLATE CONTENTS', false)
156
+ puts JSON.pretty_generate(template)
157
+
158
+ 0
159
+ end
160
+ end
161
+ end
162
+
163
+ # Get custom attributes values from user
164
+ #
165
+ # @param custom_attrs [Hash] Custom attributes from template
166
+ #
167
+ # @return [Hash] Custom attributes values
168
+ def custom_attrs(custom_attrs)
169
+ # rubocop:disable Layout/LineLength
170
+ return if custom_attrs.nil? || custom_attrs.empty?
171
+
172
+ ret = {}
173
+ ret['custom_attrs_values'] = OpenNebulaHelper.parse_user_inputs(custom_attrs)
174
+
175
+ # rubocop:enable Layout/LineLength
176
+ ret
177
+ end
178
+
179
+ def networks(vnets)
180
+ return unless vnets
181
+
182
+ ret = {}
183
+ ret['networks_values'] = parse_networks(vnets)
184
+
185
+ ret
186
+ end
187
+
188
+ def parse_networks(vnets, get_defaults = false)
189
+ unless get_defaults
190
+ puts 'There are some networks that require user input. ' \
191
+ 'Use the string <<EDITOR>> to launch an editor ' \
192
+ '(e.g. for multi-line inputs)'
193
+ end
194
+
195
+ answers = []
196
+
197
+ vnets.each do |key, val|
198
+ input_cfg = val.split('|', -1)
199
+
200
+ if input_cfg.length != 5
201
+ STDERR.puts 'Malformed user input. It should have 5'\
202
+ "parts separated by '|':"
203
+ STDERR.puts " #{key}: #{val}"
204
+ exit(-1)
205
+ end
206
+
207
+ mandatory, _type, description, _params, initial = input_cfg
208
+
209
+ vnet = {}
210
+
211
+ if initial && !initial.empty?
212
+ type, resource_id, extra = initial.split(':', -1)
213
+ end
214
+
215
+ if (type.nil? || resource_id.nil?) &&
216
+ (initial && !initial.empty?)
217
+ STDERR.puts 'Wrong type for user input default value:'
218
+ STDERR.puts " #{key}: #{val}"
219
+ exit(-1)
220
+ end
221
+
222
+ vnet[key] = {}
223
+
224
+ if get_defaults
225
+ vnet[key][type] = resource_id
226
+ vnet[key]['extra'] = extra
227
+
228
+ answers << vnet unless mandatory == 'M'
229
+ next
230
+ end
231
+
232
+ puts " * (#{key}) #{description}"
233
+
234
+ #######################################
235
+ # Asks for type
236
+ #######################################
237
+
238
+ header = ' '
239
+ header += 'TYPE Existing(1), Create(2), Reserve(3). '
240
+
241
+ if !type.nil? && type != ''
242
+ header += 'Press enter for default. '
243
+ end
244
+
245
+ print header
246
+
247
+ answer = STDIN.readline.chop
248
+
249
+ type_a = type
250
+
251
+ case answer.to_i
252
+ when 1
253
+ type_a = 'id'
254
+ when 2
255
+ type_a = 'template_id'
256
+ when 3
257
+ type_a = 'reserve_from'
258
+ end
259
+
260
+ #######################################
261
+ # Asks for resource id
262
+ #######################################
263
+
264
+ header = ' '
265
+ if type_a == 'template_id'
266
+ header += 'VN Template ID. '
267
+ else
268
+ header += 'VN ID. '
269
+ end
270
+
271
+ if !resource_id.nil? && resource_id != ''
272
+ header += "Press enter for default (#{resource_id}). "
273
+ end
274
+
275
+ print header
276
+
277
+ resource_id_a = STDIN.readline.chop
278
+
279
+ resource_id_a = resource_id if resource_id_a.empty?
280
+
281
+ #######################################
282
+ # Asks for extra
283
+ #######################################
284
+
285
+ if type_a != 'id'
286
+ header = ' '
287
+ header += 'EXTRA (Type EMPTY for leaving empty). '
288
+
289
+ if !extra.nil? && extra != ''
290
+ header += " Press enter for default (#{extra}). "
291
+ end
292
+
293
+ print header
294
+
295
+ extra_a = STDIN.readline.chop
296
+
297
+ if extra_a.empty?
298
+ vnet[key]['extra'] = extra
299
+ else
300
+ vnet[key]['extra'] = extra_a
301
+ end
302
+ end
303
+
304
+ vnet[key][type_a] = resource_id_a
305
+
306
+ answers << vnet
307
+ end
308
+
309
+ answers
310
+ end
311
+
312
+ end
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2019, OpenNebula Project, OpenNebula Systems #
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-2019, OpenNebula Project, OpenNebula Systems #
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-2019, OpenNebula Project, OpenNebula Systems #
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 #
@@ -48,25 +48,25 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
48
48
  :az => {
49
49
  :help => <<-EOT.unindent
50
50
  #-----------------------------------------------------------------------
51
- # Supported AZURE AUTH ATTRIBUTTES:
51
+ # Mandatory AZURE ATTRIBUTTES:
52
52
  #
53
- # AZ_ID = <azure classic id>
54
- # AZ_CERT = <azure classic certificate>
53
+ # AZ_SUB = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
54
+ # AZ_CLIENT = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
55
+ # AZ_SECRET = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
56
+ # AZ_TENANT = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
57
+ # AZ_REGION = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
55
58
  #
56
- # REGION_NAME = <the name of the azure region>
59
+ # CAPACITY=[
60
+ # STANDARD_B1LS =<number of machines Standard_B1ls>,
61
+ # STANDARD_A1_V2=<number of machines Standard_A1_v2>
62
+ # ]
57
63
  #
58
- # CAPACITY = [
59
- # Small = <number of small machines>,
60
- # Medium = <number of medium machines>,
61
- # Large = <number of large machines
62
- # ]
64
+ # Optional AZURE ATTRIBUTES:
63
65
  #
64
- # You can set any machine type supported by azure classic
65
- # See your az_driver.conf for more information
66
+ # AZ_RGROUP = ""
66
67
  #
67
- # Optionally you can set a endpoint
68
- #
69
- # AZ_ENDPOINT = <endpoint address>
68
+ # You can set any machine type supported by azure
69
+ # See your az_driver.conf for more information
70
70
  #
71
71
  #-----------------------------------------------------------------------
72
72
  EOT
@@ -359,14 +359,15 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
359
359
 
360
360
  print_update_info(total - size, total, host['NAME'])
361
361
 
362
- if options[:rsync]
363
- sync_cmd = "rsync -Laz --delete #{REMOTES_LOCATION}" \
364
- " #{host['NAME']}:#{remote_dir}"
365
- else
362
+ if options[:ssh]
366
363
  sync_cmd = "ssh #{host['NAME']}" \
364
+ " rm -rf '#{remote_dir}' 2>/dev/null;" \
367
365
  " mkdir -p '#{remote_dir}' 2>/dev/null &&" \
368
366
  " scp -rp #{REMOTES_LOCATION}/*" \
369
367
  " #{host['NAME']}:#{remote_dir} 2> /dev/null"
368
+ else
369
+ sync_cmd = "rsync -Laz --delete #{REMOTES_LOCATION}/" \
370
+ " #{host['NAME']}:#{remote_dir}/"
370
371
  end
371
372
 
372
373
  retries = 3
@@ -473,15 +474,15 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
473
474
 
474
475
  break unless host
475
476
 
476
- cmd = 'cat /tmp/one-collectd-client.pid | xargs kill -HUP'
477
- system("ssh #{host['NAME']} \"#{cmd}\" 2>/dev/null")
477
+ hn = host['NAME']
478
478
 
479
+ system("onehost offline #{hn} && onehost enable #{hn}")
479
480
  if !$CHILD_STATUS.success?
480
481
  error_lock.synchronize do
481
- host_errors << host['NAME']
482
+ host_errors << hn
482
483
  end
483
484
  else
484
- puts "#{host['NAME']} monitoring forced"
485
+ puts "#{hn} monitoring forced"
485
486
  end
486
487
  end
487
488
  end
@@ -565,7 +566,7 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
565
566
  puts format(str, 'IM_MAD', host['IM_MAD'])
566
567
  puts format(str, 'VM_MAD', host['VM_MAD'])
567
568
  puts format(str, 'LAST MONITORING TIME',
568
- OpenNebulaHelper.time_to_str(host['LAST_MON_TIME']))
569
+ OpenNebulaHelper.time_to_str(host['MONITORING/TIMESTAMP']))
569
570
  puts
570
571
 
571
572
  CLIHelper.print_header(str_h1 % 'HOST SHARES', false)
@@ -579,8 +580,9 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
579
580
  OpenNebulaHelper.unit_to_str(host['HOST_SHARE/MAX_MEM']
580
581
  .to_i, {}))
581
582
  puts format(str, ' USED (REAL)',
582
- OpenNebulaHelper.unit_to_str(host['HOST_SHARE/USED_MEM']
583
- .to_i, {}))
583
+ OpenNebulaHelper
584
+ .unit_to_str(host['MONITORING/CAPACITY/USED_MEMORY']
585
+ .to_i, {}))
584
586
  puts format(str, ' USED (ALLOCATED)',
585
587
  OpenNebulaHelper.unit_to_str(host['HOST_SHARE/MEM_USAGE']
586
588
  .to_i, {}))
@@ -588,7 +590,7 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
588
590
  CLIHelper.print_header(str_h1 % 'CPU', false)
589
591
  puts format(str, ' TOTAL', host['HOST_SHARE/TOTAL_CPU'])
590
592
  puts format(str, ' TOTAL +/- RESERVED', host['HOST_SHARE/MAX_CPU'])
591
- puts format(str, ' USED (REAL)', host['HOST_SHARE/USED_CPU'])
593
+ puts format(str, ' USED (REAL)', host['MONITORING/CAPACITY/USED_CPU'])
592
594
  puts format(str, ' USED (ALLOCATED)', host['HOST_SHARE/CPU_USAGE'])
593
595
  puts
594
596
 
@@ -662,13 +664,13 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
662
664
  .split("\n")
663
665
  name = wild['VM_NAME']
664
666
  import = wild_tmplt.select do |line|
665
- line[/^IMPORT_VM_ID/]
667
+ line[/DEPLOY_ID/]
666
668
  end[0].split('=')[1].tr('"', ' ').strip
667
669
  memory = wild_tmplt.select do |line|
668
- line[/^MEMORY/]
670
+ line[/MEMORY/]
669
671
  end[0].split('=')[1].tr('"', ' ').strip
670
672
  cpu = wild_tmplt.select do |line|
671
- line[/^CPU/]
673
+ line[/CPU/]
672
674
  end[0].split('=')[1].tr('"', ' ').strip
673
675
  else
674
676
  name = wild['DEPLOY_ID']