<commit_before>package com.toastcoders.VmOpsTools.vmware.Virtualmachine

import com.toastcoders.VmOpsTools.vmware.Client
import com.toastcoders.VmOpsTools.exceptions.MigrationNotPossible
import com.vmware.vim25.HostVMotionCompatibility
import com.vmware.vim25.VirtualMachineMovePriority
import com.vmware.vim25.mo.ComputeResource
import com.vmware.vim25.mo.HostSystem
import com.vmware.vim25.mo.Task
import com.vmware.vim25.mo.VirtualMachine
import org.apache.log4j.Logger

/**
 * Created with IntelliJ IDEA.
 * User: <NAME>
 * Twitter: @errr_
 * Website: http://www.errr-online.com/
 * Github: https://github.com/michaelrice
 * Date: 10/5/13
 * Time: 7:30 PM
 * Licenses: MIT http://opensource.org/licenses/MIT
 */
class Migrate {

    private Logger log = Logger.getLogger(getClass().name)
    private Client client
    /**
     *
     * @param deviceId
     */
    Migrate(Client client) {
        this.client = client
    }

    /**
     * migrate virtualmachine from its current host to another host.
     * @param vmuuid UUID of Virtualmachine device you want to move
     * @param newHostUuid UUID of the new Hostsystem you want to move the virtualmachine to
     * @return Boolean Returns true if the migration was a success
     * @throws MigrationNotPossible Thrown if the task was anything other than SUCCESS
     */
    public Boolean migrate(String vmuuid, String newHostUuid) throws MigrationNotPossible {
        log.trace("Migration job request. Move ${vmuuid} to ${newHostUuid}")
        VirtualMachine vm = client.getVmByUuid(vmuuid) as VirtualMachine
        HostSystem newHost  = client.getHostSystemByUuid(newHostUuid) as HostSystem
        HostSystem[] newHostArray = [newHost]
        ComputeResource cr = newHost.getParent() as ComputeResource
        String[] checks = ["cpu", "software"]
        HostVMotionCompatibility[] vmcs = client.serviceInstance.queryVMotionCompatibility(vm,newHostArray,checks)
        String[] comps = vmcs[0].getCompatibility()
        if(checks.length != comps.length) {
            log.trace("CPU or Software not compatible. Unable to complete migration request.")
            //uh oh. System not Compatible
            throw new MigrationNotPossible("CPU or Software not compatible.")
        }
        Task task = vm.migrateVM_Task(cr.resourcePool, newHost,
                VirtualMachineMovePriority.highPriority,
                vm.getRuntime().powerState)
        if(task.waitForTask() != Task.SUCCESS) {
            log.trace("Migration task was unsuccessful. ${task.getTaskInfo().error.fault}")
            throw new MigrationNotPossible("Something failed. ${task.getTaskInfo().error.fault}")
        }
        log.trace("Migration task successful.")
        return true
    }
}<commit_msg>migrate changes<commit_after>package com.toastcoders.VmOpsTools.vmware.Virtualmachine

import com.toastcoders.VmOpsTools.vmware.Client
import com.toastcoders.VmOpsTools.exceptions.MigrationNotPossible
import com.vmware.vim25.HostVMotionCompatibility
import com.vmware.vim25.VirtualMachineMovePriority
import com.vmware.vim25.mo.ComputeResource
import com.vmware.vim25.mo.HostSystem
import com.vmware.vim25.mo.Task
import com.vmware.vim25.mo.VirtualMachine
import org.apache.log4j.Logger

/**
 * Created with IntelliJ IDEA.
 * User: <NAME>
 * Twitter: @errr_
 * Website: http://www.errr-online.com/
 * Github: https://github.com/michaelrice
 * Date: 10/5/13
 * Time: 7:30 PM
 * Licenses: MIT http://opensource.org/licenses/MIT
 */
class Migrate {

    private Logger log = Logger.getLogger(getClass().name)
    private Client client
    /**
     *
     * @param deviceId
     */
    Migrate(Client client) {
        this.client = client
    }

    /**
     * migrate virtualmachine from its current host to another host.
     * @param vmUuid UUID of Virtualmachine device you want to move
     * @param newHostUuid UUID of the new Hostsystem you want to move the virtualmachine to
     * @return Boolean Returns true if the migration was a success
     * @throws MigrationNotPossible Thrown if the task was anything other than SUCCESS
     */
    public Boolean migrate(String vmUuid, String newHostUuid) throws MigrationNotPossible {
        log.trace("Migration job request. Move ${vmUuid} to ${newHostUuid}")
        VirtualMachine vm = client.getVmByUuid(vmUuid) as VirtualMachine
        HostSystem newHost  = client.getHostSystemByUuid(newHostUuid) as HostSystem
        HostSystem[] newHostArray = [newHost]
        ComputeResource cr = newHost.getParent() as ComputeResource
        String[] checks = ["cpu", "software"]
        HostVMotionCompatibility[] vmcs = client.serviceInstance.queryVMotionCompatibility(vm,newHostArray,checks)
        String[] comps = vmcs[0].getCompatibility()
        if(checks.length != comps.length) {
            log.trace("CPU or Software not compatible. Unable to complete migration request.")
            //uh oh. System not Compatible
            throw new MigrationNotPossible("CPU or Software not compatible.")
        }
        Task task = vm.migrateVM_Task(cr.resourcePool, newHost,
                VirtualMachineMovePriority.highPriority,
                vm.getRuntime().powerState)
        if(task.waitForTask() != Task.SUCCESS) {
            log.trace("Migration task was unsuccessful. ${task.getTaskInfo().error.fault}")
            throw new MigrationNotPossible("Something failed. ${task.getTaskInfo().error.fault}")
        }
        log.trace("Migration task successful.")
        return true
    }
}
{'fraction_non_alphanumeric': 0.0955321467490011, 'fraction_numerical': 0.007991282237559027, 'mean_word_length': 3.2166921898928025, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7664865', 'n_tokens_mistral': 1637, 'n_tokens_neox': 1570, 'n_words': 399}