@Override public String toString() { return String.format( "%s, force=%s, checkConnectivity=%s, conectivityTimeout=%s,\n\tnetworks=%s,\n\tbonds=%s,\n\tinterfaces=%s,\n\tremovedNetworks=%s,\n\tremovedBonds=%s", super.toString(), isForce(), isCheckConnectivity(), getConectivityTimeout(), Entities.collectionToString(getNetworks(), "\t\t"), Entities.collectionToString(getBonds(), "\t\t"), Entities.collectionToString(getInterfaces(), "\t\t"), getRemovedNetworks(), getRemovedBonds()); }
private Set<String> getClusterNetworksNames() { if (cachedClusterNetworksNames == null) { cachedClusterNetworksNames = Entities.objectNames(getClusterNetworks()); } return cachedClusterNetworksNames; }
private Set<String> getInterfaceNetworkNames() { if (cachedInterfaceNetworkNames == null) { cachedInterfaceNetworkNames = Entities.vmInterfacesByNetworkName(vm.getInterfaces()).keySet(); } return cachedInterfaceNetworkNames; }
/** * Filter out LUNs that are already a part of storage domains exist in the system. * * @param luns the LUNs list * @return the filtered LUNs list */ protected List<LUNs> filterLUNsThatBelongToExistingStorageDomains(List<LUNs> luns) { List<StorageDomain> existingStorageDomains = getStorageDomainDao().getAll(); final List<Guid> existingStorageDomainIDs = Entities.getIds(existingStorageDomains); return luns.stream() .filter(lun -> !existingStorageDomainIDs.contains(lun.getStorageDomainId())) .collect(Collectors.toList()); }
/** * Actually process the VM device update in DB. * * @param vm */ private void processVmDevices(Map vm) { if (vm == null || vm.get(VdsProperties.vm_guid) == null) { log.error("Received NULL VM or VM id when processing VM devices, abort."); return; } Guid vmId = new Guid((String) vm.get(VdsProperties.vm_guid)); Set<Guid> processedDevices = new HashSet<Guid>(); List<VmDevice> devices = getDbFacade().getVmDeviceDao().getVmDeviceByVmId(vmId); Map<VmDeviceId, VmDevice> deviceMap = Entities.businessEntitiesById(devices); for (Object o : (Object[]) vm.get(VdsProperties.Devices)) { Map device = (Map<String, Object>) o; if (device.get(VdsProperties.Address) == null) { logDeviceInformation(vmId, device); continue; } Guid deviceId = getDeviceId(device); VmDevice vmDevice = deviceMap.get(new VmDeviceId(deviceId, vmId)); String logicalName = null; if (deviceId != null && FeatureSupported.reportedDisksLogicalNames( getVdsManager().getGroupCompatibilityVersion()) && VmDeviceType.DISK.getName().equals(device.get(VdsProperties.Device))) { try { logicalName = getDeviceLogicalName((Map<?, ?>) vm.get(VdsProperties.GuestDiskMapping), deviceId); } catch (Exception e) { log.error( "error while getting device name when processing, vm '{}', device info '{}' with exception, skipping '{}'", vmId, device, e.getMessage()); log.error("Exception", e); } } if (deviceId == null || vmDevice == null) { deviceId = addNewVmDevice(vmId, device, logicalName); } else { vmDevice.setIsPlugged(Boolean.TRUE); vmDevice.setAddress(((Map<String, String>) device.get(VdsProperties.Address)).toString()); vmDevice.setAlias(StringUtils.defaultString((String) device.get(VdsProperties.Alias))); vmDevice.setLogicalName(logicalName); addVmDeviceToList(vmDevice); } processedDevices.add(deviceId); } handleRemovedDevices(vmId, processedDevices, devices); }
private void auditNetworkCompliance( VDS host, List<VdsNetworkInterface> dbIfaces, List<Network> clusterNetworks) { if (host.getStatus() == VDSStatus.Maintenance) { return; } final Map<String, Network> clusterNetworksByName = Entities.entitiesByName(clusterNetworks); final Collection<Network> dbHostNetworks = findNetworksOnInterfaces(dbIfaces, clusterNetworksByName); logChangedDisplayNetwork(host, dbHostNetworks, dbIfaces); logUnsynchronizedNetworks(host, clusterNetworksByName); }
/** * Create StorageDomain objects according to the specified VG-IDs list. * * @param vgIDs the VG-IDs list * @return storage domains list */ @SuppressWarnings("unchecked") protected List<StorageDomain> getStorageDomainsByVolumeGroupIds(List<String> vgIDs) { List<StorageDomain> storageDomains = new ArrayList<>(); // Get existing PhysicalVolumes. List<String> existingLunIds = Entities.getIds(getLunDao().getAll()); for (String vgID : vgIDs) { VDSReturnValue returnValue; try { returnValue = executeGetVGInfo(new GetVGInfoVDSCommandParameters(getParameters().getVdsId(), vgID)); } catch (RuntimeException e) { log.error("Could not get info for VG ID: '{}': {}", vgID, e.getMessage()); log.debug("Exception", e); continue; } ArrayList<LUNs> luns = (ArrayList<LUNs>) returnValue.getReturnValue(); List<String> lunIdsOnStorage = Entities.getIds(luns); if (CollectionUtils.containsAny(lunIdsOnStorage, existingLunIds)) { log.info("There are existing luns in the system which are part of VG id '{}'", vgID); continue; } // Get storage domain ID by a representative LUN LUNs lun = luns.get(0); Guid storageDomainId = lun.getStorageDomainId(); // Get storage domain using GetStorageDomainInfo StorageDomain storageDomain = getStorageDomainById(storageDomainId); if (storageDomain != null) { storageDomains.add(storageDomain); } } return storageDomains; }
private String getVmNetworksImplementedAsBridgeless(VDS host, List<Network> clusterNetworks) { Map<String, VdsNetworkInterface> interfacesByNetworkName = Entities.hostInterfacesByNetworkName(host.getInterfaces()); List<String> networkNames = new ArrayList<>(); for (Network net : clusterNetworks) { if (net.isVmNetwork() && interfacesByNetworkName.containsKey(net.getName()) && !interfacesByNetworkName.get(net.getName()).isBridged()) { networkNames.add(net.getName()); } } return StringUtils.join(networkNames, ","); }
@Override public PersistentHostSetupNetworksParameters buildParameters( Guid vdsId, List<Network> labeledNetworksToBeAdded, List<Network> labeledNetworksToBeRemoved, Map<String, VdsNetworkInterface> nicsByLabel) { final PersistentHostSetupNetworksParameters addSetupNetworksParameters = addNetworksByLabelParametersBuilder.buildParameters( vdsId, labeledNetworksToBeAdded, nicsByLabel); final PersistentHostSetupNetworksParameters removeSetupNetworksParameters = removeNetworksByLabelParametersBuilder.buildParameters(vdsId, labeledNetworksToBeRemoved); final PersistentHostSetupNetworksParameters combinedParams = combine(addSetupNetworksParameters, removeSetupNetworksParameters); final Collection<Network> affectedNetworks = concat(labeledNetworksToBeAdded, labeledNetworksToBeRemoved); combinedParams.setNetworkNames(StringUtils.join(Entities.objectNames(affectedNetworks), ", ")); return combinedParams; }
@Override protected void executeQueryCommand() { List<VmTemplate> vmTemplateList = getDbFacade().getVmTemplateDao().getAllForNetwork(getParameters().getId()); List<VmNetworkInterface> vmNetworkInterfaceList = getDbFacade() .getVmNetworkInterfaceDao() .getAllForTemplatesByNetwork(getParameters().getId()); final Map<Guid, VmTemplate> vmTemplatesById = Entities.businessEntitiesById(vmTemplateList); List<PairQueryable<VmNetworkInterface, VmTemplate>> vmInterfaceVmPairs = new ArrayList<PairQueryable<VmNetworkInterface, VmTemplate>>(); for (VmNetworkInterface vmNetworkInterface : vmNetworkInterfaceList) { vmInterfaceVmPairs.add( new PairQueryable<VmNetworkInterface, VmTemplate>( vmNetworkInterface, vmTemplatesById.get(vmNetworkInterface.getVmTemplateId()))); } getQueryReturnValue().setReturnValue(vmInterfaceVmPairs); }
@Override protected void executeCommand() { String address = getParameters().getAddress(); String subnet = StringUtils.isEmpty(getParameters().getSubnet()) ? getParameters().getNetwork().getSubnet() : getParameters().getSubnet(); String gateway = StringUtils.isEmpty(getParameters().getGateway()) ? "" : getParameters().getGateway(); ArrayList<String> interfaceNames = new ArrayList<>(); Map<String, VdsNetworkInterface> interfaceByName = Entities.entitiesByName(interfaces); for (VdsNetworkInterface i : getParameters().getInterfaces()) { VdsNetworkInterface existingIface = interfaceByName.get(i.getName()); if (Boolean.TRUE.equals(existingIface.getBonded()) || NetworkUtils.isBondVlan(interfaces, existingIface)) { getParameters().setBondName(NetworkUtils.stripVlan(existingIface)); for (VdsNetworkInterface ix : interfaces) { if (NetworkUtils.interfaceBasedOn(existingIface, ix.getBondName())) { interfaceNames.add(NetworkUtils.stripVlan(ix)); } } } else { interfaceNames.add(NetworkUtils.stripVlan(existingIface)); } } // updating a vlan over bond if the bond was not provided the bond device should preserve the // bonding options String bondingOptions = null; if (getParameters().getBondingOptions() == null && getParameters().getBondName() != null && !Entities.entitiesByName(getParameters().getInterfaces()) .containsKey(getParameters().getBondName())) { VdsNetworkInterface bond = Entities.entitiesByName(interfaces).get(getParameters().getBondName()); bondingOptions = bond == null ? null : bond.getBondOptions(); } else { bondingOptions = getParameters().getBondingOptions(); } NetworkVdsmVDSCommandParameters parameters = new NetworkVdsmVDSCommandParameters( getParameters().getVdsId(), getParameters().getNetwork().getName(), getParameters().getNetwork().getVlanId(), getParameters().getBondName(), interfaceNames.toArray(new String[] {}), address, subnet, gateway, getParameters().getNetwork().getStp(), bondingOptions, getParameters().getBootProtocol()); parameters.setVmNetwork(getParameters().getNetwork().isVmNetwork()); parameters.setOldNetworkName(getParameters().getOldNetworkName()); parameters.setConnectionTimeout( Config.<Integer>getValue(ConfigValues.NetworkConnectivityCheckTimeoutInSeconds)); parameters.setCheckConnectivity(getParameters().getCheckConnectivity()); IPAddress[] adresses = Dns.getHostAddresses(NetworkUtils.OS_REFERENCE_TO_MACHINE_NAME); if (adresses != null && adresses.length > 0) { parameters.setHostAddr(adresses[0].toString()); } if (getParameters().getCheckConnectivity()) { ThreadPoolUtil.execute(new EditNetworkThread(parameters)); pollVds(getVds()); } else { editNetworkThreadCompat(parameters); } if (retVal != null && editNetworkDone) { // update vds network data retVal = runVdsCommand( VDSCommandType.CollectVdsNetworkData, new CollectHostNetworkDataVdsCommandParameters(getVds())); if (retVal.getSucceeded()) { Guid groupId = getVdsDao().get(getParameters().getVdsId()).getVdsGroupId(); NetworkClusterHelper.setStatus(groupId, getParameters().getNetwork()); setSucceeded(true); } } }