<commit_before>module VCenterDriver

class Importer

VNC_ESX_HOST_FOLDER = "/tmp"

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
        vc_name   = vi_client.vim.host

        dpool = VCenterDriver::VIHelper.one_pool(OpenNebula::DatastorePool)
        if dpool.respond_to?(:message)
            raise "Could not get OpenNebula DatastorePool: #{dpool.message}"
        end
        ipool = VCenterDriver::VIHelper.one_pool(OpenNebula::ImagePool)
        if ipool.respond_to?(:message)
            raise "Could not get OpenNebula ImagePool: #{ipool.message}"
        end
        npool = VCenterDriver::VIHelper.one_pool(OpenNebula::VirtualNetworkPool)
        if npool.respond_to?(:message)
            raise "Could not get OpenNebula VirtualNetworkPool: #{npool.message}"
        end
        hpool = VCenterDriver::VIHelper.one_pool(OpenNebula::HostPool)
        if hpool.respond_to?(:message)
            raise "Could not get OpenNebula HostPool: #{hpool.message}"
        end

        vcenter_vm = VCenterDriver::VirtualMachine.new_from_ref(vm_ref, vi_client)
        vm_name    = vcenter_vm["name"]

        wild     = true
        sunstone = false

        #error, template_disks = vcenter_vm.import_vcenter_disks(vc_uuid, dpool, ipool, sunstone)
        #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,
        #                                                      hpool,
        #                                                      vc_name,
        #                                                      vm_ref,
        #                                                      wild,
        #                                                      sunstone,
        #                                                      vm_name)
        #
        #return OpenNebula::Error.new(error) if !error.empty?

        #template << template_nics

        # Get DS_ID for the deployment, the wild VM needs a System DS
        dc_ref = vcenter_vm.get_dc.item._ref
        ds_ref = template.match(/^VCENTER_DS_REF *= *"(.*)" *$/)[1]

        ds_one = dpool.select do |e|
            e["TEMPLATE/TYPE"]                == "SYSTEM_DS" &&
            e["TEMPLATE/VCENTER_DS_REF"]      == ds_ref &&<commit_msg>Feature #5247: Enable disc and nic import for wild vms<commit_after>module VCenterDriver

class Importer

VNC_ESX_HOST_FOLDER = "/tmp"

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
        vc_name   = vi_client.vim.host

        dpool = VCenterDriver::VIHelper.one_pool(OpenNebula::DatastorePool)
        if dpool.respond_to?(:message)
            raise "Could not get OpenNebula DatastorePool: #{dpool.message}"
        end
        ipool = VCenterDriver::VIHelper.one_pool(OpenNebula::ImagePool)
        if ipool.respond_to?(:message)
            raise "Could not get OpenNebula ImagePool: #{ipool.message}"
        end
        npool = VCenterDriver::VIHelper.one_pool(OpenNebula::VirtualNetworkPool)
        if npool.respond_to?(:message)
            raise "Could not get OpenNebula VirtualNetworkPool: #{npool.message}"
        end
        hpool = VCenterDriver::VIHelper.one_pool(OpenNebula::HostPool)
        if hpool.respond_to?(:message)
            raise "Could not get OpenNebula HostPool: #{hpool.message}"
        end

        vcenter_vm = VCenterDriver::VirtualMachine.new_from_ref(vm_ref, vi_client)
        vm_name    = vcenter_vm["name"]

        wild     = true
        sunstone = false

        error, template_disks = vcenter_vm.import_vcenter_disks(vc_uuid, dpool, ipool, sunstone)
        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,
                                                              hpool,
                                                              vc_name,
                                                              vm_ref,
                                                              wild,
                                                              sunstone,
                                                              vm_name)
        
        return OpenNebula::Error.new(error) if !error.empty?

        template << template_nics

        # Get DS_ID for the deployment, the wild VM needs a System DS
        dc_ref = vcenter_vm.get_dc.item._ref
        ds_ref = template.match(/^VCENTER_DS_REF *= *"(.*)" *$/)[1]

        ds_one = dpool.select do |e|
            e["TEMPLATE/TYPE"]                == "SYSTEM_DS" &&
            e["TEMPLATE/VCENTER_DS_REF"]      == ds_ref &&
{'fraction_non_alphanumeric': 0.08417830495504114, 'fraction_numerical': 0.0011478859766596518, 'mean_word_length': 1.5932539682539681, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4933770', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1432, 'n_words': 281}