Sapan Bhatia | 337aacb | 2014-09-03 15:38:28 -0400 | [diff] [blame] | 1 | from core.models import * |
| 2 | |
| 3 | def handle(network): |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 4 | from core.models import ControllerSlices,ControllerNetworks |
Sapan Bhatia | 728acce | 2014-09-15 03:48:20 -0400 | [diff] [blame] | 5 | from collections import defaultdict |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 6 | # network controllers are not visible to users. We must ensure |
Sapan Bhatia | 337aacb | 2014-09-03 15:38:28 -0400 | [diff] [blame] | 7 | # networks are deployed at all deploymets available to their slices. |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 8 | slice_controllers = ControllerSlices.objects.all() |
Sapan Bhatia | 337aacb | 2014-09-03 15:38:28 -0400 | [diff] [blame] | 9 | slice_deploy_lookup = defaultdict(list) |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 10 | for slice_controller in slice_controllers: |
| 11 | slice_deploy_lookup[slice_controller.slice].append(slice_controller.controller) |
Sapan Bhatia | 337aacb | 2014-09-03 15:38:28 -0400 | [diff] [blame] | 12 | |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 13 | network_controllers = ControllerNetworks.objects.all() |
Sapan Bhatia | 337aacb | 2014-09-03 15:38:28 -0400 | [diff] [blame] | 14 | network_deploy_lookup = defaultdict(list) |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 15 | for network_controller in network_controllers: |
| 16 | network_deploy_lookup[network_controller.network].append(network_controller.controller) |
Sapan Bhatia | 337aacb | 2014-09-03 15:38:28 -0400 | [diff] [blame] | 17 | |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 18 | expected_controllers = slice_deploy_lookup[network.owner] |
| 19 | for expected_controller in expected_controllers: |
Sapan Bhatia | 337aacb | 2014-09-03 15:38:28 -0400 | [diff] [blame] | 20 | if network not in network_deploy_lookup or \ |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 21 | expected_controller not in network_deploy_lookup[network]: |
| 22 | nd = ControllerNetworks(network=network, controller=expected_controller) |
Sapan Bhatia | 337aacb | 2014-09-03 15:38:28 -0400 | [diff] [blame] | 23 | nd.save() |