Search in sources :

Example 1 with ConnectionResources

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

the class ClusterComputeResourceService method deleteVmGroup.

public Map<String, String> deleteVmGroup(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());
        ClusterVmGroup clusterVmGroup = new ClusterVmGroup();
        clusterVmGroup.setName(vmInputs.getVmGroupName());
        ClusterGroupSpec clusterGroupSpec = new ClusterGroupSpec();
        clusterGroupSpec.setInfo(clusterVmGroup);
        clusterGroupSpec.setOperation(ArrayUpdateOperation.REMOVE);
        clusterGroupSpec.setRemoveKey(vmInputs.getVmGroupName());
        return reconfigureClusterGroup(vmInputs, connectionResources, clusterMor, clusterGroupSpec);
    } 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 2 with ConnectionResources

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

the class ClusterComputeResourceService method listGroups.

public String listGroups(HttpInputs httpInputs, String clusterName, String delimiter, Class clazz) throws Exception {
    ConnectionResources connectionResources = new ConnectionResources(httpInputs);
    try {
        ManagedObjectReference clusterMor = new MorObjectHandler().getSpecificMor(connectionResources, connectionResources.getMorRootFolder(), ClusterParameter.CLUSTER_COMPUTE_RESOURCE.getValue(), clusterName);
        ClusterConfigInfoEx clusterConfigInfoEx = getClusterConfiguration(connectionResources, clusterMor, clusterName);
        List<String> groupNameList = new ArrayList<>();
        for (ClusterGroupInfo clusterGroupInfo : clusterConfigInfoEx.getGroup()) {
            if (clusterGroupInfo.getClass().isAssignableFrom(clazz)) {
                groupNameList.add(clusterGroupInfo.getName());
            }
        }
        return StringUtilities.join(groupNameList, delimiter);
    } finally {
        if (httpInputs.isCloseSession()) {
            connectionResources.getConnection().disconnect();
            clearConnectionFromContext(httpInputs.getGlobalSessionObject());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ConnectionResources(io.cloudslang.content.vmware.connection.ConnectionResources) MorObjectHandler(io.cloudslang.content.vmware.services.helpers.MorObjectHandler)

Example 3 with ConnectionResources

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

the class GuestService method mountTools.

/**
 * Method used to connect to specified data center and start the Install Tools process on 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
 * @return Map with String as key and value that contains returnCode of the operation, success message or failure
 *         message and the exception if there is one
 * @throws Exception
 */
public Map<String, String> mountTools(HttpInputs httpInputs, VmInputs vmInputs) throws Exception {
    ConnectionResources connectionResources = new ConnectionResources(httpInputs, vmInputs);
    try {
        ManagedObjectReference vmMor = new MorObjectHandler().getMor(connectionResources, ManagedObjectType.VIRTUAL_MACHINE.getValue(), vmInputs.getVirtualMachineName());
        if (vmMor != null) {
            connectionResources.getVimPortType().mountToolsInstaller(vmMor);
            return ResponseUtils.getResultsMap(INITIATED_TOOLS_INSTALLER_MOUNT + vmInputs.getVirtualMachineName(), Outputs.RETURN_CODE_SUCCESS);
        } 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 : ConnectionResources(io.cloudslang.content.vmware.connection.ConnectionResources) MorObjectHandler(io.cloudslang.content.vmware.services.helpers.MorObjectHandler) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 4 with ConnectionResources

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

the class ClusterComputeResourceService method updateOrAddVmOverride.

/**
 * Das method looks into das Cluster’s list of VM overrides to update das VM’s restartPriority value.
 * If a VM override is found, das value will be updated, otherwise a new “override” will be created and added to das list.
 *
 * @param httpInputs
 * @param vmInputs
 * @param restartPriority
 * @return
 * @throws Exception
 */
public Map<String, String> updateOrAddVmOverride(final HttpInputs httpInputs, final VmInputs vmInputs, final String restartPriority) throws Exception {
    final ConnectionResources connectionResources = new ConnectionResources(httpInputs, vmInputs);
    try {
        final ManagedObjectReference vmMor = getVirtualMachineReference(vmInputs, connectionResources);
        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 ClusterDasVmConfigSpec clusterDasVmConfigSpec = getClusterVmConfiguration(clusterConfigInfoEx, vmMor, restartPriority);
        final ManagedObjectReference task = connectionResources.getVimPortType().reconfigureComputeResourceTask(clusterMor, createClusterConfigSpecEx(clusterConfigInfoEx, clusterDasVmConfigSpec), true);
        return new ResponseHelper(connectionResources, task).getResultsMap(String.format(SUCCESS_MSG, vmInputs.getClusterName(), task.getValue()), String.format(FAILURE_MSG, vmInputs.getClusterName()));
    } finally {
        if (httpInputs.isCloseSession()) {
            connectionResources.getConnection().disconnect();
            clearConnectionFromContext(httpInputs.getGlobalSessionObject());
        }
    }
}
Also used : ConnectionResources(io.cloudslang.content.vmware.connection.ConnectionResources) ResponseHelper(io.cloudslang.content.vmware.services.helpers.ResponseHelper) MorObjectHandler(io.cloudslang.content.vmware.services.helpers.MorObjectHandler)

Example 5 with ConnectionResources

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

the class VmService method createVM.

/**
 * Method used to connect to specified data center and create a virtual machine using 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 create a new 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> createVM(HttpInputs httpInputs, VmInputs vmInputs) throws Exception {
    ConnectionResources connectionResources = new ConnectionResources(httpInputs, vmInputs);
    try {
        VmUtils utils = new VmUtils();
        ManagedObjectReference vmFolderMor = utils.getMorFolder(vmInputs.getFolderName(), connectionResources);
        ManagedObjectReference resourcePoolMor = utils.getMorResourcePool(vmInputs.getResourcePool(), connectionResources);
        ManagedObjectReference hostMor = utils.getMorHost(vmInputs.getHostname(), connectionResources, null);
        VirtualMachineConfigSpec vmConfigSpec = new VmConfigSpecs().getVmConfigSpec(vmInputs, connectionResources);
        ManagedObjectReference task = connectionResources.getVimPortType().createVMTask(vmFolderMor, vmConfigSpec, resourcePoolMor, hostMor);
        return new ResponseHelper(connectionResources, task).getResultsMap("Success: Created [" + vmInputs.getVirtualMachineName() + "] VM. The taskId is: " + task.getValue(), "Failure: Could not create [" + vmInputs.getVirtualMachineName() + "] VM");
    } catch (Exception ex) {
        return ResponseUtils.getResultsMap(ex.toString(), Outputs.RETURN_CODE_FAILURE);
    } finally {
        if (httpInputs.isCloseSession()) {
            connectionResources.getConnection().disconnect();
            clearConnectionFromContext(httpInputs.getGlobalSessionObject());
        }
    }
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VmUtils(io.cloudslang.content.vmware.services.utils.VmUtils) ConnectionResources(io.cloudslang.content.vmware.connection.ConnectionResources) ResponseHelper(io.cloudslang.content.vmware.services.helpers.ResponseHelper) VmConfigSpecs(io.cloudslang.content.vmware.services.utils.VmConfigSpecs) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

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