public PowerState getState() { synchronized (lock) { if (runtime == null || runtime.getPowerState() == null) { return PowerState.STOPPED; } switch (runtime.getPowerState()) { case POWERED_OFF: return PowerState.STOPPED; case POWERED_ON: return PowerState.RUNNING; case SUSPENDED: return PowerState.SUSPENDED; default: return PowerState.STOPPED; } } }
/** * 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()); } }
/** * Attempts to suspend the VM stored in this CloneTask object according to its OS's suspend command. * @throws InvalidProperty * @throws RuntimeFault * @throws RemoteException * @throws InterruptedException */ public void suspendVm() throws InvalidProperty, RuntimeFault, RemoteException, InterruptedException { VirtualMachineRuntimeInfo vmri = vm.getRuntime(); if (vmri.getPowerState() == VirtualMachinePowerState.poweredOn) { com.vmware.vim25.mo.Task task = vm.suspendVM_Task(); task.waitForTask(); log.info("vm:" + vm.getName() + " was suspended."); } }
/** * Powers off the VM stored in this CloneTask object. This is a "hard" powering off. * @throws InvalidProperty * @throws RuntimeFault * @throws RemoteException * @throws InterruptedException */ public void powerOffVm() throws InvalidProperty, RuntimeFault, RemoteException, InterruptedException { VirtualMachineRuntimeInfo vmri = vm.getRuntime(); if (vmri.getPowerState() == VirtualMachinePowerState.poweredOn) { sentPowerDown = true; com.vmware.vim25.mo.Task task = vm.powerOffVM_Task(); task.waitForTask(); log.info("vm:" + vm.getName() + " powered off."); } }
public void powerOnVm() throws InvalidProperty, RuntimeFault, RemoteException, InterruptedException { Path hostPath = this.environment.getHostPath(); VirtualHost host = this.environment.fetchVirtualHost(); ComputeResource res = host.getComputeResource(hostPath); HostSystem hostSystem = res.getHosts()[0]; VirtualMachineRuntimeInfo vmri = vm.getRuntime(); if (vmri.getPowerState() == VirtualMachinePowerState.poweredOff || vmri.getPowerState() == VirtualMachinePowerState.suspended) { com.vmware.vim25.mo.Task task = vm.powerOnVM_Task(hostSystem); task.waitForTask(); log.info("vm:" + vm.getName() + " powered on."); } }
/** * 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; }
/** * 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; }
/** * 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()); } }
/** * 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()); } }
/** * 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()); } }
for (VirtualMachine vm : vms) { VirtualMachineSummary vmSummary = vm.getSummary(); if ("poweredOn".equals(vm.getRuntime().getPowerState().name())) { sharedMb = (int) (vmSummary.getQuickStats().getSwappedMemory() / 1024); sum += sharedMb * 100 / vmSummary.getConfig().getMemorySizeMB();
System.out.println(summary.toString()); VirtualMachineRuntimeInfo vmri = (VirtualMachineRuntimeInfo) vm.getRuntime(); if(vmri.getPowerState() == VirtualMachinePowerState.poweredOn && "Ubuntu704Srv".equals(vm.getName()))
System.out.println(summary.toString()); VirtualMachineRuntimeInfo vmri = (VirtualMachineRuntimeInfo) vm.getRuntime(); if(vmri.getPowerState() == VirtualMachinePowerState.poweredOn && "Ubuntu704Srv".equals(vm.getName()))
private void setState(VirtualMachinePowerState state) { synchronized (lock) { if (runtime.getPowerState().equals(state)) { return; } runtime.setPowerState(state); PowerState powerState = getState(); if (futureState != null && !futureState.isDone()) { futureState.set(powerState); futureState = null; } datacenter.getLog().info("{0} has changed state to {1}", this, powerState); } }
VirtualMachinePowerState powerState = vm.getRuntime().getPowerState(); String vmVerStr = vm.getConfig().getVersion(); int vmVer = Integer.parseInt(vmVerStr.substring(vmVerStr.length()-2));
setVal(n, "vmw_numCPU", "" + cfg.getHardware().getNumCPU()); setVal(n, "vmw_isTemplate",vm.getConfig().isTemplate()); setVal(n, "vmw_powerState",vm.getSummary().getRuntime().getPowerState().toString());