Moti Asayag has uploaded a new change for review.

Change subject: engine: Network attachments parameters completer
......................................................................

engine: Network attachments parameters completer

The purpose of the class is to ensure partial entities provided
by the clients is being populated if possible by the entity data
as appeared on engine side.

Change-Id: Ifdba99938f17db724e0c62c0780f7595619f2a9c
Signed-off-by: Moti Asayag <[email protected]>
---
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/NetworkAttachmentCompleter.java
1 file changed, 46 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/32/33332/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/NetworkAttachmentCompleter.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/NetworkAttachmentCompleter.java
new file mode 100644
index 0000000..231dfdd
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/NetworkAttachmentCompleter.java
@@ -0,0 +1,46 @@
+package org.ovirt.engine.core.bll.network.host;
+
+import java.util.List;
+import java.util.Map;
+
+import org.ovirt.engine.core.common.businessentities.BusinessEntityMap;
+import org.ovirt.engine.core.common.businessentities.Entities;
+import org.ovirt.engine.core.common.businessentities.network.Bond;
+import org.ovirt.engine.core.common.businessentities.network.NetworkAttachment;
+import 
org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface;
+import org.ovirt.engine.core.compat.Guid;
+
+/**
+ * Network interface can be provided as a parameter and identified either by 
ID or by name.<br>
+ * Class {@link NetworkAttachmentCompleter} populates the interface name if it 
was omitted from the
+ * {@link NetworkAttachment} entity or from {@link Bond} entity.
+ */
+public class NetworkAttachmentCompleter {
+
+    private List<VdsNetworkInterface> existingNics;
+
+    public NetworkAttachmentCompleter(List<VdsNetworkInterface> existingNics) {
+        this.existingNics = existingNics;
+    }
+
+    public void completeNicNames(List<NetworkAttachment> networkAttachments) {
+        BusinessEntityMap<VdsNetworkInterface> nics = new 
BusinessEntityMap<VdsNetworkInterface>(existingNics);
+
+        for (NetworkAttachment attachment : networkAttachments) {
+            VdsNetworkInterface nic = nics.get(attachment.getNicId(), 
attachment.getNicName());
+            if (nic != null) {
+                attachment.setNicName(nic.getName());
+            }
+        }
+    }
+
+    public void completeBondNames(List<Bond> bonds) {
+        Map<Guid, VdsNetworkInterface> nicsById = 
Entities.businessEntitiesById(existingNics);
+
+        for (Bond bond : bonds) {
+            if (bond.getName() == null && nicsById.containsKey(bond.getId())) {
+                bond.setName(nicsById.get(bond.getId()).getName());
+            }
+        }
+    }
+}


-- 
To view, visit http://gerrit.ovirt.org/33332
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifdba99938f17db724e0c62c0780f7595619f2a9c
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

Reply via email to