opennebula-cli 5.2.1 → 5.3.80.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aecb3a2118b60bbf27598306644f61cdb25568ed
4
- data.tar.gz: e02fbd42fe161f304e410208e80c38d34ad95439
3
+ metadata.gz: e15bbf71c016c51a6c4d926c42e0b1dd4f5f49f8
4
+ data.tar.gz: fcd4ffdb5d5f25300f2b652ff1ad082ee45d0c3e
5
5
  SHA512:
6
- metadata.gz: 82852ec8d3c9257b393a0e82ed532ad1f8367f3da73a6696cd7e41aa9de52823811566eb5c4bb11b6ef75bd6742fc23ed2bf0f9bc413a5b75e43ccae70b54675
7
- data.tar.gz: 773b75b8ef46efe736a5371d157713dd70b631386fa85e6e6868554252a50229162f54ad0662311cd3b541963e8acd593325cb84c08444bd32b81192c6a3b9a9
6
+ metadata.gz: 22f98b03d7880441572a20e1236c4975357031a645854d9ab441fa3c177cefa0d5152ab0d0ca9cd8ea58b4e2158e5efa9343a1279595f4473ec591911be38827
7
+ data.tar.gz: 83b293f1adac28bf9e75102e49968eebbf50b45c0be4aa1f7ed5f28fc0a6954b9befe4b48eba9f66d5eabce74b84dc4ae2863e12ebb7c91775c055e28cfb805f
data/bin/onehost CHANGED
@@ -79,7 +79,21 @@ cmd=CommandParser::CmdParser.new(ARGV) do
79
79
  " rsync command must be installed in the frontend and nodes."
80
80
  }
81
81
 
82
- CREAT_OPTIONS = [ IM, VMM, OneClusterHelper::CLUSTER ]
82
+ EC2_ACCESS = {
83
+ :name => "ec2access",
84
+ :large => "--ec2access id",
85
+ :description => "Set the id access for EC2 Driver",
86
+ :format => String
87
+ }
88
+
89
+ EC2_SECRET = {
90
+ :name => "ec2secret",
91
+ :large => "--ec2secret key",
92
+ :description => "Set the secret key for EC2 Driver",
93
+ :format => String
94
+ }
95
+
96
+ CREAT_OPTIONS = [ IM, VMM, OneClusterHelper::CLUSTER, EC2_ACCESS, EC2_SECRET ]
83
97
  SYNC_OPTIONS = [ OneClusterHelper::CLUSTER, FORCE, RSYNC ]
84
98
 
85
99
  ########################################################################
@@ -110,13 +124,20 @@ cmd=CommandParser::CmdParser.new(ARGV) do
110
124
  exit -1
111
125
  end
112
126
 
113
- cid = options[:cluster] || ClusterPool::NONE_CLUSTER_ID
127
+ ec2_host = !options[:ec2access].nil? && !options[:ec2secret].nil?
114
128
 
129
+ cid = options[:cluster] || ClusterPool::NONE_CLUSTER_ID
115
130
  helper.create_resource(options) do |host|
116
- host.allocate(args[0],
117
- options[:im],
118
- options[:vm],
119
- cid)
131
+ rc = host.allocate(args[0], options[:im], options[:vm], cid)
132
+
133
+ if ec2_host && !OpenNebula.is_error?(rc)
134
+ template = "EC2_ACCESS=\"#{options[:ec2access]}\"\n"\
135
+ "EC2_SECRET=\"#{options[:ec2secret]}\"\n"\
136
+
137
+ rc = host.update(template, true)
138
+ end
139
+
140
+ rc
120
141
  end
121
142
  end
122
143
 
data/bin/onevcenter CHANGED
@@ -65,9 +65,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
65
65
  helper.set_client(options)
66
66
  end
67
67
 
68
- ########################################################################
68
+ ############################################################################
69
69
  # Global Options
70
- ########################################################################
70
+ ############################################################################
71
71
  cmd_options=CommandParser::OPTIONS-[CommandParser::VERBOSE]
72
72
  set :option, cmd_options+OpenNebulaHelper::CLIENT_OPTIONS
73
73
 
@@ -93,6 +93,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
93
93
  :format => String
94
94
  }
95
95
 
96
+ USE_DEFAULTS = {
97
+ :name => "defaults",
98
+ :large => "--use-defaults",
99
+ :description => "Use defaults for answers to questions",
100
+ :format => String
101
+ }
102
+
96
103
  ############################################################################
97
104
  # Import clusters
98
105
  ############################################################################
@@ -100,470 +107,80 @@ cmd=CommandParser::CmdParser.new(ARGV) do
100
107
  Import vCenter clusters as OpenNebula hosts
101
108
  EOT
102
109
 
103
- command :hosts, hosts_desc, :options=>[ VCENTER, USER, PASS ] do
110
+ command :hosts, hosts_desc, :options=>[ VCENTER, USER, PASS, USE_DEFAULTS ] do
104
111
  con_ops = connection_options("Hosts", options)
105
112
 
106
- begin
107
- STDOUT.print "\nConnecting to vCenter: #{options[:vcenter]}..."
108
-
109
- vc = VCenterDriver::VIClient.new_connection(con_ops)
110
-
111
- STDOUT.print "done!\n\n"
112
-
113
- STDOUT.print "Exploring vCenter resources..."
114
-
115
- rs = vc.hierarchy
116
-
117
- STDOUT.print "done!\n\n"
118
-
119
- rs.each {|dc, cluster|
120
- STDOUT.print "Do you want to process datacenter #{dc} [y/n]? "
121
-
122
- next if STDIN.gets.strip.downcase != 'y'
123
-
124
- if cluster.empty?
125
- STDOUT.puts " No new clusters found in #{dc}..."
126
- next
127
- end
128
-
129
- cluster.each{ |c|
130
- STDOUT.print " * Import cluster #{c} [y/n]? "
131
-
132
- next if STDIN.gets.strip.downcase != 'y'
133
-
134
- r, m = VCenterDriver::VCenterHost.to_one(c, vc)
135
-
136
- if r == 0
137
- STDOUT.puts " OpenNebula host #{c} with id #{m}"\
138
- " successfully created."
139
- else
140
- STDOUT.puts " Error: #{m}"
141
- end
142
-
143
- STDOUT.puts
144
- }
145
- }
146
- rescue Exception => e
147
- STDOUT.puts "error: #{e.message}"
148
- exit -1
149
- end
113
+ VCenterDriver::Importer.import_clusters(con_ops, options)
150
114
 
151
115
  exit 0
152
116
  end
153
117
 
118
+ ############################################################################
119
+ # Import templates
120
+ ############################################################################
154
121
  templates_desc = <<-EOT.unindent
155
122
  Import vCenter VM Templates into OpenNebula
156
123
  EOT
157
124
 
158
- command :templates, templates_desc, :options=>[ VCENTER, USER, PASS ] do
125
+ command :templates, templates_desc, :options=>[ VCENTER, USER, PASS, USE_DEFAULTS ] do
159
126
  con_ops = connection_options("VM Templates", options)
160
127
 
161
- begin
162
- STDOUT.print "\nConnecting to vCenter: #{options[:vcenter]}..."
163
-
164
- vc = VCenterDriver::VIClient.new_connection(con_ops)
165
-
166
- STDOUT.print "done!\n\n"
167
-
168
- STDOUT.print "Looking for VM Templates..."
169
-
170
- rs = vc.vm_templates
171
-
172
- STDOUT.print "done!\n"
173
-
174
- rs.each {|dc, tmps|
175
- STDOUT.print "\nDo you want to process datacenter #{dc} [y/n]? "
176
-
177
- next if STDIN.gets.strip.downcase != 'y'
178
-
179
- if tmps.empty?
180
- STDOUT.print " No new VM Templates found in #{dc}...\n\n"
181
- next
182
- end
183
-
184
- tmps.each{ |t|
185
- STDOUT.print "\n * VM Template found:\n"\
186
- " - Name : #{t[:name]}\n"\
187
- " - UUID : #{t[:uuid]}\n"\
188
- " - Cluster: #{t[:host]}\n"\
189
- " Import this VM template [y/n]? "
190
-
191
- next if STDIN.gets.strip.downcase != 'y'
192
-
193
- ds_input = ""
194
- rp_input = ""
195
-
196
- # Datastores
197
-
198
- STDOUT.print "\n This template is currently set to be "\
199
- "deployed in datastore #{t[:default_ds]}."\
200
- "\n Press y to keep the default, n to select"\
201
- " a new datastore or d to delegate the choice"\
202
- " to the user [y/n/d]? "
203
-
204
- answer = STDIN.gets.strip.downcase
205
-
206
- case answer
207
- when 'd'
208
- ds_split = t[:ds].split("|")
209
- list_of_ds = ds_split[-2]
210
- default_ds = ds_split[-1]
211
- ds_input = ds_split[0] + "|" + ds_split[1] + "|" +
212
- ds_split[2] + "|"
213
-
214
- # Available list of datastores
215
-
216
- input_str = " The list of available datastores to be"\
217
- " presented to the user are \"#{list_of_ds}\""
218
- input_str+= "\n Press y to agree, or input a comma"\
219
- " separated list of datastores to edit "\
220
- "[y/comma separated list] "
221
- STDOUT.print input_str
222
-
223
- answer = STDIN.gets.strip
224
-
225
- if answer.downcase == 'y'
226
- ds_input += ds_split[3] + "|"
227
- else
228
- ds_input += answer + "|"
229
- end
230
-
231
- # Default
232
- input_str = " The default datastore presented to "\
233
- "the end user is set to \"#{default_ds}\"."
234
- input_str+= "\n Press y to agree, or input a new "\
235
- "datastore [y/datastore name] "
236
- STDOUT.print input_str
237
-
238
- answer = STDIN.gets.strip
239
-
240
- if answer.downcase == 'y'
241
- ds_input += ds_split[4]
242
- else
243
- ds_input += answer
244
- end
245
- when 'n'
246
- ds_split = t[:ds].split("|")
247
- list_of_ds = ds_split[-2]
248
-
249
- input_str = " The list of available datastores is"\
250
- " \"#{list_of_ds}\"."
251
- input_str+= "\n Please input the new default datastore: "
252
- STDOUT.print input_str
253
-
254
- answer = STDIN.gets.strip
255
-
256
- t[:one] += "VCENTER_DATASTORE=\"#{answer}\"\n"
257
- end
258
-
259
- # Resource Pools
260
-
261
- rp_split = t[:rp].split("|")
262
-
263
- if rp_split.size > 3
264
- STDOUT.print "\n This template is currently set to "\
265
- "launch VMs in the default resource pool."\
266
- "\n Press y to keep this behaviour, n to select"\
267
- " a new resource pool or d to delegate the choice"\
268
- " to the user [y/n/d]? "
269
-
270
- answer = STDIN.gets.strip.downcase
271
-
272
- case answer
273
- when 'd'
274
- list_of_rp = rp_split[-2]
275
- default_rp = rp_split[-1]
276
- rp_input = rp_split[0] + "|" + rp_split[1] + "|" +
277
- rp_split[2] + "|"
278
-
279
- # Available list of resource pools
280
-
281
- input_str = " The list of available resource pools "\
282
- "to be presented to the user are "\
283
- "\"#{list_of_rp}\""
284
- input_str+= "\n Press y to agree, or input a comma"\
285
- " separated list of resource pools to edit "\
286
- "[y/comma separated list] "
287
- STDOUT.print input_str
288
-
289
- answer = STDIN.gets.strip
290
-
291
- if answer.downcase == 'y'
292
- rp_input += rp_split[3] + "|"
293
- else
294
- rp_input += answer + "|"
295
- end
296
-
297
- # Default
298
- input_str = " The default resource pool presented "\
299
- "to the end user is set to"\
300
- " \"#{default_rp}\"."
301
- input_str+= "\n Press y to agree, or input a new "\
302
- "resource pool [y/resource pool name] "
303
- STDOUT.print input_str
304
-
305
- answer = STDIN.gets.strip
306
-
307
- if answer.downcase == 'y'
308
- rp_input += rp_split[4]
309
- else
310
- rp_input += answer
311
- end
312
- when 'n'
313
- list_of_rp = rp_split[-2]
314
-
315
- input_str = " The list of available resource pools is"\
316
- " \"#{list_of_rp}\"."
317
- input_str+= "\n Please input the new default resource pool: "
318
- STDOUT.print input_str
319
-
320
- answer = STDIN.gets.strip
321
-
322
- t[:one] += "RESOURCE_POOL=\"#{answer}\"\n"
323
- end
324
- end
325
-
326
- if ds_input != "" ||
327
- rp_input != ""
328
- t[:one] += "USER_INPUTS=["
329
- t[:one] += "VCENTER_DATASTORE=\"#{ds_input}\"," if ds_input != ""
330
- t[:one] += "RESOURCE_POOL=\"#{rp_input}\"," if rp_input != ""
331
- t[:one] = t[:one][0..-2]
332
- t[:one] += "]"
333
- end
334
-
335
- one_t = ::OpenNebula::Template.new(
336
- ::OpenNebula::Template.build_xml, vc.one)
337
-
338
- rc = one_t.allocate(t[:one])
339
-
340
- if ::OpenNebula.is_error?(rc)
341
- STDOUT.puts " Error creating template: #{rc.message}\n"
342
- else
343
- STDOUT.puts " OpenNebula template #{one_t.id} created!\n"
344
- end
345
- }
346
- }
347
- rescue Exception => e
348
- STDOUT.puts "error: #{e.message}"
349
- exit -1
350
- end
128
+ VCenterDriver::Importer.import_templates(con_ops, options)
351
129
 
352
130
  exit 0
353
131
  end
354
132
 
133
+ ############################################################################
134
+ # Import vms (deprecated)
135
+ ############################################################################
355
136
  vms_desc = <<-EOT.unindent
356
137
  Deprecated action in onevcenter, please use onehost importvm instead
357
138
  EOT
358
139
 
359
- command :vms, vms_desc, :options=>[ VCENTER, USER, PASS ] do
140
+ command :vms, vms_desc, :options=>[ VCENTER, USER, PASS, USE_DEFAULTS ] do
360
141
  STDERR.puts "Deprecated action in onevcenter, please use onehost "\
361
142
  "importvm instead"
362
-
363
143
  exit -1
364
144
  end
365
145
 
146
+ ############################################################################
147
+ # Import networks
148
+ ############################################################################
366
149
  network_desc = <<-EOT.unindent
367
150
  Import vCenter networks into OpenNebula
368
151
  EOT
369
152
 
370
- command :networks, network_desc, :options=>[ VCENTER, USER, PASS ] do
153
+ command :networks, network_desc, :options=>[ VCENTER, USER, PASS, USE_DEFAULTS ] do
371
154
  con_ops = connection_options("Networks", options)
372
155
 
373
- begin
374
- STDOUT.print "\nConnecting to vCenter: #{options[:vcenter]}..."
375
-
376
- vc = VCenterDriver::VIClient.new_connection(con_ops)
377
-
378
- STDOUT.print "done!\n\n"
379
-
380
- STDOUT.print "Looking for vCenter networks..."
381
-
382
- rs = vc.vcenter_networks
383
-
384
- STDOUT.print "done!\n"
385
-
386
- rs.each {|dc, tmps|
387
- STDOUT.print "\nDo you want to process datacenter #{dc} [y/n]? "
388
-
389
- next if STDIN.gets.strip.downcase != 'y'
390
-
391
- if tmps.empty?
392
- STDOUT.print " No new Networks found in #{dc}...\n\n"
393
- next
394
- end
395
-
396
- tmps.each{ |n|
397
- print_str = "\n * Network found:\n"\
398
- " - Name : #{n[:name]}\n"\
399
- " - Type : #{n[:type]}\n"
400
- print_str += " - VLAN ID : #{n[:vlan]}\n" if n[:vlan]
401
- print_str += " - Cluster : #{n[:cluster]}\n"
402
- print_str += " Import this Network [y/n]? "
403
-
404
- STDOUT.print print_str
405
-
406
- next if STDIN.gets.strip.downcase != 'y'
407
-
408
- # Size
409
-
410
- STDOUT.print " How many VMs are you planning"\
411
- " to fit into this network [255]? "
412
-
413
- size = STDIN.gets.strip
414
-
415
- size = "255" if size.to_i.to_s != size
416
-
417
- # Type
418
-
419
- STDOUT.print " What type of Virtual Network"\
420
- " do you want to create (IPv[4],IPv[6]"\
421
- ",[E]thernet) ?"
422
-
423
- type = STDIN.gets.strip
424
-
425
- ar_str = "\nAR=[TYPE=\""
426
-
427
- case type.downcase
428
- when "4"
429
- ar_str += "IP4\""
430
- STDOUT.print " Please input the first IP "\
431
- "in the range: "
432
- ip = STDIN.gets.strip
433
- ar_str += ",IP=" + ip
434
-
435
- STDOUT.print " Please input the first MAC "\
436
- "in the range [Enter for default]: "
437
- mac = STDIN.gets.strip
438
- ar_str += ",MAC=" + mac if !mac.empty?
439
- when "6"
440
- ar_str += "IP6\""
441
- STDOUT.print " Please input the first MAC "\
442
- "in the range [Enter for default]: "
443
- mac = STDIN.gets.strip
444
- ar_str += ",MAC=" + mac if !mac.empty?
445
-
446
- STDOUT.print " Please input the GLOBAL PREFIX "\
447
- "[Enter for default]: "
448
- gp = STDIN.gets.strip
449
- ar_str += ",GLOBAL_PREFIX=" + gp if !gp.empty?
450
-
451
- STDOUT.print " Please input the ULA PREFIX "\
452
- "[Enter for default]: "
453
- up = STDIN.gets.strip
454
- ar_str += ",ULA_PREFIX=" + up if !up.empty?
455
- when "e"
456
- ar_str += "ETHER\""
457
- STDOUT.print " Please input the first MAC "\
458
- "in the range [Enter for default]: "
459
- mac = STDIN.gets.strip
460
- ar_str += ",MAC=" + mac if !mac.empty?
461
- else
462
- STDOUT.puts " Type [#{type}] not supported,"\
463
- " defaulting to Ethernet."
464
- ar_str += "ETHER\""
465
- STDOUT.print " Please input the first MAC "\
466
- "in the range [Enter for default]: "
467
- mac = STDIN.gets.strip
468
- ar_str += ",MAC=" + mac if !mac.empty?
469
- end
470
-
471
- ar_str += ",SIZE = \"#{size}\"]"
472
-
473
- one_vn = ::OpenNebula::VirtualNetwork.new(
474
- ::OpenNebula::Template.build_xml, vc.one)
475
-
476
- vnet_template = n[:one] + ar_str
477
-
478
- rc = one_vn.allocate(vnet_template)
479
-
480
- if ::OpenNebula.is_error?(rc)
481
- STDOUT.puts " Error creating virtual network: " +
482
- " #{rc.message}\n"
483
- else
484
- STDOUT.puts " OpenNebula virtual network " +
485
- "#{one_vn.id} created with size #{size}!\n"
486
- end
487
- }
488
- }
489
- rescue Exception => e
490
- STDOUT.puts "error: #{e.message}"
491
- exit -1
492
- end
156
+ VCenterDriver::Importer.import_networks(con_ops, options)
493
157
 
494
158
  exit 0
495
159
  end
496
160
 
161
+ ############################################################################
162
+ # Import datastores
163
+ ############################################################################
497
164
  datastores_desc = <<-EOT.unindent
498
165
  Import vCenter Datastores into OpenNebula
499
166
  EOT
500
167
 
501
- command :datastores, datastores_desc, :options=>[ VCENTER, USER, PASS ] do
168
+ command :datastores, datastores_desc, :options=>[ VCENTER, USER, PASS, USE_DEFAULTS ] do
502
169
  con_ops = connection_options("Datastores", options)
503
170
 
504
- begin
505
- STDOUT.print "\nConnecting to vCenter: #{options[:vcenter]}..."
506
-
507
- vc = VCenterDriver::VIClient.new_connection(con_ops)
508
-
509
- STDOUT.print "done!\n\n"
510
-
511
- STDOUT.print "Looking for Datastores..."
512
-
513
- rs = vc.vcenter_datastores
514
-
515
- STDOUT.print "done!\n"
516
-
517
- rs.each {|dc, tmps|
518
- STDOUT.print "\nDo you want to process datacenter #{dc} [y/n]? "
519
-
520
- next if STDIN.gets.strip.downcase != 'y'
521
-
522
- if tmps.empty?
523
- STDOUT.print " No new Datastores found in #{dc}...\n\n"
524
- next
525
- end
526
-
527
- tmps.each{ |d|
528
- STDOUT.print "\n * Datastore found:\n"\
529
- " - Name : #{d[:name]}\n"\
530
- " - Total MB : #{d[:total_mb]}\n"\
531
- " - Free MB : #{d[:free_mb]}\n"\
532
- " - Cluster : #{d[:cluster]}\n"\
533
- " Import this Datastore [y/n]? "
534
-
535
- next if STDIN.gets.strip.downcase != 'y'
536
-
537
- one_d = ::OpenNebula::Datastore.new(
538
- ::OpenNebula::Datastore.build_xml, vc.one)
539
-
540
- rc = one_d.allocate(d[:one])
541
-
542
- if ::OpenNebula.is_error?(rc)
543
- STDOUT.puts " Error creating datastore: #{rc.message}\n"\
544
- " One datastore can exist only once, and "\
545
- "can be used in any vCenter Cluster that "\
546
- "has access to it. Also, no spaces allowed "\
547
- "in datastore name (rename it in vCenter "\
548
- "and try again)"
549
- else
550
- STDOUT.puts " OpenNebula datastore #{one_d.id} created!\n"
551
- end
552
- }
553
- }
554
- rescue Exception => e
555
- STDOUT.puts "error: #{e.message}"
556
- exit -1
557
- end
171
+ VCenterDriver::Importer.import_datastore(con_ops, options)
558
172
 
559
173
  exit 0
560
174
  end
561
175
 
176
+ ############################################################################
177
+ # Import images
178
+ ############################################################################
562
179
  images_desc = <<-EOT.unindent
563
180
  Import vCenter Images into OpenNebula
564
181
  EOT
565
182
 
566
- command :images, images_desc, :ds_name, :options=>[ VCENTER, USER, PASS ] do
183
+ command :images, images_desc, :ds_name, :options=>[ VCENTER, USER, PASS, USE_DEFAULTS ] do
567
184
  ds_name = args[0]
568
185
 
569
186
  if !ds_name
@@ -573,49 +190,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
573
190
 
574
191
  con_ops = connection_options("Images", options)
575
192
 
576
- begin
577
- STDOUT.print "\nConnecting to vCenter: #{options[:vcenter]}..."
578
-
579
- vc = VCenterDriver::VIClient.new_connection(con_ops)
580
-
581
- STDOUT.print "done!\n\n"
582
-
583
- STDOUT.print "Looking for Images..."
584
-
585
- images = vc.vcenter_images(ds_name)
586
-
587
- STDOUT.print "done!\n"
588
-
589
- images.each{ |i|
590
- STDOUT.print "\n * Image found:\n"\
591
- " - Name : #{i[:name]}\n"\
592
- " - Path : #{i[:path]}\n"\
593
- " - Type : #{i[:type]}\n"\
594
- " Import this Image [y/n]? "
595
-
596
- next if STDIN.gets.strip.downcase != 'y'
597
-
598
- one_i = ::OpenNebula::Image.new(
599
- ::OpenNebula::Image.build_xml, vc.one)
600
-
601
- rc = one_i.allocate(i[:one], i[:dsid].to_i)
602
-
603
- if ::OpenNebula.is_error?(rc)
604
- STDOUT.puts "Error creating image: #{rc.message}\n"
605
- if rc.message == "[ImageAllocate] Not enough space "\
606
- "in datastore"
607
- STDOUT.puts "Please disable DATASTORE_CAPACITY_"\
608
- "CHECK in /etc/one/oned.conf and "\
609
- "restart OpenNebula."
610
- end
611
- else
612
- STDOUT.puts " OpenNebula image #{one_i.id} created!\n"
613
- end
614
- }
615
- rescue Exception => e
616
- STDOUT.puts "error: #{e.message}"
617
- exit -1
618
- end
193
+ VCenterDriver::Importer.import_images(con_ops, ds_name, options)
619
194
 
620
195
  exit 0
621
196
  end