public AbstractManagedObject getManagedObject(ManagedObjectReference value) { return model.get(value.getValue()); }
@Override public String toString() { return "ManagedObjectReferenceWrapper [type=" + mor.getType() + ", value=" + mor.getValue() + "]"; }
<T> Future<T> addPendingTask(ManagedObjectReference moRef, ViTaskContinuation<T> c) { pendingTasks.put(moRef.getValue(), c); return c.getFuture(); }
public MoRef(ManagedObjectReference ref) { this.type = ref.getType(); this.value = ref.getValue(); }
private Element uniqueResultOrFail(List<Element> found) throws FinderException { if (found.isEmpty()) { throw new FinderException("No elements matching the input pattern found"); } if (found.size() > 1) { List<String> idList = found.stream() .map(o -> o.object.getValue()) .collect(Collectors.toList()); throw new FinderException("More than one elements found: " + idList); } return found.get(0); }
@Override public String toString() { final StringBuilder sb = new StringBuilder(super.toString()); try { sb.append(";type="); sb.append(URLEncoder.encode(moRef.getType(), "UTF-8")); sb.append(";value="); sb.append(URLEncoder.encode(moRef.getValue(), "UTF-8")); } catch (UnsupportedEncodingException e) { // ignore, this cannot happen } return sb.toString(); } }
private ObjectContent findByParent(ManagedObjectReference ref, List<ObjectContent> ocs) { if (ref == null) { return null; } for (ObjectContent oc : ocs) { ManagedObjectReference obj = oc.getObj(); if (Objects.equals(ref.getValue(), obj.getValue())) { return findByRef(prop(oc, VimNames.PROPERTY_PARENT), ocs); } } return null; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; ManagedObjectReferenceWrapper other = (ManagedObjectReferenceWrapper) obj; if (mor.getValue() == null) { if (other.mor.getValue() != null) return false; } else if (!mor.getValue().equals(other.mor.getValue())) return false; if (mor.getType() == null) { if (other.mor.getType() != null) return false; } else if (!mor.getType().equals(other.mor.getType())) return false; return true; }
public void processTask(TaskInfo taskInfo) { ViTaskContinuation<?> continuation = pendingTasks.get(taskInfo.getTask().getValue()); if (continuation != null) { switch (taskInfo.getState()) { case SUCCESS: continuation.onSuccess(); pendingTasks.remove(taskInfo.getTask().getValue()); break; case ERROR: continuation.onError(taskInfo.getError()); pendingTasks.remove(taskInfo.getTask().getValue()); break; } } }
public static void addDataToVmDetailsMap(Map<String, String> inputMap, VirtualMachineSummary virtualMachineSummary, VirtualMachineConfigSummary virtualMachineConfigSummary) { inputMap.put(VmParameter.VM_ID.getValue(), virtualMachineSummary.getVm().getValue()); inputMap.put(VmParameter.VM_FULL_NAME.getValue(), virtualMachineConfigSummary.getGuestFullName()); inputMap.put(VmParameter.VM_UUID.getValue(), virtualMachineConfigSummary.getUuid()); inputMap.put(Inputs.VM_CPU_COUNT, virtualMachineConfigSummary.getNumCpu().toString()); inputMap.put(Inputs.VM_MEMORY_SIZE, virtualMachineConfigSummary.getMemorySizeMB().toString()); inputMap.put(VmParameter.VM_ETH_COUNT.getValue(), virtualMachineConfigSummary.getNumEthernetCards().toString()); inputMap.put(VmParameter.VM_DISK_COUNT.getValue(), virtualMachineConfigSummary.getNumVirtualDisks().toString()); inputMap.put(Inputs.DATA_STORE, virtualMachineConfigSummary.getVmPathName() .substring(1, virtualMachineConfigSummary.getVmPathName().indexOf(Constants.RIGHT_SQUARE_BRACKET))); inputMap.put(VmParameter.VM_PATH_NAME.getValue(), virtualMachineConfigSummary.getVmPathName()); inputMap.put(VmParameter.VM_IS_TEMPLATE.getValue(), Boolean.toString(virtualMachineConfigSummary.isTemplate())); if (virtualMachineSummary.getGuest() != null) { if (virtualMachineSummary.getGuest().getIpAddress() != null) { inputMap.put(VmParameter.VM_IP_ADDRESS.getValue(), virtualMachineSummary.getGuest().getIpAddress()); } else { inputMap.put(VmParameter.VM_IP_ADDRESS.getValue(), Constants.EMPTY); } } }
private void writeObject(ObjectOutputStream out) throws IOException { ObjectOutputStream.PutField fields = out.putFields(); fields.put("type", moRef.getType()); fields.put("value", moRef.getValue()); out.writeFields(); }
task.getValue(), "Failure: The [" + vmInputs.getVirtualMachineName() + "] VM could not be reconfigured."); } else { return ResponseUtils.getVmNotFoundResultsMap(vmInputs);
/** * 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().getVmMor(connectionResources, VmParameter.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 { connectionResources.getConnection().disconnect(); } }
/** * 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().getVmMor(connectionResources, VmParameter.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 { connectionResources.getConnection().disconnect(); } }
/** * Method used to connect to specified data center and power-off 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> powerOffVM(HttpInputs httpInputs, VmInputs vmInputs) throws Exception { ConnectionResources connectionResources = new ConnectionResources(httpInputs, vmInputs); try { ManagedObjectReference vmMor = new MorObjectHandler().getVmMor(connectionResources, VmParameter.VIRTUAL_MACHINE.getValue(), vmInputs.getVirtualMachineName()); if (vmMor != null) { ManagedObjectReference task = connectionResources.getVimPortType().powerOffVMTask(vmMor); return new ResponseHelper(connectionResources, task).getResultsMap("Success: The [" + vmInputs.getVirtualMachineName() + "] VM was successfully powered off. The taskId is: " + task.getValue(), "Failure: The [" + vmInputs.getVirtualMachineName() + "] VM could not be powered off."); } else { return ResponseUtils.getVmNotFoundResultsMap(vmInputs); } } catch (Exception ex) { return ResponseUtils.getResultsMap(ex.toString(), Outputs.RETURN_CODE_FAILURE); } finally { connectionResources.getConnection().disconnect(); } }
/** * 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 { connectionResources.getConnection().disconnect(); } }
task.getValue(), "Failure: The [" + vmInputs.getVirtualMachineName() + "] VM could not be customized."); } else { return ResponseUtils.getVmNotFoundResultsMap(vmInputs);
taskMor.getValue(), "Failure: The [" + vmInputs.getVirtualMachineName() + "] VM could not be cloned."); } else { return ResponseUtils.getVmNotFoundResultsMap(vmInputs);