blob: 659c139c3e4799e476709c76047a91cd6483da6f [file] [log] [blame]
Sapan Bhatiab3aeb1b2014-09-03 15:39:13 -04001
2def handle(slice):
Sapan Bhatiabdac1f62014-12-22 01:38:00 -05003 import pdb
4 pdb.set_trace()
Tony Mack528d4222014-12-05 17:13:08 -05005 from core.models import Controller, ControllerSiteDeployments, ControllerSlices,Controller,Network,NetworkSlice,NetworkTemplate
Sapan Bhatia728acce2014-09-15 03:48:20 -04006 from collections import defaultdict
Tony Mack528d4222014-12-05 17:13:08 -05007 ctrl_site_deployments = ControllerSiteDeployments.objects.all()
Sapan Bhatiab3aeb1b2014-09-03 15:39:13 -04008 site_deploy_lookup = defaultdict(list)
Tony Mack528d4222014-12-05 17:13:08 -05009 for ctrl_site_deployment in ctrl_site_deployments:
10 site_deploy_lookup[ctrl_site_deployment.site_deployment].append(ctrl_site_deployment)
Sapan Bhatiab3aeb1b2014-09-03 15:39:13 -040011
Tony Mack336e0f92014-11-30 15:53:08 -050012 slice_controllers = ControllerSlices.objects.all()
Sapan Bhatiab3aeb1b2014-09-03 15:39:13 -040013 slice_deploy_lookup = defaultdict(list)
Tony Mack336e0f92014-11-30 15:53:08 -050014 for slice_controller in slice_controllers:
Tony Mack528d4222014-12-05 17:13:08 -050015 slice_deploy_lookup[slice_controller.slice].append(slice_controller)
Sapan Bhatiab3aeb1b2014-09-03 15:39:13 -040016
Tony Mack336e0f92014-11-30 15:53:08 -050017 #expected_controllers = site_deploy_lookup[slice.site]
Tony Mack528d4222014-12-05 17:13:08 -050018 all_controllers = Controller.objects.all()
Sapan Bhatiabdac1f62014-12-22 01:38:00 -050019 for expected_controller in all_controllers:
Sapan Bhatiab3aeb1b2014-09-03 15:39:13 -040020 if slice not in slice_deploy_lookup or \
Tony Mack336e0f92014-11-30 15:53:08 -050021 expected_controller not in slice_deploy_lookup[slice]:
22 sd = ControllerSlices(slice=slice, controller=expected_controller)
Sapan Bhatiab3aeb1b2014-09-03 15:39:13 -040023 sd.save()
24
Tony Mackd2046f32014-10-08 22:54:02 -040025 # make sure slice has at least 1 public and 1 private networkd
Scott Bakercb7649c2014-10-16 00:43:54 -070026 public_nets = []
Tony Mackd2046f32014-10-08 22:54:02 -040027 private_net = None
28 networks = Network.objects.filter(owner=slice)
29 for network in networks:
30 if network.template.name == 'Public dedicated IPv4':
Scott Bakercb7649c2014-10-16 00:43:54 -070031 public_nets.append(network)
32 elif network.template.name == 'Public shared IPv4':
33 public_nets.append(network)
Tony Mackd2046f32014-10-08 22:54:02 -040034 elif network.template.name == 'Private':
Scott Bakercb7649c2014-10-16 00:43:54 -070035 private_net = network
36 if not public_nets:
37 # ensure there is at least one public network, and default it to dedicated
Tony Mackd0eeed82014-11-12 10:00:12 -050038 nat_net = Network(
39 name = slice.name+'-nat',
40 template = NetworkTemplate.objects.get(name='Public shared IPv4'),
Scott Bakercb7649c2014-10-16 00:43:54 -070041 owner = slice
42 )
Tony Mackd0eeed82014-11-12 10:00:12 -050043 nat_net.save()
44 public_nets.append(nat_net)
Scott Bakercb7649c2014-10-16 00:43:54 -070045
Tony Mackd2046f32014-10-08 22:54:02 -040046 if not private_net:
47 private_net = Network(
48 name = slice.name+'-private',
49 template = NetworkTemplate.objects.get(name='Private'),
50 owner = slice
51 )
52 private_net.save()
53 # create slice networks
54 public_net_slice = None
55 private_net_slice = None
Scott Bakercb7649c2014-10-16 00:43:54 -070056 net_slices = NetworkSlice.objects.filter(slice=slice, network__in=[private_net]+public_nets)
Tony Mackd2046f32014-10-08 22:54:02 -040057 for net_slice in net_slices:
Scott Bakercb7649c2014-10-16 00:43:54 -070058 if net_slice.network in public_nets:
59 public_net_slice = net_slice
Tony Mackd2046f32014-10-08 22:54:02 -040060 elif net_slice.network == private_net:
Scott Bakercb7649c2014-10-16 00:43:54 -070061 private_net_slice = net_slice
Tony Mackd2046f32014-10-08 22:54:02 -040062 if not public_net_slice:
Scott Bakercb7649c2014-10-16 00:43:54 -070063 public_net_slice = NetworkSlice(slice=slice, network=public_nets[0])
Tony Mackd2046f32014-10-08 22:54:02 -040064 public_net_slice.save()
65 if not private_net_slice:
66 private_net_slice = NetworkSlice(slice=slice, network=private_net)
Scott Bakercb7649c2014-10-16 00:43:54 -070067 private_net_slice.save()
68
69
70
71