Bug 3287: 409 on FloatingIP create 45/20745/1
authorEd Warnicke <hagbard@gmail.com>
Tue, 19 May 2015 17:08:50 +0000 (10:08 -0700)
committerRyan Moats <rmoats@us.ibm.com>
Tue, 19 May 2015 19:23:50 +0000 (19:23 +0000)
Change-Id: I61295006844bd03c4fc55ba1e90ee3128da97702
Signed-off-by: Ed Warnicke <hagbard@gmail.com>
(cherry picked from commit 3e4215f8ce2457de411ccf3daff25753508bcd07)

neutron-spi/src/main/java/org/opendaylight/neutron/spi/NeutronSubnet.java
northbound-api/src/main/java/org/opendaylight/neutron/northbound/api/NeutronFloatingIPsNorthbound.java

index fdc21c1023d615189085a042dbe350eb21903609..02f02628a864a86e9cefc254a9bfef985a47b8ad 100644 (file)
@@ -393,6 +393,32 @@ public class NeutronSubnet implements Serializable, INeutronObject {
         myPorts.remove(port);
     }
 
+    public List<NeutronPort> getFloatingIpPortsInSubnet() {
+        List<NeutronPort> result = new ArrayList<NeutronPort>();
+        List<NeutronPort> ports = getPortsInSubnet();
+        for(NeutronPort port: ports) {
+            if(port.getDeviceOwner().equals("network:floatingip")) {
+                result.add(port);
+            }
+        }
+        return result;
+    }
+
+    public List<NeutronPort> getFloatingIpPortsInSubnet(String floatingIPaddress) {
+        List<NeutronPort> result = new ArrayList<NeutronPort>();
+        List<NeutronPort> floatingIpPorts = getFloatingIpPortsInSubnet();
+        for(NeutronPort port: floatingIpPorts) {
+            List<Neutron_IPs> fixedIps = port.getFixedIPs();
+            for(Neutron_IPs fixedIp: fixedIps) {
+                if(fixedIp.getIpAddress() != null && fixedIp.getIpAddress().equals(floatingIPaddress)) {
+                    result.add(port);
+                    break;
+                }
+            }
+        }
+        return result;
+    }
+
     /* this method tests to see if the supplied IPv4 address
      * is valid for this subnet or not
      */
index e1050b2a115352a7fa7b5f0e9f78a7d1d7952fe0..c02205e06a0119133c1b5b06037498c6da123de7 100644 (file)
@@ -210,7 +210,7 @@ public class NeutronFloatingIPsNorthbound {
                 NeutronSubnet externSubnet = subnetInterface.getSubnet(externNetwork.getSubnets().get(0));
                 if (!externSubnet.isValidIP(floatingIP))
                     throw new BadRequestException("external IP isn't valid for the specified subnet.");
-                if (externSubnet.isIPInUse(floatingIP))
+                if (externSubnet.getFloatingIpPortsInSubnet(floatingIP).isEmpty() && externSubnet.isIPInUse(floatingIP))
                     throw new ResourceConflictException("floating IP is in use.");
             }
             // if port_id is specified, then check that the port exists and has at least one IP