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 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()); } }
System.out.println(" Power State: " + vmri.getPowerState().toString()); System.out.println(" Connection State: " + vmri.getConnectionState().toString()); Calendar bTime = vmri.getBootTime(); if(bTime != null) Long mOverhead = vmri.getMemoryOverhead(); if(mOverhead != null)
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)); HostSystem host = new HostSystem(vm.getServerConnection(), vm.getRuntime().getHost()); ComputeResource cr = (ComputeResource) host.getParent(); EnvironmentBrowser envBrowser = cr.getEnvironmentBrowser();
logger.debug("virtualMachineRuntimeInfo=null"); } else { VirtualMachinePowerState virtualMachinePowerState = virtualMachineRuntimeInfo.getPowerState(); if (virtualMachinePowerState == null) { logger.debug("virtualMachinePowerState=null"); 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());
} else { VirtualMachineRuntimeInfo vmrti = vm.getRuntime(); String pState = vmrti.getPowerState().toString(); if (null != pState) { switch (pState) {
/** * 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()); } }
logger.debug("virtualMachineRuntimeInfo=null"); } else { VirtualMachinePowerState virtualMachinePowerState = virtualMachineRuntimeInfo.getPowerState(); if (virtualMachinePowerState == null) { logger.debug("virtualMachinePowerState=null"); 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());
System.out.println(" Power State: " + vmri.getPowerState().toString()); System.out.println(" Connection State: " + vmri.getConnectionState().toString()); Calendar bTime = vmri.getBootTime(); if(bTime != null) Long mOverhead = vmri.getMemoryOverhead(); if(mOverhead != null)
/** * 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()); } }
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; } }
jObject.addProperty("{#UUID}", vmUuid); VirtualMachineRuntimeInfo vmrti = vm.getRuntime(); String pState = vmrti.getPowerState().toString(); if (null != pState) { switch (pState) {
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; }
/** * 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."); } }
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; } }
} else { VirtualMachineRuntimeInfo vmrti = vm.getRuntime(); String pState = vmrti.getPowerState().toString(); if (pState.equals("poweredOn")) {
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; }
/** * 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."); } }
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; }