/** * 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()); } }
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 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; }
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 HostSystem[] queryCompatibleHostForNewDvs(ManagedEntity container, boolean recursive, DistributedVirtualSwitchProductSpec switchProductSpec) throws RuntimeFault, RemoteException { ManagedObjectReference[] mors = getVimService().queryCompatibleHostForNewDvs(getMOR(), container.getMOR(), recursive, switchProductSpec); HostSystem[] hosts = new HostSystem[mors.length]; for(int i=0; i<hosts.length; i++) { hosts[i] = new HostSystem(getServerConnection(), mors[i]); } return hosts; }
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; }
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; } }
public HostSystem[] queryCompatibleHostForExistingDvs(ManagedEntity container, boolean recursive, DistributedVirtualSwitch dvs) throws RuntimeFault, RemoteException { ManagedObjectReference[] mors = getVimService().queryCompatibleHostForExistingDvs(getMOR(), container.getMOR(), recursive, dvs.getMOR()); HostSystem[] hosts = new HostSystem[mors.length]; for(int i=0; i<hosts.length; i++) { hosts[i] = new HostSystem(getServerConnection(), mors[i]); } return hosts; }
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; }
ConfigTarget configTarget = envBrowser.queryConfigTarget(new HostSystem(vm.getServerConnection(), hmor)); if(configTarget.getNetwork() != null)
ConfigTarget configTarget = envBrowser.queryConfigTarget(new HostSystem(vm.getServerConnection(), hmor)); if(configTarget.getNetwork() != null)
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; } }
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; } }
ConfigTarget configTarget = envBrowser.queryConfigTarget(new HostSystem(vm.getServerConnection(), hmor)); if(configTarget.getDatastore() != null)
ConfigTarget configTarget = envBrowser.queryConfigTarget(new HostSystem(vm.getServerConnection(), hmor)); if(configTarget.getDatastore() != null)
HostSystem host = new HostSystem(vm.getServerConnection(), vm.getRuntime().getHost()); ComputeResource cr = (ComputeResource) host.getParent(); EnvironmentBrowser envBrowser = cr.getEnvironmentBrowser();