blob: 0d83d684a9b1da90aae34f451c7ed6356a9fe94a [file] [log] [blame]
Sapan Bhatiab3aeb1b2014-09-03 15:39:13 -04001
2def handle(slice):
Tony Mack0178aea2015-01-03 20:04:54 -05003 from core.models import Controller,ControllerSlices,Controller,Network,NetworkSlice,NetworkTemplate
Sapan Bhatia728acce2014-09-15 03:48:20 -04004 from collections import defaultdict
Tony Mack0178aea2015-01-03 20:04:54 -05005 ctrl_site_deployments = SiteDeployments.objects.all()
Sapan Bhatiab3aeb1b2014-09-03 15:39:13 -04006
Tony Mack336e0f92014-11-30 15:53:08 -05007 slice_controllers = ControllerSlices.objects.all()
Sapan Bhatiab3aeb1b2014-09-03 15:39:13 -04008 slice_deploy_lookup = defaultdict(list)
Tony Mack336e0f92014-11-30 15:53:08 -05009 for slice_controller in slice_controllers:
Tony Mack528d4222014-12-05 17:13:08 -050010 slice_deploy_lookup[slice_controller.slice].append(slice_controller)
Sapan Bhatiab3aeb1b2014-09-03 15:39:13 -040011
Tony Mack528d4222014-12-05 17:13:08 -050012 all_controllers = Controller.objects.all()
Sapan Bhatiabdac1f62014-12-22 01:38:00 -050013 for expected_controller in all_controllers:
Sapan Bhatiab3aeb1b2014-09-03 15:39:13 -040014 if slice not in slice_deploy_lookup or \
Tony Mack336e0f92014-11-30 15:53:08 -050015 expected_controller not in slice_deploy_lookup[slice]:
16 sd = ControllerSlices(slice=slice, controller=expected_controller)
Sapan Bhatiab3aeb1b2014-09-03 15:39:13 -040017 sd.save()
18
Tony Mackd2046f32014-10-08 22:54:02 -040019 # make sure slice has at least 1 public and 1 private networkd
Scott Bakercb7649c2014-10-16 00:43:54 -070020 public_nets = []
Tony Mackd2046f32014-10-08 22:54:02 -040021 private_net = None
22 networks = Network.objects.filter(owner=slice)
23 for network in networks:
24 if network.template.name == 'Public dedicated IPv4':
Scott Bakercb7649c2014-10-16 00:43:54 -070025 public_nets.append(network)
26 elif network.template.name == 'Public shared IPv4':
27 public_nets.append(network)
Tony Mackd2046f32014-10-08 22:54:02 -040028 elif network.template.name == 'Private':
Scott Bakercb7649c2014-10-16 00:43:54 -070029 private_net = network
30 if not public_nets:
31 # ensure there is at least one public network, and default it to dedicated
Tony Mackd0eeed82014-11-12 10:00:12 -050032 nat_net = Network(
33 name = slice.name+'-nat',
34 template = NetworkTemplate.objects.get(name='Public shared IPv4'),
Scott Bakercb7649c2014-10-16 00:43:54 -070035 owner = slice
36 )
Tony Mackd0eeed82014-11-12 10:00:12 -050037 nat_net.save()
38 public_nets.append(nat_net)
Scott Bakercb7649c2014-10-16 00:43:54 -070039
Tony Mackd2046f32014-10-08 22:54:02 -040040 if not private_net:
41 private_net = Network(
42 name = slice.name+'-private',
43 template = NetworkTemplate.objects.get(name='Private'),
44 owner = slice
45 )
46 private_net.save()
47 # create slice networks
48 public_net_slice = None
49 private_net_slice = None
Scott Bakercb7649c2014-10-16 00:43:54 -070050 net_slices = NetworkSlice.objects.filter(slice=slice, network__in=[private_net]+public_nets)
Tony Mackd2046f32014-10-08 22:54:02 -040051 for net_slice in net_slices:
Scott Bakercb7649c2014-10-16 00:43:54 -070052 if net_slice.network in public_nets:
53 public_net_slice = net_slice
Tony Mackd2046f32014-10-08 22:54:02 -040054 elif net_slice.network == private_net:
Scott Bakercb7649c2014-10-16 00:43:54 -070055 private_net_slice = net_slice
Tony Mackd2046f32014-10-08 22:54:02 -040056 if not public_net_slice:
Scott Bakercb7649c2014-10-16 00:43:54 -070057 public_net_slice = NetworkSlice(slice=slice, network=public_nets[0])
Tony Mackd2046f32014-10-08 22:54:02 -040058 public_net_slice.save()
59 if not private_net_slice:
60 private_net_slice = NetworkSlice(slice=slice, network=private_net)
Scott Bakercb7649c2014-10-16 00:43:54 -070061 private_net_slice.save()
62
63
64
65