public VirtualMachine[] getVms() throws InvalidProperty, RuntimeFault, RemoteException { return getVms("vm"); }
private static String findVMNotOnHost(HostSystem host) throws RemoteException { VirtualMachine[] hostVMs = host.getVms(); boolean foundMatch = false; String targetVM = null; for (String vmName : vmNames) { for (VirtualMachine vm : hostVMs) { if (vmName.equals(vm.getName())) { foundMatch = true; break; } } if (!foundMatch) { targetVM = vmName; break; } foundMatch = false; } return targetVM; }
private static boolean validateVMNotOnHost(ServiceInstance si, Folder rootFolder, HostSystem newHost, String vmName, String hostName) throws Exception { VirtualMachine[] vms = newHost.getVms(); for (VirtualMachine vmac : vms) { if (vmac.getName().equals(vmName)) { Log.getLogWriter().info( vmName + " is already running on target host " + hostName + ". Selecting another pair..."); return false; } } return true; }
/** * Returns the number of VMs running on a host */ private void getHostVMs(String hostName, PrintWriter out) throws IOException { try { HostSystem host = (HostSystem) getManagedEntity(hostName, "HostSystem"); Integer nbVM = 0; if (host == null) { LOG.warn("No host named '" + hostName + "' found"); } else { VirtualMachine[] vms = host.getVms(); for (VirtualMachine vm : vms) { VirtualMachineSummary vmSummary = vm.getSummary(); if ("poweredOn".equals(vm.getRuntime().getPowerState().name())) { nbVM++; } } } out.print(nbVM); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
/** * Returns the virtual machines compressed memory usage of a host */ private void getHostVmsStatsCompressed(String hostName, PrintWriter out) throws IOException { try { HostSystem host = (HostSystem) getManagedEntity(hostName, "HostSystem"); Integer amount = 0; int sum = 0; int activeVms = 0; if (host == null) { LOG.warn("No host named '" + hostName + "' found"); } else { VirtualMachine[] vms = (host.getVms()); for (VirtualMachine vm : vms) { VirtualMachineSummary vmSummary = vm.getSummary(); if ("poweredOn".equals(vm.getRuntime().getPowerState().name())) { sum += (vmSummary.getQuickStats().getCompressedMemory() / 1024) * 100 / vmSummary.getConfig().getMemorySizeMB(); activeVms++; } } amount = activeVms == 0 ? 0 : sum / activeVms; } out.print(amount); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
/** * Returns the virtual machines shared memory usage of a host */ private void getHostVmsStatsShared(String hostName, PrintWriter out) throws IOException { try { HostSystem host = (HostSystem) getManagedEntity(hostName, "HostSystem"); Integer amount = 0; int sum = 0; int activeVms = 0; if (host == null) { LOG.warn("No host named '" + hostName + "' found"); } else { VirtualMachine[] vms = (host.getVms()); for (VirtualMachine vm : vms) { VirtualMachineSummary vmSummary = vm.getSummary(); if ("poweredOn".equals(vm.getRuntime().getPowerState().name())) { sum += vmSummary.getQuickStats().getSharedMemory() * 100 / vmSummary.getConfig().getMemorySizeMB(); activeVms++; } } amount = activeVms == 0 ? 0 : sum / activeVms; } out.print(amount); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
LOG.warn("No host named '" + hostName + "' found"); } else { VirtualMachine[] vms = (host.getVms()); int sharedMb; for (VirtualMachine vm : vms) {
/** * Returns the virtual machines private memory usage of a host */ private void getHostVmsStatsPrivate(String hostName, PrintWriter out) throws IOException { try { HostSystem host = (HostSystem) getManagedEntity(hostName, "HostSystem"); Integer amount = 0; int sum = 0; int activeVms = 0; if (host == null) { LOG.warn("No host named '" + hostName + "' found"); } else { VirtualMachine[] vms = (host.getVms()); for (VirtualMachine vm : vms) { VirtualMachineSummary vmSummary = vm.getSummary(); if ("poweredOn".equals(vm.getRuntime().getPowerState().name())) { sum += vmSummary.getQuickStats().getPrivateMemory() * 100 / vmSummary.getConfig().getMemorySizeMB(); activeVms++; } } amount = activeVms == 0 ? 0 : sum / activeVms; } out.print(amount); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
/** * Returns the virtual machines ballooned memory usage of a host */ private void getHostVmsStatsBallooned(String hostName, PrintWriter out) throws IOException { try { HostSystem host = (HostSystem) getManagedEntity(hostName, "HostSystem"); Integer amount = 0; int sum = 0; int activeVms = 0; if (host == null) { LOG.warn("No host named '" + hostName + "' found"); } else { VirtualMachine[] vms = (host.getVms()); for (VirtualMachine vm : vms) { VirtualMachineSummary vmSummary = vm.getSummary(); if ("poweredOn".equals(vm.getRuntime().getPowerState().name())) { sum += vmSummary.getQuickStats().getBalloonedMemory() * 100 / vmSummary.getConfig().getMemorySizeMB(); activeVms++; } } amount = activeVms == 0 ? 0 : sum / activeVms; } out.print(amount); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
/** * Returns the virtual machines overhead memory usage of a host */ private void getHostVmsStatsOverhCons(String hostName, PrintWriter out) throws IOException { try { HostSystem host = (HostSystem) getManagedEntity(hostName, "HostSystem"); Integer amount = 0; int sum = 0; int activeVms = 0; if (host == null) { LOG.warn("No host named '" + hostName + "' found"); } else { VirtualMachine[] vms = (host.getVms()); for (VirtualMachine vm : vms) { VirtualMachineSummary vmSummary = vm.getSummary(); if ("poweredOn".equals(vm.getRuntime().getPowerState().name())) { sum += vmSummary.getQuickStats().getConsumedOverheadMemory() * 100 / vmSummary.getConfig().getMemorySizeMB(); activeVms++; } } amount = activeVms == 0 ? 0 : sum / activeVms; } out.print(amount); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
/** * Returns the virtual machines memory usage of a host */ private void getHostVmsStatsConsumed(String hostName, PrintWriter out) throws IOException { try { HostSystem host = (HostSystem) getManagedEntity(hostName, "HostSystem"); Integer amount = 0; int sum = 0; int activeVms = 0; if (host == null) { LOG.warn("No host named '" + hostName + "' found"); } else { VirtualMachine[] vms = (host.getVms()); for (VirtualMachine vm : vms) { VirtualMachineSummary vmSummary = vm.getSummary(); if ("poweredOn".equals(vm.getRuntime().getPowerState().name())) { sum += vmSummary.getQuickStats().getHostMemoryUsage() * 100 / vmSummary.getConfig().getMemorySizeMB(); activeVms++; } } amount = activeVms == 0 ? 0 : sum / activeVms; } out.print(amount); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
/** * Returns the virtual machines active memory usage of a host */ private void getHostVmsStatsActive(String hostName, PrintWriter out) throws IOException { try { HostSystem host = (HostSystem) getManagedEntity(hostName, "HostSystem"); Integer amount = 0; int sum = 0; int activeVms = 0; if (host == null) { LOG.warn("No host named '" + hostName + "' found"); } else { VirtualMachine[] vms = (host.getVms()); for (VirtualMachine vm : vms) { VirtualMachineSummary vmSummary = vm.getSummary(); if ("poweredOn".equals(vm.getRuntime().getPowerState().name())) { sum += vmSummary.getQuickStats().getGuestMemoryUsage() * 100 / vmSummary.getConfig().getMemorySizeMB(); activeVms++; } } amount = activeVms == 0 ? 0 : sum / activeVms; } out.print(amount); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
VirtualMachine[] vms = host.getVms(); if (vms != null) { int count =0;
@Override public List<VmServerDO> getVirtualMachines(String hostName) { this.login(); //List<String> list=new ArrayList<String>(); List<VmServerDO> vmServers = new ArrayList<VmServerDO>(); try { ManagedEntity mes = new InventoryNavigator(serviceInstance.getRootFolder()).searchManagedEntity("HostSystem", hostName); if (mes != null) { HostSystem systems = (HostSystem) mes; VirtualMachine[] virtualMachines = systems.getVms(); if (virtualMachines != null && virtualMachines.length > 0) { for (VirtualMachine virtualMachine : virtualMachines) { VirtualMachinePowerState state = virtualMachine.getRuntime().powerState; //String virtualMachineName=virtualMachine.getName(); //String vmname[]=virtualMachineName.split(":"); //System.err.println(virtualMachine.getName()); VmServerDO vmServerDO = new VmServerDO(virtualMachine); vmServers.add(vmServerDO); } } } } catch (Exception e) { serviceInstance.getServerConnection().logout(); return vmServers; } finally { serviceInstance.getServerConnection().logout(); } return vmServers; }
System.out.println("Datastore : " + host.getDatastores()[0].getName()); Folder vmFolder = (Folder) host.getVms()[0].getParent();
System.out.println("Datastore : " + host.getDatastores()[0].getName()); Folder vmFolder = (Folder) host.getVms()[0].getParent();