Moti Asayag has uploaded a new change for review.
Change subject: engine: Support 3.1 network topologies by AttachNetwork
......................................................................
engine: Support 3.1 network topologies by AttachNetwork
The patch provides support for 3.1 network topologies by
the AttachNetworkCommand, also exposed via the api by:
api/hosts/{host:id}/nics/{nic:id}/attach
The supported networktopologies over a nic are:
1. Attach a VM network (with/without vlan)
2. Attach a non-VM network (with/without vlan)
3. Attach a non-VM network to a nic which a vlan is already attached to.
4. Attach a vlan to a nic which a non-VM network is already attached to.
The unsupported network topologies are:
1. Attaching any network to a nic which a VM network is already attached to.
2. Attach a VM network to a nic which any network is already attached to.
3. Attach a non-VM network to a nic which a non-VM network is already attached
to.
Change-Id: I9e1abe84e2877171be5af41c9bb3ab590fed3653
Signed-off-by: Moti Asayag <[email protected]>
---
M
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/AttachNetworkToVdsInterfaceCommand.java
1 file changed, 54 insertions(+), 16 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/22/13722/1
diff --git
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/AttachNetworkToVdsInterfaceCommand.java
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/AttachNetworkToVdsInterfaceCommand.java
index 4d88a0f..addffe1 100644
---
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/AttachNetworkToVdsInterfaceCommand.java
+++
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/AttachNetworkToVdsInterfaceCommand.java
@@ -8,6 +8,7 @@
import org.ovirt.engine.core.bll.Backend;
import org.ovirt.engine.core.bll.network.cluster.NetworkClusterHelper;
import org.ovirt.engine.core.common.AuditLogType;
+import org.ovirt.engine.core.common.FeatureSupported;
import org.ovirt.engine.core.common.action.AttachNetworkToVdsParameters;
import org.ovirt.engine.core.common.businessentities.Entities;
import org.ovirt.engine.core.common.businessentities.network.Network;
@@ -103,11 +104,22 @@
addCanDoActionMessage(VdcBllMessages.NETWORK_INTERFACE_ALREADY_IN_BOND);
return false;
}
- // Check that the specify interface has no network
- if (!StringUtils.isEmpty(iface.getNetworkName())) {
+
+ Map<String, Network> networksByName =
+
Entities.entitiesByName(getNetworkDAO().getAllForCluster(getVds().getVdsGroupId()));
+ // check that the network exists in current cluster
+ if (!networksByName.containsKey(params.getNetwork().getName())) {
+
addCanDoActionMessage(VdcBllMessages.NETWORK_NOT_EXISTS_IN_CLUSTER);
+ return false;
+ } else {
+ logicalNetwork = networksByName.get(params.getNetwork().getName());
+ }
+
+ if (!networkConfigurationSupported(iface, networksByName)) {
addCanDoActionMessage(VdcBllMessages.NETWORK_INTERFACE_ALREADY_HAVE_NETWORK);
return false;
}
+
if
(!NetworkUtils.getEngineNetwork().equals(params.getNetwork().getName())
&& !StringUtils.isEmpty(params.getGateway())) {
addCanDoActionMessage(VdcBllMessages.NETWORK_ATTACH_ILLEGAL_GATEWAY);
@@ -121,19 +133,6 @@
return false;
}
- // check that the network exists in current cluster
-
- Map<String, Network> networksByName =
-
Entities.entitiesByName(getNetworkDAO().getAllForCluster(getVds().getVdsGroupId()));
-
- if (!networksByName.containsKey(params.getNetwork().getName())) {
-
addCanDoActionMessage(VdcBllMessages.NETWORK_NOT_EXISTS_IN_CLUSTER);
- return false;
- } else {
- logicalNetwork = networksByName.get(params.getNetwork().getName());
- }
-
-
// check address exists in static ip
if (params.getBootProtocol() == NetworkBootProtocol.STATIC_IP) {
if (StringUtils.isEmpty(params.getAddress())) {
@@ -143,7 +142,7 @@
}
// check that nic have no vlans
- if (params.getNetwork().getVlanId() == null) {
+ if (vmNetworkNonVlan(params.getNetwork())) {
VdcQueryReturnValue ret = Backend.getInstance().runInternalQuery(
VdcQueryType.GetAllChildVlanInterfaces,
new InterfaceAndIdQueryParameters(params.getVdsId(), params
@@ -164,4 +163,43 @@
return getSucceeded() ? AuditLogType.NETWORK_ATTACH_NETWORK_TO_VDS
: AuditLogType.NETWORK_ATTACH_NETWORK_TO_VDS_FAILED;
}
+
+ /**
+ * Validates whether the network configuration is supported.
+ *
+ * @param iface
+ * The target network interface
+ * @param networksByName
+ * A map contains all cluster's networks
+ * @return <code>true</code> if the configuration is supported, else
<code>false</code>
+ */
+ private boolean networkConfigurationSupported(VdsNetworkInterface iface,
Map<String, Network> networksByName) {
+ if (StringUtils.isEmpty(iface.getNetworkName())) {
+ return true;
+ }
+
+ Network attachedNetwork = networksByName.get(iface.getNetworkName());
+
+ // Prevent attaching a VM network when a VM network is already attached
+ if (vmNetworkNonVlan(attachedNetwork) ||
vmNetworkNonVlan(logicalNetwork)) {
+ return false;
+ }
+
+ // Verify Non-VM networks are supported
+ if
(!FeatureSupported.nonVmNetwork(getVds().getVdsGroupCompatibilityVersion())
+ && (!attachedNetwork.isVmNetwork() ||
!logicalNetwork.isVmNetwork())) {
+ return false;
+ }
+
+ // Prevent attaching non-VM network to a nic which already has an
attached non-VM network
+ if (NetworkUtils.isNonVmNonVlanNetwork(attachedNetwork) &&
NetworkUtils.isNonVmNonVlanNetwork(logicalNetwork)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ private boolean vmNetworkNonVlan(Network network) {
+ return network.isVmNetwork() && network.getVlanId() == null;
+ }
}
--
To view, visit http://gerrit.ovirt.org/13722
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9e1abe84e2877171be5af41c9bb3ab590fed3653
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Moti Asayag <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches