Mike Kolesnik has uploaded a new change for review.

Change subject: engine: Utility class for managing external networks
......................................................................

engine: Utility class for managing external networks

This utility class is useful for managing external networks, currently
it provides an easy way to deallocate the vNIC from the external
network.

Change-Id: I1c93d7a74c66bbcae54cd4667744b0a88882622c
Signed-off-by: Mike Kolesnik <mkole...@redhat.com>
---
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/ExternalNetworkManager.java
1 file changed, 69 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/65/19965/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/ExternalNetworkManager.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/ExternalNetworkManager.java
new file mode 100644
index 0000000..9b1fecf
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/ExternalNetworkManager.java
@@ -0,0 +1,69 @@
+package org.ovirt.engine.core.bll.network;
+
+import org.ovirt.engine.core.bll.network.cluster.NetworkHelper;
+import org.ovirt.engine.core.bll.provider.ProviderProxyFactory;
+import org.ovirt.engine.core.bll.provider.network.NetworkProviderProxy;
+import org.ovirt.engine.core.common.businessentities.network.Network;
+import org.ovirt.engine.core.common.businessentities.network.VmNic;
+import org.ovirt.engine.core.dal.dbbroker.DbFacade;
+
+/**
+ * Utility class to help manage external networks, such as deallocate NICs.
+ */
+public class ExternalNetworkManager {
+
+    private VmNic nic;
+
+    private Network network;
+
+    /**
+     * Create a manager for the specific vNIC, the manager can be used as is - 
network information will be taken from
+     * the vNIC.
+     *
+     * @param nic
+     *            The vNIC to create a manager for.
+     */
+    public ExternalNetworkManager(VmNic nic) {
+        this.nic = nic;
+    }
+
+    /**
+     * Create a manager for the network, the manager can't be used until you
+     * {@link ExternalNetworkManager#setNic(VmNic)} with a specific vNIC to 
manage. This mode allows effective managing
+     * of several vNICs on the same network.
+     *
+     * @param network
+     *            The network to manage.
+     */
+    public ExternalNetworkManager(Network network) {
+        this.network = network;
+    }
+
+    /**
+     * @param nic
+     *            The vNIC to manage (for deallocation).
+     */
+    public void setNic(VmNic nic) {
+        this.nic = nic;
+    }
+
+    private Network getNetwork() {
+        if (network == null) {
+            network = 
NetworkHelper.getNetworkByVnicProfileId(nic.getVnicProfileId());
+        }
+
+        return network;
+    }
+
+    /**
+     * Deallocate the vNIC from the external network, if it's attached to a 
network and the network is indeed an
+     * external network (otherwise, nothing is done).
+     */
+    public void deallocateIfExternal() {
+        if (getNetwork() != null && getNetwork().isExternal()) {
+            NetworkProviderProxy providerProxy = 
ProviderProxyFactory.getInstance().create(
+                    
DbFacade.getInstance().getProviderDao().get(getNetwork().getProvidedBy().getProviderId()));
+            providerProxy.deallocate(nic);
+        }
+    }
+}


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1c93d7a74c66bbcae54cd4667744b0a88882622c
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Mike Kolesnik <mkole...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to