public ManagedObjectReference getServiceInstance() { ManagedObjectReference serviceInstanceMOR = new ManagedObjectReference(); serviceInstanceMOR.setType(TYPE_SERVICE_INSTANCE); serviceInstanceMOR.setValue(TYPE_SERVICE_INSTANCE); return serviceInstanceMOR; }
public static boolean isTraversable(ManagedObjectReference ref) { switch (ref.getType()) { case "Folder": case "Datacenter": case "ComputeResource": case "ClusterComputeResource": // Treat ComputeResource and ClusterComputeResource as one and the same. // It doesn't matter from the perspective of the lister. return true; default: return false; } }
public static ManagedObjectReference createMOR(String type, String id) { ManagedObjectReference mor = new ManagedObjectReference(); mor.setType(type); mor.set_value(id); return mor; } }
/** * Returns a host system by a given managed object Id. * * @param managedObjectId the managed object Id * @return the host system object */ public HostSystem getHostSystemByManagedObjectId(String managedObjectId) { ManagedObjectReference managedObjectReference = new ManagedObjectReference(); managedObjectReference.setType("HostSystem"); managedObjectReference.setVal(managedObjectId); HostSystem hostSystem = (HostSystem) MorUtil.createExactManagedEntity(m_serviceInstance.getServerConnection(), managedObjectReference); return hostSystem; }
@Test public void testComputeMacId() { ManagedObjectReference mor = new ManagedObjectReference(); mor.setType("HostSystem"); mor.setVal("host-123"); VMWareScanner s = Mockito.mock(VMWareScanner.class); when(s.getVCenterId()).thenReturn("abcdef"); Mockito.when(s.computeUniqueId(mor)).thenCallRealMethod(); assertThat(mor.getType()).isEqualTo("HostSystem"); assertThat(s.computeUniqueId(mor)).isEqualTo("21b23eae3d48797d8d057329705825e637e35d81"); VMWareScanner s2 = Mockito.mock(VMWareScanner.class); when(s2.getVCenterId()).thenReturn("another"); Mockito.when(s2.computeUniqueId(mor)).thenCallRealMethod(); assertThat(s.computeUniqueId(mor)).isNotEqualTo(s2.computeUniqueId(mor)); /* * try { new VSphereScanner().computeMacId(null); } catch (Exception e) * { assertThat(e) .isExactlyInstanceOf(NullPointerException.class) * .hasMessageContaining("cannot be null"); } * * mor = new ManagedObjectReference(); mor.setType("VirtualMachine"); * mor.setVal("vm-123"); try { new VSphereScanner().computeMacId(mor); * fail(); } catch (Exception e) { assertThat(e).isInstanceOf( * IllegalArgumentException.class); } */ }
.forEach(hostSystem -> { synchronized (m_hostSystemMap) { m_hostSystemMap.put(hostSystem.getMOR().getVal(), hostSystem.getName()); .filter(hostSystem -> checkForAttribute(hostSystem)) .map(hostSystem -> CompletableFuture.supplyAsync(() -> { logger.debug("Adding Host System '{}' (ID: {})", hostSystem.getName(), hostSystem.getMOR().getVal()); logger.debug("Found {} IP addresses for Host System '{}' (ID: {}): {}", ipAddresses.size(), hostSystem.getName(), hostSystem.getMOR().getVal(), ipAddresses); node.putAsset(new RequisitionAsset("cpu", hostSystem.getHardware().getCpuInfo().getNumCpuCores() + " cores")); } catch (Exception e) { logger.debug("Can't find CPU information for '{}' (ID: {})", hostSystem.getName(), hostSystem.getMOR().getVal()); node.putAsset(new RequisitionAsset("ram", Math.round(hostSystem.getHardware().getMemorySize() / 1000000f) + " MB")); } catch (Exception e) { logger.debug("Can't find Memory information for '{}' (ID: {})", hostSystem.getName(), hostSystem.getMOR().getVal());
public AbstractManagedObject getManagedObject(ManagedObjectReference value) { return model.get(value.getValue()); }
private static ManagedObjectReference createMOR(String type, String value) { ManagedObjectReference mor = new ManagedObjectReference(); mor.val = value; mor.type = type; return mor; }
public static ManagedObjectReference createMOR(String type, String id) { ManagedObjectReference mor = new ManagedObjectReference(); mor.setType(type); mor.set_value(id); return mor; } }
/** * Returns a virtual machine by a given managed object Id. * * @param managedObjectId the managed object Id * @return the virtual machine object */ public VirtualMachine getVirtualMachineByManagedObjectId(String managedObjectId) { ManagedObjectReference managedObjectReference = new ManagedObjectReference(); managedObjectReference.setType("VirtualMachine"); managedObjectReference.setVal(managedObjectId); VirtualMachine virtualMachine = (VirtualMachine) MorUtil.createExactManagedEntity(m_serviceInstance.getServerConnection(), managedObjectReference); return virtualMachine; }
/** * Checks whether the virtual machine should be imported into the requisition. * * @param virtualMachine the system to check * @return true for import, false otherwise */ private boolean checkVMPowerState(VirtualMachine virtualMachine) { logger.debug("Checking power state for VM {} (ID: {})", virtualMachine.getName(), virtualMachine.getMOR().getVal()); String powerState = virtualMachine.getRuntime().getPowerState().toString(); if ("poweredOn".equals(powerState) && request.isImportVMPoweredOn()) { return true; } if ("poweredOff".equals(powerState) && request.isImportVMPoweredOff()) { return true; } if ("suspended".equals(powerState) && request.isImportVMSuspended()) { return true; } return false; }
/** * Create an instance of {@link ManagedObjectReference } * */ public ManagedObjectReference createManagedObjectReference() { return new ManagedObjectReference(); }
public static final ManagedObjectReference getServiceInstance() { ManagedObjectReference serviceInstance = new ManagedObjectReference(); serviceInstance.setType("ServiceInstance"); serviceInstance.setValue("ServiceInstance"); return serviceInstance; }
public static ManagedObjectReference createMOR(String type, String id) { ManagedObjectReference mor = new ManagedObjectReference(); mor.setType(type); mor.set_value(id); return mor; } }