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