Repository: ionos-cloud/dim (language: python)

Issue:
can't reserve same IP in different layer3domains
It is not possible to reserve the same IP in different layer3domains, even though the subnet was created with overlap being allowed.

```
# ndcli create layer3domain layerfoo
# ndcli create layer3domain layerbar
# ndcli create pool foo layer3domain layerfoo
# ndcli create pool bar layer3domain layerbar
# ndcli modify pool foo add subnet 192.168.42.0/24
# ndcli modify pool bar add subnet 192.168.42.0/24 --allow-overlap
# ndcli modify pool foo get ip
created:2021-12-15 08:35:07.369708
ip:192.168.42.1
layer3domain:layerfoo
mask:255.255.255.0
modified:2021-12-15 08:35:07.369724
modified_by:admin
pool:foo
reverse_zone:42.168.192.in-addr.arpa
status:Static
subnet:192.168.42.0/24
# ndcli modify pool bar get ip
ERROR - 192.168.42.1 from layer3domain foo is already allocated with status Static
```

It should be possible to reserve the same IP in different pools of different layer3domains when it is possible to allow overlapping subnets.


Discussion / hints:

Fix patch:
diff --git a/dim/dim/rpc.py b/dim/dim/rpc.py
index 8bdbc7fa..a73a982d 100644
--- a/dim/dim/rpc.py
+++ b/dim/dim/rpc.py
@@ -1432,7 +1432,7 @@ def subnet_remove_gateway(self, subnet, layer3domain=None, **options):
     @updating
     def ippool_get_ip(self, pool, attributes=None, full=False):
         pool = get_pool(pool)
-        ipblock = self._ip_mark(allocate_ip(pool), attributes=attributes, pool=pool)
+        ipblock = self._ip_mark(allocate_ip(pool), layer3domain=pool.layer3domain, attributes=attributes, pool=pool)
         if ipblock:
             return self.ipblock_get_attrs(ipblock, full=full)
 


Test patch:
diff --git a/dim-testsuite/t/ippool-reserve-overlapping.t b/dim-testsuite/t/ippool-reserve-overlapping.t
new file mode 100644
index 00000000..f0466535
--- /dev/null
+++ b/dim-testsuite/t/ippool-reserve-overlapping.t
@@ -0,0 +1,38 @@
+$ ndcli create layer3domain foo type foo
+$ ndcli create layer3domain bar type bar
+$ ndcli create pool foo layer3domain foo
+$ ndcli create pool bar layer3domain bar
+$ ndcli create container 192.168.0.0/16 layer3domain foo
+INFO - Creating container 192.168.0.0/16 in layer3domain foo
+$ ndcli create container 192.168.0.0/16 layer3domain bar
+INFO - Creating container 192.168.0.0/16 in layer3domain bar
+$ ndcli modify pool foo add subnet 192.168.42.0/24
+INFO - Created subnet 192.168.42.0/24 in layer3domain foo
+WARNING - Creating zone 42.168.192.in-addr.arpa without profile
+WARNING - Primary NS for this Domain is now localhost.
+$ ndcli modify pool bar add subnet 192.168.42.0/24 --allow-overlap
+INFO - Created subnet 192.168.42.0/24 in layer3domain bar
+WARNING - 192.168.42.0/24 in layer3domain bar overlaps with 192.168.42.0/24 in layer3domain foo
+INFO - Creating view bar in zone 42.168.192.in-addr.arpa without profile
+$ ndcli modify pool foo get ip
+created:2021-12-15 08:35:07.369708
+ip:192.168.42.1
+layer3domain:foo
+mask:255.255.255.0
+modified:2021-12-15 08:35:07.369724
+modified_by:admin
+pool:foo
+reverse_zone:42.168.192.in-addr.arpa
+status:Static
+subnet:192.168.42.0/24
+$ ndcli modify pool bar get ip
+created:2022-02-09 10:40:26.140923
+ip:192.168.42.1
+layer3domain:bar
+mask:255.255.255.0
+modified:2022-02-09 10:40:26.140939
+modified_by:admin
+pool:bar
+reverse_zone:42.168.192.in-addr.arpa
+status:Static
+subnet:192.168.42.0/24