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;
}
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);
}
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;
}
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;
}
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());
}
}
}
Aggregations