opennebula-cli 5.10.2 → 5.10.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 295cccef022aa2264f24ed89bdd3c7ff0a88d7af
4
- data.tar.gz: d0147da36b571179d0a783eb4a0aca095eb75170
3
+ metadata.gz: db84680874bbde511e8ffc04129cf914bf23e04b
4
+ data.tar.gz: ba353a408b6ac968cf13fe5e3cd062d08bb5ed91
5
5
  SHA512:
6
- metadata.gz: a09dc31b0b49468074f6ec70bdebf46e9f59f174226c328fe77b62add87a1b96c4620705e432271d9775875e529e92079fb19571bc142fa7aa55602e02d9711b
7
- data.tar.gz: 4632563ed7e4098f7a20e48e30f6842574664ee0b3ab37ba2b3819a03294b07770fe54cd1247805d67429d375bd2247f2f611ef850da71076779880b6eb4684e
6
+ metadata.gz: 1709c9dbc7100d21beb1c0ca96f1c8281bdda6758a727f30cbe98b49ffbdafd7ccc659d3bf8db2e46abb70ec9007225478170c7d94c07c454a2e061cfec42975
7
+ data.tar.gz: 0a1bf968f039c46a6a6b032ef9888caf86c88946361650e2c109bc9ed8006cb62f3056556e10b4fedb9f6d4cd1c3c53b98c74e3b4cf4666e09d254766f69ef71
@@ -79,8 +79,12 @@ CommandParser::CmdParser.new(ARGV) do
79
79
  :description => 'execution ID'
80
80
  }
81
81
 
82
- set :format, :hookid, OpenNebulaHelper.rname_to_id_desc('HOOK') do |arg|
83
- OpenNebulaHelper.rname_to_id(arg, 'HOOK')
82
+ set :format, :hookid, OneHookHelper.to_id_desc do |arg|
83
+ helper.to_id(arg)
84
+ end
85
+
86
+ set :format, :hookid_list, OneHookHelper.list_to_id_desc do |arg|
87
+ helper.list_to_id(arg)
84
88
  end
85
89
 
86
90
  ########################################################################
@@ -172,8 +176,8 @@ CommandParser::CmdParser.new(ARGV) do
172
176
  EOT
173
177
 
174
178
  command :delete, delete_desc, [:range, :hookid_list] do
175
- helper.perform_actions(args[0], options, 'deleted') do |t|
176
- t.delete
179
+ helper.perform_actions(args[0], options, 'deleted') do |hook|
180
+ hook.delete
177
181
  end
178
182
  end
179
183
 
@@ -224,8 +224,8 @@ CommandParser::CmdParser.new(ARGV) do
224
224
  next -1
225
225
  end
226
226
 
227
- number = options[:multiple] || 1
228
- user_inputs = nil
227
+ number = options[:multiple] || 1
228
+ user_inputs = options[:user_inputs]
229
229
 
230
230
  number.times do |i|
231
231
  exit_code = helper.perform_action(args[0], options,
@@ -258,6 +258,10 @@ CommandParser::CmdParser.new(ARGV) do
258
258
 
259
259
  if !user_inputs
260
260
  user_inputs = OneTemplateHelper.get_user_inputs(t.to_hash)
261
+ else
262
+ optionals = OneTemplateHelper.get_user_inputs(t.to_hash,
263
+ true)
264
+ user_inputs = user_inputs + "\n" + optionals
261
265
  end
262
266
 
263
267
  extra_template << "\n#{user_inputs}"
@@ -633,7 +633,7 @@ module CLIHelper
633
633
  def expand_columns(expand_columns, all = false)
634
634
  return if expand_columns.empty?
635
635
 
636
- if $stdout.tty?
636
+ if $stdout.tty? || (IO.console && IO.console.tty?)
637
637
  terminal_size = IO.console.winsize[1]
638
638
  else
639
639
  terminal_size = nil
@@ -381,6 +381,21 @@ EOT
381
381
  :description => "In a vCenter environment sets the the VMs and Template folder where the VM will be placed in." \
382
382
  " The path uses slashes to separate folders. For example: --vcenter_vm_folder \"/Management/VMs\""
383
383
  },
384
+ {
385
+ :name => 'user_inputs',
386
+ :large => '--user-inputs ui1,ui2,ui3',
387
+ :format => Array,
388
+ :description => 'Specify the user inputs values when instantiating',
389
+ :proc => lambda do |o, options|
390
+ # escape values
391
+ options[:user_inputs].map! do |user_input|
392
+ user_input_split = user_input.split('=')
393
+ "#{user_input_split[0]}=\"#{user_input_split[1]}\""
394
+ end
395
+
396
+ options[:user_inputs] = o.join("\n")
397
+ end
398
+ },
384
399
  AS_GROUP,
385
400
  AS_USER
386
401
  ]
@@ -17,139 +17,140 @@
17
17
  require 'one_helper'
18
18
  require 'one_helper/onevm_helper'
19
19
 
20
+ # CLI helper for oneimage command
20
21
  class OneImageHelper < OpenNebulaHelper::OneHelper
22
+
21
23
  TEMPLATE_OPTIONS=[
22
24
  {
23
- :name => "name",
24
- :large => "--name name",
25
+ :name => 'name',
26
+ :large => '--name name',
25
27
  :format => String,
26
- :description => "Name of the new image"
28
+ :description => 'Name of the new image'
27
29
  },
28
30
  {
29
- :name => "description",
30
- :large => "--description description",
31
+ :name => 'description',
32
+ :large => '--description description',
31
33
  :format => String,
32
- :description => "Description for the new Image"
34
+ :description => 'Description for the new Image'
33
35
  },
34
36
  {
35
- :name => "type",
36
- :large => "--type type",
37
+ :name => 'type',
38
+ :large => '--type type',
37
39
  :format => String,
38
- :description => "Type of the new Image: #{Image::IMAGE_TYPES.join(", ")}",
39
- :proc => lambda do |o, options|
40
+ :description => "Type of the new Image: \
41
+ #{Image::IMAGE_TYPES.join(', ')}",
42
+
43
+ :proc => lambda do |o, _options|
40
44
  type=o.strip.upcase
41
45
 
42
46
  if Image::IMAGE_TYPES.include? type
43
47
  [0, type]
44
48
  else
45
- [-1, "Type should be: #{Image::IMAGE_TYPES.join(", ")}"]
49
+ [-1, "Type should be: #{Image::IMAGE_TYPES.join(', ')}"]
46
50
  end
47
51
  end
48
52
  },
49
53
  {
50
- :name => "persistent",
51
- :large => "--persistent",
52
- :description => "Tells if the image will be persistent"
54
+ :name => 'persistent',
55
+ :large => '--persistent',
56
+ :description => 'Tells if the image will be persistent'
53
57
  },
54
58
  {
55
- :name => "prefix",
56
- :large => "--prefix prefix",
59
+ :name => 'prefix',
60
+ :large => '--prefix prefix',
57
61
  :description => "Device prefix for the disk (eg. hd, sd, xvd\n"<<
58
- " "*31<<"or vd)",
62
+ ' '*31<<'or vd)',
59
63
  :format => String,
60
- :proc => lambda do |o, options|
64
+ :proc => lambda do |o, _options|
61
65
  prefix=o.strip.downcase
62
- if %w{hd sd xvd vd}.include? prefix
66
+ if %w[hd sd xvd vd].include? prefix
63
67
  [0, prefix]
64
68
  else
65
- [-1, "The prefix must be hd, sd, xvd or vd"]
69
+ [-1, 'The prefix must be hd, sd, xvd or vd']
66
70
  end
67
71
  end
68
72
  },
69
73
  {
70
- :name => "target",
71
- :large => "--target target",
72
- :description => "Device the disk will be attached to",
74
+ :name => 'target',
75
+ :large => '--target target',
76
+ :description => 'Device the disk will be attached to',
73
77
  :format => String
74
78
  },
75
79
  {
76
- :name => "path",
77
- :large => "--path path",
78
- :description => "Path of the image file",
80
+ :name => 'path',
81
+ :large => '--path path',
82
+ :description => 'Path of the image file',
79
83
  :format => String,
80
- :proc => lambda do |o, options|
81
- if o.match(/^https?:\/\//)
82
- next [0, o]
83
- elsif o[0,1]=='/'
84
+ :proc => lambda do |o, _options|
85
+ next [0, o] if o.match(%r{^https?://})
86
+
87
+ if o[0, 1]=='/'
84
88
  path=o
85
89
  else
86
- path=Dir.pwd+"/"+o
90
+ path=Dir.pwd+'/'+o
87
91
  end
88
92
 
89
- if File.readable?(path)
90
- [0, path]
91
- else
92
- [-1, "File '#{path}' does not exist or is not readable."]
93
- end
93
+ [0, path]
94
94
  end
95
95
  },
96
96
  {
97
- :name => "driver",
98
- :large => "--driver driver",
99
- :description => "Driver to use image (raw, qcow2, tap:aio:...)",
97
+ :name => 'driver',
98
+ :large => '--driver driver',
99
+ :description => 'Driver to use image (raw, qcow2, tap:aio:...)',
100
100
  :format => String
101
101
  },
102
102
  {
103
- :name => "disk_type",
104
- :large => "--disk_type disk_type",
103
+ :name => 'disk_type',
104
+ :large => '--disk_type disk_type',
105
105
  :description => "Type of the image \n"<<
106
- " " * 31 << "BLOCK, CDROM, RBD or FILE \n" <<
107
- "(for others, check the documentation) ",
106
+ ' ' * 31 << "BLOCK, CDROM, RBD or FILE \n" \
107
+ '(for others, check the documentation) ',
108
108
  :format => String
109
109
  },
110
110
  {
111
- :name => "vcenter_disk_type",
112
- :large => "--vcenter_disk_type vcenter_disk_type",
111
+ :name => 'vcenter_disk_type',
112
+ :large => '--vcenter_disk_type vcenter_disk_type',
113
113
  :description => "The vCenter Disk Type of the image \n"<<
114
- " " * 31 <<
115
- "for vCenter: THIN, THICK, ZEROEDTHICK " <<
116
- "(for others, check the documentation) ",
114
+ ' ' * 31 <<
115
+ 'for vCenter: THIN, THICK, ZEROEDTHICK ' \
116
+ '(for others, check the documentation) ',
117
117
  :format => String
118
118
  },
119
119
  {
120
- :name => "vcenter_adapter_type",
121
- :large => "--vcenter_adapter_type vcenter_adapter_type",
122
- :description => "Controller that will handle this image in " <<
123
- "vCenter (lsiLogic, ide, busLogic). For other "<<
124
- "values check the documentation",
120
+ :name => 'vcenter_adapter_type',
121
+ :large => '--vcenter_adapter_type vcenter_adapter_type',
122
+ :description => 'Controller that will handle this image in ' \
123
+ 'vCenter (lsiLogic, ide, busLogic). For other '\
124
+ 'values check the documentation',
125
125
  :format => String
126
126
  },
127
127
  {
128
- :name => "source",
129
- :large => "--source source",
128
+ :name => 'source',
129
+ :large => '--source source',
130
130
  :description =>
131
131
  "Source to be used. Useful for not file-based\n"<<
132
- " "*31<<"images",
132
+ ' '*31<<'images',
133
133
  :format => String
134
134
  },
135
135
  {
136
- :name => "size",
137
- :large => "--size size",
138
- :description => "Size in MB. Used for DATABLOCK type or SOURCE based images.",
139
- :format => String,
140
- :proc => lambda do |o, options|
136
+ :name => 'size',
137
+ :large => '--size size',
138
+ :description => "Size in MB. \
139
+ Used for DATABLOCK type or SOURCE based images.",
141
140
 
141
+ :format => String,
142
+ :proc => lambda do |o, _options|
142
143
  m=o.strip.match(/^(\d+(?:\.\d+)?)(m|mb|g|gb)?$/i)
143
144
 
144
145
  if !m
145
146
  [-1, 'Size value malformed']
146
147
  else
147
148
  multiplier=case m[2]
148
- when /(g|gb)/i
149
- 1024
150
- else
151
- 1
152
- end
149
+ when /(g|gb)/i
150
+ 1024
151
+ else
152
+ 1
153
+ end
153
154
 
154
155
  value=m[1].to_f*multiplier
155
156
 
@@ -161,89 +162,89 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
161
162
  ]
162
163
 
163
164
  IMAGE = {
164
- :name => "no_check_capacity",
165
- :large => "--no_check_capacity",
165
+ :name => 'no_check_capacity',
166
+ :large => '--no_check_capacity',
166
167
  :description =>
167
- "Check Datastore capacity. By Default YES",
168
+ 'Check Datastore capacity. By Default YES',
168
169
  :format => String
169
170
  }
170
171
 
171
172
  def self.rname
172
- "IMAGE"
173
+ 'IMAGE'
173
174
  end
174
175
 
175
176
  def self.conf_file
176
- "oneimage.yaml"
177
+ 'oneimage.yaml'
177
178
  end
178
179
 
179
180
  def self.state_to_str(id)
180
181
  id = id.to_i
181
182
  state_str = Image::IMAGE_STATES[id]
182
- return Image::SHORT_IMAGE_STATES[state_str]
183
+ Image::SHORT_IMAGE_STATES[state_str]
183
184
  end
184
185
 
185
186
  def self.type_to_str(id)
186
187
  id = id.to_i
187
188
  type_str = Image::IMAGE_TYPES[id]
188
- return Image::SHORT_IMAGE_TYPES[type_str]
189
+ Image::SHORT_IMAGE_TYPES[type_str]
189
190
  end
190
191
 
191
192
  def format_pool(options)
192
193
  config_file = self.class.table_conf
193
194
 
194
195
  table = CLIHelper::ShowTable.new(config_file, self) do
195
- column :ID, "ONE identifier for the Image", :size=>4 do |d|
196
- d["ID"]
196
+ column :ID, 'ONE identifier for the Image', :size=>4 do |d|
197
+ d['ID']
197
198
  end
198
199
 
199
- column :USER, "Username of the Image owner", :left,
200
- :size=>10 do |d|
200
+ column :USER, 'Username of the Image owner', :left,
201
+ :size=>10 do |d|
201
202
  helper.user_name(d, options)
202
203
  end
203
204
 
204
- column :GROUP, "Group of the Image", :left,
205
- :size=>10 do |d|
205
+ column :GROUP, 'Group of the Image', :left,
206
+ :size=>10 do |d|
206
207
  helper.group_name(d, options)
207
208
  end
208
209
 
209
- column :NAME, "Name of the Image", :left, :size=>15 do |d|
210
- d["NAME"]
210
+ column :NAME, 'Name of the Image', :left, :size=>15 do |d|
211
+ d['NAME']
211
212
  end
212
213
 
213
- column :DATASTORE, "Name of the Datastore", :left, :size=>10 do |d|
214
- d["DATASTORE"]
214
+ column :DATASTORE, 'Name of the Datastore', :left, :size=>10 do |d|
215
+ d['DATASTORE']
215
216
  end
216
217
 
217
- column :TYPE, "Type of the Image", :left, :size=>4 do |d,e|
218
- OneImageHelper.type_to_str(d["TYPE"])
218
+ column :TYPE, 'Type of the Image', :left, :size=>4 do |d, _e|
219
+ OneImageHelper.type_to_str(d['TYPE'])
219
220
  end
220
221
 
221
- column :REGTIME, "Registration time of the Image",
222
- :size=>15 do |d|
223
- OpenNebulaHelper.time_to_str(d["REGTIME"])
222
+ column :REGTIME, 'Registration time of the Image',
223
+ :size=>15 do |d|
224
+ OpenNebulaHelper.time_to_str(d['REGTIME'])
224
225
  end
225
226
 
226
- column :PERSISTENT, "Whether the Image is persistent or not",
227
- :size=>3 do |d|
228
- OpenNebulaHelper.boolean_to_str(d["PERSISTENT"])
227
+ column :PERSISTENT, 'Whether the Image is persistent or not',
228
+ :size=>3 do |d|
229
+ OpenNebulaHelper.boolean_to_str(d['PERSISTENT'])
229
230
  end
230
231
 
231
- column :STAT, "State of the Image", :left, :size=>4 do |d|
232
- OneImageHelper.state_to_str(d["STATE"])
232
+ column :STAT, 'State of the Image', :left, :size=>4 do |d|
233
+ OneImageHelper.state_to_str(d['STATE'])
233
234
  end
234
235
 
235
- column :RVMS, "Number of VMs currently running from this Image",
236
- :size=>4 do |d|
236
+ column :RVMS, 'Number of VMs currently running from this Image',
237
+ :size=>4 do |d|
237
238
  d['RUNNING_VMS']
238
239
  end
239
240
 
240
- column :SIZE, "Size of the image",
241
- :size=>7 do |d|
242
- OpenNebulaHelper.unit_to_str(d['SIZE'].to_i,options,"M")
241
+ column :SIZE, 'Size of the image',
242
+ :size=>7 do |d|
243
+ OpenNebulaHelper.unit_to_str(d['SIZE'].to_i, options, 'M')
243
244
  end
244
245
 
245
246
  default :ID, :USER, :GROUP, :NAME, :DATASTORE, :SIZE, :TYPE,
246
- :PERSISTENT , :STAT, :RVMS
247
+ :PERSISTENT, :STAT, :RVMS
247
248
  end
248
249
 
249
250
  table
@@ -274,7 +275,7 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
274
275
 
275
276
  private
276
277
 
277
- def factory(id=nil)
278
+ def factory(id = nil)
278
279
  if id
279
280
  OpenNebula::Image.new_with_id(id, @client)
280
281
  else
@@ -283,109 +284,115 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
283
284
  end
284
285
  end
285
286
 
286
- def factory_pool(user_flag=-2)
287
+ def factory_pool(user_flag = -2)
287
288
  OpenNebula::ImagePool.new(@client, user_flag)
288
289
  end
289
290
 
290
- def format_resource(image, options = {})
291
- str="%-15s: %-20s"
292
- str_h1="%-80s"
291
+ def format_resource(image, _options = {})
292
+ str='%-15s: %-20s'
293
+ str_h1='%-80s'
294
+
295
+ path = image['PATH']
296
+ fstype = image['FSTYPE']
297
+
298
+ size = OpenNebulaHelper.unit_to_str(image['SIZE'].to_i, {}, 'M')
299
+ lock = OpenNebulaHelper.level_lock_to_str(image['LOCK/LOCKED'])
300
+ regtime = OpenNebulaHelper.time_to_str(image['REGTIME'])
301
+ pers = OpenNebulaHelper.boolean_to_str(image['PERSISTENT'])
293
302
 
294
303
  CLIHelper.print_header(str_h1 % "IMAGE #{image['ID']} INFORMATION")
295
- puts str % ["ID", image.id.to_s]
296
- puts str % ["NAME", image.name]
297
- puts str % ["USER", image['UNAME']]
298
- puts str % ["GROUP",image['GNAME']]
299
- puts str % ["LOCK", OpenNebulaHelper.level_lock_to_str(image['LOCK/LOCKED'])]
300
- puts str % ["DATASTORE",image['DATASTORE']]
301
- puts str % ["TYPE", image.type_str]
302
- puts str % ["REGISTER TIME",
303
- OpenNebulaHelper.time_to_str(image['REGTIME'])]
304
- puts str % ["PERSISTENT",
305
- OpenNebulaHelper.boolean_to_str(image["PERSISTENT"])]
306
- puts str % ["SOURCE",image['SOURCE']]
307
- puts str % ["PATH",image['PATH']] if image['PATH'] && !image['PATH'].empty?
308
- puts str % ["FSTYPE",image['FSTYPE']] if image['FSTYPE'] && !image['FSTYPE'].empty?
309
- puts str % ["SIZE", OpenNebulaHelper.unit_to_str(image['SIZE'].to_i,{},"M")]
310
- puts str % ["STATE", image.short_state_str]
311
- puts str % ["RUNNING_VMS", image['RUNNING_VMS']]
304
+ puts format(str, 'ID', image.id.to_s)
305
+ puts format(str, 'NAME', image.name)
306
+ puts format(str, 'USER', image['UNAME'])
307
+ puts format(str, 'GROUP', image['GNAME'])
308
+ puts format(str, 'LOCK', lock)
309
+ puts format(str, 'DATASTORE', image['DATASTORE'])
310
+ puts format(str, 'TYPE', image.type_str)
311
+ puts format(str, 'REGISTER TIME', regtime)
312
+ puts format(str, 'PERSISTENT', pers)
313
+ puts format(str, 'SOURCE', image['SOURCE'])
314
+ puts format(str, 'PATH', path) if path && !path.empty?
315
+ puts format(str, 'FSTYPE', fstype) if fstype && !fstype.empty?
316
+ puts format(str, 'SIZE', size)
317
+ puts format(str, 'STATE', image.short_state_str)
318
+ puts format(str, 'RUNNING_VMS', image['RUNNING_VMS'])
312
319
  puts
313
320
 
314
- CLIHelper.print_header(str_h1 % "PERMISSIONS",false)
321
+ CLIHelper.print_header(str_h1 % 'PERMISSIONS', false)
315
322
 
316
- ["OWNER", "GROUP", "OTHER"].each { |e|
317
- mask = "---"
318
- mask[0] = "u" if image["PERMISSIONS/#{e}_U"] == "1"
319
- mask[1] = "m" if image["PERMISSIONS/#{e}_M"] == "1"
320
- mask[2] = "a" if image["PERMISSIONS/#{e}_A"] == "1"
323
+ %w[OWNER GROUP OTHER].each do |e|
324
+ mask = '---'
325
+ mask[0] = 'u' if image["PERMISSIONS/#{e}_U"] == '1'
326
+ mask[1] = 'm' if image["PERMISSIONS/#{e}_M"] == '1'
327
+ mask[2] = 'a' if image["PERMISSIONS/#{e}_A"] == '1'
321
328
 
322
- puts str % [e, mask]
323
- }
329
+ puts format(str, e, mask)
330
+ end
324
331
 
325
- if image.has_elements?("/IMAGE/SNAPSHOTS/SNAPSHOT")
332
+ if image.has_elements?('/IMAGE/SNAPSHOTS/SNAPSHOT')
326
333
  puts
327
- CLIHelper.print_header(str_h1 % "IMAGE SNAPSHOTS",false)
334
+ CLIHelper.print_header(str_h1 % 'IMAGE SNAPSHOTS', false)
328
335
  format_snapshots(image)
329
336
  end
330
337
 
331
338
  puts
332
339
 
333
- CLIHelper.print_header(str_h1 % "IMAGE TEMPLATE",false)
340
+ CLIHelper.print_header(str_h1 % 'IMAGE TEMPLATE', false)
334
341
  puts image.template_str
335
342
 
336
343
  puts
337
- CLIHelper.print_header("VIRTUAL MACHINES", false)
344
+ CLIHelper.print_header('VIRTUAL MACHINES', false)
338
345
  puts
339
346
 
340
- vms=image.retrieve_elements("VMS/ID")
347
+ vms=image.retrieve_elements('VMS/ID')
341
348
 
342
- if vms
343
- vms.map!{|e| e.to_i }
344
- onevm_helper=OneVMHelper.new
345
- onevm_helper.client=@client
346
- onevm_helper.list_pool({:ids=>vms, :no_pager => true}, false)
347
- end
349
+ return unless vms
350
+
351
+ vms.map! {|e| e.to_i }
352
+ onevm_helper=OneVMHelper.new
353
+ onevm_helper.client=@client
354
+ onevm_helper.list_pool({ :ids=>vms, :no_pager => true }, false)
348
355
  end
349
356
 
350
357
  def format_snapshots(image)
351
358
  table=CLIHelper::ShowTable.new(nil, self) do
352
- column :AC , "Is active", :left, :size => 2 do |d|
353
- if d["ACTIVE"] == "YES"
354
- "=>"
359
+ column :AC, 'Is active', :left, :size => 2 do |d|
360
+ if d['ACTIVE'] == 'YES'
361
+ '=>'
355
362
  else
356
- ""
363
+ ''
357
364
  end
358
365
  end
359
- column :ID, "Snapshot ID", :size=>3 do |d|
360
- d["ID"]
366
+ column :ID, 'Snapshot ID', :size=>3 do |d|
367
+ d['ID']
361
368
  end
362
369
 
363
- column :PARENT, "Snapshot Parent ID", :size=>6 do |d|
364
- d["PARENT"]
370
+ column :PARENT, 'Snapshot Parent ID', :size=>6 do |d|
371
+ d['PARENT']
365
372
  end
366
373
 
367
- column :CHILDREN, "Snapshot Children IDs", :size=>10 do |d|
368
- d["CHILDREN"]
374
+ column :CHILDREN, 'Snapshot Children IDs', :size=>10 do |d|
375
+ d['CHILDREN']
369
376
  end
370
377
 
371
- column :SIZE, "", :left, :size=>8 do |d|
372
- if d["SIZE"]
378
+ column :SIZE, '', :left, :size=>8 do |d|
379
+ if d['SIZE']
373
380
  OpenNebulaHelper.unit_to_str(
374
- d['SIZE'].to_i,
375
- {},
376
- "M"
377
- )
381
+ d['SIZE'].to_i,
382
+ {},
383
+ 'M'
384
+ )
378
385
  else
379
- "-"
386
+ '-'
380
387
  end
381
388
  end
382
389
 
383
- column :NAME, "Snapshot Name", :left, :size=>37 do |d|
384
- d["NAME"]
390
+ column :NAME, 'Snapshot Name', :left, :size=>37 do |d|
391
+ d['NAME']
385
392
  end
386
393
 
387
- column :DATE, "Snapshot creation date", :size=>15 do |d|
388
- OpenNebulaHelper.time_to_str(d["DATE"])
394
+ column :DATE, 'Snapshot creation date', :size=>15 do |d|
395
+ OpenNebulaHelper.time_to_str(d['DATE'])
389
396
  end
390
397
 
391
398
  default :AC, :ID, :PARENT, :DATE, :SIZE, :NAME
@@ -397,41 +404,46 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
397
404
  table.show(image_snapshots)
398
405
  end
399
406
 
400
- def self.create_image_variables(options, name)
401
- if Array === name
402
- names = name
403
- else
404
- names = [name]
405
- end
407
+ class << self
406
408
 
407
- t = ''
408
- names.each do |n|
409
- if options[n]
410
- t << "#{n.to_s.upcase}=\"#{options[n]}\"\n"
409
+ def create_image_variables(options, name)
410
+ if name.is_a?(Array)
411
+ names = name
412
+ else
413
+ names = [name]
411
414
  end
412
- end
413
415
 
414
- t
415
- end
416
+ t = ''
417
+ names.each do |n|
418
+ if options[n]
419
+ t << "#{n.to_s.upcase}=\"#{options[n]}\"\n"
420
+ end
421
+ end
416
422
 
417
- def self.create_image_template(options)
418
- template_options = TEMPLATE_OPTIONS.map do |o|
419
- o[:name].to_sym
423
+ t
420
424
  end
421
425
 
422
- template = create_image_variables(
423
- options,
424
- template_options - [:persistent, :dry, :prefix ]
425
- )
426
+ def create_image_template(options)
427
+ template_options = TEMPLATE_OPTIONS.map do |o|
428
+ o[:name].to_sym
429
+ end
426
430
 
427
- if options[:persistent]
428
- template << "PERSISTENT=YES\n"
429
- end
431
+ template = create_image_variables(
432
+ options,
433
+ template_options - [:persistent, :dry, :prefix]
434
+ )
435
+
436
+ if options[:persistent]
437
+ template << "PERSISTENT=YES\n"
438
+ end
430
439
 
431
- if options[:prefix]
432
- template << "DEV_PREFIX=\"#{options[:prefix]}\"\n"
440
+ if options[:prefix]
441
+ template << "DEV_PREFIX=\"#{options[:prefix]}\"\n"
442
+ end
443
+
444
+ [0, template]
433
445
  end
434
446
 
435
- [0, template]
436
447
  end
448
+
437
449
  end
@@ -128,14 +128,18 @@ EOT
128
128
  INT_EXP = /^-?\d+$/
129
129
  FLOAT_EXP = /^-?\d+(\.\d+)?$/
130
130
 
131
- def self.get_user_inputs(template)
131
+ def self.get_user_inputs(template, get_defaults = false)
132
132
  user_inputs = template['VMTEMPLATE']['TEMPLATE']['USER_INPUTS']
133
133
 
134
134
  return "" if !user_inputs
135
135
 
136
136
  answers = ""
137
137
 
138
- puts "There are some parameters that require user input. Use the string <<EDITOR>> to launch an editor (e.g. for multi-line inputs)"
138
+ unless get_defaults
139
+ puts 'There are some parameters that require user input. ' \
140
+ 'Use the string <<EDITOR>> to launch an editor ' \
141
+ '(e.g. for multi-line inputs)'
142
+ end
139
143
 
140
144
  user_inputs.each do |key, val|
141
145
  input_cfg = val.split('|', -1)
@@ -162,6 +166,11 @@ EOT
162
166
  initial.strip!
163
167
  end
164
168
 
169
+ if get_defaults
170
+ answers << "#{key}=\"#{initial}\"" unless mandatory == 'M'
171
+ next
172
+ end
173
+
165
174
  puts " * (#{key}) #{description}"
166
175
 
167
176
  header = " "
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opennebula-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.10.2
4
+ version: 5.10.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenNebula
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-11 00:00:00.000000000 Z
11
+ date: 2020-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opennebula
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 5.10.2
19
+ version: 5.10.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 5.10.2
26
+ version: 5.10.3
27
27
  description: Commands used to talk to OpenNebula
28
28
  email: contact@opennebula.org
29
29
  executables: