コード例 #1
0
  private void setupBondInfo(
      DynaActionForm form, RequestContext context, KickstartScheduleCommand cmd) {
    Server server = cmd.getServer();
    List<NetworkInterface> nics = new LinkedList<NetworkInterface>(server.getNetworkInterfaces());

    if (nics.isEmpty()) {
      return;
    }

    for (Iterator<NetworkInterface> itr = nics.iterator(); itr.hasNext(); ) {
      NetworkInterface nic = itr.next();
      if ("127.0.0.1".equals(nic.getIpaddr())) {
        itr.remove();
      }
    }

    context.getRequest().setAttribute(ALL_NETWORK_INTERFACES, nics);

    if (StringUtils.isBlank(form.getString(BOND_TYPE))) {
      form.set(BOND_TYPE, DONT_CREATE_BOND_VALUE);
    }

    NetworkInterface oldBond = null;
    for (NetworkInterface nic : nics) {
      if (nic.isBond()) {
        oldBond = nic;
        break;
      }
    }

    if (oldBond != null) {
      if (StringUtils.isBlank(form.getString(BOND_INTERFACE))) {
        form.set(BOND_INTERFACE, oldBond.getName());
      }

      if (StringUtils.isBlank(form.getString(BOND_IP_ADDRESS))) {
        form.set(BOND_IP_ADDRESS, oldBond.getIpaddr());
      }

      if (StringUtils.isBlank(form.getString(BOND_NETMASK))) {
        form.set(BOND_NETMASK, oldBond.getNetmask());
      }
    }

    String[] slaves = (String[]) form.get(BOND_SLAVE_INTERFACES);
    if (slaves == null || slaves.length == 0) {
      List<String> slavesList = new ArrayList<String>();
      // if there is a bonded interface on the system
      if (!StringUtils.isBlank(form.getString(BOND_INTERFACE))) {
        for (NetworkInterface nic : nics) {
          // if the nic does not have an IP address it is probably a
          // slave to the bond, add it to the default selected list
          if (StringUtils.isBlank(nic.getIpaddr())) {
            slavesList.add(nic.getName());
          }
        }
      }

      form.set(BOND_SLAVE_INTERFACES, convertToStringArray(slavesList.toArray()));
    }
  }