1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

F #4913: Add Wild VMs import, images and vnets created for VM's disk and nics

This commit is contained in:
mcabrerizo 2017-04-12 09:15:45 +02:00
parent 906404aa9c
commit 7343c80fe3
4 changed files with 63 additions and 7 deletions

View File

@ -223,12 +223,23 @@ module OpenNebula
xml = OpenNebula::VirtualMachine.build_xml
vm = OpenNebula::VirtualMachine.new(xml, @client)
rc = vm.allocate(template)
# vCenter wild VMs has a different process
# image and vnets objects representing existing nics and disks
# must be created and referenced
vcenter_wild_vm = wild.key? "VCENTER_TEMPLATE"
if vcenter_wild_vm
require 'vcenter_driver'
host_id = self["ID"]
vm_ref = wild["DEPLOY_ID"]
return VCenterDriver::Importer.import_wild(host_id, vm_ref, vm, template)
else
rc = vm.allocate(template)
return rc if OpenNebula.is_error?(rc)
return rc if OpenNebula.is_error?(rc)
vm.deploy(id, false)
return vm.id
vm.deploy(id, false)
return vm.id
end
end
#######################################################################

View File

@ -484,7 +484,7 @@ class ClusterComputeResource
if number == -1
vm_template_64 = Base64.encode64(vm.vm_to_one(vm_name)).gsub("\n","")
str_info << "VCENTER_TEMPLATE=\"YES\","
str_info << "IMPORT_TEMPLATE=\"#{vm_template_64}\","
end

View File

@ -2,6 +2,51 @@ module VCenterDriver
class Importer
def self.import_wild(host_id, vm_ref, one_vm, template)
begin
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
vc_uuid = vi_client.vim.serviceContent.about.instanceUuid
dc_name = vi_client.vim.host
dpool = VCenterDriver::VIHelper.one_pool(OpenNebula::DatastorePool)
ipool = VCenterDriver::VIHelper.one_pool(OpenNebula::ImagePool)
npool = VCenterDriver::VIHelper.one_pool(OpenNebula::VirtualNetworkPool)
vcenter_vm = VCenterDriver::VirtualMachine.new_from_ref(vm_ref, vi_client)
error, template_disks = vcenter_vm.import_vcenter_disks(vc_uuid, dpool, ipool)
return OpenNebula::Error.new(error) if !error.empty?
template << template_disks
# Create images or get nics information for template
error, template_nics = vcenter_vm.import_vcenter_nics(vc_uuid, npool, dc_name)
return OpenNebula::Error.new(error) if !error.empty?
template << template_nics
rc = one_vm.allocate(template)
return rc if OpenNebula.is_error?(rc)
one_vm.deploy(host_id, false)
# Set reference to template disks and nics in VM template
vcenter_vm.one_item = one_vm
vcenter_vm.reference_imported_disks(vm_ref)
vcenter_vm.reference_imported_nics
return one_vm.id
rescue Exception => e
vi_client.close_connection if vi_client
return OpenNebula::Error.new(e.message)
end
end
def self.import_clusters(con_ops, options)
begin
STDOUT.print "\nConnecting to vCenter: #{options[:vcenter]}..."

View File

@ -471,12 +471,12 @@ class Template
"vCPU = \"#{@vm_info["config.hardware.numCPU"]}\"\n"\
"MEMORY = \"#{@vm_info["config.hardware.memoryMB"]}\"\n"\
"HYPERVISOR = \"vcenter\"\n"\
"SCHED_REQUIREMENTS=\"ID=\\\"#{@vm_info["host_id"]}\\\"\"\n"\
"SCHED_REQUIREMENTS=\"ID=\\\"#{@vm_info[:host_id]}\\\"\"\n"\
"CONTEXT = [\n"\
" NETWORK = \"YES\",\n"\
" SSH_PUBLIC_KEY = \"$USER[SSH_PUBLIC_KEY]\"\n"\
"]\n"\
"VCENTER_INSTANCE_ID =\"#{@vm_info["vc_uuid"]}\"\n"
"VCENTER_INSTANCE_ID =\"#{@vm_info[:vc_uuid]}\"\n"
str << "IMPORT_VM_ID =\"#{self["_ref"]}\"\n"
str << "IMPORT_STATE =\"#{@state}\"\n"