opennebula-cli 3.9.0.beta → 3.9.80.beta

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
2
+ # Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
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-2012, OpenNebula Project Leads (OpenNebula.org) #
2
+ # Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
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 #
@@ -23,7 +23,7 @@ class OneTemplateHelper < OpenNebulaHelper::OneHelper
23
23
  :format => String,
24
24
  :description => <<-EOT.strip
25
25
  Name of the new VM or TEMPLATE. When instantiating
26
- multiple VMs you can use the\"%i\" wildcard to produce
26
+ multiple VMs you can use the \"%i\" wildcard to produce
27
27
  different names such as vm-0, vm-1...
28
28
  EOT
29
29
  }
@@ -91,7 +91,7 @@ EOT
91
91
  OpenNebula::TemplatePool.new(@client, user_flag)
92
92
  end
93
93
 
94
- def format_resource(template)
94
+ def format_resource(template, options = {})
95
95
  str="%-15s: %-20s"
96
96
  str_h1="%-80s"
97
97
 
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
2
+ # Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
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 #
@@ -42,7 +42,8 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
42
42
  end
43
43
 
44
44
  if options[:driver] == OpenNebula::User::X509_AUTH
45
- password.delete!("\s")
45
+ require 'opennebula/x509_auth'
46
+ password = OpenNebula::X509Auth.escape_dn(password)
46
47
  end
47
48
 
48
49
  if options[:sha1] || options[:driver] == OpenNebula::User::CIPHER_AUTH
@@ -147,12 +148,8 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
147
148
  def format_pool(options)
148
149
  config_file = self.class.table_conf
149
150
 
150
- system = System.new(@client)
151
- default_quotas = system.get_user_quotas()
152
-
153
- if OpenNebula::is_error?(default_quotas)
154
- raise "Error retrieving the default user quotas: #{default_quotas.message}"
155
- end
151
+ prefix = '/USER_POOL/DEFAULT_USER_QUOTAS/'
152
+ user_pool = @user_pool
156
153
 
157
154
  table = CLIHelper::ShowTable.new(config_file, self) do
158
155
  column :ID, "ONE identifier for the User", :size=>4 do |d|
@@ -176,7 +173,7 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
176
173
  limit = d['VM_QUOTA']['VM']["VMS"]
177
174
 
178
175
  if limit == "-1"
179
- limit = default_quotas['VM_QUOTA/VM/VMS']
176
+ limit = user_pool["#{prefix}VM_QUOTA/VM/VMS"]
180
177
  limit = "0" if limit.nil? || limit == ""
181
178
  end
182
179
 
@@ -191,7 +188,7 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
191
188
  limit = d['VM_QUOTA']['VM']["MEMORY"]
192
189
 
193
190
  if limit == "-1"
194
- limit = default_quotas['VM_QUOTA/VM/MEMORY']
191
+ limit = user_pool["#{prefix}VM_QUOTA/VM/MEMORY"]
195
192
  limit = "0" if limit.nil? || limit == ""
196
193
  end
197
194
 
@@ -208,7 +205,7 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
208
205
  limit = d['VM_QUOTA']['VM']["CPU"]
209
206
 
210
207
  if limit == "-1"
211
- limit = default_quotas['VM_QUOTA/VM/CPU']
208
+ limit = user_pool["#{prefix}VM_QUOTA/VM/CPU"]
212
209
  limit = "0" if limit.nil? || limit == ""
213
210
  end
214
211
 
@@ -241,16 +238,12 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
241
238
 
242
239
  def factory_pool(user_flag=-2)
243
240
  #TBD OpenNebula::UserPool.new(@client, user_flag)
244
- OpenNebula::UserPool.new(@client)
241
+ @user_pool = OpenNebula::UserPool.new(@client)
242
+ return @user_pool
245
243
  end
246
244
 
247
- def format_resource(user)
245
+ def format_resource(user, options = {})
248
246
  system = System.new(@client)
249
- default_quotas = system.get_user_quotas()
250
-
251
- if OpenNebula::is_error?(default_quotas)
252
- raise "Error retrieving the default user quotas: #{default_quotas.message}"
253
- end
254
247
 
255
248
  str="%-15s: %-20s"
256
249
  str_h1="%-80s"
@@ -272,6 +265,12 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
272
265
 
273
266
  user_hash = user.to_hash
274
267
 
268
+ default_quotas = nil
269
+
270
+ user.each('/USER/DEFAULT_USER_QUOTAS') { |elem|
271
+ default_quotas = elem
272
+ }
273
+
275
274
  helper = OneQuotaHelper.new
276
275
  helper.format_quota(user_hash['USER'], default_quotas)
277
276
  end
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
2
+ # Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
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 #
@@ -15,6 +15,7 @@
15
15
  #--------------------------------------------------------------------------- #
16
16
 
17
17
  require 'one_helper'
18
+ require 'optparse/time'
18
19
 
19
20
  class OneVMHelper < OpenNebulaHelper::OneHelper
20
21
  MULTIPLE={
@@ -36,6 +37,17 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
36
37
  }
37
38
  }
38
39
 
40
+ NETWORK = {
41
+ :name => "network",
42
+ :short => "-n id|name",
43
+ :large => "--network id|name" ,
44
+ :description => "Selects the virtual network",
45
+ :format => String,
46
+ :proc => lambda { |o, options|
47
+ OpenNebulaHelper.rname_to_id(o, "VNET")
48
+ }
49
+ }
50
+
39
51
  FILE = {
40
52
  :name => "file",
41
53
  :short => "-f file",
@@ -51,6 +63,44 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
51
63
  }
52
64
  }
53
65
 
66
+ HOLD = {
67
+ :name => "hold",
68
+ :large => "--hold",
69
+ :description => "Creates the new VM on hold state instead of pending"
70
+ }
71
+
72
+ SCHEDULE = {
73
+ :name => "schedule",
74
+ :large => "--schedule TIME",
75
+ :description => "Schedules this action to be executed after" \
76
+ "the given time. For example: onevm resume 0 --schedule \"09/23 14:15\"",
77
+ :format => Time
78
+ }
79
+
80
+ ALL_TEMPLATE = {
81
+ :name => "all",
82
+ :large => "--all",
83
+ :description => "Show all template data"
84
+ }
85
+
86
+ LIVE = {
87
+ :name => "live",
88
+ :large => "--live",
89
+ :description => "Do the action with the VM running"
90
+ }
91
+
92
+ HARD = {
93
+ :name => "hard",
94
+ :large => "--hard",
95
+ :description=> "Does not communicate with the guest OS"
96
+ }
97
+
98
+ RECREATE = {
99
+ :name => "recreate",
100
+ :large => "--recreate",
101
+ :description=> "Resubmits a fresh VM"
102
+ }
103
+
54
104
  def self.rname
55
105
  "VM"
56
106
  end
@@ -115,7 +165,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
115
165
  column :HOST, "Host where the VM is running", :left, :size=>10 do |d|
116
166
  if d['HISTORY_RECORDS'] && d['HISTORY_RECORDS']['HISTORY']
117
167
  state_str = VirtualMachine::VM_STATE[d['STATE'].to_i]
118
- if %w{ACTIVE SUSPENDED}.include? state_str
168
+ if %w{ACTIVE SUSPENDED POWEROFF}.include? state_str
119
169
  d['HISTORY_RECORDS']['HISTORY']['HOSTNAME']
120
170
  end
121
171
  end
@@ -135,6 +185,38 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
135
185
  table
136
186
  end
137
187
 
188
+
189
+ def schedule_actions(ids,options,action)
190
+ # Verbose by default
191
+ options[:verbose] = true
192
+
193
+ perform_actions(
194
+ ids, options,
195
+ "#{action} scheduled at #{options[:schedule]}") do |vm|
196
+
197
+ rc = vm.info
198
+
199
+ if OpenNebula.is_error?(rc)
200
+ puts rc.message
201
+ exit -1
202
+ end
203
+
204
+ ids = vm.retrieve_elements('USER_TEMPLATE/SCHED_ACTION/ID')
205
+
206
+ id = 0
207
+ if (!ids.nil? && !ids.empty?)
208
+ ids.map! {|e| e.to_i }
209
+ id = ids.max + 1
210
+ end
211
+
212
+ tmp_str = vm.user_template_str
213
+
214
+ tmp_str << "\nSCHED_ACTION = [ID = #{id}, ACTION = #{action}, TIME = #{options[:schedule].to_i}]"
215
+
216
+ vm.update(tmp_str)
217
+ end
218
+ end
219
+
138
220
  private
139
221
 
140
222
  def factory(id=nil)
@@ -150,7 +232,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
150
232
  OpenNebula::VirtualMachinePool.new(@client, user_flag)
151
233
  end
152
234
 
153
- def format_resource(vm)
235
+ def format_resource(vm, options = {})
154
236
  str_h1="%-80s"
155
237
  str="%-20s: %-20s"
156
238
 
@@ -204,18 +286,247 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
204
286
 
205
287
  puts str % [e, mask]
206
288
  }
207
- puts
208
289
 
209
- CLIHelper.print_header(str_h1 % "VIRTUAL MACHINE TEMPLATE",false)
210
- puts vm.template_str
290
+ if vm.has_elements?("/VM/TEMPLATE/DISK")
291
+ puts
292
+ CLIHelper.print_header(str_h1 % "VM DISKS",false)
293
+ CLIHelper::ShowTable.new(nil, self) do
294
+ column :ID, "", :size=>3 do |d|
295
+ d["DISK_ID"]
296
+ end
211
297
 
212
- if vm.has_elements?("/VM/HISTORY_RECORDS")
298
+ column :DATASTORE, "", :left, :size=>10 do |d|
299
+ d["DATASTORE"]
300
+ end
301
+
302
+ column :TARGET, "", :left, :size=>6 do |d|
303
+ d["TARGET"]
304
+ end
305
+
306
+ column :IMAGE, "", :left, :size=>35 do |d|
307
+ if d["IMAGE"]
308
+ d["IMAGE"]
309
+ else
310
+ case d["TYPE"].upcase
311
+ when "FS"
312
+ "#{d["FORMAT"]} - "<<
313
+ OpenNebulaHelper.unit_to_str(d["SIZE"].to_i,
314
+ {}, "M")
315
+ when "SWAP"
316
+ OpenNebulaHelper.unit_to_str(d["SIZE"].to_i,
317
+ {}, "M")
318
+
319
+ end
320
+ end
321
+ end
322
+
323
+ column :TYPE, "", :left, :size=>4 do |d|
324
+ d["TYPE"].downcase
325
+ end
326
+
327
+ column :"R/O", "", :size=>3 do |d|
328
+ d["READONLY"]
329
+ end
330
+
331
+ column :"SAVE", "", :size=>4 do |d|
332
+ d["SAVE"] || "NO"
333
+ end
334
+
335
+ column :"CLONE", "", :size=>5 do |d|
336
+ d["CLONE"]
337
+ end
338
+
339
+ column :"SAVE_AS", "", :size=>7 do |d|
340
+ d["SAVE_AS"] || "-"
341
+ end
342
+
343
+
344
+ default :ID, :TARGET, :IMAGE, :TYPE,
345
+ :SAVE, :SAVE_AS
346
+ end.show([vm.to_hash['VM']['TEMPLATE']['DISK']].flatten, {})
347
+
348
+ while vm.has_elements?("/VM/TEMPLATE/DISK")
349
+ vm.delete_element("/VM/TEMPLATE/DISK")
350
+ end if !options[:all]
351
+ end
352
+
353
+ if vm.has_elements?("/VM/TEMPLATE/NIC")
354
+ puts
355
+ CLIHelper.print_header(str_h1 % "VM NICS",false)
356
+
357
+ vm_nics = [vm.to_hash['VM']['TEMPLATE']['NIC']].flatten
358
+
359
+ nic_default = {"NETWORK" => "-",
360
+ "IP" => "-",
361
+ "MAC"=> "-",
362
+ "VLAN"=>"no",
363
+ "BRIDGE"=>"-"}
364
+
365
+ array_id = 0
366
+
367
+ vm_nics.each {|nic|
368
+
369
+ next if nic.has_key?("CLI_DONE")
370
+
371
+ if nic.has_key?("IP6_LINK")
372
+ ip6_link = {"IP" => nic.delete("IP6_LINK"),
373
+ "CLI_DONE" => true,
374
+ "DOUBLE_ENTRY" => true}
375
+ vm_nics.insert(array_id+1,ip6_link)
376
+
377
+ array_id += 1
378
+ end
379
+
380
+ if nic.has_key?("IP6_SITE")
381
+ ip6_link = {"IP" => nic.delete("IP6_SITE"),
382
+ "CLI_DONE" => true,
383
+ "DOUBLE_ENTRY" => true}
384
+ vm_nics.insert(array_id+1,ip6_link)
385
+
386
+ array_id += 1
387
+ end
388
+
389
+ if nic.has_key?("IP6_GLOBAL")
390
+ ip6_link = {"IP" => nic.delete("IP6_GLOBAL"),
391
+ "CLI_DONE" => true,
392
+ "DOUBLE_ENTRY" => true}
393
+ vm_nics.insert(array_id+1,ip6_link)
394
+
395
+ array_id += 1
396
+ end
397
+
398
+ nic.merge!(nic_default) {|k,v1,v2| v1}
399
+ array_id += 1
400
+ }
401
+
402
+ CLIHelper::ShowTable.new(nil, self) do
403
+ column :ID, "", :size=>3 do |d|
404
+ if d["DOUBLE_ENTRY"]
405
+ ""
406
+ else
407
+ d["NIC_ID"]
408
+ end
409
+ end
410
+
411
+ column :NETWORK, "", :left, :size=>20 do |d|
412
+ if d["DOUBLE_ENTRY"]
413
+ ""
414
+ else
415
+ d["NETWORK"]
416
+ end
417
+ end
418
+
419
+ column :VLAN, "", :size=>4 do |d|
420
+ if d["DOUBLE_ENTRY"]
421
+ ""
422
+ else
423
+ d["VLAN"].downcase
424
+ end
425
+ end
426
+
427
+ column :BRIDGE, "", :left, :size=>12 do |d|
428
+ if d["DOUBLE_ENTRY"]
429
+ ""
430
+ else
431
+ d["BRIDGE"]
432
+ end
433
+ end
434
+
435
+ column :IP, "",:left, :donottruncate, :size=>15 do |d|
436
+ d["IP"]
437
+ end
438
+
439
+ column :MAC, "", :left, :size=>17 do |d|
440
+ if d["DOUBLE_ENTRY"]
441
+ ""
442
+ else
443
+ d["MAC"]
444
+ end
445
+ end
446
+
447
+ end.show(vm_nics,{})
448
+
449
+ while vm.has_elements?("/VM/TEMPLATE/NIC")
450
+ vm.delete_element("/VM/TEMPLATE/NIC")
451
+ end if !options[:all]
452
+ end
453
+
454
+ if vm.has_elements?("/VM/TEMPLATE/SNAPSHOT")
213
455
  puts
456
+ CLIHelper.print_header(str_h1 % "SNAPSHOTS",false)
457
+
458
+ CLIHelper::ShowTable.new(nil, self) do
214
459
 
460
+ column :"ID", "", :size=>4 do |d|
461
+ d["SNAPSHOT_ID"] if !d.nil?
462
+ end
463
+
464
+ column :"TIME", "", :size=>12 do |d|
465
+ OpenNebulaHelper.time_to_str(d["TIME"], false) if !d.nil?
466
+ end
467
+
468
+ column :"NAME", "", :left, :size=>46 do |d|
469
+ d["NAME"] if !d.nil?
470
+ end
471
+
472
+ column :"HYPERVISOR_ID", "", :left, :size=>15 do |d|
473
+ d["HYPERVISOR_ID"] if !d.nil?
474
+ end
475
+
476
+ end.show([vm.to_hash['VM']['TEMPLATE']['SNAPSHOT']].flatten, {})
477
+
478
+ vm.delete_element("/VM/TEMPLATE/SNAPSHOT")
479
+ end
480
+
481
+ if vm.has_elements?("/VM/HISTORY_RECORDS")
482
+ puts
215
483
 
216
484
  CLIHelper.print_header(str_h1 % "VIRTUAL MACHINE HISTORY",false)
217
485
  format_history(vm)
218
486
  end
487
+
488
+ if vm.has_elements?("/VM/USER_TEMPLATE/SCHED_ACTION")
489
+ puts
490
+ CLIHelper.print_header(str_h1 % "SCHEDULED ACTIONS",false)
491
+
492
+ CLIHelper::ShowTable.new(nil, self) do
493
+
494
+ column :"ID", "", :size=>2 do |d|
495
+ d["ID"] if !d.nil?
496
+ end
497
+
498
+ column :"ACTION", "", :left, :size=>15 do |d|
499
+ d["ACTION"] if !d.nil?
500
+ end
501
+
502
+ column :"SCHEDULED", "", :size=>12 do |d|
503
+ OpenNebulaHelper.time_to_str(d["TIME"], false) if !d.nil?
504
+ end
505
+
506
+ column :"DONE", "", :size=>12 do |d|
507
+ OpenNebulaHelper.time_to_str(d["DONE"], false) if !d.nil?
508
+ end
509
+
510
+ column :"MESSAGE", "", :left, :donottruncate, :size=>35 do |d|
511
+ d["MESSAGE"] if !d.nil?
512
+ end
513
+ end.show([vm.to_hash['VM']['USER_TEMPLATE']['SCHED_ACTION']].flatten, {})
514
+ end
515
+
516
+ if vm.has_elements?("/VM/USER_TEMPLATE")
517
+ puts
518
+
519
+ if !options[:all]
520
+ vm.delete_element("/VM/USER_TEMPLATE/SCHED_ACTION")
521
+ end
522
+
523
+ CLIHelper.print_header(str_h1 % "USER TEMPLATE",false)
524
+ puts vm.template_like_str('USER_TEMPLATE')
525
+ end
526
+
527
+ puts
528
+ CLIHelper.print_header(str_h1 % "VIRTUAL MACHINE TEMPLATE",false)
529
+ puts vm.template_str
219
530
  end
220
531
 
221
532
  def format_history(vm)
@@ -224,7 +535,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
224
535
  d["SEQ"]
225
536
  end
226
537
 
227
- column :HOST, "Host name of the VM container", :left, :size=>15 do |d|
538
+ column :HOST, "Host name of the VM container", :left, :size=>20 do |d|
228
539
  d["HOSTNAME"]
229
540
  end
230
541