/** * Returns the running host of a virtual machine */ private void getVmHost(String vmName, PrintWriter out) throws IOException { try { VirtualMachine vm = (VirtualMachine) getManagedEntity(vmName, "VirtualMachine"); String vmHost = ""; if (vm == null) { LOG.warn("No vm named '" + vmName + "' found"); } else { VirtualMachineRuntimeInfo vmRuntimeInfo = vm.getRuntime(); ManagedObjectReference hmor = vmRuntimeInfo.getHost(); HostSystem host = new HostSystem(vm.getServerConnection(), hmor); vmHost = host.getName(); } out.print(vmHost); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
/** * Returns the total CPU of a virtual machine in MHz */ private void getVmCpuTotal(String vmName, PrintWriter out) throws IOException { try { VirtualMachine vm = (VirtualMachine) getManagedEntity(vmName, "VirtualMachine"); Integer mhz = 0; if (vm == null) { LOG.warn("No vm named '" + vmName + "' found"); } else { VirtualMachineRuntimeInfo vmrti = vm.getRuntime(); ManagedObjectReference hostMor = vmrti.getHost(); if (hostMor == null) { return; } ManagedEntity me = MorUtil.createExactManagedEntity(serviceInstance.getServerConnection(), hostMor); HostSystem host = (HostSystem) me; mhz = getHostMHZ(host); } out.print(mhz); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
private static VirtualDevice[] getDefaultDevices(VirtualMachine vm) throws Exception { VirtualMachineRuntimeInfo vmRuntimeInfo = vm.getRuntime(); EnvironmentBrowser envBrowser = vm.getEnvironmentBrowser(); ManagedObjectReference hmor = vmRuntimeInfo.getHost(); VirtualMachineConfigOption cfgOpt = envBrowser.queryConfigOption(null, new HostSystem(vm.getServerConnection(), hmor)); VirtualDevice[] defaultDevs = null; if (cfgOpt == null) { throw new Exception("No VirtualHardwareInfo found in ComputeResource"); } else { defaultDevs = cfgOpt.getDefaultDevice(); if (defaultDevs == null) { throw new Exception("No Datastore found in ComputeResource"); } } return defaultDevs; }
static VirtualDevice[] getDefaultDevices(VirtualMachine vm) throws Exception { VirtualMachineRuntimeInfo vmRuntimeInfo = vm.getRuntime(); EnvironmentBrowser envBrowser = vm.getEnvironmentBrowser(); ManagedObjectReference hmor = vmRuntimeInfo.getHost(); VirtualMachineConfigOption cfgOpt = envBrowser.queryConfigOption(null, new HostSystem(vm.getServerConnection(), hmor)); VirtualDevice[] defaultDevs = null; if (cfgOpt != null) { defaultDevs = cfgOpt.getDefaultDevice(); if (defaultDevs == null) { throw new Exception("No Datastore found in ComputeResource"); } } else { throw new Exception("No VirtualHardwareInfo found in ComputeResource"); } return defaultDevs; } }
static VirtualDevice[] getDefaultDevices(VirtualMachine vm) throws Exception { VirtualMachineRuntimeInfo vmRuntimeInfo = vm.getRuntime(); EnvironmentBrowser envBrowser = vm.getEnvironmentBrowser(); ManagedObjectReference hmor = vmRuntimeInfo.getHost(); VirtualMachineConfigOption cfgOpt = envBrowser.queryConfigOption(null, new HostSystem(vm.getServerConnection(), hmor)); VirtualDevice[] defaultDevs = null; if (cfgOpt != null) { defaultDevs = cfgOpt.getDefaultDevice(); if (defaultDevs == null) { throw new Exception("No Datastore found in ComputeResource"); } } else { throw new Exception("No VirtualHardwareInfo found in ComputeResource"); } return defaultDevs; } }
private static DistributedVirtualPortgroupInfo getDvPortGroupInfo(VirtualMachine vm, String dvPort) throws Exception{ HostSystem host = new HostSystem(vm.getServerConnection(), vm.getRuntime().getHost()); ComputeResource cr = (ComputeResource) host.getParent(); EnvironmentBrowser envBrowser = cr.getEnvironmentBrowser(); ConfigTarget configTarget = envBrowser.queryConfigTarget(host); DistributedVirtualPortgroupInfo dvPortgroupInfo = null; DistributedVirtualPortgroupInfo[] availableDvPortGroupInfo = configTarget.getDistributedVirtualPortgroup(); int j = 0; while (j < availableDvPortGroupInfo.length && dvPortgroupInfo == null) { dvPortgroupInfo = (availableDvPortGroupInfo[j].portgroupName.equalsIgnoreCase(dvPort)) ? availableDvPortGroupInfo[j] : null; j++; } if (dvPortgroupInfo == null) { throw new Exception("Impossible to find dvPortGroupInfo with name : " + dvPort); } return dvPortgroupInfo; }
private static VirtualDevice[] getDefaultDevices(VirtualMachine vm) throws Exception { VirtualMachineRuntimeInfo vmRuntimeInfo = vm.getRuntime(); EnvironmentBrowser envBrowser = vm.getEnvironmentBrowser(); ManagedObjectReference hmor = vmRuntimeInfo.getHost(); VirtualMachineConfigOption cfgOpt = envBrowser.queryConfigOption(null, new HostSystem(vm.getServerConnection(), hmor)); VirtualDevice[] defaultDevs = null; if (cfgOpt == null) { throw new Exception("No VirtualHardwareInfo found in ComputeResource"); } else { defaultDevs = cfgOpt.getDefaultDevice(); if (defaultDevs == null) { throw new Exception("No Datastore found in ComputeResource"); } } return defaultDevs; }
public ManagedObjectReference getMorHost(String hostname, ConnectionResources connectionResources, ManagedObjectReference vmMor) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg { ManagedObjectReference host = null; if (StringUtils.isNotBlank(hostname)) { ManagedObjectReference reference = connectionResources.getMorRootFolder(); host = new MorObjectHandler().getSpecificMor(connectionResources, reference, VmParameter.HOST_SYSTEM.getValue(), hostname); if (host == null) { throw new RuntimeException(ErrorMessages.HOST_NOT_FOUND); } } else if (StringUtils.isBlank(hostname) && vmMor != null) { ObjectContent[] objectContents = GetObjectProperties.getObjectProperties(connectionResources, vmMor, new String[]{VmParameter.SUMMARY.getValue()}); for (ObjectContent objectItem : objectContents) { List<DynamicProperty> vmProperties = objectItem.getPropSet(); for (DynamicProperty propertyItem : vmProperties) { VirtualMachineSummary virtualMachineSummary = (VirtualMachineSummary) propertyItem.getVal(); host = virtualMachineSummary.getRuntime().getHost(); break; } break; } } else { host = connectionResources.getHostMor(); } return host; }
static DatastoreSummary findDatastoreSummary(VirtualMachine vm, String dsName) throws Exception { DatastoreSummary dsSum = null; VirtualMachineRuntimeInfo vmRuntimeInfo = vm.getRuntime(); EnvironmentBrowser envBrowser = vm.getEnvironmentBrowser(); ManagedObjectReference hmor = vmRuntimeInfo.getHost(); if(hmor == null) { System.out.println("No Datastore found"); return null; } ConfigTarget configTarget = envBrowser.queryConfigTarget(new HostSystem(vm.getServerConnection(), hmor)); VirtualMachineDatastoreInfo[] dis = configTarget.getDatastore(); for (int i=0; dis!=null && i<dis.length; i++) { dsSum = dis[i].getDatastore(); if (dsSum.isAccessible() && dsName.equals(dsSum.getName())) { break; } } return dsSum; }
static DatastoreSummary findDatastoreSummary(VirtualMachine vm, String dsName) throws Exception { DatastoreSummary dsSum = null; VirtualMachineRuntimeInfo vmRuntimeInfo = vm.getRuntime(); EnvironmentBrowser envBrowser = vm.getEnvironmentBrowser(); ManagedObjectReference hmor = vmRuntimeInfo.getHost(); if(hmor == null) { System.out.println("No Datastore found"); return null; } ConfigTarget configTarget = envBrowser.queryConfigTarget(new HostSystem(vm.getServerConnection(), hmor)); VirtualMachineDatastoreInfo[] dis = configTarget.getDatastore(); for (int i=0; dis!=null && i<dis.length; i++) { dsSum = dis[i].getDatastore(); if (dsSum.isAccessible() && dsName.equals(dsSum.getName())) { break; } } return dsSum; }
ManagedObjectReference hmor = vmRuntimeInfo.getHost();
static boolean doesNetworkNameExist(VirtualMachine vm, String netName) throws Exception { VirtualMachineRuntimeInfo vmRuntimeInfo = vm.getRuntime(); EnvironmentBrowser envBrowser = vm.getEnvironmentBrowser(); ManagedObjectReference hmor = vmRuntimeInfo.getHost(); HostSystem host = new HostSystem( vm.getServerConnection(), hmor); ConfigTarget cfg = envBrowser.queryConfigTarget(host); VirtualMachineNetworkInfo[] nets = cfg.getNetwork(); for (int i = 0; nets!=null && i < nets.length; i++) { NetworkSummary netSummary = nets[i].getNetwork(); if (netSummary.isAccessible() && netSummary.getName().equalsIgnoreCase(netName)) { return true; } } return false; } }
ManagedObjectReference hmor = vmRuntimeInfo.getHost();
static boolean doesNetworkNameExist(VirtualMachine vm, String netName) throws Exception { VirtualMachineRuntimeInfo vmRuntimeInfo = vm.getRuntime(); EnvironmentBrowser envBrowser = vm.getEnvironmentBrowser(); ManagedObjectReference hmor = vmRuntimeInfo.getHost(); HostSystem host = new HostSystem( vm.getServerConnection(), hmor); ConfigTarget cfg = envBrowser.queryConfigTarget(host); VirtualMachineNetworkInfo[] nets = cfg.getNetwork(); for (int i = 0; nets!=null && i < nets.length; i++) { NetworkSummary netSummary = nets[i].getNetwork(); if (netSummary.isAccessible() && netSummary.getName().equalsIgnoreCase(netName)) { return true; } } return false; } }
qSpec.setEntity(vm.getRuntime().getHost());
if (m_hostSystemMap.get(virtualMachine.getRuntime().getHost().getVal()) != null) { vmwareTopologyInfo.append(virtualMachine.getRuntime().getHost().getVal() + "/" + URLEncoder.encode(m_hostSystemMap.get(virtualMachine.getRuntime().getHost().getVal()), StandardCharsets.UTF_8.name())); } else { logger.warn("Problem building topology information for virtual machine '{}' with power state '{}' running on host system '{}'", virtualMachine.getMOR().getVal(), powerState, virtualMachine.getRuntime().getHost().getVal());
VirtualMachineRuntimeInfo vmRuntimeInfo = vm.getRuntime(); EnvironmentBrowser envBrowser = vm.getEnvironmentBrowser(); ManagedObjectReference hmor = vmRuntimeInfo.getHost();
VirtualMachineRuntimeInfo vmRuntimeInfo = vm.getRuntime(); EnvironmentBrowser envBrowser = vm.getEnvironmentBrowser(); ManagedObjectReference hmor = vmRuntimeInfo.getHost();
HostSystem host = new HostSystem(vm.getServerConnection(), vm.getRuntime().getHost()); ComputeResource cr = (ComputeResource) host.getParent(); EnvironmentBrowser envBrowser = cr.getEnvironmentBrowser();
qSpec.setEntity(vm.getRuntime().getHost());