Alona Kaplan has uploaded a new change for review. Change subject: engine: Adjust NetworkUtils to accept vlan devices identified by any name ......................................................................
engine: Adjust NetworkUtils to accept vlan devices identified by any name The changes in this class will be done in two phases. Phase 1 (in this patch)- Adjusting NetworkUtils to get the underling interface name of the nic by using VdsNetworkInterface.getBaseInterface() instead of determine the underling nicName from the vlan device name. In this patch old methods signatures are NOT changed in order to avoid breaking the compilation. If a change to the signature is needed, a new method overloads the old one is added. Phase 2- Removing the old methods. Will be done after all the usages of the old methods are replaced/fixed. Change-Id: I426159c169b1fa478776abafb38cb7ae6fdac3be Signed-off-by: Alona Kaplan <[email protected]> --- M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/NetworkUtils.java 1 file changed, 26 insertions(+), 15 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/08/26608/1 diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/NetworkUtils.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/NetworkUtils.java index ef75c6b..a43da8d 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/NetworkUtils.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/NetworkUtils.java @@ -24,6 +24,7 @@ return Config.<String> getValue(ConfigValues.ManagementNetwork); } + // TODO this method should be removed at the end of accept vlan devices identified by any name // method return interface name without vlan: // input: eth0.5 output eth0 // input" eth0 output eth0 @@ -38,6 +39,12 @@ sb.append(tokens[i]).append("."); } return StringUtils.stripEnd(sb.toString(), "."); + } + + // method returns underlying interface name: + // if the interface is not vlan returns the interface name + public static String stripVlan(VdsNetworkInterface nic) { + return NetworkUtils.isVlan(nic) ? nic.getBaseInterface() : nic.getName(); } // method return interface name without vlan: @@ -57,23 +64,10 @@ return StringUtils.stripEnd(sb.toString(), "."); } - // method return the vlan part of the interface name (if exists), - // else - return null - public static Integer getVlanId(String ifaceName) { - String[] tokens = ifaceName.split("[.]", -1); - if (tokens.length > 1) { - Integer vlan = IntegerCompat.tryParse(tokens[tokens.length - 1]); - if (vlan != null) { - return vlan; - } - } - return null; - } - public static boolean isBondVlan(List<VdsNetworkInterface> interfaces, VdsNetworkInterface iface) { if (isVlan(iface)) { for (VdsNetworkInterface i : interfaces) { - if (Boolean.TRUE.equals(i.getBonded()) && interfaceBasedOn(iface.getName(), i.getName())) { + if (Boolean.TRUE.equals(i.getBonded()) && iface.getBaseInterface().equals(i.getName())) { return true; } } @@ -82,6 +76,7 @@ return false; } + // TODO this method should be removed at the end of accept vlan devices identified by any name /** * Check if the proposed interface name represents a VLAN of the given interface name or is equal to it.<br> * If either of the parameters is null, <code>false</code> is returned. @@ -98,9 +93,25 @@ return iface != null && proposedIface != null && iface.equals(stripVlan(proposedIface)); } + /** + * Check if the proposed interface represents a VLAN of the given interface name or is equal to it.<br> + * If either of the parameters is null, <code>false</code> is returned. + * + * @param proposedIface + * The interface to check if it's a VLAN of the other interface or it is the other interface. + * @param iface + * The interface to check for. + * + * @return <code>true</code> if the proposed interface is a VLAN on the interface or if it is the other interface, + * <code>false</code> otherwise. + */ + public static boolean interfaceBasedOn(VdsNetworkInterface proposedIface, String iface) { + return iface != null && proposedIface != null && iface.equals(stripVlan(proposedIface)); + } + public static boolean interfaceHasVlan(VdsNetworkInterface iface, List<VdsNetworkInterface> allIfaces) { for (VdsNetworkInterface i : allIfaces) { - if (isVlan(i) && interfaceBasedOn(i.getName(), iface.getName())) { + if (isVlan(i) && interfaceBasedOn(i, iface.getName())) { return true; } } -- To view, visit http://gerrit.ovirt.org/26608 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I426159c169b1fa478776abafb38cb7ae6fdac3be Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Alona Kaplan <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
