Search in sources :

Example 16 with ConnectionResources

use of io.cloudslang.content.vmware.connection.ConnectionResources in project cs-actions by CloudSlang.

the class ClusterComputeResourceService method createAffinityRule.

public Map<String, String> createAffinityRule(HttpInputs httpInputs, VmInputs vmInputs, String affineHostGroupName, String antiAffineHostGroupName) throws Exception {
    ConnectionResources connectionResources = new ConnectionResources(httpInputs);
    try {
        ManagedObjectReference clusterMor = new MorObjectHandler().getSpecificMor(connectionResources, connectionResources.getMorRootFolder(), ClusterParameter.CLUSTER_COMPUTE_RESOURCE.getValue(), vmInputs.getClusterName());
        if (ruleExists(getClusterConfiguration(connectionResources, clusterMor, vmInputs.getClusterName()), vmInputs.getRuleName())) {
            throw new Exception(String.format(RULE_ALREADY_EXISTS, vmInputs.getRuleName()));
        } else {
            ClusterVmHostRuleInfo clusterVmHostRuleInfo = getClusterVmHostRuleInfo(getClusterConfiguration(connectionResources, clusterMor, vmInputs.getClusterName()), vmInputs, affineHostGroupName, antiAffineHostGroupName);
            ClusterRuleSpec clusterRuleSpec = new ClusterRuleSpec();
            clusterRuleSpec.setInfo(clusterVmHostRuleInfo);
            clusterRuleSpec.setOperation(ArrayUpdateOperation.ADD);
            return reconfigureClusterRule(vmInputs, connectionResources, clusterMor, clusterRuleSpec);
        }
    } finally {
        if (httpInputs.isCloseSession()) {
            connectionResources.getConnection().disconnect();
            clearConnectionFromContext(httpInputs.getGlobalSessionObject());
        }
    }
}
Also used : ConnectionResources(io.cloudslang.content.vmware.connection.ConnectionResources) MorObjectHandler(io.cloudslang.content.vmware.services.helpers.MorObjectHandler)

Example 17 with ConnectionResources

use of io.cloudslang.content.vmware.connection.ConnectionResources in project cs-actions by CloudSlang.

the class GuestService method customizeVM.

/**
 * Method used to connect to specified data center and customize the windows OS based virtual machine identified
 * by the inputs provided.
 *
 * @param httpInputs  Object that has all the inputs necessary to made a connection to data center
 * @param vmInputs    Object that has all the specific inputs necessary to identify the targeted virtual machine
 * @param guestInputs Object that has all specific inputs necessary to customize specified virtual machine
 * @return Map with String as key and value that contains returnCode of the operation, success message with task id
 *         of the execution or failure message and the exception if there is one
 * @throws Exception
 */
public Map<String, String> customizeVM(HttpInputs httpInputs, VmInputs vmInputs, GuestInputs guestInputs, boolean isWin) throws Exception {
    ConnectionResources connectionResources = new ConnectionResources(httpInputs, vmInputs);
    try {
        ManagedObjectReference vmMor = new MorObjectHandler().getMor(connectionResources, ManagedObjectType.VIRTUAL_MACHINE.getValue(), vmInputs.getVirtualMachineName());
        if (vmMor != null) {
            CustomizationSpec customizationSpec = isWin ? new GuestConfigSpecs().getWinCustomizationSpec(guestInputs) : new GuestConfigSpecs().getLinuxCustomizationSpec(guestInputs);
            connectionResources.getVimPortType().checkCustomizationSpec(vmMor, customizationSpec);
            ManagedObjectReference task = connectionResources.getVimPortType().customizeVMTask(vmMor, customizationSpec);
            return new ResponseHelper(connectionResources, task).getResultsMap("Success: The [" + vmInputs.getVirtualMachineName() + "] VM was successfully customized. The taskId is: " + task.getValue(), "Failure: The [" + vmInputs.getVirtualMachineName() + "] VM could not be customized.");
        } else {
            return ResponseUtils.getVmNotFoundResultsMap(vmInputs);
        }
    } catch (Exception ex) {
        return ResponseUtils.getResultsMap(ex.toString(), Outputs.RETURN_CODE_FAILURE);
    } finally {
        if (httpInputs.isCloseSession()) {
            connectionResources.getConnection().disconnect();
            clearConnectionFromContext(httpInputs.getGlobalSessionObject());
        }
    }
}
Also used : CustomizationSpec(com.vmware.vim25.CustomizationSpec) ConnectionResources(io.cloudslang.content.vmware.connection.ConnectionResources) ResponseHelper(io.cloudslang.content.vmware.services.helpers.ResponseHelper) MorObjectHandler(io.cloudslang.content.vmware.services.helpers.MorObjectHandler) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) GuestConfigSpecs(io.cloudslang.content.vmware.services.utils.GuestConfigSpecs)

Example 18 with ConnectionResources

use of io.cloudslang.content.vmware.connection.ConnectionResources in project cs-actions by CloudSlang.

the class ClusterComputeResourceService method deleteClusterRule.

public Map<String, String> deleteClusterRule(HttpInputs httpInputs, VmInputs vmInputs) throws Exception {
    ConnectionResources connectionResources = new ConnectionResources(httpInputs);
    try {
        ManagedObjectReference clusterMor = new MorObjectHandler().getSpecificMor(connectionResources, connectionResources.getMorRootFolder(), ClusterParameter.CLUSTER_COMPUTE_RESOURCE.getValue(), vmInputs.getClusterName());
        List<ClusterRuleInfo> clusterRuleInfoList = getClusterConfiguration(connectionResources, clusterMor, vmInputs.getClusterName()).getRule();
        ClusterRuleInfo clusterRuleInfo = getClusterRuleInfo(clusterRuleInfoList, vmInputs.getRuleName());
        ClusterRuleSpec clusterRuleSpec = new ClusterRuleSpec();
        clusterRuleSpec.setInfo(clusterRuleInfo);
        clusterRuleSpec.setOperation(ArrayUpdateOperation.REMOVE);
        clusterRuleSpec.setRemoveKey(clusterRuleInfo.getKey());
        return reconfigureClusterRule(vmInputs, connectionResources, clusterMor, clusterRuleSpec);
    } finally {
        if (httpInputs.isCloseSession()) {
            connectionResources.getConnection().disconnect();
            clearConnectionFromContext(httpInputs.getGlobalSessionObject());
        }
    }
}
Also used : ConnectionResources(io.cloudslang.content.vmware.connection.ConnectionResources) MorObjectHandler(io.cloudslang.content.vmware.services.helpers.MorObjectHandler)

Example 19 with ConnectionResources

use of io.cloudslang.content.vmware.connection.ConnectionResources in project cs-actions by CloudSlang.

the class ClusterComputeResourceService method createVmGroup.

public Map<String, String> createVmGroup(HttpInputs httpInputs, VmInputs vmInputs, List<String> vmNameList) throws Exception {
    ConnectionResources connectionResources = new ConnectionResources(httpInputs);
    try {
        ClusterVmGroup clusterVmGroup = new ClusterVmGroup();
        clusterVmGroup.setName(vmInputs.getVmGroupName());
        clusterVmGroup.getVm().addAll(getVmManagedObjectReferences(vmNameList, connectionResources));
        return createGroup(vmInputs, connectionResources, clusterVmGroup);
    } finally {
        if (httpInputs.isCloseSession()) {
            connectionResources.getConnection().disconnect();
            clearConnectionFromContext(httpInputs.getGlobalSessionObject());
        }
    }
}
Also used : ConnectionResources(io.cloudslang.content.vmware.connection.ConnectionResources)

Example 20 with ConnectionResources

use of io.cloudslang.content.vmware.connection.ConnectionResources in project cs-actions by CloudSlang.

the class ClusterComputeResourceService method getVmOverride.

public String getVmOverride(final HttpInputs httpInputs, final VmInputs vmInputs) throws Exception {
    ConnectionResources connectionResources = new ConnectionResources(httpInputs, vmInputs);
    try {
        final ManagedObjectReference clusterMor = new MorObjectHandler().getSpecificMor(connectionResources, connectionResources.getMorRootFolder(), ClusterParameter.CLUSTER_COMPUTE_RESOURCE.getValue(), vmInputs.getClusterName());
        final ClusterConfigInfoEx clusterConfigInfoEx = getClusterConfiguration(connectionResources, clusterMor, vmInputs.getClusterName());
        final String restartPriority;
        if (StringUtilities.isNotBlank(vmInputs.getVirtualMachineId()) || StringUtilities.isNotBlank(vmInputs.getVirtualMachineName())) {
            final ManagedObjectReference vmMor = getVirtualMachineReference(vmInputs, connectionResources);
            restartPriority = getVmRestartPriority(clusterConfigInfoEx, vmMor);
        } else {
            restartPriority = getVmRestartPriority(clusterConfigInfoEx);
        }
        return restartPriority;
    } finally {
        if (httpInputs.isCloseSession()) {
            connectionResources.getConnection().disconnect();
            clearConnectionFromContext(httpInputs.getGlobalSessionObject());
        }
    }
}
Also used : ConnectionResources(io.cloudslang.content.vmware.connection.ConnectionResources) MorObjectHandler(io.cloudslang.content.vmware.services.helpers.MorObjectHandler)

Aggregations

ConnectionResources (io.cloudslang.content.vmware.connection.ConnectionResources)21 MorObjectHandler (io.cloudslang.content.vmware.services.helpers.MorObjectHandler)17 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)12 ResponseHelper (io.cloudslang.content.vmware.services.helpers.ResponseHelper)8 VmUtils (io.cloudslang.content.vmware.services.utils.VmUtils)3 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)2 VmConfigSpecs (io.cloudslang.content.vmware.services.utils.VmConfigSpecs)2 CustomizationSpec (com.vmware.vim25.CustomizationSpec)1 DynamicProperty (com.vmware.vim25.DynamicProperty)1 GuestOsDescriptor (com.vmware.vim25.GuestOsDescriptor)1 HttpNfcLeaseDeviceUrl (com.vmware.vim25.HttpNfcLeaseDeviceUrl)1 HttpNfcLeaseInfo (com.vmware.vim25.HttpNfcLeaseInfo)1 ObjectContent (com.vmware.vim25.ObjectContent)1 OvfCreateImportSpecResult (com.vmware.vim25.OvfCreateImportSpecResult)1 VirtualMachineCloneSpec (com.vmware.vim25.VirtualMachineCloneSpec)1 VirtualMachineConfigOption (com.vmware.vim25.VirtualMachineConfigOption)1 VirtualMachineConfigSummary (com.vmware.vim25.VirtualMachineConfigSummary)1 VirtualMachineRelocateSpec (com.vmware.vim25.VirtualMachineRelocateSpec)1 VirtualMachineSummary (com.vmware.vim25.VirtualMachineSummary)1 AsyncProgressUpdater (io.cloudslang.content.vmware.entities.AsyncProgressUpdater)1