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