3 from core.models import SiteDeployments,SliceDeployments,Deployment,Network,NetworkSlice,NetworkTemplate
4 from collections import defaultdict
5 site_deployments = SiteDeployments.objects.all()
6 site_deploy_lookup = defaultdict(list)
7 for site_deployment in site_deployments:
8 site_deploy_lookup[site_deployment.site].append(site_deployment.deployment)
10 slice_deployments = SliceDeployments.objects.all()
11 slice_deploy_lookup = defaultdict(list)
12 for slice_deployment in slice_deployments:
13 slice_deploy_lookup[slice_deployment.slice].append(slice_deployment.deployment)
15 all_deployments = Deployment.objects.all()
16 # slices are added to all deployments for now
17 expected_deployments = all_deployments
18 #expected_deployments = site_deploy_lookup[slice.site]
19 for expected_deployment in expected_deployments:
20 if slice not in slice_deploy_lookup or \
21 expected_deployment not in slice_deploy_lookup[slice]:
22 sd = SliceDeployments(slice=slice, deployment=expected_deployment)
25 # make sure slice has at least 1 public and 1 private networkd
28 networks = Network.objects.filter(owner=slice)
29 for network in networks:
30 if network.template.name == 'Public dedicated IPv4':
32 elif network.template.name == 'Private':
36 name = slice.name+'-public',
37 template = NetworkTemplate.objects.get(name='Public dedicated IPv4'),
43 private_net = Network(
44 name = slice.name+'-private',
45 template = NetworkTemplate.objects.get(name='Private'),
49 # create slice networks
50 public_net_slice = None
51 private_net_slice = None
52 net_slices = NetworkSlice.objects.filter(slice=slice, network__in=[public_net,private_net])
53 for net_slice in net_slices:
54 if net_slice.network == public_net:
55 public_net_slice = net_slice
56 elif net_slice.network == private_net:
57 private_net_slice = net_slice
58 if not public_net_slice:
59 public_net_slice = NetworkSlice(slice=slice, network=public_net)
60 public_net_slice.save()
61 if not private_net_slice:
62 private_net_slice = NetworkSlice(slice=slice, network=private_net)
63 private_net_slice.save()