Sapan Bhatia | b3aeb1b | 2014-09-03 15:39:13 -0400 | [diff] [blame] | 1 | |
| 2 | def handle(slice): |
Sapan Bhatia | bdac1f6 | 2014-12-22 01:38:00 -0500 | [diff] [blame^] | 3 | import pdb |
| 4 | pdb.set_trace() |
Tony Mack | 528d422 | 2014-12-05 17:13:08 -0500 | [diff] [blame] | 5 | from core.models import Controller, ControllerSiteDeployments, ControllerSlices,Controller,Network,NetworkSlice,NetworkTemplate |
Sapan Bhatia | 728acce | 2014-09-15 03:48:20 -0400 | [diff] [blame] | 6 | from collections import defaultdict |
Tony Mack | 528d422 | 2014-12-05 17:13:08 -0500 | [diff] [blame] | 7 | ctrl_site_deployments = ControllerSiteDeployments.objects.all() |
Sapan Bhatia | b3aeb1b | 2014-09-03 15:39:13 -0400 | [diff] [blame] | 8 | site_deploy_lookup = defaultdict(list) |
Tony Mack | 528d422 | 2014-12-05 17:13:08 -0500 | [diff] [blame] | 9 | for ctrl_site_deployment in ctrl_site_deployments: |
| 10 | site_deploy_lookup[ctrl_site_deployment.site_deployment].append(ctrl_site_deployment) |
Sapan Bhatia | b3aeb1b | 2014-09-03 15:39:13 -0400 | [diff] [blame] | 11 | |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 12 | slice_controllers = ControllerSlices.objects.all() |
Sapan Bhatia | b3aeb1b | 2014-09-03 15:39:13 -0400 | [diff] [blame] | 13 | slice_deploy_lookup = defaultdict(list) |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 14 | for slice_controller in slice_controllers: |
Tony Mack | 528d422 | 2014-12-05 17:13:08 -0500 | [diff] [blame] | 15 | slice_deploy_lookup[slice_controller.slice].append(slice_controller) |
Sapan Bhatia | b3aeb1b | 2014-09-03 15:39:13 -0400 | [diff] [blame] | 16 | |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 17 | #expected_controllers = site_deploy_lookup[slice.site] |
Tony Mack | 528d422 | 2014-12-05 17:13:08 -0500 | [diff] [blame] | 18 | all_controllers = Controller.objects.all() |
Sapan Bhatia | bdac1f6 | 2014-12-22 01:38:00 -0500 | [diff] [blame^] | 19 | for expected_controller in all_controllers: |
Sapan Bhatia | b3aeb1b | 2014-09-03 15:39:13 -0400 | [diff] [blame] | 20 | if slice not in slice_deploy_lookup or \ |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 21 | expected_controller not in slice_deploy_lookup[slice]: |
| 22 | sd = ControllerSlices(slice=slice, controller=expected_controller) |
Sapan Bhatia | b3aeb1b | 2014-09-03 15:39:13 -0400 | [diff] [blame] | 23 | sd.save() |
| 24 | |
Tony Mack | d2046f3 | 2014-10-08 22:54:02 -0400 | [diff] [blame] | 25 | # make sure slice has at least 1 public and 1 private networkd |
Scott Baker | cb7649c | 2014-10-16 00:43:54 -0700 | [diff] [blame] | 26 | public_nets = [] |
Tony Mack | d2046f3 | 2014-10-08 22:54:02 -0400 | [diff] [blame] | 27 | private_net = None |
| 28 | networks = Network.objects.filter(owner=slice) |
| 29 | for network in networks: |
| 30 | if network.template.name == 'Public dedicated IPv4': |
Scott Baker | cb7649c | 2014-10-16 00:43:54 -0700 | [diff] [blame] | 31 | public_nets.append(network) |
| 32 | elif network.template.name == 'Public shared IPv4': |
| 33 | public_nets.append(network) |
Tony Mack | d2046f3 | 2014-10-08 22:54:02 -0400 | [diff] [blame] | 34 | elif network.template.name == 'Private': |
Scott Baker | cb7649c | 2014-10-16 00:43:54 -0700 | [diff] [blame] | 35 | private_net = network |
| 36 | if not public_nets: |
| 37 | # ensure there is at least one public network, and default it to dedicated |
Tony Mack | d0eeed8 | 2014-11-12 10:00:12 -0500 | [diff] [blame] | 38 | nat_net = Network( |
| 39 | name = slice.name+'-nat', |
| 40 | template = NetworkTemplate.objects.get(name='Public shared IPv4'), |
Scott Baker | cb7649c | 2014-10-16 00:43:54 -0700 | [diff] [blame] | 41 | owner = slice |
| 42 | ) |
Tony Mack | d0eeed8 | 2014-11-12 10:00:12 -0500 | [diff] [blame] | 43 | nat_net.save() |
| 44 | public_nets.append(nat_net) |
Scott Baker | cb7649c | 2014-10-16 00:43:54 -0700 | [diff] [blame] | 45 | |
Tony Mack | d2046f3 | 2014-10-08 22:54:02 -0400 | [diff] [blame] | 46 | 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 Baker | cb7649c | 2014-10-16 00:43:54 -0700 | [diff] [blame] | 56 | net_slices = NetworkSlice.objects.filter(slice=slice, network__in=[private_net]+public_nets) |
Tony Mack | d2046f3 | 2014-10-08 22:54:02 -0400 | [diff] [blame] | 57 | for net_slice in net_slices: |
Scott Baker | cb7649c | 2014-10-16 00:43:54 -0700 | [diff] [blame] | 58 | if net_slice.network in public_nets: |
| 59 | public_net_slice = net_slice |
Tony Mack | d2046f3 | 2014-10-08 22:54:02 -0400 | [diff] [blame] | 60 | elif net_slice.network == private_net: |
Scott Baker | cb7649c | 2014-10-16 00:43:54 -0700 | [diff] [blame] | 61 | private_net_slice = net_slice |
Tony Mack | d2046f3 | 2014-10-08 22:54:02 -0400 | [diff] [blame] | 62 | if not public_net_slice: |
Scott Baker | cb7649c | 2014-10-16 00:43:54 -0700 | [diff] [blame] | 63 | public_net_slice = NetworkSlice(slice=slice, network=public_nets[0]) |
Tony Mack | d2046f3 | 2014-10-08 22:54:02 -0400 | [diff] [blame] | 64 | public_net_slice.save() |
| 65 | if not private_net_slice: |
| 66 | private_net_slice = NetworkSlice(slice=slice, network=private_net) |
Scott Baker | cb7649c | 2014-10-16 00:43:54 -0700 | [diff] [blame] | 67 | private_net_slice.save() |
| 68 | |
| 69 | |
| 70 | |
| 71 | |