private Set<String> getAllSlaveNames() { Set<String> slaveNames = new HashSet<>(); for (CreateOrUpdateBond bond : hostSetupNetworksParametersData.getBonds()) { slaveNames.addAll(bond.getSlaves()); } return slaveNames; }
private Map<String, List<VdsNetworkInterface>> getBondNameToSlaves() { final Map<String, VdsNetworkInterface> nicMap = Entities.entitiesByName(allExistingNics); Map<String, List<VdsNetworkInterface>> bondToSlaves = new HashMap<>(); for (CreateOrUpdateBond createOrUpdateBond : hostSetupNetworksParametersData.getBonds()) { String bondName = createOrUpdateBond.getName(); assert !bondToSlaves.containsKey(bondName) : "the same bond shouldn't exist twice in the parameters"; //$NON-NLS-1$ bondToSlaves.put(bondName, new ArrayList<VdsNetworkInterface>()); Set<String> slavesNames = createOrUpdateBond.getSlaves(); for (String slaveName : slavesNames) { bondToSlaves.get(bondName).add(nicMap.get(slaveName)); } } return bondToSlaves; }
private boolean bondsHasSameSlaves(Bond existingNic) { Collection<String> slavesOfBondFromRequest = replaceNullWithEmptyList(getSlaves()); Collection<String> slavesOfExistingBond = replaceNullWithEmptyList(existingNic.getSlaves()); //bonds can be in any order, and I don't want to change this order during this check. return slavesOfBondFromRequest.size() == slavesOfExistingBond.size() && slavesOfBondFromRequest.containsAll(slavesOfExistingBond); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof CreateOrUpdateBond)) { return false; } CreateOrUpdateBond that = (CreateOrUpdateBond) o; return Objects.equals(getId(), that.getId()) && Objects.equals(getName(), that.getName()) && Objects.equals(getBondOptions(), that.getBondOptions()) && Objects.equals(getSlaves(), that.getSlaves()); }
@Override public int hashCode() { return Objects.hash(getId(), getName(), getBondOptions(), getSlaves()); }
private void assertBond(CreateOrUpdateBond bond, Guid bondId, List<VdsNetworkInterface> slaves) { assertThat("id mismatch", bond.getId(), is(bondId)); //$NON-NLS-1$ for (VdsNetworkInterface slave : slaves) { assertThat("missing slave", bond.getSlaves().contains(slave.getName()), is(true)); //$NON-NLS-1$ } assertThat("invalid slaves count", bond.getSlaves().size(), is(slaves.size())); //$NON-NLS-1$ }
public Bond toBond() { Bond bond = new Bond(); bond.setId(getId()); bond.setName(getName()); bond.setSlaves(new ArrayList<>(getSlaves())); bond.setBondOptions(getBondOptions()); return bond; }
private CreateOrUpdateBond createBond(Guid id, String bondName, List<VdsNetworkInterface> slaves) { CreateOrUpdateBond result = new CreateOrUpdateBond(); result.setId(id); result.setName(bondName); for (VdsNetworkInterface slave : slaves) { result.getSlaves().add(slave.getName()); } return result; }
protected ToStringBuilder appendAttributes(ToStringBuilder tsb) { return tsb.append("id", getId()) .append("name", getName()) .append("bondingOptions", getBondOptions()) .append("slaves", getSlaves()); }