use of io.cloudslang.content.vmware.services.helpers.MorObjectHandler in project cs-actions by CloudSlang.
the class ClusterComputeResourceService method deleteVmGroup.
public Map<String, String> deleteVmGroup(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());
ClusterVmGroup clusterVmGroup = new ClusterVmGroup();
clusterVmGroup.setName(vmInputs.getVmGroupName());
ClusterGroupSpec clusterGroupSpec = new ClusterGroupSpec();
clusterGroupSpec.setInfo(clusterVmGroup);
clusterGroupSpec.setOperation(ArrayUpdateOperation.REMOVE);
clusterGroupSpec.setRemoveKey(vmInputs.getVmGroupName());
return reconfigureClusterGroup(vmInputs, connectionResources, clusterMor, clusterGroupSpec);
} 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 ClusterComputeResourceService method listGroups.
public String listGroups(HttpInputs httpInputs, String clusterName, String delimiter, Class clazz) throws Exception {
ConnectionResources connectionResources = new ConnectionResources(httpInputs);
try {
ManagedObjectReference clusterMor = new MorObjectHandler().getSpecificMor(connectionResources, connectionResources.getMorRootFolder(), ClusterParameter.CLUSTER_COMPUTE_RESOURCE.getValue(), clusterName);
ClusterConfigInfoEx clusterConfigInfoEx = getClusterConfiguration(connectionResources, clusterMor, clusterName);
List<String> groupNameList = new ArrayList<>();
for (ClusterGroupInfo clusterGroupInfo : clusterConfigInfoEx.getGroup()) {
if (clusterGroupInfo.getClass().isAssignableFrom(clazz)) {
groupNameList.add(clusterGroupInfo.getName());
}
}
return StringUtilities.join(groupNameList, delimiter);
} 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 GuestService method mountTools.
/**
* Method used to connect to specified data center and start the Install Tools process 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 or failure
* message and the exception if there is one
* @throws Exception
*/
public Map<String, String> mountTools(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) {
connectionResources.getVimPortType().mountToolsInstaller(vmMor);
return ResponseUtils.getResultsMap(INITIATED_TOOLS_INSTALLER_MOUNT + vmInputs.getVirtualMachineName(), Outputs.RETURN_CODE_SUCCESS);
} 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 getDataStore.
private ManagedObjectReference getDataStore(String dataStoreName, ConnectionResources connectionResources, ManagedObjectReference vmMor) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
ArrayOfManagedObjectReference dataStoresArray = (ArrayOfManagedObjectReference) new MorObjectHandler().getObjectProperties(connectionResources, vmMor, ManagedObjectType.DATA_STORE.getValue());
List<ManagedObjectReference> dataStores = dataStoresArray.getManagedObjectReference();
for (ManagedObjectReference dataStore : dataStores) {
DatastoreSummary datastoreSummary = (DatastoreSummary) new MorObjectHandler().getObjectProperties(connectionResources, dataStore, ManagedObjectType.SUMMARY.getValue());
if (dataStoreName.equalsIgnoreCase(datastoreSummary.getName())) {
return dataStore;
}
}
return null;
}
use of io.cloudslang.content.vmware.services.helpers.MorObjectHandler in project cs-actions by CloudSlang.
the class VmUtils method getManagedObjectReference.
@NotNull
private ManagedObjectReference getManagedObjectReference(String resourceName, ConnectionResources connectionResources, String filter, String errorMessage) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
ManagedObjectReference reference = connectionResources.getMorRootFolder();
ManagedObjectReference managedObjectReference = new MorObjectHandler().getSpecificMor(connectionResources, reference, filter, resourceName);
if (managedObjectReference == null) {
throw new RuntimeException(errorMessage);
}
return managedObjectReference;
}
Aggregations