Search in sources :

Example 6 with MorObjectHandler

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

the class DeployOvfTemplateService method getOvfNetworkMappings.

private List<OvfNetworkMapping> getOvfNetworkMappings(final Map<String, String> ovfNetworkMap, final ConnectionResources connectionResources) throws Exception {
    final List<OvfNetworkMapping> mappings = new ArrayList<>();
    for (Map.Entry<String, String> entry : ovfNetworkMap.entrySet()) {
        final OvfNetworkMapping mapping = new OvfNetworkMapping();
        mapping.setNetwork(new MorObjectHandler().getSpecificMor(connectionResources, connectionResources.getMorRootFolder(), ManagedObject.NETWORK.getName(), entry.getValue()));
        mapping.setName(entry.getKey());
        mappings.add(mapping);
    }
    return mappings;
}
Also used : OvfNetworkMapping(com.vmware.vim25.OvfNetworkMapping) ArrayList(java.util.ArrayList) Map(java.util.Map) MorObjectHandler(io.cloudslang.content.vmware.services.helpers.MorObjectHandler)

Example 7 with MorObjectHandler

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

the class DeployOvfTemplateService method createLeaseSetup.

protected ImmutablePair<ManagedObjectReference, OvfCreateImportSpecResult> createLeaseSetup(final ConnectionResources connectionResources, final VmInputs vmInputs, final String templatePath, final Map<String, String> ovfNetworkMap, final Map<String, String> ovfPropertyMap) throws Exception {
    final ManagedObjectReference ovfManager = getOvfManager(connectionResources);
    final VmUtils vmUtils = new VmUtils();
    final ManagedObjectReference resourcePool;
    if (StringUtilities.isBlank(vmInputs.getClusterName())) {
        resourcePool = vmUtils.getMorResourcePool(vmInputs.getResourcePool(), connectionResources);
    } else {
        ManagedObjectReference clusterMor = new MorObjectHandler().getSpecificMor(connectionResources, connectionResources.getMorRootFolder(), ClusterParameter.CLUSTER_COMPUTE_RESOURCE.getValue(), vmInputs.getClusterName());
        resourcePool = vmUtils.getMorResourcePoolFromCluster(connectionResources, clusterMor, vmInputs.getResourcePool());
    }
    final ManagedObjectReference hostMor = vmUtils.getMorHost(vmInputs.getHostname(), connectionResources, null);
    final ManagedObjectReference datastoreMor = vmUtils.getMorDataStore(vmInputs.getDataStore(), connectionResources, null, vmInputs);
    final ManagedObjectReference folderMor = vmUtils.getMorFolder(vmInputs.getFolderName(), connectionResources);
    final List<OvfNetworkMapping> ovfNetworkMappings = getOvfNetworkMappings(ovfNetworkMap, connectionResources);
    final List<KeyValue> ovfPropertyMappings = getOvfPropertyMappings(ovfPropertyMap);
    final OvfCreateImportSpecResult importSpecResult = connectionResources.getVimPortType().createImportSpec(ovfManager, getOvfTemplateAsString(templatePath), resourcePool, datastoreMor, getOvfCreateImportSpecParams(vmInputs, hostMor, ovfNetworkMappings, ovfPropertyMappings));
    checkImportSpecResultForErrors(importSpecResult);
    final ManagedObjectReference httpNfcLease = OvfUtils.getHttpNfcLease(connectionResources, importSpecResult.getImportSpec(), resourcePool, hostMor, folderMor);
    return ImmutablePair.of(httpNfcLease, importSpecResult);
}
Also used : KeyValue(com.vmware.vim25.KeyValue) OvfNetworkMapping(com.vmware.vim25.OvfNetworkMapping) VmUtils(io.cloudslang.content.vmware.services.utils.VmUtils) OvfCreateImportSpecResult(com.vmware.vim25.OvfCreateImportSpecResult) MorObjectHandler(io.cloudslang.content.vmware.services.helpers.MorObjectHandler) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 8 with MorObjectHandler

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

the class VmUtils method getHostConfigTarget.

ConfigTarget getHostConfigTarget(ConnectionResources connectionResources, ManagedObjectReference hostMor) throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {
    ManagedObjectReference environmentBrowserMor = new MorObjectHandler().getEnvironmentBrowser(connectionResources, ManagedObjectType.ENVIRONMENT_BROWSER.getValue());
    ConfigTarget configTarget = connectionResources.getVimPortType().queryConfigTarget(environmentBrowserMor, hostMor);
    if (configTarget == null) {
        throw new RuntimeException(ErrorMessages.CONFIG_TARGET_NOT_FOUND_IN_COMPUTE_RESOURCE);
    }
    return configTarget;
}
Also used : ConfigTarget(com.vmware.vim25.ConfigTarget) MorObjectHandler(io.cloudslang.content.vmware.services.helpers.MorObjectHandler) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 9 with MorObjectHandler

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

the class VmUtils method getMorResourcePool.

public ManagedObjectReference getMorResourcePool(String resourcePoolName, ConnectionResources connectionResources) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ManagedObjectReference resourcePool;
    if (isNotBlank(resourcePoolName)) {
        resourcePool = getManagedObjectReference(resourcePoolName, connectionResources, ManagedObjectType.RESOURCE_POOL.getValue(), ErrorMessages.RESOURCE_POOL_NOT_FOUND);
    } else {
        resourcePool = connectionResources.getResourcePoolMor();
        if (resourcePool == null) {
            ManagedObjectReference reference = connectionResources.getMorRootFolder();
            resourcePool = new MorObjectHandler().getSpecificMor(connectionResources, reference, ManagedObjectType.RESOURCE_POOL.getValue(), ManagedObjectType.RESOURCES.getValue());
        }
    }
    return resourcePool;
}
Also used : MorObjectHandler(io.cloudslang.content.vmware.services.helpers.MorObjectHandler) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 10 with MorObjectHandler

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

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