Search in sources :

Example 21 with MorObjectHandler

use of io.cloudslang.content.vmware.services.helpers.MorObjectHandler in project cs-actions by CloudSlang.

the class ClusterComputeResourceService method createGroup.

private Map<String, String> createGroup(VmInputs vmInputs, ConnectionResources connectionResources, ClusterGroupInfo clusterGroupInfo) throws Exception {
    ManagedObjectReference clusterMor = new MorObjectHandler().getSpecificMor(connectionResources, connectionResources.getMorRootFolder(), ClusterParameter.CLUSTER_COMPUTE_RESOURCE.getValue(), vmInputs.getClusterName());
    ClusterGroupSpec clusterGroupSpec = new ClusterGroupSpec();
    clusterGroupSpec.setInfo(clusterGroupInfo);
    clusterGroupSpec.setOperation(ArrayUpdateOperation.ADD);
    return reconfigureClusterGroup(vmInputs, connectionResources, clusterMor, clusterGroupSpec);
}
Also used : MorObjectHandler(io.cloudslang.content.vmware.services.helpers.MorObjectHandler)

Example 22 with MorObjectHandler

use of io.cloudslang.content.vmware.services.helpers.MorObjectHandler 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 23 with MorObjectHandler

use of io.cloudslang.content.vmware.services.helpers.MorObjectHandler in project cs-actions by CloudSlang.

the class VmUtils method getSpecificMorFolder.

private ManagedObjectReference getSpecificMorFolder(ConnectionResources connectionResources, String folderPath) throws Exception {
    ManagedObjectReference currFolder = connectionResources.getVmFolderMor();
    String[] fullPath = split(folderPath, "/");
    for (String searchedChild : fullPath) {
        if (isBlank(searchedChild)) {
            continue;
        }
        currFolder = findChildFolder(connectionResources, new MorObjectHandler(), currFolder, searchedChild);
    }
    return currFolder;
}
Also used : MorObjectHandler(io.cloudslang.content.vmware.services.helpers.MorObjectHandler) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 24 with MorObjectHandler

use of io.cloudslang.content.vmware.services.helpers.MorObjectHandler in project cs-actions by CloudSlang.

the class VmConfigSpecs method getDefaultDevicesList.

private List<VirtualDevice> getDefaultDevicesList(ConnectionResources connectionResources) throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {
    ManagedObjectReference environmentBrowserMor = new MorObjectHandler().getEnvironmentBrowser(connectionResources, ManagedObjectType.ENVIRONMENT_BROWSER.getValue());
    VirtualMachineConfigOption configOptions = connectionResources.getVimPortType().queryConfigOption(environmentBrowserMor, null, connectionResources.getHostMor());
    if (configOptions == null) {
        throw new RuntimeException(ErrorMessages.VIRTUAL_HARDWARE_INFO_NOT_FOUND_IN_COMPUTE_RESOURCE);
    }
    List<VirtualDevice> listVirtualDevices = configOptions.getDefaultDevice();
    if (listVirtualDevices == null) {
        throw new RuntimeException(ErrorMessages.DATA_STORE_NOT_FOUND_IN_COMPUTE_RESOURCE);
    }
    return listVirtualDevices;
}
Also used : MorObjectHandler(io.cloudslang.content.vmware.services.helpers.MorObjectHandler)

Example 25 with MorObjectHandler

use of io.cloudslang.content.vmware.services.helpers.MorObjectHandler 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)

Aggregations

MorObjectHandler (io.cloudslang.content.vmware.services.helpers.MorObjectHandler)27 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)17 ConnectionResources (io.cloudslang.content.vmware.connection.ConnectionResources)17 ResponseHelper (io.cloudslang.content.vmware.services.helpers.ResponseHelper)7 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)6 VmUtils (io.cloudslang.content.vmware.services.utils.VmUtils)3 OvfNetworkMapping (com.vmware.vim25.OvfNetworkMapping)2 ArrayList (java.util.ArrayList)2 ConfigTarget (com.vmware.vim25.ConfigTarget)1 CustomizationSpec (com.vmware.vim25.CustomizationSpec)1 DatastoreSummary (com.vmware.vim25.DatastoreSummary)1 DynamicProperty (com.vmware.vim25.DynamicProperty)1 GuestOsDescriptor (com.vmware.vim25.GuestOsDescriptor)1 KeyValue (com.vmware.vim25.KeyValue)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 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)1 VirtualMachineConfigSummary (com.vmware.vim25.VirtualMachineConfigSummary)1