Search in sources :

Example 1 with ClusterDasVmConfigInfo

use of com.vmware.vim25.ClusterDasVmConfigInfo in project cloudstack by apache.

the class ClusterMO method getRestartPriorityForVM.

private String getRestartPriorityForVM(VirtualMachineMO vmMo) throws Exception {
    if (vmMo == null) {
        s_logger.debug("Failed to get restart priority for VM, invalid VM object reference");
        return null;
    }
    ManagedObjectReference vmMor = vmMo.getMor();
    if (vmMor == null || !vmMor.getType().equals("VirtualMachine")) {
        s_logger.debug("Failed to get restart priority for VM: " + vmMo.getName() + ", invalid VM object reference");
        return null;
    }
    ClusterConfigInfoEx configInfo = getClusterConfigInfo();
    if (configInfo == null) {
        s_logger.debug("Failed to get restart priority for VM: " + vmMo.getName() + ", no cluster config information");
        return null;
    }
    List<ClusterDasVmConfigInfo> dasVmConfig = configInfo.getDasVmConfig();
    for (int dasVmConfigIndex = 0; dasVmConfigIndex < dasVmConfig.size(); dasVmConfigIndex++) {
        ClusterDasVmConfigInfo dasVmConfigInfo = dasVmConfig.get(dasVmConfigIndex);
        if (dasVmConfigInfo != null && dasVmConfigInfo.getKey().getValue().equals(vmMor.getValue())) {
            DasVmPriority dasVmPriority = dasVmConfigInfo.getRestartPriority();
            if (dasVmPriority != null) {
                return dasVmPriority.value();
            } else {
                //VM uses cluster restart priority when DasVmPriority for the VM is null.
                return ClusterDasVmSettingsRestartPriority.CLUSTER_RESTART_PRIORITY.value();
            }
        }
    }
    s_logger.debug("VM: " + vmMo.getName() + " uses default restart priority in the cluster: " + getName());
    return null;
}
Also used : ClusterConfigInfoEx(com.vmware.vim25.ClusterConfigInfoEx) ClusterDasVmConfigInfo(com.vmware.vim25.ClusterDasVmConfigInfo) DasVmPriority(com.vmware.vim25.DasVmPriority) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 2 with ClusterDasVmConfigInfo

use of com.vmware.vim25.ClusterDasVmConfigInfo 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));
    }
}
Also used : ClusterDasVmConfigInfo(com.vmware.vim25.ClusterDasVmConfigInfo) ClusterDasConfigInfo(com.vmware.vim25.ClusterDasConfigInfo) ClusterDasVmConfigSpec(com.vmware.vim25.ClusterDasVmConfigSpec) ClusterDasVmSettings(com.vmware.vim25.ClusterDasVmSettings) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) ClusterConfigSpecEx(com.vmware.vim25.ClusterConfigSpecEx)

Aggregations

ClusterDasVmConfigInfo (com.vmware.vim25.ClusterDasVmConfigInfo)2 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)2 ClusterConfigInfoEx (com.vmware.vim25.ClusterConfigInfoEx)1 ClusterConfigSpecEx (com.vmware.vim25.ClusterConfigSpecEx)1 ClusterDasConfigInfo (com.vmware.vim25.ClusterDasConfigInfo)1 ClusterDasVmConfigSpec (com.vmware.vim25.ClusterDasVmConfigSpec)1 ClusterDasVmSettings (com.vmware.vim25.ClusterDasVmSettings)1 DasVmPriority (com.vmware.vim25.DasVmPriority)1