private boolean qosConfiguredOnInterface(VdsNetworkInterface iface, Network network) {
   if (iface.isQosOverridden()) {
     return iface.getQos() != null;
   } else {
     return network.getQosId() != null;
   }
 }
Esempio n. 2
0
 /**
  * Check whether the network attachment has any QoS configured on it, whether via its network or
  * overridden.
  *
  * @param networkAttachment The network interface.
  * @param network The network attached to the interface.
  * @return true iff any QoS is applied to the interface.
  */
 public static boolean qosConfiguredOnInterface(
     NetworkAttachment networkAttachment, Network network) {
   if (networkAttachment != null && networkAttachment.isQosOverridden()) {
     return networkAttachment.getHostNetworkQos() != null
         && !networkAttachment
             .getHostNetworkQos()
             .isEmpty(); // TODO MM: I think that is empty is wrong, since qos can be overridden
                         // back to unlimited.
   } else {
     return network != null && network.getQosId() != null;
   }
 }
  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;
  }