private String getMigrationNetworkIp() { if (!FeatureSupported.migrationNetwork(getVm().getVdsGroupCompatibilityVersion())) { return null; } Network migrationNetwork = null; // Find migrationNetworkCluster List<Network> allNetworksInCluster = getNetworkDao().getAllForCluster(getVm().getVdsGroupId()); for (Network tempNetwork : allNetworksInCluster) { if (tempNetwork.getCluster().isMigration()) { migrationNetwork = tempNetwork; break; } } if (migrationNetwork != null) { // assure migration network is active on source host if (getMigrationNetworkAddress(getVds().getId(), migrationNetwork.getName()) == null) { return null; } // find migration IP address on destination host return getMigrationNetworkAddress(getDestinationVds().getId(), migrationNetwork.getName()); } return null; }
/** * Checks that the destination cluster has all the networks that the given NICs require.<br> * No network on a NIC is allowed (it's checked when running VM). * * @param interfaces The NICs to check networks on. * @return Whether the destination cluster has all networks configured or not. */ private boolean validateDestinationClusterContainsNetworks(List<VmNic> interfaces) { List<Network> networks = DbFacade.getInstance().getNetworkDao().getAllForCluster(targetClusterId); StringBuilder missingNets = new StringBuilder(); for (VmNic iface : interfaces) { Network network = NetworkHelper.getNetworkByVnicProfileId(iface.getVnicProfileId()); if (network != null) { boolean exists = false; for (Network net : networks) { if (net.getName().equals(network.getName())) { exists = true; break; } } if (!exists) { if (missingNets.length() > 0) { missingNets.append(", "); } missingNets.append(network.getName()); } } } if (missingNets.length() > 0) { parentCommand.addCanDoActionMessage(EngineMessage.MOVE_VM_CLUSTER_MISSING_NETWORK); parentCommand.addCanDoActionMessageVariable("networks", missingNets.toString()); return false; } return true; }
/** * filter networks which are not VM networks from the newtorkNames list * * @param networks logical networks * @param networkNames target names to match non-VM networks upon * @return */ public static List<String> filterNonVmNetworkNames( List<Network> networks, Set<String> networkNames) { List<String> list = new ArrayList<>(); for (Network net : networks) { if (!net.isVmNetwork() && networkNames.contains(net.getName())) { list.add(net.getName()); } } return list; }
private String getMissingOperationalClusterNetworks(VDS host, List<Network> clusterNetworks) { List<String> networkNames = new ArrayList<>(); for (Network net : clusterNetworks) { if (net.getCluster().getStatus() == OPERATIONAL && net.getCluster().isRequired() && !host.getNetworkNames().contains(net.getName())) { networkNames.add(net.getName()); } } return StringUtils.join(networkNames, ","); }
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, ","); }
protected void buildVmNetworkCluster() { // set Display network List<NetworkCluster> all = DbFacade.getInstance().getNetworkClusterDao().getAllForCluster(vm.getVdsGroupId()); NetworkCluster networkCluster = null; for (NetworkCluster tempNetworkCluster : all) { if (tempNetworkCluster.isDisplay()) { networkCluster = tempNetworkCluster; break; } } if (networkCluster != null) { Network net = null; List<Network> allNetworks = DbFacade.getInstance().getNetworkDao().getAll(); for (Network tempNetwork : allNetworks) { if (tempNetwork.getId().equals(networkCluster.getNetworkId())) { net = tempNetwork; break; } } if (net != null) { createInfo.put(VdsProperties.DISPLAY_NETWORK, net.getName()); } } }
private void logChangedDisplayNetwork( VDS host, Collection<Network> engineHostNetworks, Collection<VdsNetworkInterface> engineInterfaces) { if (isVmRunningOnHost(host.getId())) { final Network engineDisplayNetwork = findDisplayNetwork(host.getVdsGroupId(), engineHostNetworks); if (engineDisplayNetwork == null) { return; } final IsNetworkOnInterfacePredicate isNetworkOnInterfacePredicate = new IsNetworkOnInterfacePredicate(engineDisplayNetwork.getName()); final VdsNetworkInterface vdsmDisplayInterface = LinqUtils.firstOrNull(host.getInterfaces(), isNetworkOnInterfacePredicate); final VdsNetworkInterface engineDisplayInterface = LinqUtils.firstOrNull(engineInterfaces, isNetworkOnInterfacePredicate); final DisplayInterfaceEqualityPredicate displayIneterfaceEqualityPredicate = new DisplayInterfaceEqualityPredicate(engineDisplayInterface); if (vdsmDisplayInterface == null // the display interface is't on host anymore || !displayIneterfaceEqualityPredicate.eval(vdsmDisplayInterface)) { final AuditLogableBase loggable = new AuditLogableBase(host.getId()); auditLogDirector.log(loggable, AuditLogType.NETWORK_UPDATE_DISPLAY_FOR_HOST_WITH_ACTIVE_VM); } } }
private void skipManagementNetworkCheck( List<VdsNetworkInterface> ifaces, List<Network> clusterNetworks, Guid clusterId) { final Network managementNetwork = managementNetworkUtil.getManagementNetwork(clusterId); final String managementNetworkName = managementNetwork.getName(); for (VdsNetworkInterface iface : ifaces) { if (managementNetworkName.equals(iface.getNetworkName())) { return; } } for (Iterator<Network> iterator = clusterNetworks.iterator(); iterator.hasNext(); ) { Network network = iterator.next(); if (managementNetworkName.equals(network.getName())) { iterator.remove(); break; } } }
public static Map<String, Network> networksByName(List<Network> networks) { if (!networks.isEmpty()) { Map<String, Network> byName = new HashMap<>(); for (Network net : networks) { byName.put(net.getName(), net); } return byName; } else { return Collections.emptyMap(); } }
private void addVnicProfile(Network network, boolean publicUse) { VnicProfile vnicProfile = new VnicProfile(); vnicProfile.setName(network.getName()); vnicProfile.setNetworkId(network.getId()); VnicProfileParameters parameters = new VnicProfileParameters(vnicProfile); parameters.setPublicUse(publicUse); Frontend.getInstance() .runAction( VdcActionType.AddVnicProfile, parameters, new IFrontendActionAsyncCallback() { @Override public void executed(FrontendActionAsyncResult result) { sourceListModel.getSearchCommand().execute(); } }); }
private Map<String, Object> generateNetworks() { Map<String, Object> networks = new HashMap<String, Object>(); NetworkQoSDao qosDao = getDbFacade().getQosDao(); for (Network network : getParameters().getNetworks()) { Map<String, Object> opts = new HashMap<String, Object>(); VdsNetworkInterface iface = findNetworkInterface( network.getName(), getParameters().getInterfaces(), getParameters().getBonds()); String ifaceNameWithoutVlan = NetworkUtils.stripVlan(iface); Boolean bonded = findInterfaceByName(ifaceNameWithoutVlan).getBonded(); String type = (bonded != null && bonded) ? "bonding" : "nic"; opts.put(type, ifaceNameWithoutVlan); if (NetworkUtils.isVlan(network)) { opts.put("vlan", network.getVlanId().toString()); } if (iface.getBootProtocol() != null) { addBootProtocol(opts, iface); } if (network.getMtu() == 0) { opts.put("mtu", NetworkUtils.getDefaultMtu().toString()); } else { opts.put("mtu", String.valueOf(network.getMtu())); } opts.put("bridged", Boolean.toString(network.isVmNetwork())); if (network.isVmNetwork()) { opts.put(VdsProperties.STP, network.getStp() ? "yes" : "no"); } VDS host = getDbFacade().getVdsDao().get(getParameters().getVdsId()); Version version = host.getVdsGroupCompatibilityVersion(); if (qosConfiguredOnInterface(iface, network) && FeatureSupported.hostNetworkQos(version)) { NetworkQosMapper qosMapper = new NetworkQosMapper( opts, VdsProperties.HOST_QOS_INBOUND, VdsProperties.HOST_QOS_OUTBOUND); qosMapper.serialize( iface.isQosOverridden() ? iface.getQos() : qosDao.get(network.getQosId())); } Set<Version> supportedClusterVersionsSet = host.getSupportedClusterVersionsSet(); if (supportedClusterVersionsSet == null || supportedClusterVersionsSet.isEmpty()) { log.warnFormat( "Host {0} ({1}) doesn't contain Supported Cluster Versions, therefore 'defaultRoute'" + " will not be sent via the SetupNetworks", host.getName(), host.getId()); } else if (FeatureSupported.defaultRoute(Collections.max(supportedClusterVersionsSet)) && NetworkUtils.isManagementNetwork(network) && (iface.getBootProtocol() == NetworkBootProtocol.DHCP || (iface.getBootProtocol() == NetworkBootProtocol.STATIC_IP && StringUtils.isNotEmpty(iface.getGateway())))) { opts.put(DEFAULT_ROUTE, Boolean.TRUE); } if (iface.hasCustomProperties()) { opts.put(VdsProperties.NETWORK_CUSTOM_PROPERTIES, iface.getCustomProperties()); } networks.put(network.getName(), opts); } for (String net : getParameters().getRemovedNetworks()) { networks.put(net, REMOVE_OBJ); } return networks; }