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.
data/NOTICE CHANGED
@@ -1,7 +1,6 @@
1
1
  OpenNebula Open Source Project
2
2
  --------------------------------------------------------------------------------
3
- Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org)
4
- Copyright 2010-2012, C12G Labs S.L. (C12G.com)
3
+ Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs
5
4
  --------------------------------------------------------------------------------
6
5
 
7
6
  You can find more information about the project, release notes and
@@ -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 #
@@ -48,8 +48,8 @@ cmd = CommandParser::CmdParser.new(ARGV) do
48
48
 
49
49
  main do
50
50
  filter_flag = (options[:userfilter] || VirtualMachinePool::INFO_ALL)
51
- start_time = options[:start] ? options[:start].to_i : -1
52
- end_time = options[:end] ? options[:end].to_i : -1
51
+ start_time = options[:start_time] ? options[:start_time].to_i : -1
52
+ end_time = options[:end_time] ? options[:end_time].to_i : -1
53
53
 
54
54
  common_opts = {
55
55
  :start_time => start_time,
@@ -83,7 +83,8 @@ cmd = CommandParser::CmdParser.new(ARGV) do
83
83
  order_by[:order_by_1] = 'VM/UID'
84
84
  order_by[:order_by_2] = 'VM/ID' if options[:split]
85
85
 
86
- acct_hash = pool.accounting(filter_flag, common_opts.merge(order_by))
86
+ acct_hash = pool.accounting(filter_flag,
87
+ common_opts.merge(order_by))
87
88
  if OpenNebula.is_error?(acct_hash)
88
89
  puts acct_hash.message
89
90
  exit -1
data/bin/oneacl CHANGED
@@ -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,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 #
@@ -69,7 +69,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
69
69
  OpenNebulaHelper.rname_to_id(arg, "HOST")
70
70
  end
71
71
 
72
- set :format, :datastoreid, OpenNebulaHelper.rname_to_id_desc("DATASTORE") do |arg|
72
+ set :format, :datastoreid,
73
+ OpenNebulaHelper.rname_to_id_desc("DATASTORE") do |arg|
73
74
  OpenNebulaHelper.rname_to_id(arg, "DATASTORE")
74
75
  end
75
76
 
@@ -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 #
@@ -62,7 +62,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
62
62
  helper.list_to_id(arg)
63
63
  end
64
64
 
65
- set :format, :clusterid, OpenNebulaHelper.rname_to_id_desc("CLUSTER") do |arg|
65
+ set :format, :clusterid,
66
+ OpenNebulaHelper.rname_to_id_desc("CLUSTER") do |arg|
66
67
  OpenNebulaHelper.rname_to_id(arg, "CLUSTER")
67
68
  end
68
69
 
@@ -82,7 +83,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
82
83
  Creates a new Datastore from the given template file
83
84
  EOT
84
85
 
85
- command :create, create_desc, :file, :options=>[OneClusterHelper::CLUSTER] do
86
+ command :create, create_desc, :file,
87
+ :options=>[OneClusterHelper::CLUSTER] do
86
88
 
87
89
  cid = options[:cluster] || ClusterPool::NONE_CLUSTER_ID
88
90
 
@@ -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 #
@@ -103,8 +103,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
103
103
  end
104
104
 
105
105
  quota_desc = <<-EOT.unindent
106
- Set the quota limits for the group. If a path is not provided the editor
107
- will be launched to modify the current quotas.
106
+ Set the quota limits for the group. If a path is not provided the
107
+ editor will be launched to modify the current quotas.
108
108
  EOT
109
109
 
110
110
  command :quota, quota_desc, :groupid, [:file, nil] do
@@ -131,7 +131,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
131
131
  provided the editor will be launched to create new quotas.
132
132
  EOT
133
133
 
134
- command :batchquota, batchquota_desc, [:range, :groupid_list], [:file, nil] do
134
+ command :batchquota, batchquota_desc, [:range, :groupid_list],
135
+ [:file, nil] do
135
136
  batch_str = OneQuotaHelper.get_batch_quota(args[1])
136
137
 
137
138
  helper.perform_actions(args[0], options, "modified") do |group|
@@ -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 #
@@ -44,7 +44,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
44
44
  ########################################################################
45
45
  # Global Options
46
46
  ########################################################################
47
- set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
47
+ cmd_options=CommandParser::OPTIONS-[CommandParser::VERBOSE]
48
+ set :option, cmd_options+OpenNebulaHelper::CLIENT_OPTIONS
48
49
 
49
50
  IM = {
50
51
  :name => "im",
@@ -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 #
@@ -81,7 +81,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
81
81
  if Image::IMAGE_TYPES.include? type
82
82
  [0, type]
83
83
  else
84
- [1, "Image type not supported. Must be #{Image::IMAGE_TYPES.join(", ")}."]
84
+ [1, "Image type not supported. Must be "<<
85
+ Image::IMAGE_TYPES.join(", ")<<"."]
85
86
  end
86
87
  end
87
88
 
@@ -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 #
@@ -29,6 +29,7 @@ $: << RUBY_LIB_LOCATION+"/cli"
29
29
 
30
30
  require 'command_parser'
31
31
  require 'one_helper/onetemplate_helper'
32
+ require 'one_helper/onevm_helper'
32
33
 
33
34
  cmd=CommandParser::CmdParser.new(ARGV) do
34
35
  usage "`onetemplate` <command> [<args>] [<options>]"
@@ -52,7 +53,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
52
53
 
53
54
  instantiate_options = [
54
55
  OneTemplateHelper::VM_NAME,
55
- OneTemplateHelper::MULTIPLE
56
+ OneTemplateHelper::MULTIPLE,
57
+ OneVMHelper::HOLD
56
58
  ]
57
59
 
58
60
  ########################################################################
@@ -92,12 +94,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
92
94
 
93
95
  - new VM Template named "arch vm" with a disk and a nic:
94
96
 
95
- onetemplate create --name "arch vm" --memory 128 --cpu 1 --disk arch \\
96
- --network private_lan
97
+ onetemplate create --name "arch vm" --memory 128 --cpu 1 \\
98
+ --disk arch --network private_lan
97
99
 
98
100
  - using two disks:
99
101
 
100
- onetempate create --name "test vm" --memory 128 --cpu 1 --disk arch,data
102
+ onetempate create --name "test vm" --memory 128 --cpu 1 \\
103
+ --disk arch,data
101
104
 
102
105
  EOT
103
106
 
@@ -170,16 +173,41 @@ cmd=CommandParser::CmdParser.new(ARGV) do
170
173
  managed with the 'onevm' command
171
174
  EOT
172
175
 
173
- command :instantiate, instantiate_desc, :templateid,
174
- :options=>instantiate_options do
176
+ command :instantiate, instantiate_desc, :templateid, [:file, nil],
177
+ :options=>instantiate_options+OpenNebulaHelper::TEMPLATE_OPTIONS do
175
178
  exit_code=0
176
179
 
180
+ if args[1] && OpenNebulaHelper.create_template_options_used?(options)
181
+ STDERR.puts "You cannot use both template file and template"<<
182
+ " creation options."
183
+ next -1
184
+ end
185
+
177
186
  number = options[:multiple] || 1
178
187
  number.times do |i|
179
- exit_code=helper.perform_action(args[0],options,"instantiated") do |t|
188
+ exit_code=helper.perform_action(args[0], options,
189
+ "instantiated") do |t|
180
190
  name = options[:name]
181
191
  name = name.gsub("%i",i.to_s) if name
182
- res = t.instantiate(name)
192
+
193
+ on_hold = options[:hold] != nil
194
+
195
+ extra_template = ""
196
+
197
+ if args[1]
198
+ extra_template = File.read(args[1])
199
+ else
200
+ res = OpenNebulaHelper.create_template(options)
201
+
202
+ if res.first != 0
203
+ STDERR.puts res.last
204
+ next -1
205
+ end
206
+
207
+ extra_template = res.last
208
+ end
209
+
210
+ res = t.instantiate(name, on_hold, extra_template)
183
211
 
184
212
  if !OpenNebula.is_error?(res)
185
213
  puts "VM ID: #{res}"
@@ -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 #
@@ -228,7 +228,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
228
228
  provided the editor will be launched to create new quotas.
229
229
  EOT
230
230
 
231
- command :batchquota, batchquota_desc, [:range, :userid_list], [:file, nil] do
231
+ command :batchquota, batchquota_desc, [:range, :userid_list],
232
+ [:file, nil] do
232
233
  batch_str = OneQuotaHelper.get_batch_quota(args[1])
233
234
 
234
235
  helper.perform_actions(args[0], options, "modified") do |user|
@@ -270,6 +271,39 @@ cmd=CommandParser::CmdParser.new(ARGV) do
270
271
  exit 0
271
272
  end
272
273
 
274
+ umask_desc = <<-EOT.unindent
275
+ Changes the umask used to create the default permissions. In a similar
276
+ way to the Unix umask command, the expected value is a three-digit
277
+ base-8 number. Each digit is a mask that disables permissions for the
278
+ owner, group and other, respectively.
279
+
280
+ If mask is not given, or if it is an empty string, the umask will
281
+ be unset
282
+ EOT
283
+
284
+ command :umask, umask_desc, [:range, :userid_list], [:mask, nil] do
285
+ helper.perform_actions(args[0],options,
286
+ "umask changed") do |user|
287
+
288
+ rc = user.info
289
+
290
+ if OpenNebula.is_error?(rc)
291
+ puts rc.message
292
+ exit -1
293
+ end
294
+
295
+ user.delete_element('/USER/TEMPLATE/UMASK')
296
+
297
+ tmp_str = user.template_str
298
+
299
+ if !args[1].nil? && args[1] != ""
300
+ tmp_str << "\nUMASK = #{args[1]}"
301
+ end
302
+
303
+ user.update(tmp_str)
304
+ end
305
+ end
306
+
273
307
  login_desc = <<-EOT.unindent
274
308
  Creates the Login token for authentication
275
309
  Examples:
data/bin/onevm CHANGED
@@ -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 #
@@ -56,6 +56,22 @@ cmd=CommandParser::CmdParser.new(ARGV) do
56
56
  :description => "Device where the image will be attached"
57
57
  }
58
58
 
59
+ IP={
60
+ :name => "ip",
61
+ :short => "-i ip",
62
+ :large => "--ip ip",
63
+ :format => String,
64
+ :description => "IP address for the new NIC"
65
+ }
66
+
67
+ CACHE={
68
+ :name => "cache",
69
+ :large => "--cache cache_mode",
70
+ :format => String,
71
+ :description => "Hypervisor cache mode: default, none, writethrough,"<<
72
+ " writeback, directsync or unsafe. (Only KVM driver)"
73
+ }
74
+
59
75
  ENFORCE={
60
76
  :name => "enforce",
61
77
  :short => "-e",
@@ -104,8 +120,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
104
120
  ########################################################################
105
121
 
106
122
  create_desc = <<-EOT.unindent
107
- Creates a new VM from the given description instead of using a previously
108
- defined template (see 'onetemplate create' and 'onetemplate instantiate').
123
+ Creates a new VM from the given description instead of using a
124
+ previously defined template (see 'onetemplate create' and
125
+ 'onetemplate instantiate').
109
126
 
110
127
  Examples:
111
128
 
@@ -125,7 +142,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
125
142
  EOT
126
143
 
127
144
  command :create, create_desc, [:file, nil], :options =>
128
- [OneVMHelper::MULTIPLE]+OpenNebulaHelper::TEMPLATE_OPTIONS_VM do
145
+ [OneVMHelper::MULTIPLE, OneVMHelper::HOLD]+
146
+ OpenNebulaHelper::TEMPLATE_OPTIONS_VM do
129
147
 
130
148
  number = options[:multiple] || 1
131
149
  exit_code = nil
@@ -160,9 +178,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do
160
178
  exit 0
161
179
  end
162
180
 
181
+ on_hold = options[:hold] != nil
182
+
163
183
  number.times do
164
184
  exit_code = helper.create_resource(options) do |vm|
165
- error = vm.allocate(template)
185
+ error = vm.allocate(template, on_hold)
166
186
  end
167
187
 
168
188
  break if exit_code == -1
@@ -171,15 +191,41 @@ cmd=CommandParser::CmdParser.new(ARGV) do
171
191
  exit_code
172
192
  end
173
193
 
174
- delete_desc = <<-EOT.unindent
175
- Deletes the given VM
194
+ update_desc = <<-EOT.unindent
195
+ Update the user template contents. If a path is not provided the
196
+ editor will be launched to modify the current content.
197
+ EOT
198
+
199
+ command :update, update_desc, :vmid, [:file, nil] do
200
+ helper.perform_action(args[0],options,"modified") do |vm|
201
+ str = OpenNebulaHelper.update_template(args[0], vm, args[1],
202
+ 'USER_TEMPLATE')
203
+ vm.update(str)
204
+ end
205
+ end
206
+
207
+ destroy_desc = <<-EOT.unindent
208
+ Deletes the given VM. Using --recreate resubmits the VM.
209
+
210
+ Resubmits the VM to PENDING state. This is intended for VMs stuck in a
211
+ transient state. To re-deploy a fresh copy of the same VM, create a
212
+ Template and instantiate it, see 'onetemplate instantiate'
176
213
 
177
214
  States: ANY
178
215
  EOT
179
216
 
180
- command :delete, delete_desc, [:range, :vmid_list] do
181
- helper.perform_actions(args[0],options,"deleted") do |vm|
182
- vm.finalize
217
+ command :destroy, destroy_desc, [:range, :vmid_list],
218
+ :options => [OneVMHelper::SCHEDULE, OneVMHelper::RECREATE] do
219
+
220
+ command_name="destroy"
221
+ command_name<<"-recreate" if options[:recreate]
222
+
223
+ if (!options[:schedule].nil?)
224
+ helper.schedule_actions(args[0], options, command_name)
225
+ else
226
+ helper.perform_actions(args[0],options,"deleted") do |vm|
227
+ vm.destroy(options[:recreate]==true)
228
+ end
183
229
  end
184
230
  end
185
231
 
@@ -190,9 +236,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do
190
236
  States: PENDING
191
237
  EOT
192
238
 
193
- command :hold, hold_desc, [:range,:vmid_list] do
194
- helper.perform_actions(args[0],options,"put on hold") do |vm|
195
- vm.hold
239
+ command :hold, hold_desc, [:range,:vmid_list],
240
+ :options => [OneVMHelper::SCHEDULE] do
241
+ if (!options[:schedule].nil?)
242
+ helper.schedule_actions(args[0], options, @comm_name)
243
+ else
244
+ helper.perform_actions(args[0],options,"put on hold") do |vm|
245
+ vm.hold
246
+ end
196
247
  end
197
248
  end
198
249
 
@@ -202,22 +253,30 @@ cmd=CommandParser::CmdParser.new(ARGV) do
202
253
  States: HOLD
203
254
  EOT
204
255
 
205
- command :release, release_desc, [:range,:vmid_list] do
206
- helper.perform_actions(args[0],options,"released") do |vm|
207
- vm.release
256
+ command :release, release_desc, [:range,:vmid_list],
257
+ :options => [OneVMHelper::SCHEDULE] do
258
+ if (!options[:schedule].nil?)
259
+ helper.schedule_actions(args[0], options, @comm_name)
260
+ else
261
+ helper.perform_actions(args[0],options,"released") do |vm|
262
+ vm.release
263
+ end
208
264
  end
209
265
  end
210
266
 
211
- saveas_desc = <<-EOT.unindent
267
+ disk_snapshot_desc = <<-EOT.unindent
212
268
  Sets the specified VM disk to be saved in a new Image. The Image is
213
269
  created immediately, but the contents are saved only if the VM is
214
270
  shut down gracefully (i.e., using 'onevm shutdown' and not
215
- 'onevm delete')
271
+ 'onevm destroy')
272
+
273
+ If '--live' is specified, the Image will be saved immediately.
216
274
 
217
275
  States: ANY
218
276
  EOT
219
277
 
220
- command :saveas, saveas_desc, :vmid, :diskid, :img_name, :options=>[TYPE] do
278
+ command :"disk-snapshot", disk_snapshot_desc, :vmid, :diskid, :img_name,
279
+ :options=>[TYPE, OneVMHelper::LIVE] do
221
280
  disk_id = args[1].to_i
222
281
  image_name = args[2]
223
282
  image_type = options[:type] || ""
@@ -226,7 +285,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
226
285
  "the image #{image_name}"
227
286
 
228
287
  helper.perform_action(args[0],options,verbose) do |vm|
229
- res = vm.save_as(disk_id, image_name, image_type)
288
+ res = vm.disk_snapshot(disk_id, image_name, image_type,
289
+ options[:live]==true)
230
290
 
231
291
  if !OpenNebula.is_error?(res)
232
292
  puts "Image ID: #{res}"
@@ -239,25 +299,41 @@ cmd=CommandParser::CmdParser.new(ARGV) do
239
299
  shutdown_desc = <<-EOT.unindent
240
300
  Shuts down the given VM. The VM life cycle will end.
241
301
 
302
+ With --hard it unplugs the VM.
303
+
242
304
  States: RUNNING
243
305
  EOT
244
306
 
245
- command :shutdown, shutdown_desc, [:range,:vmid_list] do
246
- helper.perform_actions(args[0],options,"shutting down") do |vm|
247
- vm.shutdown
307
+ command :shutdown, shutdown_desc, [:range,:vmid_list],
308
+ :options => [OneVMHelper::SCHEDULE, OneVMHelper::HARD] do
309
+
310
+ command_name='shutdown'
311
+ command_name<<'-hard' if options[:hard]
312
+
313
+ if (!options[:schedule].nil?)
314
+ helper.schedule_actions(args[0], options, command_name)
315
+ else
316
+ helper.perform_actions(args[0],options,"shutting down") do |vm|
317
+ vm.shutdown(options[:hard]==true)
318
+ end
248
319
  end
249
320
  end
250
321
 
251
322
  poweroff_desc = <<-EOT.unindent
252
323
  Powers off the given VM. The VM will remain in the poweroff state, and
253
- can be powered on with the 'onevm restart' command.
324
+ can be powered on with the 'onevm boot' command.
254
325
 
255
326
  States: RUNNING
256
327
  EOT
257
328
 
258
- command :poweroff, poweroff_desc, [:range,:vmid_list] do
259
- helper.perform_actions(args[0],options,"shutting down") do |vm|
260
- vm.poweroff
329
+ command :poweroff, poweroff_desc, [:range,:vmid_list],
330
+ :options => [OneVMHelper::SCHEDULE] do
331
+ if (!options[:schedule].nil?)
332
+ helper.schedule_actions(args[0], options, @comm_name)
333
+ else
334
+ helper.perform_actions(args[0],options,"shutting down") do |vm|
335
+ vm.poweroff
336
+ end
261
337
  end
262
338
  end
263
339
 
@@ -265,24 +341,23 @@ cmd=CommandParser::CmdParser.new(ARGV) do
265
341
  Reboots the given VM, this is equivalent to execute the reboot command
266
342
  from the VM console.
267
343
 
344
+ The VM will be ungracefully rebooted if --hard is used.
345
+
268
346
  States: RUNNING
269
347
  EOT
270
348
 
271
- command :reboot, reboot_desc, [:range,:vmid_list] do
272
- helper.perform_actions(args[0],options,"rebooting") do |vm|
273
- vm.reboot
274
- end
275
- end
349
+ command :reboot, reboot_desc, [:range,:vmid_list],
350
+ :options => [OneVMHelper::SCHEDULE, OneVMHelper::HARD] do
276
351
 
277
- reset_desc = <<-EOT.unindent
278
- Resets the given VM
352
+ command_name='reboot'
353
+ command_name<<'-hard' if options[:hard]
279
354
 
280
- States: RUNNING
281
- EOT
282
-
283
- command :reset, reset_desc, [:range,:vmid_list] do
284
- helper.perform_actions(args[0],options,"resetting") do |vm|
285
- vm.reset
355
+ if (!options[:schedule].nil?)
356
+ helper.schedule_actions(args[0], options, command_name)
357
+ else
358
+ helper.perform_actions(args[0],options,"rebooting") do |vm|
359
+ vm.reboot(options[:hard])
360
+ end
286
361
  end
287
362
  end
288
363
 
@@ -294,7 +369,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
294
369
  States: PENDING
295
370
  EOT
296
371
 
297
- command :deploy, deploy_desc, [:range,:vmid_list], :hostid, :options=>[ENFORCE] do
372
+ command :deploy, deploy_desc, [:range,:vmid_list], :hostid,
373
+ :options=>[ENFORCE] do
298
374
  host_id = args[1]
299
375
  verbose = "deploying in host #{host_id}"
300
376
 
@@ -307,81 +383,39 @@ cmd=CommandParser::CmdParser.new(ARGV) do
307
383
  end
308
384
  end
309
385
 
310
- livemigrate_desc = <<-EOT.unindent
311
- Migrates the given running VM to another Host without downtime
312
-
313
- States: RUNNING
314
- EOT
315
-
316
- command :livemigrate, livemigrate_desc, [:range,:vmid_list], :hostid, :options=>[ENFORCE] do
317
- host_id = args[1]
318
- verbose = "live migrating to #{host_id}"
319
-
320
- helper.perform_actions(args[0],options,verbose) do |vm|
321
- if !options[:enforce].nil?
322
- vm.live_migrate(host_id, options[:enforce])
323
- else
324
- vm.live_migrate(host_id)
325
- end
326
- end
327
- end
328
-
329
386
  migrate_desc = <<-EOT.unindent
330
- Saves the given running VM and starts it again in the specified Host
387
+ Migrates the given running VM to another Host. If used with --live
388
+ parameter the miration is done without downtime.
331
389
 
332
390
  States: RUNNING
333
391
  EOT
334
392
 
335
- command :migrate, migrate_desc, [:range,:vmid_list], :hostid, :options=>[ENFORCE] do
393
+ command :migrate, migrate_desc, [:range,:vmid_list], :hostid,
394
+ :options=>[ENFORCE, OneVMHelper::LIVE] do
336
395
  host_id = args[1]
337
396
  verbose = "migrating to #{host_id}"
338
397
 
339
398
  helper.perform_actions(args[0],options,verbose) do |vm|
340
- if !options[:enforce].nil?
341
- vm.migrate(host_id, options[:enforce])
342
- else
343
- vm.migrate(host_id)
344
- end
399
+ vm.migrate( host_id,
400
+ options[:live]==true,
401
+ options[:enforce]==true)
345
402
  end
346
403
  end
347
404
 
348
- restart_desc = <<-EOT.unindent
405
+ boot_desc = <<-EOT.unindent
349
406
  Boots the given VM.
350
407
 
351
408
  States: UNKNOWN, BOOT, POWEROFF
352
409
  EOT
353
410
 
354
- command :restart, restart_desc, [:range,:vmid_list] do
355
- helper.perform_actions(args[0],options,"restarting") do |vm|
356
- vm.restart
357
- end
358
- end
359
-
360
- resubmit_desc = <<-EOT.unindent
361
- Resubmits the VM to PENDING state. This is intended for VMs stuck in a
362
- transient state. To re-deploy a fresh copy of the same VM, create a
363
- Template and instantiate it, see 'onetemplate instantiate'
364
-
365
- States: ANY, except SUSPENDED or DONE
366
- EOT
367
-
368
- command :resubmit, resubmit_desc, [:range,:vmid_list] do
369
- helper.perform_actions(args[0],options,"resubmiting") do |vm|
370
- vm.resubmit
371
- end
372
- end
373
-
374
- cancel_desc = <<-EOT.unindent
375
- Cancels the given VM. The process is checked by OpenNebula, so
376
- if the process fails the VM remains in running state. If the action
377
- succeeds the VMDIR in the remote machine is not deleted
378
-
379
- States: RUNNING
380
- EOT
381
-
382
- command :cancel, cancel_desc, [:range,:vmid_list] do
383
- helper.perform_actions(args[0],options,"canceling") do |vm|
384
- vm.cancel
411
+ command :boot, boot_desc, [:range,:vmid_list],
412
+ :options => [OneVMHelper::SCHEDULE] do
413
+ if (!options[:schedule].nil?)
414
+ helper.schedule_actions(args[0], options, @comm_name)
415
+ else
416
+ helper.perform_actions(args[0],options,"booting") do |vm|
417
+ vm.boot
418
+ end
385
419
  end
386
420
  end
387
421
 
@@ -392,9 +426,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do
392
426
  States: RUNNING
393
427
  EOT
394
428
 
395
- command :stop, stop_desc, [:range,:vmid_list] do
396
- helper.perform_actions(args[0],options,"stopping") do |vm|
397
- vm.stop
429
+ command :stop, stop_desc, [:range,:vmid_list],
430
+ :options => [OneVMHelper::SCHEDULE] do
431
+ if (!options[:schedule].nil?)
432
+ helper.schedule_actions(args[0], options, @comm_name)
433
+ else
434
+ helper.perform_actions(args[0],options,"stopping") do |vm|
435
+ vm.stop
436
+ end
398
437
  end
399
438
  end
400
439
 
@@ -407,9 +446,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do
407
446
  States: RUNNING
408
447
  EOT
409
448
 
410
- command :suspend, suspend_desc, [:range,:vmid_list] do
411
- helper.perform_actions(args[0],options,"suspending") do |vm|
412
- vm.suspend
449
+ command :suspend, suspend_desc, [:range,:vmid_list],
450
+ :options => [OneVMHelper::SCHEDULE] do
451
+ if (!options[:schedule].nil?)
452
+ helper.schedule_actions(args[0], options, @comm_name)
453
+ else
454
+ helper.perform_actions(args[0],options,"suspending") do |vm|
455
+ vm.suspend
456
+ end
413
457
  end
414
458
  end
415
459
 
@@ -419,20 +463,26 @@ cmd=CommandParser::CmdParser.new(ARGV) do
419
463
  States: STOPPED, SUSPENDED
420
464
  EOT
421
465
 
422
- command :resume, resume_desc, [:range,:vmid_list] do
423
- helper.perform_actions(args[0],options,"resuming") do |vm|
424
- vm.resume
466
+ command :resume, resume_desc, [:range,:vmid_list],
467
+ :options => [OneVMHelper::SCHEDULE] do
468
+ if (!options[:schedule].nil?)
469
+ helper.schedule_actions(args[0], options, @comm_name)
470
+ else
471
+ helper.perform_actions(args[0],options,"resuming") do |vm|
472
+ vm.resume
473
+ end
425
474
  end
426
475
  end
427
476
 
428
- attachdisk_desc = <<-EOT.unindent
477
+ disk_attach_desc = <<-EOT.unindent
429
478
  Attaches a disk to a running VM
430
479
 
431
480
  States: RUNNING
432
481
  EOT
433
482
 
434
- command :attachdisk, attachdisk_desc, :vmid,
435
- :options => [OneVMHelper::FILE, OneVMHelper::IMAGE, TARGET] do
483
+ command :"disk-attach", disk_attach_desc, :vmid,
484
+ :options => [OneVMHelper::FILE, OneVMHelper::IMAGE,
485
+ TARGET, CACHE] do
436
486
 
437
487
  if options[:file].nil? and options[:image].nil?
438
488
  STDERR.puts "Provide a template file or an image:"
@@ -448,29 +498,82 @@ cmd=CommandParser::CmdParser.new(ARGV) do
448
498
  target = options[:target]
449
499
  if target
450
500
  template =
451
- "DISK = [ IMAGE_ID = #{image_id}, TARGET = #{target} ]"
501
+ "DISK = [ IMAGE_ID = #{image_id}, TARGET = #{target}"
452
502
  else
453
503
  template =
454
- "DISK = [ IMAGE_ID = #{image_id}, DEV_PREFIX = sd ]"
504
+ "DISK = [ IMAGE_ID = #{image_id}, DEV_PREFIX = sd"
455
505
  end
506
+
507
+ if options[:cache]
508
+ template<<", CACHE = \"#{options[:cache]}\""
509
+ end
510
+
511
+ template << " ]"
456
512
  end
457
513
 
458
514
  helper.perform_action(args[0],options,"Attach disk") do |vm|
459
- vm.attachdisk(template)
515
+ vm.disk_attach(template)
460
516
  end
461
517
  end
462
518
 
463
- detachdisk_desc = <<-EOT.unindent
519
+ disk_detach_desc = <<-EOT.unindent
464
520
  Detaches a disk from a running VM
465
521
 
466
522
  States: RUNNING
467
523
  EOT
468
524
 
469
- command :detachdisk, detachdisk_desc, :vmid, :diskid do
525
+ command :"disk-detach", disk_detach_desc, :vmid, :diskid do
470
526
  diskid = args[1].to_i
471
527
 
472
528
  helper.perform_action(args[0],options,"Detach disk") do |vm|
473
- vm.detachdisk(diskid)
529
+ vm.disk_detach(diskid)
530
+ end
531
+ end
532
+
533
+ nic_attach_desc = <<-EOT.unindent
534
+ Attaches a NIC to a running VM
535
+
536
+ States: RUNNING
537
+ EOT
538
+
539
+ command :"nic-attach", nic_attach_desc, :vmid,
540
+ :options => [OneVMHelper::FILE, OneVMHelper::NETWORK, IP] do
541
+
542
+ if options[:file].nil? and options[:network].nil?
543
+ STDERR.puts "Provide a template file or a network:"
544
+ STDERR.puts "\t--file <file>"
545
+ STDERR.puts "\t--network <network>"
546
+ exit -1
547
+ end
548
+
549
+ if options[:file]
550
+ template = File.read(options[:file])
551
+ else
552
+ network_id = options[:network]
553
+ ip = options[:ip]
554
+ if ip
555
+ template = "NIC = [ NETWORK_ID = #{network_id}, IP = #{ip} ]"
556
+ else
557
+ template = "NIC = [ NETWORK_ID = #{network_id} ]"
558
+ end
559
+ end
560
+
561
+ helper.perform_action(args[0],options,"Attach NIC") do |vm|
562
+ vm.nic_attach(template)
563
+ end
564
+ end
565
+
566
+ nic_detach_desc = <<-EOT.unindent
567
+ Detaches a NIC from a running VM
568
+
569
+ States: RUNNING
570
+ EOT
571
+
572
+ command :"nic-detach", nic_detach_desc, :vmid, :nicid do
573
+ nicid = args[1].to_i
574
+
575
+ helper.perform_action(args[0],options,"Detach NIC") do |vm|
576
+ vm.nic_detach(nicid)
474
577
  end
475
578
  end
476
579
 
@@ -530,10 +633,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do
530
633
  end
531
634
  end
532
635
 
533
- list_desc = <<-EOT.unindent
534
- Lists VMs in the pool
535
- EOT
536
-
537
636
  rename_desc = <<-EOT.unindent
538
637
  Renames the VM
539
638
  EOT
@@ -544,6 +643,52 @@ cmd=CommandParser::CmdParser.new(ARGV) do
544
643
  end
545
644
  end
546
645
 
646
+ # TODO: Write a more complete description:
647
+ # what is a snapshot (system snapshot)
648
+ # how to revert to a snapshot
649
+ snapshot_create_desc = <<-EOT.unindent
650
+ Creates a new VM snapshot
651
+ EOT
652
+
653
+ command :"snapshot-create", snapshot_create_desc, [:range,:vmid_list],
654
+ [:name, nil], :options => [OneVMHelper::SCHEDULE] do
655
+
656
+ if (!options[:schedule].nil?)
657
+ helper.schedule_actions(args[0], options, @comm_name)
658
+ else
659
+ helper.perform_actions(args[0],options,"snapshot created") do |o|
660
+ o.snapshot_create(args[1])
661
+ end
662
+ end
663
+ end
664
+
665
+ # TODO: Write a more complete description:
666
+ snapshot_revert_desc = <<-EOT.unindent
667
+ Reverts a VM to a saved snapshot
668
+ EOT
669
+
670
+ command :"snapshot-revert", snapshot_revert_desc, :vmid, :snapshot_id do
671
+
672
+ helper.perform_action(args[0],options,"snapshot reverted") do |o|
673
+ o.snapshot_revert(args[1].to_i)
674
+ end
675
+ end
676
+
677
+ # TODO: Write a more complete description:
678
+ snapshot_delete_desc = <<-EOT.unindent
679
+ Delets a snapshot of a VM
680
+ EOT
681
+
682
+ command :"snapshot-delete", snapshot_delete_desc, :vmid, :snapshot_id do
683
+ helper.perform_action(args[0],options,"snapshot deleted") do |o|
684
+ o.snapshot_delete(args[1].to_i)
685
+ end
686
+ end
687
+
688
+ list_desc = <<-EOT.unindent
689
+ Lists VMs in the pool
690
+ EOT
691
+
547
692
  command :list, list_desc, [:filterflag, nil],
548
693
  :options=>CLIHelper::OPTIONS+OpenNebulaHelper::OPTIONS+
549
694
  [OpenNebulaHelper::DESCRIBE] do
@@ -555,7 +700,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
555
700
  EOT
556
701
 
557
702
  command :show, show_desc, :vmid,
558
- :options=>OpenNebulaHelper::XML do
703
+ :options=>[OpenNebulaHelper::XML, OneVMHelper::ALL_TEMPLATE] do
559
704
  helper.show_resource(args[0],options)
560
705
  end
561
706
 
@@ -567,4 +712,38 @@ cmd=CommandParser::CmdParser.new(ARGV) do
567
712
  :options=>CLIHelper::OPTIONS+OpenNebulaHelper::OPTIONS do
568
713
  helper.list_pool(options, true, args[0])
569
714
  end
715
+
716
+ resize_desc = <<-EOT.unindent
717
+ Resizes the capacity of a Virtual Machine (offline, the VM cannot be
718
+ RUNNING)
719
+
720
+ EOT
721
+
722
+ command :resize, resize_desc, :vmid, :options =>
723
+ OpenNebulaHelper::CAPACITY_OPTIONS_VM + [ENFORCE, OneVMHelper::FILE] do
724
+
725
+ if options[:file]
726
+ template = File.read(options[:file])
727
+ else
728
+ template = ""
729
+
730
+ if !options[:cpu].nil?
731
+ template << "CPU = #{options[:cpu]}\n"
732
+ end
733
+
734
+ if !options[:vcpu].nil?
735
+ template << "VCPU = #{options[:vcpu]}\n"
736
+ end
737
+
738
+ if !options[:memory].nil?
739
+ template << "MEMORY = #{options[:memory]}\n"
740
+ end
741
+ end
742
+
743
+ enforce = options[:enforce] || false
744
+
745
+ helper.perform_action(args[0], options, "Resizing VM") do |vm|
746
+ vm.resize(template, enforce)
747
+ end
748
+ end
570
749
  end