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