do not create dedicated-public network if a shared-public network already exists
diff --git a/planetstack/model_policies/model_policy_Slice.py b/planetstack/model_policies/model_policy_Slice.py
index 493975f..cf73aa0 100644
--- a/planetstack/model_policies/model_policy_Slice.py
+++ b/planetstack/model_policies/model_policy_Slice.py
@@ -23,22 +23,26 @@
sd.save()
# make sure slice has at least 1 public and 1 private networkd
- public_net = None
+ public_nets = []
private_net = None
networks = Network.objects.filter(owner=slice)
for network in networks:
if network.template.name == 'Public dedicated IPv4':
- public_net = network
+ public_nets.append(network)
+ elif network.template.name == 'Public shared IPv4':
+ public_nets.append(network)
elif network.template.name == 'Private':
- private_net = network
- if not public_net:
- public_net = Network(
- name = slice.name+'-public',
- template = NetworkTemplate.objects.get(name='Public dedicated IPv4'),
- owner = slice
- )
- public_net.save()
-
+ private_net = network
+ if not public_nets:
+ # ensure there is at least one public network, and default it to dedicated
+ dedicated_public_net = Network(
+ name = slice.name+'-public',
+ template = NetworkTemplate.objects.get(name='Public dedicated IPv4'),
+ owner = slice
+ )
+ dedicated_public_net.save()
+ public_nets.append(dedicated_public_net)
+
if not private_net:
private_net = Network(
name = slice.name+'-private',
@@ -49,19 +53,19 @@
# create slice networks
public_net_slice = None
private_net_slice = None
- net_slices = NetworkSlice.objects.filter(slice=slice, network__in=[public_net,private_net])
+ net_slices = NetworkSlice.objects.filter(slice=slice, network__in=[private_net]+public_nets)
for net_slice in net_slices:
- if net_slice.network == public_net:
- public_net_slice = net_slice
+ if net_slice.network in public_nets:
+ public_net_slice = net_slice
elif net_slice.network == private_net:
- private_net_slice = net_slice
+ private_net_slice = net_slice
if not public_net_slice:
- public_net_slice = NetworkSlice(slice=slice, network=public_net)
+ public_net_slice = NetworkSlice(slice=slice, network=public_nets[0])
public_net_slice.save()
if not private_net_slice:
private_net_slice = NetworkSlice(slice=slice, network=private_net)
- private_net_slice.save()
-
-
-
-
+ private_net_slice.save()
+
+
+
+