use of org.ovirt.engine.core.common.action.CreateOrUpdateBond in project ovirt-engine by oVirt.
the class HostSetupNetworksCommand method isBonding.
private boolean isBonding(NetworkAttachment attachment, BusinessEntityMap<VdsNetworkInterface> nics) {
for (CreateOrUpdateBond bond : getParameters().getCreateOrUpdateBonds()) {
if (bond.getName() != null && bond.getName().equals(attachment.getNicName())) {
return true;
}
}
VdsNetworkInterface attachedNic = nics.get(attachment.getNicId(), attachment.getNicName());
Validate.notNull(attachedNic, "NicId/NicName must refer to a resolvable interface");
return Boolean.TRUE.equals(attachedNic.getBonded());
}
use of org.ovirt.engine.core.common.action.CreateOrUpdateBond in project ovirt-engine by oVirt.
the class HostSetupNetworksValidator method validNewOrModifiedBonds.
ValidationResult validNewOrModifiedBonds() {
for (CreateOrUpdateBond modifiedOrNewBond : params.getCreateOrUpdateBonds()) {
String bondName = modifiedOrNewBond.getName();
Guid bondId = modifiedOrNewBond.getId();
/*
* bondId is provided, but bondName not. This means that user attempted update, but bond of such ID does not
* exit, thus completors did not complete name.
*/
if (bondId != null && bondName == null) {
return new ValidationResult(EngineMessage.HOST_NETWORK_INTERFACE_HAVING_ID_DOES_NOT_EXIST, ReplacementUtils.createSetVariableString(VAR_NIC_ID, bondId));
}
/*
* user did not provide neither bondId nor bondName. That means he probably attempted new bond creation
* but forgot to provide bondName.
*/
if (bondId == null && bondName == null) {
return new ValidationResult(EngineMessage.BOND_DOES_NOT_HAVE_NEITHER_ID_NOR_NAME_SPECIFIED);
}
/*
* if (bondId == null && bondName != null) …
* User provided only bondName, and completors failed to find existing bonds id for that name.
* We cannot tell, what user wanted to do(create/update). We have to assume, it's new record creation, which
* is valid scenario.
*/
ValidationResult validateCoherentNicIdentification = validateCoherentNicIdentification(modifiedOrNewBond);
if (!validateCoherentNicIdentification.isValid()) {
return validateCoherentNicIdentification;
}
boolean validBondName = bondName.matches(BusinessEntitiesDefinitions.BOND_NAME_PATTERN);
if (!validBondName) {
EngineMessage engineMessage = EngineMessage.NETWORK_BOND_NAME_BAD_FORMAT;
return new ValidationResult(engineMessage, ReplacementUtils.getVariableAssignmentString(engineMessage, bondName));
}
// either it's newly create bond, thus non existing, or given name must reference existing bond.
ValidationResult interfaceIsBondOrNull = createHostInterfaceValidator(existingInterfacesMap.get(bondName)).interfaceIsBondOrNull();
if (!interfaceIsBondOrNull.isValid()) {
return interfaceIsBondOrNull;
}
// count of bond slaves must be at least two.
if (modifiedOrNewBond.getSlaves().size() < 2) {
return new ValidationResult(EngineMessage.NETWORK_BONDS_INVALID_SLAVE_COUNT, ReplacementUtils.getVariableAssignmentString(EngineMessage.NETWORK_BONDS_INVALID_SLAVE_COUNT, bondName));
}
ValidationResult validateModifiedBondSlaves = validateModifiedBondSlaves(modifiedOrNewBond);
if (!validateModifiedBondSlaves.isValid()) {
return validateModifiedBondSlaves;
}
}
return ValidationResult.VALID;
}
use of org.ovirt.engine.core.common.action.CreateOrUpdateBond in project ovirt-engine by oVirt.
the class HostSetupNetworksCommand method removeUnchangedBonds.
private void removeUnchangedBonds(List<VdsNetworkInterface> existingNics) {
Map<Guid, VdsNetworkInterface> nicsById = Entities.businessEntitiesById(existingNics);
List<CreateOrUpdateBond> createOrUpdateBonds = getParameters().getCreateOrUpdateBonds();
for (Iterator<CreateOrUpdateBond> iterator = createOrUpdateBonds.iterator(); iterator.hasNext(); ) {
CreateOrUpdateBond bondFromRequest = iterator.next();
Guid idOfBondFromRequest = bondFromRequest.getId();
boolean bondFromRequestIsNewBond = idOfBondFromRequest == null;
if (!bondFromRequestIsNewBond) {
if (bondFromRequest.equalToBond((Bond) nicsById.get(idOfBondFromRequest))) {
iterator.remove();
}
}
}
}
use of org.ovirt.engine.core.common.action.CreateOrUpdateBond in project ovirt-engine by oVirt.
the class NicLabelValidatorTest method labelBeingAttachedToValidBondNewBondValid.
@Test
public void labelBeingAttachedToValidBondNewBondValid() {
CreateOrUpdateBond createOrUpdateBond = new CreateOrUpdateBond();
createOrUpdateBond.setName("bond");
createOrUpdateBond.setSlaves(new HashSet<>(Arrays.asList("slave1", "slave2")));
HostSetupNetworksParameters params = createHostSetupNetworksParams();
params.getCreateOrUpdateBonds().add(createOrUpdateBond);
NicLabel nicLabel = new NicLabel(createOrUpdateBond.getId(), createOrUpdateBond.getName(), "lbl1");
assertThat(createNicLabelValidator(params, new ArrayList<>()).labelBeingAttachedToValidBond(nicLabel), isValid());
}
use of org.ovirt.engine.core.common.action.CreateOrUpdateBond in project ovirt-engine by oVirt.
the class NicLabelValidatorTest method labelBeingAttachedToNonVlanNonSlaveInterfaceAttachToRemovedSlave.
@Test
public void labelBeingAttachedToNonVlanNonSlaveInterfaceAttachToRemovedSlave() {
HostSetupNetworksParameters params = createHostSetupNetworksParams();
VdsNetworkInterface slave = createNic();
Bond bondWithSlave = new Bond("bond");
bondWithSlave.setSlaves(Collections.singletonList(slave.getName()));
CreateOrUpdateBond updatedBond = new CreateOrUpdateBond();
updatedBond.setName(bondWithSlave.getName());
updatedBond.setSlaves(new HashSet<>());
params.setCreateOrUpdateBonds(Collections.singletonList(updatedBond));
NicLabel nicLabel = new NicLabel();
nicLabel.setNicName(slave.getName());
NicLabelValidator nicLabelValidator = createNicLabelValidator(params, Arrays.asList(bondWithSlave, slave));
assertThat(nicLabelValidator.labelBeingAttachedToNonVlanNonSlaveInterface(nicLabel), isValid());
}
Aggregations