blob: cc9f2b0b3904c3c89e26798f2b3e0cc847dada7e [file] [log] [blame]
Sapan Bhatiab3aeb1b2014-09-03 15:39:13 -04001
2def handle(slice):
Tony Macka7dbd422015-01-05 22:48:11 -05003 from core.models import Controller, ControllerSlice, SiteDeployment, Network, NetworkSlice,NetworkTemplate
4 from collections import defaultdict
5 controller_slices = ControllerSlice.objects.filter(slice=slice)
6 existing_controllers = [cs.controller for cs in controller_slices]
7
8 all_controllers = Controller.objects.all()
9 for controller in all_controllers:
10 if controller not in existing_controllers:
Tony Mack26564362015-01-06 17:49:25 -050011 sd = ControllerSlice(slice=slice, controller=controller)
Tony Macka7dbd422015-01-05 22:48:11 -050012 sd.save()
Sapan Bhatiab3aeb1b2014-09-03 15:39:13 -040013
Tony Macka7dbd422015-01-05 22:48:11 -050014 # make sure slice has at least 1 public and 1 private networkd
15 public_nets = []
16 private_net = None
17 networks = Network.objects.filter(owner=slice)
18 for network in networks:
19 if network.template.name == 'Public dedicated IPv4':
20 public_nets.append(network)
21 elif network.template.name == 'Public shared IPv4':
22 public_nets.append(network)
23 elif network.template.name == 'Private':
24 private_net = network
25 if not public_nets:
Scott Bakercb7649c2014-10-16 00:43:54 -070026 # ensure there is at least one public network, and default it to dedicated
Tony Macka7dbd422015-01-05 22:48:11 -050027 nat_net = Network(
28 name = slice.name+'-nat',
29 template = NetworkTemplate.objects.get(name='Public shared IPv4'),
30 owner = slice
31 )
32 nat_net.save()
33 public_nets.append(nat_net)
Scott Bakercb7649c2014-10-16 00:43:54 -070034
Tony Macka7dbd422015-01-05 22:48:11 -050035 if not private_net:
36 private_net = Network(
37 name = slice.name+'-private',
38 template = NetworkTemplate.objects.get(name='Private'),
39 owner = slice
40 )
41 private_net.save()
42 # create slice networks
43 public_net_slice = None
44 private_net_slice = None
45 net_slices = NetworkSlice.objects.filter(slice=slice, network__in=[private_net]+public_nets)
46 for net_slice in net_slices:
47 if net_slice.network in public_nets:
48 public_net_slice = net_slice
49 elif net_slice.network == private_net:
50 private_net_slice = net_slice
51 if not public_net_slice:
52 public_net_slice = NetworkSlice(slice=slice, network=public_nets[0])
53 public_net_slice.save()
54 if not private_net_slice:
55 private_net_slice = NetworkSlice(slice=slice, network=private_net)
56 private_net_slice.save()
Scott Bakercb7649c2014-10-16 00:43:54 -070057
58
59
60