216 |
216 |
end
|
217 |
217 |
|
218 |
218 |
vms_desc = <<-EOT.unindent
|
219 |
|
Import vCenter running Virtual Machines into OpenNebula
|
|
219 |
Deprecated action in onevcenter, please use onehost importvm instead
|
220 |
220 |
EOT
|
221 |
221 |
|
222 |
222 |
command :vms, vms_desc, :options=>[ VCENTER, USER, PASS ] do
|
223 |
|
if options[:vuser].nil? ||
|
224 |
|
options[:vpass].nil? ||
|
225 |
|
options[:vcenter].nil?
|
226 |
|
STDERR.puts "vCenter connection parameters are mandatory to import"\
|
227 |
|
" VM templates:\n"\
|
228 |
|
"\t --vcenter vCenter hostname\n"\
|
229 |
|
"\t --vuser username to login in vcenter\n"\
|
230 |
|
"\t --vpass password for the user"
|
231 |
|
exit -1
|
232 |
|
end
|
233 |
|
|
234 |
|
begin
|
235 |
|
STDOUT.print "\nConnecting to vCenter: #{options[:vcenter]}..."
|
236 |
|
|
237 |
|
vc = VCenterDriver::VIClient.new_connection(
|
238 |
|
:user => options[:vuser],
|
239 |
|
:password => options[:vpass],
|
240 |
|
:host => options[:vcenter])
|
241 |
|
|
242 |
|
STDOUT.print "done!\n\n"
|
243 |
|
|
244 |
|
STDOUT.print "Looking for running Virtual Machines..."
|
245 |
|
|
246 |
|
rs = vc.running_vms
|
247 |
|
|
248 |
|
STDOUT.print "done!\n"
|
249 |
|
|
250 |
|
rs.each {|dc, tmps|
|
251 |
|
STDOUT.print "\nDo you want to process datacenter #{dc} [y/n]? "
|
|
223 |
STDERR.puts "Deprecated action in onevcenter, please use onehost "\
|
|
224 |
"importvm instead"
|
252 |
225 |
|
253 |
|
next if STDIN.gets.strip.downcase != 'y'
|
254 |
|
|
255 |
|
if tmps.empty?
|
256 |
|
STDOUT.print " No new running Virtual Machines found in"\
|
257 |
|
" #{dc}...\n\n"
|
258 |
|
next
|
259 |
|
end
|
260 |
|
|
261 |
|
tmps.each{ |v|
|
262 |
|
STDOUT.print "\n * Running Virtual Machine found:\n"\
|
263 |
|
" - Name : #{v[:name]}\n"\
|
264 |
|
" - UUID : #{v[:uuid]}\n"\
|
265 |
|
" - Cluster: #{v[:host]}\n"\
|
266 |
|
" Import this Virtual Machine [y/n]? "
|
267 |
|
|
268 |
|
next if STDIN.gets.strip.downcase != 'y'
|
269 |
|
|
270 |
|
one_v = ::OpenNebula::VirtualMachine.new(
|
271 |
|
::OpenNebula::VirtualMachine.build_xml, vc.one)
|
272 |
|
|
273 |
|
rc = one_v.allocate(v[:one])
|
274 |
|
|
275 |
|
if ::OpenNebula.is_error?(rc)
|
276 |
|
STDOUT.puts " Error creating Virtual Machine: "\
|
277 |
|
"#{rc.message}\n"
|
278 |
|
end
|
279 |
|
|
280 |
|
rc = one_v.deploy v[:host_id]
|
281 |
|
|
282 |
|
if ::OpenNebula.is_error?(rc)
|
283 |
|
STDOUT.puts " Error creating Virtual Machine: "\
|
284 |
|
"#{rc.message}\n"
|
285 |
|
else
|
286 |
|
STDOUT.puts " OpenNebula VM #{one_v.id} "\
|
287 |
|
"created!\n"
|
288 |
|
end
|
289 |
|
}
|
290 |
|
}
|
291 |
|
rescue Exception => e
|
292 |
|
STDOUT.puts "error: #{e.message}"
|
293 |
|
exit -1
|
294 |
|
end
|
295 |
|
|
296 |
|
exit 0
|
|
226 |
exit -1
|
297 |
227 |
end
|
298 |
228 |
|
299 |
229 |
network_desc = <<-EOT.unindent
|