Source:
<code>protected void executeCommand() { VM vm = getVm(); if (vm.getClusterId().equals(getParameters().getClusterId())) { setSucceeded(true); return; } List<Network> networks = getNetworkDao().getAllForCluster(getParameters().getClusterId()); List<VmNic> interfaces = getVmNicDao().getAllForVm(getParameters().getVmId()); for (final VmNic iface : interfaces) { if (iface.getVnicProfileId() != null) { final Network network = NetworkHelper.getNetworkByVnicProfileId(iface.getVnicProfileId()); boolean networkFoundInCluster = networks.stream().anyMatch(n -> Objects.equals(n.getId(), network.getId())); if (!networkFoundInCluster) { iface.setVnicProfileId(null); getVmNicDao().update(iface); } } } if (vm.getDedicatedVmForVdsList().size() > 0) { vm.setDedicatedVmForVdsList(Collections.<Guid>emptyList()); dedicatedHostWasCleared = true; } vm.setClusterId(getParameters().getClusterId()); <START> CpuProfile cpuProfile = getCpuProfileDao().getAllForCluster( vm.getClusterId(), getUserId(), true, ActionGroup.ASSIGN_CPU_PROFILE).get(0); vm.setCpuProfileId(cpuProfile.getId()); <END> getVmStaticDao().update(vm.getStaticData()); List<AffinityGroup> allAffinityGroupsByVmId = DbFacade.getInstance().getAffinityGroupDao().getAllAffinityGroupsByVmId(vm.getId()); if (!allAffinityGroupsByVmId.isEmpty()) { StringBuilder sb = new StringBuilder(); for (AffinityGroup affinityGroup : allAffinityGroupsByVmId) { sb.append(affinityGroup.getName() + " "); } log.info("Due to cluster change, removing VM from associated affinity group(s): {}", sb); DbFacade.getInstance().getAffinityGroupDao().removeVmFromAffinityGroups(vm.getId()); } setSucceeded(true); }</code><technical_language>org.ovirt.engine.core.bll.profiles.CpuProfileHelper#setAndValidateCpuProfileForUser and/or org.ovirt.engine.core.bll.profiles.CpuProfileHelper#assignFirstCpuProfile</technical_language>

Target:
protected void executeCommand() { VM vm = getVm(); if (vm.getClusterId().equals(getParameters().getClusterId())) { setSucceeded(true); return; } List<Network> networks = getNetworkDao().getAllForCluster(getParameters().getClusterId()); List<VmNic> interfaces = getVmNicDao().getAllForVm(getParameters().getVmId()); for (final VmNic iface : interfaces) { if (iface.getVnicProfileId() != null) { final Network network = NetworkHelper.getNetworkByVnicProfileId(iface.getVnicProfileId()); boolean networkFoundInCluster = networks.stream().anyMatch(n -> Objects.equals(n.getId(), network.getId())); if (!networkFoundInCluster) { iface.setVnicProfileId(null); getVmNicDao().update(iface); } } } if (vm.getDedicatedVmForVdsList().size() > 0) { vm.setDedicatedVmForVdsList(Collections.<Guid>emptyList()); dedicatedHostWasCleared = true; } vm.setClusterId(getParameters().getClusterId()); CpuProfileHelper.assignFirstCpuProfile(vm.getStaticData(), getUserId()); getVmStaticDao().update(vm.getStaticData()); List<AffinityGroup> allAffinityGroupsByVmId = DbFacade.getInstance().getAffinityGroupDao().getAllAffinityGroupsByVmId(vm.getId()); if (!allAffinityGroupsByVmId.isEmpty()) { StringBuilder sb = new StringBuilder(); for (AffinityGroup affinityGroup : allAffinityGroupsByVmId) { sb.append(affinityGroup.getName() + " "); } log.info("Due to cluster change, removing VM from associated affinity group(s): {}", sb); DbFacade.getInstance().getAffinityGroupDao().removeVmFromAffinityGroups(vm.getId()); } setSucceeded(true); }