use of com.vmware.vim25.ClusterDasConfigInfo in project cloudstack by apache.
the class ClusterMO method setRestartPriorityForVM.
@Override
public void setRestartPriorityForVM(VirtualMachineMO vmMo, String priority) throws Exception {
if (vmMo == null || StringUtils.isBlank(priority)) {
return;
}
if (!isHAEnabled()) {
s_logger.debug("Couldn't set restart priority for VM: " + vmMo.getName() + ", HA disabled in the cluster");
return;
}
ManagedObjectReference vmMor = vmMo.getMor();
if (vmMor == null || !vmMor.getType().equals("VirtualMachine")) {
s_logger.debug("Failed to set restart priority for VM: " + vmMo.getName() + ", invalid VM object reference");
return;
}
String currentVmRestartPriority = getRestartPriorityForVM(vmMo);
if (StringUtils.isNotBlank(currentVmRestartPriority) && currentVmRestartPriority.equalsIgnoreCase(priority)) {
return;
}
ClusterDasVmSettings clusterDasVmSettings = new ClusterDasVmSettings();
clusterDasVmSettings.setRestartPriority(priority);
ClusterDasVmConfigInfo clusterDasVmConfigInfo = new ClusterDasVmConfigInfo();
clusterDasVmConfigInfo.setKey(vmMor);
clusterDasVmConfigInfo.setDasSettings(clusterDasVmSettings);
ClusterDasVmConfigSpec clusterDasVmConfigSpec = new ClusterDasVmConfigSpec();
clusterDasVmConfigSpec.setOperation((StringUtils.isNotBlank(currentVmRestartPriority)) ? ArrayUpdateOperation.EDIT : ArrayUpdateOperation.ADD);
clusterDasVmConfigSpec.setInfo(clusterDasVmConfigInfo);
ClusterConfigSpecEx clusterConfigSpecEx = new ClusterConfigSpecEx();
ClusterDasConfigInfo clusterDasConfigInfo = new ClusterDasConfigInfo();
clusterConfigSpecEx.setDasConfig(clusterDasConfigInfo);
clusterConfigSpecEx.getDasVmConfigSpec().add(clusterDasVmConfigSpec);
ManagedObjectReference morTask = _context.getService().reconfigureComputeResourceTask(_mor, clusterConfigSpecEx, true);
boolean result = _context.getVimClient().waitForTask(morTask);
if (result) {
_context.waitForTaskProgressDone(morTask);
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - setRestartPriority done(successfully)");
} else {
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - setRestartPriority done(failed)");
s_logger.error("Set restart priority failed for VM: " + vmMo.getName() + " due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
}
Aggregations