3 from core.models import Controller, ControllerSlice, SiteDeployment, Network, NetworkSlice,NetworkTemplate, Slice
4 from collections import defaultdict
6 # slice = Slice.get(slice_id)
8 controller_slices = ControllerSlice.objects.filter(slice=slice)
9 existing_controllers = [cs.controller for cs in controller_slices]
11 all_controllers = Controller.objects.all()
12 for controller in all_controllers:
13 if controller not in existing_controllers:
14 sd = ControllerSlice(slice=slice, controller=controller)
17 # make sure slice has at least 1 public and 1 private networkd
20 networks = Network.objects.filter(owner=slice)
21 for network in networks:
22 if network.template.name == 'Public dedicated IPv4':
23 public_nets.append(network)
24 elif network.template.name == 'Public shared IPv4':
25 public_nets.append(network)
26 elif network.template.name == 'Private':
29 # ensure there is at least one public network, and default it to dedicated
31 name = slice.name+'-nat',
32 template = NetworkTemplate.objects.get(name='Public shared IPv4'),
36 public_nets.append(nat_net)
39 private_net = Network(
40 name = slice.name+'-private',
41 template = NetworkTemplate.objects.get(name='Private'),
45 # create slice networks
46 public_net_slice = None
47 private_net_slice = None
48 net_slices = NetworkSlice.objects.filter(slice=slice, network__in=[private_net]+public_nets)
49 for net_slice in net_slices:
50 if net_slice.network in public_nets:
51 public_net_slice = net_slice
52 elif net_slice.network == private_net:
53 private_net_slice = net_slice
54 if not public_net_slice:
55 public_net_slice = NetworkSlice(slice=slice, network=public_nets[0])
56 public_net_slice.save()
57 if not private_net_slice:
58 private_net_slice = NetworkSlice(slice=slice, network=private_net)
59 private_net_slice.save()