use of io.cloudslang.content.vmware.services.helpers.ResponseHelper 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());
}
}
}
use of io.cloudslang.content.vmware.services.helpers.ResponseHelper 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());
}
}
}
use of io.cloudslang.content.vmware.services.helpers.ResponseHelper in project cs-actions by CloudSlang.
the class VmService method powerOnVM.
/**
* Method used to connect to specified data center and power-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 with task id
* of the execution or failure message and the exception if there is one
* @throws Exception
*/
public Map<String, String> powerOnVM(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) {
ManagedObjectReference task = connectionResources.getVimPortType().powerOnVMTask(vmMor, null);
return new ResponseHelper(connectionResources, task).getResultsMap("Success: The [" + vmInputs.getVirtualMachineName() + "] VM was successfully powered on. The taskId is: " + task.getValue(), "Failure: The [" + vmInputs.getVirtualMachineName() + "] VM could not be powered on.");
} 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.services.helpers.ResponseHelper in project cs-actions by CloudSlang.
the class VmService method cloneVM.
/**
* Method used to connect to data center and clone a 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 virtual machine that will be
* cloned
* @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> cloneVM(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) {
VmUtils utils = new VmUtils();
ManagedObjectReference folder = utils.getMorFolder(vmInputs.getFolderName(), connectionResources);
ManagedObjectReference resourcePool = utils.getMorResourcePool(vmInputs.getCloneResourcePool(), connectionResources);
ManagedObjectReference host = utils.getMorHost(vmInputs.getCloneHost(), connectionResources, vmMor);
ManagedObjectReference dataStore = utils.getMorDataStore(vmInputs.getCloneDataStore(), connectionResources, vmMor, vmInputs);
VirtualMachineRelocateSpec vmRelocateSpec = utils.getVirtualMachineRelocateSpec(resourcePool, host, dataStore, vmInputs);
VirtualMachineCloneSpec cloneSpec = new VmConfigSpecs().getCloneSpec(vmInputs, vmRelocateSpec);
ManagedObjectReference taskMor = connectionResources.getVimPortType().cloneVMTask(vmMor, folder, vmInputs.getCloneName(), cloneSpec);
return new ResponseHelper(connectionResources, taskMor).getResultsMap("Success: The [" + vmInputs.getVirtualMachineName() + "] VM was successfully cloned. The taskId is: " + taskMor.getValue(), "Failure: The [" + vmInputs.getVirtualMachineName() + "] VM could not be cloned.");
} 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.services.helpers.ResponseHelper in project cs-actions by CloudSlang.
the class VmService method deleteVM.
/**
* Method used to connect to specified data center and delete the 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 with task id
* of the execution or failure message and the exception if there is one
* @throws Exception
*/
public Map<String, String> deleteVM(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) {
ManagedObjectReference task = connectionResources.getVimPortType().destroyTask(vmMor);
return new ResponseHelper(connectionResources, task).getResultsMap("Success: The [" + vmInputs.getVirtualMachineName() + "] VM was deleted. The taskId is: " + task.getValue(), "Failure: The [" + vmInputs.getVirtualMachineName() + "] VM could not be deleted.");
} 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());
}
}
}
Aggregations