public void waitForStopped(String machineName) { VirtualMachine machine = getVirtualMachine(machineName); // 停止判定処理 while (true) { try { Thread.sleep(30 * 1000L); } catch (InterruptedException ignore) { } VirtualMachineRuntimeInfo runtimeInfo = machine.getRuntime(); if (runtimeInfo.getPowerState() == VirtualMachinePowerState.poweredOff) { break; } } }
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 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 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 ManagedObjectReference getNetworkFromHost(VMwareClient vmw, ManagedObjectReference vmwInstance, String networkName) throws Exception { logger.debug("networkName: " + networkName); VirtualMachineRuntimeInfo vmRuntimeInfo = (VirtualMachineRuntimeInfo) vmw .getServiceUtil().getDynamicProperty(vmwInstance, "runtime"); ManagedObjectReference hostRef = vmRuntimeInfo.getHost(); List<ManagedObjectReference> networkRefList = (List<ManagedObjectReference>) vmw .getServiceUtil().getDynamicProperty(hostRef, "network"); ManagedObjectReference netCard = null; StringBuffer networks = new StringBuffer(); for (ManagedObjectReference networkRef : networkRefList) { String netCardName = (String) vmw.getServiceUtil() .getDynamicProperty(networkRef, "name"); networks.append(netCardName + " "); if (netCardName.equalsIgnoreCase(networkName)) { netCard = networkRef; break; } } if (netCard == null) { String hostName = (String) vmw.getServiceUtil() .getDynamicProperty(hostRef, "name"); logger.error("Network " + networkName + " not found on host " + hostName); logger.debug("available networks are: " + networks.toString()); throw new Exception("Network card " + networkName + " not found on host " + hostName); } return netCard; }
public boolean isStopped() throws Exception { VirtualMachineRuntimeInfo vmRuntimeInfo = (VirtualMachineRuntimeInfo) vmw .getServiceUtil().getDynamicProperty(vmInstance, "runtime"); if (vmRuntimeInfo != null) { return VirtualMachinePowerState.POWERED_OFF .equals(vmRuntimeInfo.getPowerState()); } LOG.warn("Failed to retrieve runtime information from VM " + instanceName); return false; }
public void shutdownGuest(String machineName) { // VirtualMachine VirtualMachine machine = getVirtualMachine(machineName); // パワーオフ状態の場合はスキップ VirtualMachineRuntimeInfo runtimeInfo = machine.getRuntime(); if (runtimeInfo.getPowerState() == VirtualMachinePowerState.poweredOff) { return; } // 仮想マシンのシャットダウン try { machine.shutdownGuest(); } catch (RemoteException e) { throw new AutoException("EPROCESS-000519", e, machineName); } if (log.isInfoEnabled()) { log.info(MessageUtils.getMessage("IPROCESS-100415", machineName)); } // シャットダウンが完了するまで待機 waitForStopped(machineName); if (log.isInfoEnabled()) { log.info(MessageUtils.getMessage("IPROCESS-100416", machineName)); } }
public HostMO getRunningHost() throws Exception { VirtualMachineRuntimeInfo runtimeInfo = getRuntimeInfo(); return new HostMO(_context, runtimeInfo.getHost()); }
public VirtualMachineRuntimeInfo getRuntimeInfo() throws Exception { return (VirtualMachineRuntimeInfo)_context.getVimClient().getDynamicProperty(_mor, "runtime"); }
public static PowerState getVmState(VirtualMachineMO vmMo) throws Exception { VirtualMachineRuntimeInfo runtimeInfo = vmMo.getRuntimeInfo(); return convertPowerState(runtimeInfo.getPowerState()); }
public static PowerState getVmPowerState(VirtualMachineMO vmMo) throws Exception { VirtualMachineRuntimeInfo runtimeInfo = vmMo.getRuntimeInfo(); return convertPowerState(runtimeInfo.getPowerState()); }