private ValidatorError validateNetworkInterface() { if (!LINK_NETWORK_TYPE.equals(networkInterface)) { boolean nicAvailable = false; for (NetworkInterface nic : server.getNetworkInterfaces()) { if (networkInterface.equals(nic.getName())) { nicAvailable = true; break; } } if (!nicAvailable) { return new ValidatorError( "kickstart.schedule.nosuchdevice", server.getName(), networkInterface); } } return null; }
private void setupNetworkInfo( DynaActionForm form, RequestContext context, KickstartScheduleCommand cmd) { Server server = cmd.getServer(); List<NetworkInterface> nics = getPublicNetworkInterfaces(server); if (nics.isEmpty()) { return; } context.getRequest().setAttribute(NETWORK_INTERFACES, nics); if (StringUtils.isBlank(form.getString(NETWORK_INTERFACE))) { String defaultInterface = ConfigDefaults.get().getDefaultKickstartNetworkInterface(); for (NetworkInterface nic : nics) { if (nic.getName().equals(defaultInterface)) { form.set(NETWORK_INTERFACE, ConfigDefaults.get().getDefaultKickstartNetworkInterface()); } } if (StringUtils.isBlank(form.getString(NETWORK_INTERFACE))) { form.set(NETWORK_INTERFACE, server.findPrimaryNetworkInterface().getName()); } } }
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())); } }