Пример #1
0
  /**
   * @param clusterNetworks cluster logical networks
   * @param interfaceNetworkNames VM interface network names
   * @return true if all VM network interfaces are attached to VM networks
   */
  protected ValidationResult validateInterfacesAttachedToVmNetworks(
      final List<Network> clusterNetworks, Set<String> interfaceNetworkNames) {
    List<String> nonVmNetworkNames =
        NetworkUtils.filterNonVmNetworkNames(clusterNetworks, interfaceNetworkNames);

    return nonVmNetworkNames.isEmpty()
        ? ValidationResult.VALID
        : new ValidationResult(
            VdcBllMessages.ACTION_TYPE_FAILED_NOT_A_VM_NETWORK,
            String.format("$networks %1$s", StringUtils.join(nonVmNetworkNames, ",")));
  }
Пример #2
0
  protected boolean migrationInterfaceUp(VdsNetworkInterface nic, List<VdsNetworkInterface> nics) {
    if (NetworkUtils.isVlan(nic)) {
      String physicalNic = nic.getBaseInterface();
      for (VdsNetworkInterface iface : nics) {
        if (iface.getName().equals(physicalNic)) {
          return iface.getStatistics().getStatus() == InterfaceStatus.UP;
        }
      }
    }

    return nic.getStatistics().getStatus() == InterfaceStatus.UP;
  }
Пример #3
0
 /**
  * Returns the underlying interface name of a given nic
  *
  * @param nic
  * @return Base interface name if the nic is a vlan device. Otherwise, the name of the nic
  */
 public static String stripVlan(VdsNetworkInterface nic) {
   return NetworkUtils.isVlan(nic) ? nic.getBaseInterface() : nic.getName();
 }
  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;
  }
  @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);
      }
    }
  }