Shahar Havivi has uploaded a new change for review. Change subject: API: support name attribute for PortMirrorings Network (#842163) ......................................................................
API: support name attribute for PortMirrorings Network (#842163) https://bugzilla.redhat.com/show_bug.cgi?id=842163 Change-Id: I4405f1a551dbc32b81e3e521844eee1376e61f6c Signed-off-by: Shahar Havivi <[email protected]> --- M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmNicResource.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmNicsResource.java 2 files changed, 81 insertions(+), 43 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/02/7602/1 diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmNicResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmNicResource.java index 5e95d9f..38dbfe9 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmNicResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmNicResource.java @@ -42,6 +42,7 @@ Networks networks = new Networks(); Network net = new Network(); net.setId(networkId); + net.setName(network.getname()); portMirroring.setNetworks(networks); portMirroring.getNetworks().getNetworks().add(net); model.setPortMirroring(portMirroring); @@ -56,40 +57,42 @@ // in port mirroring validateEnums(NIC.class, device); boolean fault = false; - String faultString = null; + String faultString = "The port mirroring network must match the Network set on the NIC"; boolean isPortMirroring = device.isSetPortMirroring() && device.getPortMirroring().isSetNetworks(); boolean isPortMirroringExceeded = isPortMirroring && device.getPortMirroring().getNetworks().getNetworks().size() > 1; isPortMirroring = isPortMirroring && device.getPortMirroring().getNetworks().getNetworks().size() == 1; - - // Check if user set more then one network in port mirroring networks collection if (isPortMirroringExceeded) { fault = true; faultString = "Cannot set more than one network in port mirroring mode"; } - + String networkId = + (device.isSetNetwork() && device.getNetwork().isSetId()) ? device.getNetwork().getId() : null; + String networkName = + (device.isSetNetwork() && device.getNetwork().isSetName()) ? device.getNetwork().getName() : null; if (!fault && isPortMirroring) { - boolean isNetwork = device.isSetNetwork() && device.getNetwork().isSetId(); - // if Nics network set no need to check the Nics network from the engine - if (isNetwork) { - if (!device.getNetwork() - .getId() - .equals(device.getPortMirroring().getNetworks().getNetworks().get(0).getId())) { - fault = true; - faultString = "The port mirroring network must match the Network set on the NIC"; + Network pmNetwork = device.getPortMirroring().getNetworks().getNetworks().get(0); + String pmNetworkId = (pmNetwork.isSetId() ? pmNetwork.getId() : null); + String pmNetworkName = (pmNetwork.isSetName() ? pmNetwork.getName() : null); + if (pmNetworkId != null) { + if (networkId == null) { + networkId = (networkName != null) ? getNetworkId(networkName) : get().getNetwork().getId(); } - // check if port mirroring network match the Nics network that is store in the engine - } else if (!device.getPortMirroring() - .getNetworks() - .getNetworks() - .get(0) - .getId() - .equals(get().getNetwork().getId())) { + fault = (!pmNetworkId.equals(networkId)); + } else if (pmNetworkName != null) { + if (networkName == null) { + if (networkId == null) { + networkId = get().getNetwork().getId(); + } + pmNetworkId = getNetworkId(pmNetworkName); + fault = (!networkId.equals(pmNetworkId)); + } + fault = fault || (!pmNetworkName.equals(networkName)); + } else { fault = true; - faultString = "The port mirroring network must match the Network set on the NIC"; + faultString = "Network must have name or id property for port mirroring"; } } - if (fault) { Fault f = new Fault(); f.setReason(faultString); @@ -99,6 +102,17 @@ return super.update(device); } + private String getNetworkId(String networkName) { + BackendVmNicsResource parent = (BackendVmNicsResource) collection; + Guid clusterId = parent.getClusterId(); + org.ovirt.engine.core.common.businessentities.Network n = + parent.getClusterNetwork(clusterId, null, networkName); + if (n != null) { + return n.getId().toString(); + } + return null; + } + @Override public ActionResource getActionSubresource(String action, String oid) { return null; diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmNicsResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmNicsResource.java index 6c9c0ce..946dae5 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmNicsResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmNicsResource.java @@ -59,34 +59,58 @@ // port mirroring network collection, next engine version will support the network collection // in port mirroring - // if port mirroring exists we check that the network id is equals to the nic network name validateEnums(NIC.class, device); - if (device.isSetPortMirroring() && - device.getPortMirroring().isSetNetworks() - && - device.getPortMirroring().getNetworks().getNetworks().size() == 1 - && - device.getPortMirroring().getNetworks().getNetworks().get(0).isSetId() - && - device.isSetNetwork() && device.getNetwork().isSetId() && - !device.getNetwork() - .getId() - .equals(device.getPortMirroring().getNetworks().getNetworks().get(0).getId())) { - Fault fault = new Fault(); - fault.setReason("The port mirroring network must match the Network set on the NIC"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity(fault).build(); - throw new WebApplicationException(response); - } else if (device.isSetPortMirroring() && - device.getPortMirroring().isSetNetworks() && - device.getPortMirroring().getNetworks().getNetworks().size() > 1) { - Fault fault = new Fault(); - fault.setReason("cannot set more than one network in port mirroring mode"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity(fault).build(); + boolean fault = false; + String faultString = "The port mirroring network must match the Network set on the NIC"; + boolean isPortMirroring = device.isSetPortMirroring() && device.getPortMirroring().isSetNetworks(); + boolean isPortMirroringExceeded = + isPortMirroring && device.getPortMirroring().getNetworks().getNetworks().size() > 1; + if (!fault && isPortMirroringExceeded) { + fault = true; + faultString = "Cannot set more than one network in port mirroring mode"; + } + isPortMirroring = isPortMirroring && device.getPortMirroring().getNetworks().getNetworks().size() == 1; + if (!fault && isPortMirroring) { + org.ovirt.engine.api.model.Network pmNetwork = device.getPortMirroring().getNetworks().getNetworks().get(0); + String pmNetworkId = (pmNetwork.isSetId() ? pmNetwork.getId() : null); + String pmNetworkName = (pmNetwork.isSetName() ? pmNetwork.getName() : null); + String networkId = + (device.isSetNetwork() && device.getNetwork().isSetId()) ? device.getNetwork().getId() : null; + String networkName = + (device.isSetNetwork() && device.getNetwork().isSetName()) ? device.getNetwork().getName() : null; + if (pmNetworkId != null) { + networkId = (networkId == null) ? getNetworkId(networkName) : networkId; + fault = (!pmNetworkId.equals(networkId)); + } else if (pmNetworkName != null) { + if (networkName == null && networkId != null) { + pmNetworkId = getNetworkId(pmNetworkName); + fault = (!pmNetworkId.equals(networkId)); + } + fault = fault || (!pmNetworkName.equals(networkName)); + } else { + fault = true; + faultString = "Network must have name or id property for port mirroring"; + } + } + if (fault) { + Fault f = new Fault(); + f.setReason(faultString); + Response response = Response.status(Response.Status.BAD_REQUEST).entity(f).build(); throw new WebApplicationException(response); } return super.add(device); } + private String getNetworkId(String networkName) { + Guid clusterId = getClusterId(); + org.ovirt.engine.core.common.businessentities.Network n = + getClusterNetwork(clusterId, null, networkName); + if (n != null) { + return n.getId().toString(); + } + return null; + } + @Override protected NIC populate(NIC model, VmNetworkInterface entity) { return addStatistics(model, entity, uriInfo, httpHeaders); -- To view, visit http://gerrit.ovirt.org/7602 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4405f1a551dbc32b81e3e521844eee1376e61f6c Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Shahar Havivi <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
