opennebula-cli 3.9.0.beta → 3.9.80.beta

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.
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # -------------------------------------------------------------------------- #
4
- # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
4
+ # Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
5
5
  # #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License"); you may #
7
7
  # 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 #
@@ -252,6 +252,9 @@ module CLIHelper
252
252
  if @columns[field]
253
253
  minus=( @columns[field][:left] ? "-" : "" )
254
254
  size=@columns[field][:size]
255
+ if @columns[field][:donottruncate]
256
+ return "%#{minus}#{size}s" % [ data.to_s ]
257
+ end
255
258
  return "%#{minus}#{size}.#{size}s" % [ data.to_s ]
256
259
  else
257
260
  exit -1, "Column #{field} not defined."
@@ -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 #
@@ -635,14 +635,20 @@ module CommandParser
635
635
  end
636
636
 
637
637
  def print_option(o)
638
- opt_format = "#{' '*5}%-25s %s"
638
+ opt_format = "#{' '*5}%-25s"
639
639
 
640
640
  str = ""
641
641
  str << o[:short].split(' ').first << ', ' if o[:short]
642
642
  str << o[:large]
643
643
 
644
- printf opt_format, str, o[:description]
645
- puts
644
+ params=sprintf(opt_format, str)
645
+
646
+ first_line=80-params.length
647
+
648
+ description=word_wrap(80-32, o[:description], first_line).
649
+ join(("\n"+" "*31))
650
+
651
+ puts "#{params} #{description}"
646
652
  end
647
653
 
648
654
  def print_commands
@@ -707,6 +713,30 @@ module CommandParser
707
713
  }
708
714
  end
709
715
 
716
+ def word_wrap(size, text, first_size=nil)
717
+ output=[]
718
+ line=""
719
+ if first_size
720
+ line_size=first_size
721
+ else
722
+ line_size=size
723
+ end
724
+
725
+ text.scan(/[^\s]+/) do |word|
726
+ if line.length+word.length+1<=line_size
727
+ line+=" #{word}"
728
+ else
729
+ output<<line
730
+ line=word
731
+ line_size=size
732
+ end
733
+ end
734
+
735
+ output<<line
736
+ output[0].strip!
737
+ output
738
+ end
739
+
710
740
  ########################################################################
711
741
  # Default Formatters for arguments
712
742
  ########################################################################
@@ -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 #
@@ -22,7 +22,7 @@ include OpenNebula
22
22
  module OpenNebulaHelper
23
23
  ONE_VERSION=<<-EOT
24
24
  OpenNebula #{OpenNebula::VERSION}
25
- Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org)
25
+ Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs
26
26
 
27
27
  Licensed under the Apache License, Version 2.0 (the "License"); you may
28
28
  not use this file except in compliance with the License. You may obtain
@@ -103,6 +103,7 @@ EOT
103
103
  }
104
104
  ]
105
105
 
106
+ #NOTE: Other options defined using this array, add new options at the end
106
107
  TEMPLATE_OPTIONS=[
107
108
  {
108
109
  :name => 'cpu',
@@ -152,16 +153,16 @@ EOT
152
153
  },
153
154
  {
154
155
  :name => 'disk',
155
- :large => '--disk disk0,disk1',
156
- :description => "Disks to attach. To use a disk owned by other\n"<<
157
- " "*31<<"user use user[disk]",
156
+ :large => '--disk image0,image1',
157
+ :description => "Disks to attach. To use an image owned by"<<
158
+ " other user use user[disk]",
158
159
  :format => Array
159
160
  },
160
161
  {
161
- :name => 'network',
162
- :large => '--network network0,network1',
163
- :description => "Networks to attach. To use a network owned by\n"<<
164
- " "*31<<"other user use user[network]",
162
+ :name => 'nic',
163
+ :large => '--nic network0,network1',
164
+ :description => "Networks to attach. To use a network owned by"<<
165
+ " other user use user[network]",
165
166
  :format => Array
166
167
  },
167
168
  {
@@ -212,6 +213,8 @@ EOT
212
213
 
213
214
  TEMPLATE_OPTIONS_VM=[TEMPLATE_NAME_VM]+TEMPLATE_OPTIONS+[DRY]
214
215
 
216
+ CAPACITY_OPTIONS_VM=[TEMPLATE_OPTIONS[0],TEMPLATE_OPTIONS[1],TEMPLATE_OPTIONS[3]]
217
+
215
218
  OPTIONS = XML, NUMERIC, KILOBYTES
216
219
 
217
220
  class OneHelper
@@ -315,7 +318,15 @@ EOT
315
318
  pool_to_array(pool)
316
319
  }
317
320
  else
318
- table.show(pool_to_array(pool), options)
321
+ array=pool_to_array(pool)
322
+
323
+ if options[:ids]
324
+ array=array.select do |element|
325
+ options[:ids].include? element['ID'].to_i
326
+ end
327
+ end
328
+
329
+ table.show(array, options)
319
330
  end
320
331
 
321
332
  return 0
@@ -331,7 +342,7 @@ EOT
331
342
  if options[:xml]
332
343
  return 0, resource.to_xml(true)
333
344
  else
334
- format_resource(resource)
345
+ format_resource(resource, options)
335
346
  return 0
336
347
  end
337
348
  end
@@ -569,13 +580,19 @@ EOT
569
580
  end
570
581
  end
571
582
 
572
- def OpenNebulaHelper.time_to_str(time)
583
+ def OpenNebulaHelper.time_to_str(time, print_seconds=true)
573
584
  value=time.to_i
574
585
  if value==0
575
586
  value='-'
576
587
  else
577
- value=Time.at(value).strftime("%m/%d %H:%M:%S")
588
+ if print_seconds
589
+ value=Time.at(value).strftime("%m/%d %H:%M:%S")
590
+ else
591
+ value=Time.at(value).strftime("%m/%d %H:%M")
592
+ end
578
593
  end
594
+
595
+ return value
579
596
  end
580
597
 
581
598
  def OpenNebulaHelper.period_to_str(time, print_seconds=true)
@@ -623,7 +640,7 @@ EOT
623
640
  end
624
641
  end
625
642
 
626
- def OpenNebulaHelper.update_template(id, resource, path=nil)
643
+ def OpenNebulaHelper.update_template(id, resource, path=nil, xpath='TEMPLATE')
627
644
  unless path
628
645
  require 'tempfile'
629
646
 
@@ -637,7 +654,7 @@ EOT
637
654
  exit -1
638
655
  end
639
656
 
640
- tmp << resource.template_str
657
+ tmp << resource.template_like_str(xpath)
641
658
  tmp.flush
642
659
 
643
660
  editor_path = ENV["EDITOR"] ? ENV["EDITOR"] : EDITOR_PATH
@@ -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 AcctHelper < OpenNebulaHelper::OneHelper
20
21
  START_TIME = {
@@ -22,7 +23,7 @@ class AcctHelper < OpenNebulaHelper::OneHelper
22
23
  :short => "-s TIME",
23
24
  :large => "--start TIME" ,
24
25
  :description => "Start date and time to take into account",
25
- :format => String # TODO Time
26
+ :format => Time
26
27
  }
27
28
 
28
29
  END_TIME = {
@@ -30,7 +31,7 @@ class AcctHelper < OpenNebulaHelper::OneHelper
30
31
  :short => "-e TIME",
31
32
  :large => "--end TIME" ,
32
33
  :description => "End date and time",
33
- :format => String # TODO Time
34
+ :format => Time
34
35
  }
35
36
 
36
37
  USERFILTER = {
@@ -144,7 +145,7 @@ class AcctHelper < OpenNebulaHelper::OneHelper
144
145
  default :VID, :HOSTNAME, :REASON, :START_TIME, :END_TIME, :MEMORY, :CPU, :NET_RX, :NET_TX
145
146
  end
146
147
 
147
- def self.print_start_enc_time_header(start_time, end_time)
148
+ def self.print_start_end_time_header(start_time, end_time)
148
149
  print "Showing active history records from "
149
150
 
150
151
  CLIHelper.scr_bold
@@ -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 #
@@ -95,13 +95,14 @@ class OneClusterHelper < OpenNebulaHelper::OneHelper
95
95
  OpenNebula::ClusterPool.new(@client)
96
96
  end
97
97
 
98
- def format_resource(cluster)
99
- str="%-15s: %-20s"
98
+ def format_resource(cluster, options = {})
99
+ str="%-18s: %-20s"
100
100
  str_h1="%-80s"
101
101
 
102
102
  CLIHelper.print_header(str_h1 % "CLUSTER #{cluster['ID']} INFORMATION")
103
103
  puts str % ["ID", cluster.id.to_s]
104
104
  puts str % ["NAME", cluster.name]
105
+ puts str % ["SYSTEM DS", cluster['SYSTEM_DS']]
105
106
  puts
106
107
 
107
108
  CLIHelper.print_header(str_h1 % "CLUSTER TEMPLATE", false)
@@ -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 #
@@ -95,7 +95,7 @@ class OneDatastoreHelper < OpenNebulaHelper::OneHelper
95
95
  OpenNebula::DatastorePool.new(@client)
96
96
  end
97
97
 
98
- def format_resource(datastore)
98
+ def format_resource(datastore, options = {})
99
99
  str="%-15s: %-20s"
100
100
  str_h1="%-80s"
101
101
 
@@ -110,6 +110,7 @@ class OneDatastoreHelper < OpenNebulaHelper::OneHelper
110
110
  puts str % ["DS_MAD", datastore['DS_MAD']]
111
111
  puts str % ["TM_MAD", datastore['TM_MAD']]
112
112
  puts str % ["BASE PATH",datastore['BASE_PATH']]
113
+ puts str % ["DISK_TYPE",Image::DISK_TYPES[datastore['DISK_TYPE'].to_i]]
113
114
  puts
114
115
 
115
116
  CLIHelper.print_header(str_h1 % "PERMISSIONS",false)
@@ -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 #
@@ -48,12 +48,8 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
48
48
  def format_pool(options)
49
49
  config_file = self.class.table_conf
50
50
 
51
- system = System.new(@client)
52
- default_quotas = system.get_group_quotas()
53
-
54
- if OpenNebula::is_error?(default_quotas)
55
- raise "Error retrieving the default group quotas: #{default_quotas.message}"
56
- end
51
+ prefix = '/GROUP_POOL/DEFAULT_GROUP_QUOTAS/'
52
+ group_pool = @group_pool
57
53
 
58
54
  table = CLIHelper::ShowTable.new(config_file, self) do
59
55
  column :ID, "ONE identifier for the Group", :size=>4 do |d|
@@ -77,7 +73,7 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
77
73
  limit = d['VM_QUOTA']['VM']["VMS"]
78
74
 
79
75
  if limit == "-1"
80
- limit = default_quotas['VM_QUOTA/VM/VMS']
76
+ limit = group_pool["#{prefix}VM_QUOTA/VM/VMS"]
81
77
  limit = "0" if limit.nil? || limit == ""
82
78
  end
83
79
 
@@ -92,7 +88,7 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
92
88
  limit = d['VM_QUOTA']['VM']["MEMORY"]
93
89
 
94
90
  if limit == "-1"
95
- limit = default_quotas['VM_QUOTA/VM/MEMORY']
91
+ limit = group_pool["#{prefix}VM_QUOTA/VM/MEMORY"]
96
92
  limit = "0" if limit.nil? || limit == ""
97
93
  end
98
94
 
@@ -109,7 +105,7 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
109
105
  limit = d['VM_QUOTA']['VM']["CPU"]
110
106
 
111
107
  if limit == "-1"
112
- limit = default_quotas['VM_QUOTA/VM/CPU']
108
+ limit = group_pool["#{prefix}VM_QUOTA/VM/CPU"]
113
109
  limit = "0" if limit.nil? || limit == ""
114
110
  end
115
111
 
@@ -138,16 +134,12 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
138
134
 
139
135
  def factory_pool(user_flag=-2)
140
136
  #TBD OpenNebula::UserPool.new(@client, user_flag)
141
- OpenNebula::GroupPool.new(@client)
137
+ @group_pool = OpenNebula::GroupPool.new(@client)
138
+ return @group_pool
142
139
  end
143
140
 
144
- def format_resource(group)
141
+ def format_resource(group, options = {})
145
142
  system = System.new(@client)
146
- default_quotas = system.get_group_quotas()
147
-
148
- if OpenNebula::is_error?(default_quotas)
149
- raise "Error retrieving the default group quotas: #{default_quotas.message}"
150
- end
151
143
 
152
144
  str="%-15s: %-20s"
153
145
  str_h1="%-80s"
@@ -165,6 +157,12 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
165
157
 
166
158
  group_hash = group.to_hash
167
159
 
160
+ default_quotas = nil
161
+
162
+ group.each('/GROUP/DEFAULT_GROUP_QUOTAS') { |elem|
163
+ default_quotas = elem
164
+ }
165
+
168
166
  helper = OneQuotaHelper.new
169
167
  helper.format_quota(group_hash['GROUP'], default_quotas)
170
168
  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 #
@@ -162,7 +162,7 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
162
162
  OpenNebula::HostPool.new(@client)
163
163
  end
164
164
 
165
- def format_resource(host)
165
+ def format_resource(host, options = {})
166
166
  str = "%-22s: %-20s"
167
167
  str_h1 = "%-80s"
168
168
 
@@ -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 'one_helper/onevm_helper'
18
19
 
19
20
  class OneImageHelper < OpenNebulaHelper::OneHelper
20
21
  TEMPLATE_OPTIONS=[
@@ -101,14 +102,14 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
101
102
  {
102
103
  :name => "disk_type",
103
104
  :large => "--disk_type disk_type",
104
- :description => "Type of the image (BLOCK, CDROM or FILE)",
105
+ :description => "Type of the image (BLOCK, CDROM, RBD or FILE)",
105
106
  :format => String,
106
107
  :proc => lambda do |o, options|
107
108
  type=o.strip.upcase
108
- if %w{BLOCK CDROM FILE}.include? type
109
+ if %w{BLOCK CDROM FILE RBD}.include? type
109
110
  [0, type]
110
111
  else
111
- [-1, "Disk type must be BLOCK, CDROM or FILE"]
112
+ [-1, "Disk type must be BLOCK, CDROM, RBD or FILE"]
112
113
  end
113
114
  end
114
115
  },
@@ -261,7 +262,7 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
261
262
  OpenNebula::ImagePool.new(@client, user_flag)
262
263
  end
263
264
 
264
- def format_resource(image)
265
+ def format_resource(image, options = {})
265
266
  str="%-15s: %-20s"
266
267
  str_h1="%-80s"
267
268
 
@@ -298,6 +299,19 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
298
299
 
299
300
  CLIHelper.print_header(str_h1 % "IMAGE TEMPLATE",false)
300
301
  puts image.template_str
302
+
303
+ puts
304
+ CLIHelper.print_header("VIRTUAL MACHINES", false)
305
+ puts
306
+
307
+ vms=image.retrieve_elements("VMS/ID")
308
+
309
+ if vms
310
+ vms.map!{|e| e.to_i }
311
+ onevm_helper=OneVMHelper.new
312
+ onevm_helper.client=@client
313
+ onevm_helper.list_pool({:ids=>vms}, false)
314
+ end
301
315
  end
302
316
 
303
317
  def self.create_image_variables(options, name)
@@ -323,9 +337,12 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
323
337
  end
324
338
 
325
339
  template=create_image_variables(
326
- options, template_options-[:persistent, :dry])
340
+ options, template_options-[:persistent, :dry, :prefix])
327
341
 
328
342
  template<<"PERSISTENT=YES\n" if options[:persistent]
343
+ if options[:prefix]
344
+ template<<"DEV_PREFIX=\"#{options[:prefix]}\"\n"
345
+ end
329
346
 
330
347
  [0, template]
331
348
  end