You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by an...@apache.org on 2014/03/05 08:53:03 UTC

[18/20] git commit: updated refs/heads/4.3 to 3297fcc

CLOUDSTACK-6183: unplug the nic when all the ips of  public vlan range is removed
(cherry picked from commit 7700a1b71622c1d45b2b54aa7444be5adc4fb8ab)

Signed-off-by: Animesh Chaturvedi <an...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/86643d6e
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/86643d6e
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/86643d6e

Branch: refs/heads/4.3
Commit: 86643d6e3fd3261cabe105a452e33017a77a23e3
Parents: 9e1525c
Author: Jayapal <ja...@apache.org>
Authored: Thu Feb 27 18:39:37 2014 +0530
Committer: Animesh Chaturvedi <an...@apache.org>
Committed: Tue Mar 4 23:43:03 2014 -0800

----------------------------------------------------------------------
 .../kvm/resource/LibvirtComputingResource.java  | 31 ++++++++++++++++++++
 .../xen/resource/CitrixResourceBase.java        | 15 ++++++++--
 2 files changed, 44 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/86643d6e/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
index 6e0c6fa..36382e3 100755
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
@@ -1789,6 +1789,23 @@ ServerResource {
     	return new Answer(cmd, true, result);
     }
 
+    private void vifHotUnPlug (Connect conn, String vmName, String macAddr) throws InternalErrorException, LibvirtException {
+
+        Domain vm = null;
+        vm = getDomain(conn, vmName);
+        List<InterfaceDef> pluggedNics = getInterfaces(conn, vmName);
+        for (InterfaceDef pluggedNic : pluggedNics) {
+            if (pluggedNic.getMacAddress().equalsIgnoreCase(macAddr)) {
+                vm.detachDevice(pluggedNic.toString());
+                // We don't know which "traffic type" is associated with
+                // each interface at this point, so inform all vif drivers
+                for (VifDriver vifDriver : getAllVifDrivers()) {
+                    vifDriver.unplug(pluggedNic);
+                }
+            }
+        }
+    }
+
     private void VifHotPlug(Connect conn, String vmName, String broadcastUri,
             String macAddr) throws InternalErrorException, LibvirtException {
         NicTO nicTO = new NicTO();
@@ -2103,6 +2120,12 @@ ServerResource {
             String result = null;
             int nicNum = 0;
             boolean newNic = false;
+            int numOfIps = 0;
+
+            if (ips != null) {
+                numOfIps = ips.length;
+            }
+
             for (IpAddressTO ip : ips) {
                 if (!broadcastUriAllocatedToVM.containsKey(ip.getBroadcastUri())) {
                     /* plug a vif into router */
@@ -2121,6 +2144,14 @@ ServerResource {
                 if (result == null) {
                     results[i++] = ip.getPublicIp() + " - success";
                 }
+
+                //there is only only ip in public subnet and it is deleted so unplug the vif
+                if (numOfIps == 1 && !ip.isAdd()) {
+                    // There are no ips on the vm so delete the vif
+                    networkUsage(routerIp, "deleteVif", "eth" + nicNum);
+                    vifHotUnPlug(conn, routerName, ip.getVifMacAddress());
+                }
+
             }
             return new IpAssocAnswer(cmd, results);
         } catch (LibvirtException e) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/86643d6e/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
index 3c7b4ac..1f37167 100644
--- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
+++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
@@ -2383,7 +2383,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
 
 
     protected void assignPublicIpAddress(Connection conn, String vmName, String privateIpAddress, String publicIpAddress, boolean add, boolean firstIP,
-            boolean sourceNat, String vlanId, String vlanGateway, String vlanNetmask, String vifMacAddress, Integer networkRate, TrafficType trafficType, String name) throws InternalErrorException {
+            boolean sourceNat, String vlanId, String vlanGateway, String vlanNetmask, String vifMacAddress, Integer networkRate, TrafficType trafficType, String name,
+            int numOfips) throws InternalErrorException {
 
         try {
             VM router = getVM(conn, vmName);
@@ -2474,6 +2475,11 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
                 throw new InternalErrorException("Xen plugin \"ipassoc\" failed.");
             }
 
+            //there is only only ip in public subnet and it is deleted so unplug the vif
+            if (numOfips == 1 && !add) {
+                removeVif = true;
+            }
+
             if (removeVif) {
                 network = correctVif.getNetwork(conn);
 
@@ -2575,14 +2581,19 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
         Connection conn = getConnection();
         String[] results = new String[cmd.getIpAddresses().length];
         int i = 0;
+        int numOfIps = 0;
         String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
         String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
         try {
             IpAddressTO[] ips = cmd.getIpAddresses();
+            if (ips != null) {
+                numOfIps = ips.length;
+            }
+
             for (IpAddressTO ip : ips) {
 
                 assignPublicIpAddress(conn, routerName, routerIp, ip.getPublicIp(), ip.isAdd(), ip.isFirstIP(), ip.isSourceNat(), ip.getBroadcastUri(),
-                        ip.getVlanGateway(), ip.getVlanNetmask(), ip.getVifMacAddress(), ip.getNetworkRate(), ip.getTrafficType(), ip.getNetworkName());
+                        ip.getVlanGateway(), ip.getVlanNetmask(), ip.getVifMacAddress(), ip.getNetworkRate(), ip.getTrafficType(), ip.getNetworkName(), numOfIps);
                 results[i++] = ip.getPublicIp() + " - success";
             }
         } catch (InternalErrorException e) {