opennebula-cli 3.9.80.beta → 3.9.90.rc

Sign up to get free protection for your applications and to get access to all the features.
data/bin/oneuser CHANGED
@@ -326,7 +326,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
326
326
  EOT
327
327
 
328
328
  command :key, key_desc, :options=>[KEY] do
329
- require 'ssh_auth'
329
+ require 'opennebula/ssh_auth'
330
330
 
331
331
  options[:key] ||= ENV['HOME']+'/.ssh/id_rsa'
332
332
 
data/bin/onevm CHANGED
@@ -204,7 +204,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
204
204
  end
205
205
  end
206
206
 
207
- destroy_desc = <<-EOT.unindent
207
+ delete_desc = <<-EOT.unindent
208
208
  Deletes the given VM. Using --recreate resubmits the VM.
209
209
 
210
210
  Resubmits the VM to PENDING state. This is intended for VMs stuck in a
@@ -214,17 +214,17 @@ cmd=CommandParser::CmdParser.new(ARGV) do
214
214
  States: ANY
215
215
  EOT
216
216
 
217
- command :destroy, destroy_desc, [:range, :vmid_list],
217
+ command :delete, delete_desc, [:range, :vmid_list],
218
218
  :options => [OneVMHelper::SCHEDULE, OneVMHelper::RECREATE] do
219
219
 
220
- command_name="destroy"
220
+ command_name="delete"
221
221
  command_name<<"-recreate" if options[:recreate]
222
222
 
223
223
  if (!options[:schedule].nil?)
224
224
  helper.schedule_actions(args[0], options, command_name)
225
225
  else
226
226
  helper.perform_actions(args[0],options,"deleted") do |vm|
227
- vm.destroy(options[:recreate]==true)
227
+ vm.delete(options[:recreate]==true)
228
228
  end
229
229
  end
230
230
  end
@@ -268,7 +268,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
268
268
  Sets the specified VM disk to be saved in a new Image. The Image is
269
269
  created immediately, but the contents are saved only if the VM is
270
270
  shut down gracefully (i.e., using 'onevm shutdown' and not
271
- 'onevm destroy')
271
+ 'onevm delete')
272
272
 
273
273
  If '--live' is specified, the Image will be saved immediately.
274
274
 
@@ -319,20 +319,47 @@ cmd=CommandParser::CmdParser.new(ARGV) do
319
319
  end
320
320
  end
321
321
 
322
+ undeploy_desc = <<-EOT.unindent
323
+ Shuts down the given VM. The VM is saved in the system Datastore.
324
+
325
+ With --hard it unplugs the VM.
326
+
327
+ States: RUNNING
328
+ EOT
329
+
330
+ command :undeploy, undeploy_desc, [:range,:vmid_list],
331
+ :options => [OneVMHelper::SCHEDULE, OneVMHelper::HARD] do
332
+
333
+ command_name='undeploy'
334
+ command_name<<'-hard' if options[:hard]
335
+
336
+ if (!options[:schedule].nil?)
337
+ helper.schedule_actions(args[0], options, command_name)
338
+ else
339
+ helper.perform_actions(args[0],options,"shutting down") do |vm|
340
+ vm.undeploy(options[:hard]==true)
341
+ end
342
+ end
343
+ end
344
+
322
345
  poweroff_desc = <<-EOT.unindent
323
346
  Powers off the given VM. The VM will remain in the poweroff state, and
324
- can be powered on with the 'onevm boot' command.
347
+ can be powered on with the 'onevm resume' command.
325
348
 
326
349
  States: RUNNING
327
350
  EOT
328
351
 
329
352
  command :poweroff, poweroff_desc, [:range,:vmid_list],
330
- :options => [OneVMHelper::SCHEDULE] do
353
+ :options => [OneVMHelper::SCHEDULE, OneVMHelper::HARD] do
354
+
355
+ command_name='poweroff'
356
+ command_name<<'-hard' if options[:hard]
357
+
331
358
  if (!options[:schedule].nil?)
332
359
  helper.schedule_actions(args[0], options, @comm_name)
333
360
  else
334
361
  helper.perform_actions(args[0],options,"shutting down") do |vm|
335
- vm.poweroff
362
+ vm.poweroff(options[:hard]==true)
336
363
  end
337
364
  end
338
365
  end
@@ -405,7 +432,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
405
432
  boot_desc = <<-EOT.unindent
406
433
  Boots the given VM.
407
434
 
408
- States: UNKNOWN, BOOT, POWEROFF
435
+ States: UNKNOWN, BOOT
409
436
  EOT
410
437
 
411
438
  command :boot, boot_desc, [:range,:vmid_list],
@@ -460,7 +487,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
460
487
  resume_desc = <<-EOT.unindent
461
488
  Resumes the execution of the a saved VM
462
489
 
463
- States: STOPPED, SUSPENDED
490
+ States: STOPPED, SUSPENDED, UNDEPLOYED, POWEROFF
464
491
  EOT
465
492
 
466
493
  command :resume, resume_desc, [:range,:vmid_list],
@@ -746,4 +773,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do
746
773
  vm.resize(template, enforce)
747
774
  end
748
775
  end
776
+
777
+ # Deprecated commands
778
+
779
+ deprecated_command(:attachdisk, 'disk-attach')
780
+ deprecated_command(:detachdisk, 'disk-detach')
781
+ deprecated_command(:saveas, 'disk-snapshot')
782
+ deprecated_command(:livemigrate, 'migrate --live')
783
+ deprecated_command(:cancel, 'shutdown --hard')
784
+ deprecated_command(:reset, 'reboot --hard')
785
+ deprecated_command(:restart, 'boot')
786
+ deprecated_command(:resubmit, 'destroy --recreate')
749
787
  end
data/lib/cli_helper.rb CHANGED
@@ -226,7 +226,7 @@ module CLIHelper
226
226
 
227
227
  str
228
228
  }.join(' ')
229
- }.join("\n")
229
+ }.join("\n").gsub(/ *$/, '')
230
230
  rescue Errno::EPIPE
231
231
  end
232
232
 
@@ -56,6 +56,7 @@ module CommandParser
56
56
  def initialize(args=[], &block)
57
57
  @available_options = Array.new
58
58
  @commands = Hash.new
59
+ @command_list = Array.new
59
60
  @formats = Hash.new
60
61
 
61
62
  @main = nil
@@ -288,6 +289,21 @@ module CommandParser
288
289
  end
289
290
  }
290
291
  cmd[:proc] = block
292
+ @command_list << name.to_sym
293
+ @commands[name.to_sym] = cmd
294
+ end
295
+
296
+ def deprecated_command(name, new_command)
297
+ cmd = Hash.new
298
+ cmd[:desc] = "Deprecated, use #{new_command} instead"
299
+ cmd[:arity] = 0
300
+ cmd[:options] = []
301
+ cmd[:args_format] = [[:string, nil]] * 20
302
+ cmd[:deprecated] = new_command
303
+ cmd[:proc] = lambda do
304
+ print_deprecated(new_command)
305
+ end
306
+
291
307
  @commands[name.to_sym] = cmd
292
308
  end
293
309
 
@@ -418,6 +434,10 @@ module CommandParser
418
434
  exit -1
419
435
  end
420
436
 
437
+ if comm[:deprecated]
438
+ print_deprecated(comm[:deprecated])
439
+ end
440
+
421
441
  extra_options = comm[:options] if comm
422
442
  parse(extra_options)
423
443
 
@@ -617,7 +637,9 @@ module CommandParser
617
637
  puts "## OPTIONS"
618
638
 
619
639
  shown_opts = Array.new
620
- @commands.each do |key,value|
640
+ @command_list.each do |key|
641
+ value = @commands[key]
642
+
621
643
  value[:options].flatten.each do |o|
622
644
  if shown_opts.include?(o[:name])
623
645
  next
@@ -659,11 +681,12 @@ module CommandParser
659
681
  else
660
682
  puts "## COMMANDS"
661
683
 
662
- @commands.each{ |key,value|
684
+ @command_list.each do |key|
685
+ value = @commands[key]
663
686
  printf cmd_format5, "* #{key} "
664
687
 
665
688
  print_command(value)
666
- }
689
+ end
667
690
  end
668
691
  end
669
692
 
@@ -713,6 +736,12 @@ module CommandParser
713
736
  }
714
737
  end
715
738
 
739
+ def print_deprecated(new_command)
740
+ puts "This command is deprecated, use instead:"
741
+ puts " $ #{File.basename $0} #{new_command}"
742
+ exit(-1)
743
+ end
744
+
716
745
  def word_wrap(size, text, first_size=nil)
717
746
  output=[]
718
747
  line=""
data/lib/one_helper.rb CHANGED
@@ -130,7 +130,9 @@ EOT
130
130
  {
131
131
  :name => 'memory',
132
132
  :large => '--memory memory',
133
- :description => 'Memory ammount given to the VM',
133
+ :description => 'Memory amount given to the VM. By default the '<<
134
+ "unit is megabytes. To use gigabytes add a 'g', floats "<<
135
+ "can be used: 8g=8192, 0.5g=512",
134
136
  :format => String,
135
137
  :proc => lambda do |o,options|
136
138
  m=o.strip.match(/^(\d+(?:\.\d+)?)(m|mb|g|gb)?$/i)
@@ -608,6 +610,18 @@ EOT
608
610
  end
609
611
  end
610
612
 
613
+ def OpenNebulaHelper.short_period_to_str(time, print_seconds=true)
614
+ seconds=time.to_i
615
+ minutes, seconds=seconds.divmod(60)
616
+ hours, minutes=minutes.divmod(60)
617
+
618
+ if print_seconds
619
+ "%3dh%02dm%02ds" % [hours, minutes, seconds]
620
+ else
621
+ "%3dh%02dm" % [hours, minutes]
622
+ end
623
+ end
624
+
611
625
  BinarySufix = ["K", "M", "G", "T" ]
612
626
 
613
627
  def OpenNebulaHelper.unit_to_str(value, options, unit="K")
@@ -729,8 +743,8 @@ EOT
729
743
  end
730
744
  end
731
745
 
732
- if options[:net_context] && options[:network]
733
- nets=options[:network].map {|n| parse_user_object(n).last }
746
+ if options[:net_context] && options[:nic]
747
+ nets=options[:nic].map {|n| parse_user_object(n).last }
734
748
 
735
749
  if nets!=nets.uniq
736
750
  STDERR.puts "Network context generation from command "<<
@@ -745,6 +759,9 @@ EOT
745
759
  lines<<"ETH#{index}_MASK = \"$NETWORK[NETWORK_MASK, NETWORK=\\\"#{name}\\\"]\""
746
760
  lines<<"ETH#{index}_GATEWAY = \"$NETWORK[GATEWAY, NETWORK=\\\"#{name}\\\"]\""
747
761
  lines<<"ETH#{index}_DNS = \"$NETWORK[DNS, NETWORK=\\\"#{name}\\\"]\""
762
+ lines<<"ETH#{index}_IPV6 = \"$NIC[IP6_GLOBAL, NETWORK=\\\"#{name}\\\"]\""
763
+ lines<<"ETH#{index}_GATEWAY6 = \"$NETWORK[GATEWAY6, NETWORK=\\\"#{name}\\\"]\""
764
+ lines<<"ETH#{index}_CONTEXT_FORCE_IPV4 = \"$NETWORK[CONTEXT_FORCE_IPV4, NETWORK=\\\"#{name}\\\"]\""
748
765
  end
749
766
  end
750
767
 
@@ -789,8 +806,8 @@ EOT
789
806
  template<<res.last
790
807
  end
791
808
 
792
- if options[:network]
793
- res=create_disk_net(options[:network], 'NIC', 'NETWORK')
809
+ if options[:nic]
810
+ res=create_disk_net(options[:nic], 'NIC', 'NETWORK')
794
811
  return res if res.first!=0
795
812
 
796
813
  template<<res.last
@@ -112,6 +112,10 @@ class AcctHelper < OpenNebulaHelper::OneHelper
112
112
  d["HOSTNAME"]
113
113
  end
114
114
 
115
+ column :"ACTION", "VM state change action", :left, :size=>16 do |d|
116
+ VirtualMachine.get_history_action d["ACTION"]
117
+ end
118
+
115
119
  column :REASON, "VM state change reason", :left, :size=>4 do |d|
116
120
  VirtualMachine.get_reason d["REASON"]
117
121
  end
@@ -142,7 +146,7 @@ class AcctHelper < OpenNebulaHelper::OneHelper
142
146
  OpenNebulaHelper.unit_to_str(d["VM"]["NET_TX"].to_i / 1024.0, {})
143
147
  end
144
148
 
145
- default :VID, :HOSTNAME, :REASON, :START_TIME, :END_TIME, :MEMORY, :CPU, :NET_RX, :NET_TX
149
+ default :VID, :HOSTNAME, :ACTION, :REASON, :START_TIME, :END_TIME, :MEMORY, :CPU, :NET_RX, :NET_TX
146
150
  end
147
151
 
148
152
  def self.print_start_end_time_header(start_time, end_time)
@@ -109,7 +109,7 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
109
109
  limit = "0" if limit.nil? || limit == ""
110
110
  end
111
111
 
112
- "%4.0f / %4.0f" % [d['VM_QUOTA']['VM']["CPU_USED"], limit]
112
+ "%3.1f / %3.0f" % [d['VM_QUOTA']['VM']["CPU_USED"], limit]
113
113
  else
114
114
  "-"
115
115
  end
@@ -102,13 +102,19 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
102
102
 
103
103
  column :ALLOCATED_CPU, "Allocated CPU)", :size=>18 do |d|
104
104
  max_cpu = d["HOST_SHARE"]["MAX_CPU"].to_i
105
+ cpu_usage = d["HOST_SHARE"]["CPU_USAGE"].to_i
105
106
 
106
- if max_cpu != 0
107
- cpu_usage = d["HOST_SHARE"]["CPU_USAGE"].to_i
108
- ratio = (cpu_usage*100) / max_cpu
109
- "#{cpu_usage} / #{max_cpu} (#{ratio}%)"
110
- else
107
+ if max_cpu == 0 && cpu_usage == 0
111
108
  '-'
109
+ else
110
+ cpu_usage = d["HOST_SHARE"]["CPU_USAGE"].to_i
111
+
112
+ if max_cpu != 0
113
+ ratio = (cpu_usage*100) / max_cpu
114
+ "#{cpu_usage} / #{max_cpu} (#{ratio}%)"
115
+ else
116
+ "#{cpu_usage} / -"
117
+ end
112
118
  end
113
119
  end
114
120
 
@@ -126,13 +132,17 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
126
132
 
127
133
  column :ALLOCATED_MEM, "Allocated MEM", :size=>18 do |d|
128
134
  max_mem = d["HOST_SHARE"]["MAX_MEM"].to_i
135
+ mem_usage = d["HOST_SHARE"]["MEM_USAGE"].to_i
129
136
 
130
- if max_mem != 0
131
- mem_usage = d["HOST_SHARE"]["MEM_USAGE"].to_i
132
- ratio = (mem_usage*100) / max_mem
133
- "#{OpenNebulaHelper.unit_to_str(mem_usage,options)} / #{OpenNebulaHelper.unit_to_str(max_mem,options)} (#{ratio}%)"
134
- else
137
+ if max_mem == 0 && mem_usage == 0
135
138
  '-'
139
+ else
140
+ if max_mem != 0
141
+ ratio = (mem_usage*100) / max_mem
142
+ "#{OpenNebulaHelper.unit_to_str(mem_usage,options)} / #{OpenNebulaHelper.unit_to_str(max_mem,options)} (#{ratio}%)"
143
+ else
144
+ "#{OpenNebulaHelper.unit_to_str(mem_usage,options)} / -"
145
+ end
136
146
  end
137
147
  end
138
148
 
@@ -209,7 +209,7 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
209
209
  limit = "0" if limit.nil? || limit == ""
210
210
  end
211
211
 
212
- "%4.0f / %4.0f" % [d['VM_QUOTA']['VM']["CPU_USED"], limit]
212
+ "%3.1f / %3.0f" % [d['VM_QUOTA']['VM']["CPU_USED"], limit]
213
213
  else
214
214
  "-"
215
215
  end
@@ -247,7 +247,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
247
247
  puts str % ["RESCHED", OpenNebulaHelper.boolean_to_str(vm['RESCHED'])]
248
248
  puts str % ["HOST",
249
249
  vm['/VM/HISTORY_RECORDS/HISTORY[last()]/HOSTNAME']] if
250
- %w{ACTIVE SUSPENDED}.include? vm.state_str
250
+ %w{ACTIVE SUSPENDED POWEROFF}.include? vm.state_str
251
251
  puts str % ["START TIME",
252
252
  OpenNebulaHelper.time_to_str(vm['/VM/STIME'])]
253
253
  puts str % ["END TIME",
@@ -531,15 +531,19 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
531
531
 
532
532
  def format_history(vm)
533
533
  table=CLIHelper::ShowTable.new(nil, self) do
534
- column :SEQ, "Sequence number", :size=>4 do |d|
534
+ column :SEQ, "Sequence number", :size=>3 do |d|
535
535
  d["SEQ"]
536
536
  end
537
537
 
538
- column :HOST, "Host name of the VM container", :left, :size=>20 do |d|
538
+ column :HOST, "Host name of the VM container", :left, :size=>15 do |d|
539
539
  d["HOSTNAME"]
540
540
  end
541
541
 
542
- column :REASON, "VM state change reason", :left, :size=>6 do |d|
542
+ column :"ACTION", "VM state change action", :left, :size=>16 do |d|
543
+ VirtualMachine.get_history_action d["ACTION"]
544
+ end
545
+
546
+ column :REASON, "VM state change reason", :left, :size=>4 do |d|
543
547
  VirtualMachine.get_reason d["REASON"]
544
548
  end
545
549
 
@@ -547,14 +551,14 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
547
551
  OpenNebulaHelper.time_to_str(d['STIME'])
548
552
  end
549
553
 
550
- column :TIME, "Total time in this state", :size=>15 do |d|
554
+ column :TIME, "Total time in this state", :size=>11 do |d|
551
555
  stime = d["STIME"].to_i
552
556
  etime = d["ETIME"]=="0" ? Time.now.to_i : d["ETIME"].to_i
553
557
  dtime = etime-stime
554
- OpenNebulaHelper.period_to_str(dtime)
558
+ OpenNebulaHelper.period_to_str(dtime, false)
555
559
  end
556
560
 
557
- column :PROLOG_TIME, "Prolog time for this state", :size=>15 do |d|
561
+ column :PROLOG, "Prolog time for this state", :size=>10 do |d|
558
562
  stime = d["PSTIME"].to_i
559
563
  if d["PSTIME"]=="0"
560
564
  etime=0
@@ -562,10 +566,10 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
562
566
  etime = d["PETIME"]=="0" ? Time.now.to_i: d["PETIME"].to_i
563
567
  end
564
568
  dtime = etime-stime
565
- OpenNebulaHelper.period_to_str(dtime)
569
+ OpenNebulaHelper.short_period_to_str(dtime)
566
570
  end
567
571
 
568
- default :SEQ, :HOST, :REASON, :START, :TIME, :PROLOG_TIME
572
+ default :SEQ, :HOST, :ACTION, :REASON, :START, :TIME, :PROLOG
569
573
  end
570
574
 
571
575
  vm_hash=vm.to_hash
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opennebula-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.9.80.beta
4
+ version: 3.9.90.rc
5
5
  prerelease: 7
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-26 00:00:00.000000000 Z
12
+ date: 2013-04-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: opennebula
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 3.9.80.beta
21
+ version: 3.9.90.rc
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 3.9.80.beta
29
+ version: 3.9.90.rc
30
30
  description: Commands used to talk to OpenNebula
31
31
  email: contact@opennebula.org
32
32
  executables:
@@ -95,6 +95,6 @@ rubyforge_project:
95
95
  rubygems_version: 1.8.25
96
96
  signing_key:
97
97
  specification_version: 3
98
- summary: OpenNebula Client API
98
+ summary: OpenNebula Command Line Interface
99
99
  test_files: []
100
100
  has_rdoc: