protected List<CustomizationAdapterMapping> createCustomizationAdapterMappings( VmwareProcessClient vmwareProcessClient, VirtualMachine machine) { List<CustomizationAdapterMapping> nicSettingMap = new ArrayList<CustomizationAdapterMapping>(); // VirtualEthernetCardを取得 VirtualMachineConfigInfo configInfo = machine.getConfig(); for (VirtualDevice device : configInfo.getHardware().getDevice()) { if (device instanceof VirtualEthernetCard) { VirtualEthernetCard virtualEthernetCard = VirtualEthernetCard.class.cast(device); CustomizationAdapterMapping mapping = new CustomizationAdapterMapping(); CustomizationIPSettings settings = new CustomizationIPSettings(); // すべてのNICをDHCPにする CustomizationDhcpIpGenerator dhcpIp = new CustomizationDhcpIpGenerator(); settings.setIp(dhcpIp); mapping.setMacAddress(virtualEthernetCard.getMacAddress()); mapping.setAdapter(settings); nicSettingMap.add(mapping); } } return nicSettingMap; }
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; }
@Override public void destroyNode(String vmName) { try (VSphereServiceInstance instance = serviceInstance.get();) { VirtualMachine virtualMachine = getVM(vmName, instance.getInstance().getRootFolder()); Task powerOffTask = virtualMachine.powerOffVM_Task(); if (powerOffTask.waitForTask().equals(Task.SUCCESS)) logger.debug(String.format("VM %s powered off", vmName)); else logger.debug(String.format("VM %s could not be powered off", vmName)); Task destroyTask = virtualMachine.destroy_Task(); if (destroyTask.waitForTask().equals(Task.SUCCESS)) logger.debug(String.format("VM %s destroyed", vmName)); else logger.debug(String.format("VM %s could not be destroyed", vmName)); } catch (Exception e) { logger.error("Can't destroy vm " + vmName, e); Throwables.propagateIfPossible(e); } }
@Override public void resumeNode(String vmName) { VirtualMachine virtualMachine = getNode(vmName); if (virtualMachine.getRuntime().getPowerState().equals(VirtualMachinePowerState.poweredOff)) { try { Task task = virtualMachine.powerOnVM_Task(null); if (task.waitForTask().equals(Task.SUCCESS)) logger.debug(virtualMachine.getName() + " resumed"); } catch (Exception e) { logger.error("Can't resume vm " + vmName, e); propagate(e); } } else logger.debug(vmName + " can't be resumed"); }
@Override public Optional<VirtualMachine> load(String vmName) { Optional<VirtualMachine> results = Optional.absent(); try (VSphereServiceInstance instance = serviceInstance.get();) { VirtualMachine vm = (VirtualMachine) new InventoryNavigator(instance.getInstance().getRootFolder()).searchManagedEntity("VirtualMachine", vmName); if (VSpherePredicate.isTemplatePredicate.apply(vm)) { results = Optional.of(vm); } } catch (Exception e) { logger.error("Can't find template " + vmName, e); Throwables.propagateIfPossible(e); } return results; }
private VirtualMachineSnapshot getCurrentSnapshotOrCreate(String snapshotName, String snapshotDescription, VirtualMachine master) throws InvalidName, VmConfigFault, SnapshotFault, TaskInProgress, FileFault, InvalidState, RuntimeFault, RemoteException { if (master.getSnapshot() == null) { Task task = master.createSnapshot_Task(snapshotName, snapshotDescription, false, false); try { if (task.waitForTask().equals(Task.SUCCESS)) { logger.debug(String.format("snapshot taken for '%s'", master.getName())); } } catch (Exception e) { logger.debug(String.format("Can't take snapshot for '%s'", master.getName()), e); throw propagate(e); } } else logger.debug(String.format("snapshot already available for '%s'", master.getName())); return master.getCurrentSnapShot(); }
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; } } }
protected VirtualSCSIController getSCSIController(VirtualMachine machine) { // 仮想マシンにあるSCSIコントローラのうち、BusNumberが0のものを取得する VirtualSCSIController scsiController = null; for (VirtualDevice device : machine.getConfig().getHardware().getDevice()) { if (device instanceof VirtualSCSIController) { VirtualSCSIController scsiController2 = VirtualSCSIController.class.cast(device); if (scsiController2.getBusNumber() == 0) { scsiController = scsiController2; break; } } } if (scsiController == null) { // SCSIコントローラが見つからない場合 // TODO: SCSIコントローラを作る? throw new AutoException("EPROCESS-000517", 0); } return scsiController; }
protected VirtualDisk getVirtualDisk(VirtualMachine machine, Integer scsiId) { // SCSIコントローラを取得 VirtualSCSIController scsiController = getSCSIController(machine); // SCSIコントローラとSCSI IDが一致するディスクを取得 VirtualDisk disk = null; for (VirtualDevice device : machine.getConfig().getHardware().getDevice()) { if (device instanceof VirtualDisk) { VirtualDisk tmpDisk = VirtualDisk.class.cast(device); if (tmpDisk.getControllerKey() != null && tmpDisk.getControllerKey().equals(scsiController.getKey())) { if (tmpDisk.getUnitNumber() != null && tmpDisk.getUnitNumber().equals(scsiId)) { disk = tmpDisk; break; } } } } if (disk == null) { // VirtualDiskが見つからない場合 throw new AutoException("EPROCESS-000518", scsiId); } return disk; }
protected VirtualEthernetCard editEthernetCards(VirtualMachine machine, String networkName) { // ネットワークアダプタ E1000を使用する VirtualEthernetCard ethernetCard = new VirtualE1000(); // 分散ポートグループ情報取得 DistributedVirtualPortgroupInfo dvPortgroupInfo = getDVPortgroupInfo(machine, networkName); if (dvPortgroupInfo != null) { // 分散ポートグループの場合 VirtualEthernetCardDistributedVirtualPortBackingInfo nicBacking = new VirtualEthernetCardDistributedVirtualPortBackingInfo(); nicBacking.setPort(new DistributedVirtualSwitchPortConnection()); nicBacking.getPort().setPortgroupKey(dvPortgroupInfo.getPortgroupKey()); nicBacking.getPort().setSwitchUuid(dvPortgroupInfo.getSwitchUuid()); ethernetCard.setBacking(nicBacking); } else { // 標準ポートグループの場合 VirtualEthernetCardNetworkBackingInfo backingInfo = new VirtualEthernetCardNetworkBackingInfo(); backingInfo.setDeviceName(networkName); ethernetCard.setBacking(backingInfo); } return ethernetCard; }
public DistributedVirtualPortgroupInfo getDVPortgroupInfo(VirtualMachine machine, String networkName) { HostSystem host = new HostSystem(machine.getServerConnection(), machine.getRuntime().getHost()); ComputeResource computeResource = (ComputeResource) host.getParent(); EnvironmentBrowser envBrowser = computeResource.getEnvironmentBrowser(); DistributedVirtualPortgroupInfo dvPortgroupInfo = null; try { ConfigTarget configTarget = envBrowser.queryConfigTarget(host); // 分散ポートグループの場合 if (configTarget.getDistributedVirtualPortgroup() != null) { // 分散ポートグループ情報を取得 dvPortgroupInfo = findDVPortgroupInfo(configTarget.getDistributedVirtualPortgroup(), networkName); } } catch (RemoteException e) { throw new RuntimeException(e); } return dvPortgroupInfo; }
/** * TODO: メソッドコメントを記述 * * @param vmwareProcessClient * @param instanceNo */ public void updateCustomValue(VmwareProcessClient vmwareProcessClient, Long instanceNo) { // カスタムフィールドがない場合は作成 CustomFieldDef customFieldDef = vmwareProcessClient.getCustomFieldDef(fieldUserName, VirtualMachine.class); if (customFieldDef == null) { vmwareProcessClient.addCustomFieldDef(fieldUserName, VirtualMachine.class); } VmwareInstance vmwareInstance = vmwareInstanceDao.read(instanceNo); Instance instance = instanceDao.read(instanceNo); Farm farm = farmDao.read(instance.getFarmNo()); User user = userDao.read(farm.getUserNo()); // カスタムフィールドの値を設定 vmwareProcessClient.setCustomValue(vmwareInstance.getMachineName(), fieldUserName, user.getUsername()); }
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 VirtualMachineSnapshot getSnapshotInTree( VirtualMachine vm, String snapName) { if (vm == null || snapName == null) { return null; } VirtualMachineSnapshotTree[] snapTree = vm.getSnapshot().getRootSnapshotList(); if(snapTree!=null) { ManagedObjectReference mor = findSnapshotInTree( snapTree, snapName); if(mor!=null) { return new VirtualMachineSnapshot( vm.getServerConnection(), mor); } } return null; }
static VirtualDeviceConfigSpec createRemoveDiskConfigSpec( VirtualMachine vm, String diskName) throws Exception { VirtualDeviceConfigSpec diskSpec = new VirtualDeviceConfigSpec(); VirtualDisk disk = (VirtualDisk) findVirtualDevice(vm.getConfig(), diskName); if(disk != null) { diskSpec.setOperation(VirtualDeviceConfigSpecOperation.remove); diskSpec.setFileOperation(VirtualDeviceConfigSpecFileOperation.destroy); diskSpec.setDevice(disk); return diskSpec; } else { System.out.println("No device found: " + diskName); return null; } }
static String getFreeDatastoreName(VirtualMachine vm, int size) throws Exception { String dsName = null; Datastore[] datastores = vm.getDatastores(); for(int i=0; i<datastores.length; i++) { DatastoreSummary ds = datastores[i].getSummary(); if(ds.getFreeSpace() > size) { dsName = ds.getName(); break; } } return dsName; }
static VirtualDeviceConfigSpec createAddCdConfigSpec(VirtualMachine vm, String dsName, String isoName) throws Exception { VirtualDeviceConfigSpec cdSpec = new VirtualDeviceConfigSpec(); cdSpec.setOperation(VirtualDeviceConfigSpecOperation.add); VirtualCdrom cdrom = new VirtualCdrom(); VirtualCdromIsoBackingInfo cdDeviceBacking = new VirtualCdromIsoBackingInfo(); DatastoreSummary ds = findDatastoreSummary(vm, dsName); cdDeviceBacking.setDatastore(ds.getDatastore()); cdDeviceBacking.setFileName("[" + dsName +"] "+ vm.getName() + "/" + isoName + ".iso"); VirtualDevice vd = getIDEController(vm); cdrom.setBacking(cdDeviceBacking); cdrom.setControllerKey(vd.getKey()); cdrom.setUnitNumber(vd.getUnitNumber()); cdrom.setKey(-1); cdSpec.setDevice(cdrom); return cdSpec; }
static VirtualDeviceConfigSpec createRemoveCdConfigSpec(VirtualMachine vm, String cdName) throws Exception { VirtualDeviceConfigSpec cdSpec = new VirtualDeviceConfigSpec(); cdSpec.setOperation(VirtualDeviceConfigSpecOperation.remove); VirtualCdrom cdRemove = (VirtualCdrom)findVirtualDevice(vm.getConfig(), cdName); if(cdRemove != null) { cdSpec.setDevice(cdRemove); return cdSpec; } else { System.out.println("No device available " + cdName); return null; } }
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; }
@Override public boolean isMachineRunning( TargetHandlerParameters parameters, String machineId ) throws TargetException { boolean result; try { final ServiceInstance vmwareServiceInstance = getServiceInstance( parameters.getTargetProperties()); VirtualMachine vm = getVirtualMachine( vmwareServiceInstance, machineId ); result = vm != null; } catch( Exception e ) { throw new TargetException( e ); } return result; }
@Override public String retrievePublicIpAddress( TargetHandlerParameters parameters, String machineId ) throws TargetException { String result = null; try { ServiceInstance vmwareServiceInstance = VmwareIaasHandler.getServiceInstance( parameters.getTargetProperties()); String rootInstanceName = InstanceHelpers.findRootInstancePath( parameters.getScopedInstancePath()); VirtualMachine vm = VmwareIaasHandler.getVirtualMachine( vmwareServiceInstance, rootInstanceName ); if( vm != null ) result = vm.getGuest().getIpAddress(); } catch( Exception e ) { throw new TargetException( e ); } return result; }
/** * Searches for all ip addresses of a virtual machine * * @param virtualMachine the virtual machine to query * @return the ip addresses of the virtual machine, the first one is the primary * @throws RemoteException */ public TreeSet<String> getVirtualMachineIpAddresses(VirtualMachine virtualMachine) throws RemoteException { TreeSet<String> ipAddresses = new TreeSet<String>(); // add the Ip address reported by VMware tools, this should be primary if (virtualMachine.getGuest().getIpAddress() != null) ipAddresses.add(virtualMachine.getGuest().getIpAddress()); // if possible, iterate over all virtual networks networks and add interface Ip addresses if (virtualMachine.getGuest().getNet() != null) { for (GuestNicInfo guestNicInfo : virtualMachine.getGuest().getNet()) { if (guestNicInfo.getIpAddress() != null) { for (String ipAddress : guestNicInfo.getIpAddress()) { ipAddresses.add(ipAddress); } } } } return ipAddresses; }
public void removeVirtualMachineSnapshot(VirtualMachine vm, String nameVm) throws Exception { logger.info("Launching old snapshot removing process for {}", nameVm); if(vm.getSnapshot() != null) { logger.info("Deleting snapshot ..."); VirtualMachineSnapshotTree[] _stree = vm.getSnapshot().getRootSnapshotList(); if(_stree != null) { for(VirtualMachineSnapshotTree _st : _stree) { if(_st.getName().equals(nameVm)) { logger.info("Old snahpot {} found"); VirtualMachineSnapshot _vmsSnap = new VirtualMachineSnapshot(vm.getServerConnection(), _st.getSnapshot()); Task _taskSnap = _vmsSnap.removeSnapshot_Task(true); logger.info("Removing process launched..."); if(_taskSnap.waitForTask() != Task.SUCCESS) { logger.error("Error on snapshot removing process. {}",_taskSnap.getTaskInfo().getError().getLocalizedMessage()); throw new Exception(_taskSnap.getTaskInfo().getError().getLocalizedMessage()); } logger.info("Snapshot removed successfully"); } } } } }
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; }
private Iterable<VirtualMachine> listNodes(VSphereServiceInstance instance) { Iterable<VirtualMachine> vms = ImmutableSet.of(); try { Folder nodesFolder = instance.getInstance().getRootFolder(); ManagedEntity[] managedEntities = new InventoryNavigator(nodesFolder).searchManagedEntities("VirtualMachine"); vms = Iterables.transform(Arrays.asList(managedEntities), new Function<ManagedEntity, VirtualMachine>() { public VirtualMachine apply(ManagedEntity input) { return (VirtualMachine) input; } }); } catch (Throwable e) { logger.error("Can't find vm", e); } return vms; }
@Override public Iterable<VirtualMachine> listNodes() { try (VSphereServiceInstance instance = serviceInstance.get();) { return listNodes(instance); } catch (Throwable e) { logger.error("Can't find vm", e); Throwables.propagateIfPossible(e); return ImmutableSet.of(); } }
@Override public Iterable<VirtualMachine> listNodesByIds(Iterable<String> ids) { Iterable<VirtualMachine> vms = ImmutableSet.of(); try (VSphereServiceInstance instance = serviceInstance.get();) { Folder nodesFolder = instance.getInstance().getRootFolder(); List<List<String>> list = new ArrayList<List<String>>(); Iterator<String> idsIterator = ids.iterator(); while (idsIterator.hasNext()) { list.add(Lists.newArrayList("VirtualMachine", idsIterator.next())); } String[][] typeInfo = ListsUtils.ListToArray(list); ManagedEntity[] managedEntities = new InventoryNavigator(nodesFolder).searchManagedEntities( typeInfo, true); vms = Iterables.transform(Arrays.asList(managedEntities), new Function<ManagedEntity, VirtualMachine>() { public VirtualMachine apply(ManagedEntity input) { return (VirtualMachine) input; } }); } catch (Throwable e) { logger.error("Can't find vms ", e); } return vms; // Iterable<VirtualMachine> nodes = listNodes(); // Iterable<VirtualMachine> selectedNodes = Iterables.filter(nodes, VSpherePredicate.isNodeIdInList(ids)); // return selectedNodes; }
@Override public Iterable<Image> listImages() { try (VSphereServiceInstance instance = serviceInstance.get();) { Iterable<VirtualMachine> nodes = listNodes(instance); Iterable<VirtualMachine> templates = Iterables.filter(nodes, VSpherePredicate.isTemplatePredicate); Iterable<Image> images = Iterables.transform(templates, virtualMachineToImage); return FluentIterable.from(images).toList(); } catch (Throwable t) { Throwables.propagateIfPossible(t); return ImmutableSet.of(); } }
@Override public VirtualMachine getNode(String vmName) { try (VSphereServiceInstance instance = serviceInstance.get()) { return getVM(vmName, instance.getInstance().getRootFolder()); } catch (Throwable e) { Throwables.propagateIfPossible(e); } return null; }
@Override public void rebootNode(String vmName) { VirtualMachine virtualMachine = getNode(vmName); try { virtualMachine.rebootGuest(); } catch (Exception e) { logger.error("Can't reboot vm " + vmName, e); propagate(e); } logger.debug(vmName + " rebooted"); }
@Override public void suspendNode(String vmName) { VirtualMachine virtualMachine = getNode(vmName); try { Task task = virtualMachine.suspendVM_Task(); if (task.waitForTask().equals(Task.SUCCESS)) logger.debug(vmName + " suspended"); else logger.debug(vmName + " can't be suspended"); } catch (Exception e) { logger.error("Can't suspend vm " + vmName, e); propagate(e); } }
private VirtualMachine cloneMaster(VirtualMachine master, String tag, String name, VirtualMachineCloneSpec cloneSpec, String folderName) { VirtualMachine cloned = null; try { FolderNameToFolderManagedEntity toFolderManagedEntity = new FolderNameToFolderManagedEntity(serviceInstance, master); Folder folder = toFolderManagedEntity.apply(folderName); Task task = master.cloneVM_Task(folder, name, cloneSpec); String result = task.waitForTask(); if (result.equals(Task.SUCCESS)) { logger.trace("<< after clone search for VM with name: " + name); Retryer<VirtualMachine> retryer = RetryerBuilder.<VirtualMachine>newBuilder() .retryIfResult(Predicates.<VirtualMachine>isNull()) .withStopStrategy(StopStrategies.stopAfterAttempt(5)) .retryIfException().withWaitStrategy(WaitStrategies.fixedWait(1, TimeUnit.SECONDS)) .build(); cloned = retryer.call(new GetVirtualMachineCallable(name, folder, serviceInstance.get().getInstance().getRootFolder())); } else { String errorMessage = task.getTaskInfo().getError().getLocalizedMessage(); logger.error(errorMessage); } } catch (Exception e) { if (e instanceof NoPermission){ NoPermission noPermission = (NoPermission)e; logger.error("NoPermission: " + noPermission.getPrivilegeId()); } logger.error("Can't clone vm: " + e.toString(), e); propagate(e); } if (cloned == null) logger.error("<< Failed to get cloned VM. " + name); return checkNotNull(cloned, "cloned"); }
@Override public VirtualMachine call() throws Exception { VirtualMachine cloned = null; cloned = getVM(vmName, folder); if (cloned == null) cloned = getVM(vmName, rootFolder); return cloned; }
private VirtualMachine getVMwareTemplate(String imageName, Folder rootFolder) { VirtualMachine image = null; try { VirtualMachine node = getVM(imageName, rootFolder); if (VSpherePredicate.isTemplatePredicate.apply(node)) image = node; } catch (Exception e) { logger.error("cannot find an image called " + imageName, e); propagate(e); } return checkNotNull(image, "image with name " + imageName + " not found."); }
private void waitForPort(VirtualMachine vm, int port, long timeout) { GuestOperationsManager gom = serviceInstance.get().getInstance().getGuestOperationsManager(); GuestAuthManager gam = gom.getAuthManager(vm); NamePasswordAuthentication npa = new NamePasswordAuthentication(); npa.setUsername("root"); npa.setPassword(vmInitPassword); GuestProgramSpec gps = new GuestProgramSpec(); gps.programPath = "/bin/sh"; StringBuilder openPortScript = new StringBuilder("netstat -nat | grep LIST | grep -q ':" + port + " ' && touch /tmp/portopen.txt"); gps.arguments = "-c \"" + openPortScript.toString() + "\""; List<String> env = Lists.newArrayList("PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin", "SHELL=/bin/bash"); gps.setEnvVariables(env.toArray(new String[env.size()])); GuestProcessManager gpm = gom.getProcessManager(vm); try { long pid = gpm.startProgramInGuest(npa, gps); GuestFileManager guestFileManager = vm.getServerConnection().getServiceInstance().getGuestOperationsManager().getFileManager(vm); FileTransferInformation fti = guestFileManager.initiateFileTransferFromGuest(npa, "/tmp/portopen.txt"); if (fti.getSize() == 0) logger.debug(" "); } catch (RemoteException e) { logger.error(e.getMessage(), e); Throwables.propagate(e); } }
@Override public boolean apply(VirtualMachine virtualMachine) { try { return virtualMachine.getConfig().isTemplate(); } catch (Exception e) { return true; } }
@Override public boolean apply(@Nullable VirtualMachine input) { if (input == null) return false; GuestNicInfo[] nics = input.getGuest().getNet(); boolean nicConnected = false; if (null != nics) { for (GuestNicInfo nic : nics) { nicConnected = nicConnected || nic.connected; } } return nicConnected; }