opennebula-cli 5.10.5 → 5.11.80.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 +2 -1
  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 +2 -1
  26. data/lib/cli_helper.rb +10 -4
  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 +1 -1
  32. data/lib/one_helper/onedatastore_helper.rb +1 -1
  33. data/lib/one_helper/oneflow_helper.rb +413 -0
  34. data/lib/one_helper/oneflowtemplate_helper.rb +306 -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 +29 -27
  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 +1 -1
  54. metadata +10 -8
@@ -0,0 +1,306 @@
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
+ # Get client to make request
23
+ #
24
+ # @options [Hash] CLI options
25
+ def client(options)
26
+ Service::Client.new(
27
+ :username => options[:username],
28
+ :password => options[:password],
29
+ :url => options[:server],
30
+ :user_agent => USER_AGENT
31
+ )
32
+ end
33
+
34
+ # Get service template pool
35
+ def format_service_template_pool
36
+ # TODO: config file
37
+ CLIHelper::ShowTable.new(nil, self) do
38
+ column :ID, 'ID', :size => 10 do |d|
39
+ d['ID']
40
+ end
41
+
42
+ column :USER, 'Username', :left, :size => 15 do |d|
43
+ d['UNAME']
44
+ end
45
+
46
+ column :GROUP, 'Group', :left, :size => 15 do |d|
47
+ d['GNAME']
48
+ end
49
+
50
+ column :NAME, 'Name', :left, :expand => true do |d|
51
+ d['NAME']
52
+ end
53
+
54
+ default :ID, :USER, :GROUP, :NAME
55
+ end
56
+ end
57
+
58
+ # List service template pool
59
+ #
60
+ # @param client [Service::Client] Petition client
61
+ # @param options [Hash] CLI options
62
+ def list_service_template_pool(client, options)
63
+ response = client.get(RESOURCE_PATH)
64
+
65
+ if CloudClient.is_error?(response)
66
+ [response.code.to_i, response.to_s]
67
+ else
68
+ if options[:json]
69
+ [0, response.body]
70
+ else
71
+ documents = JSON.parse(response.body)['DOCUMENT_POOL']
72
+ format_service_template_pool.show(documents['DOCUMENT'])
73
+
74
+ 0
75
+ end
76
+ end
77
+ end
78
+
79
+ # List service template pool continiously
80
+ #
81
+ # @param client [Service::Client] Petition client
82
+ # @param options [Hash] CLI options
83
+ def top_service_template_pool(client, options)
84
+ # TODO: make default delay configurable
85
+ options[:delay] ? delay = options[:delay] : delay = 4
86
+
87
+ begin
88
+ loop do
89
+ CLIHelper.scr_cls
90
+ CLIHelper.scr_move(0, 0)
91
+
92
+ list_service_template_pool(client, options)
93
+
94
+ sleep delay
95
+ end
96
+ rescue StandardError => e
97
+ STDERR.puts e.message
98
+ exit(-1)
99
+ end
100
+
101
+ 0
102
+ end
103
+
104
+ # Show service template detailed information
105
+ #
106
+ # @param client [Service::Client] Petition client
107
+ # @param service_template [Integer] Service template ID
108
+ # @param options [Hash] CLI options
109
+ def format_resource(client, service_template, options)
110
+ response = client.get("#{RESOURCE_PATH}/#{service_template}")
111
+
112
+ if CloudClient.is_error?(response)
113
+ [response.code.to_i, response.to_s]
114
+ else
115
+ if options[:json]
116
+ [0, response.body]
117
+ else
118
+ str = '%-20s: %-20s'
119
+ str_h1 = '%-80s'
120
+
121
+ document = JSON.parse(response.body)['DOCUMENT']
122
+ template = document['TEMPLATE']['BODY']
123
+
124
+ CLIHelper.print_header(
125
+ str_h1 % "SERVICE TEMPLATE #{document['ID']} INFORMATION"
126
+ )
127
+
128
+ puts Kernel.format str, 'ID', document['ID']
129
+ puts Kernel.format str, 'NAME', document['NAME']
130
+ puts Kernel.format str, 'USER', document['UNAME']
131
+ puts Kernel.format str, 'GROUP', document['GNAME']
132
+
133
+ puts
134
+
135
+ CLIHelper.print_header(str_h1 % 'PERMISSIONS', false)
136
+
137
+ %w[OWNER GROUP OTHER].each do |e|
138
+ mask = '---'
139
+ permissions_hash = document['PERMISSIONS']
140
+ mask[0] = 'u' if permissions_hash["#{e}_U"] == '1'
141
+ mask[1] = 'm' if permissions_hash["#{e}_M"] == '1'
142
+ mask[2] = 'a' if permissions_hash["#{e}_A"] == '1'
143
+
144
+ puts Kernel.format str, e, mask
145
+ end
146
+
147
+ puts
148
+
149
+ CLIHelper.print_header(str_h1 % 'TEMPLATE CONTENTS', false)
150
+ puts JSON.pretty_generate(template)
151
+
152
+ 0
153
+ end
154
+ end
155
+ end
156
+
157
+ # Get custom attributes values from user
158
+ #
159
+ # @param custom_attrs [Hash] Custom attributes from template
160
+ #
161
+ # @return [Hash] Custom attributes values
162
+ def custom_attrs(custom_attrs)
163
+ # rubocop:disable Layout/LineLength
164
+ return if custom_attrs.nil? || custom_attrs.empty?
165
+
166
+ ret = {}
167
+ ret['custom_attrs_values'] = OpenNebulaHelper.parse_user_inputs(custom_attrs)
168
+
169
+ # rubocop:enable Layout/LineLength
170
+ ret
171
+ end
172
+
173
+ def networks(vnets)
174
+ return unless vnets
175
+
176
+ ret = {}
177
+ ret['networks_values'] = parse_networks(vnets)
178
+
179
+ ret
180
+ end
181
+
182
+ def parse_networks(vnets, get_defaults = false)
183
+ unless get_defaults
184
+ puts 'There are some networks that require user input. ' \
185
+ 'Use the string <<EDITOR>> to launch an editor ' \
186
+ '(e.g. for multi-line inputs)'
187
+ end
188
+
189
+ answers = []
190
+
191
+ vnets.each do |key, val|
192
+ input_cfg = val.split('|', -1)
193
+
194
+ if input_cfg.length != 5
195
+ STDERR.puts 'Malformed user input. It should have 5'\
196
+ "parts separated by '|':"
197
+ STDERR.puts " #{key}: #{val}"
198
+ exit(-1)
199
+ end
200
+
201
+ mandatory, _type, description, _params, initial = input_cfg
202
+
203
+ vnet = {}
204
+
205
+ if initial && !initial.empty?
206
+ type, resource_id, extra = initial.split(':', -1)
207
+ end
208
+
209
+ if (type.nil? || resource_id.nil?) &&
210
+ (initial && !initial.empty?)
211
+ STDERR.puts 'Wrong type for user input default value:'
212
+ STDERR.puts " #{key}: #{val}"
213
+ exit(-1)
214
+ end
215
+
216
+ vnet[key] = {}
217
+
218
+ if get_defaults
219
+ vnet[key][type] = resource_id
220
+ vnet[key]['extra'] = extra
221
+
222
+ answers << vnet unless mandatory == 'M'
223
+ next
224
+ end
225
+
226
+ puts " * (#{key}) #{description}"
227
+
228
+ #######################################
229
+ # Asks for type
230
+ #######################################
231
+
232
+ header = ' '
233
+ header += 'TYPE Existing(1), Create(2), Reserve(3). '
234
+
235
+ if !type.nil? && type != ''
236
+ header += 'Press enter for default. '
237
+ end
238
+
239
+ print header
240
+
241
+ answer = STDIN.readline.chop
242
+
243
+ type_a = type
244
+
245
+ case answer.to_i
246
+ when 1
247
+ type_a = 'id'
248
+ when 2
249
+ type_a = 'template_id'
250
+ when 3
251
+ type_a = 'reserve_from'
252
+ end
253
+
254
+ #######################################
255
+ # Asks for resource id
256
+ #######################################
257
+
258
+ header = ' '
259
+ if type_a == 'template_id'
260
+ header += 'VN Template ID. '
261
+ else
262
+ header += 'VN ID. '
263
+ end
264
+
265
+ if !resource_id.nil? && resource_id != ''
266
+ header += "Press enter for default (#{resource_id}). "
267
+ end
268
+
269
+ print header
270
+
271
+ resource_id_a = STDIN.readline.chop
272
+
273
+ resource_id_a = resource_id if resource_id_a.empty?
274
+
275
+ #######################################
276
+ # Asks for extra
277
+ #######################################
278
+
279
+ if type_a != 'id'
280
+ header = ' '
281
+ header += 'EXTRA (Type EMPTY for leaving empty). '
282
+
283
+ if !extra.nil? && extra != ''
284
+ header += " Press enter for default (#{extra}). "
285
+ end
286
+
287
+ print header
288
+
289
+ extra_a = STDIN.readline.chop
290
+
291
+ if extra_a.empty?
292
+ vnet[key]['extra'] = extra
293
+ else
294
+ vnet[key]['extra'] = extra_a
295
+ end
296
+ end
297
+
298
+ vnet[key][type_a] = resource_id_a
299
+
300
+ answers << vnet
301
+ end
302
+
303
+ answers
304
+ end
305
+
306
+ 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
- # ]
63
- #
64
- # You can set any machine type supported by azure classic
65
- # See your az_driver.conf for more information
64
+ # Optional AZURE ATTRIBUTES:
66
65
  #
67
- # Optionally you can set a endpoint
66
+ # AZ_RGROUP = ""
68
67
  #
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,7 +474,7 @@ 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
+ cmd = 'cat /tmp/one-monitord-client.pid | xargs kill -HUP'
477
478
  system("ssh #{host['NAME']} \"#{cmd}\" 2>/dev/null")
478
479
 
479
480
  if !$CHILD_STATUS.success?
@@ -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[/IMPORT_VM_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']
@@ -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 #
@@ -82,7 +82,7 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
82
82
  :description => 'Path of the image file',
83
83
  :format => String,
84
84
  :proc => lambda do |o, _options|
85
- next [0, o] if o.match(%r{^https?://})
85
+ next [0, o] if o.match(%r{^(https?|docker)://})
86
86
 
87
87
  if o[0, 1]=='/'
88
88
  path=o