blob: 8702d21f50d61bb99b592936492478f45f9396ab [file] [log] [blame]
Sapan Bhatia337aacb2014-09-03 15:38:28 -04001from core.models import *
2
3def handle(network):
Sapan Bhatia085ed482015-01-17 00:56:36 +00004 from core.models import ControllerSlice,ControllerNetwork, Network
Sapan Bhatia728acce2014-09-15 03:48:20 -04005 from collections import defaultdict
Sapan Bhatia085ed482015-01-17 00:56:36 +00006
7 # network = Network.get(network_id)
Tony Mack336e0f92014-11-30 15:53:08 -05008 # network controllers are not visible to users. We must ensure
Sapan Bhatia337aacb2014-09-03 15:38:28 -04009 # networks are deployed at all deploymets available to their slices.
Tony Macka7dbd422015-01-05 22:48:11 -050010 slice_controllers = ControllerSlice.objects.all()
Sapan Bhatia337aacb2014-09-03 15:38:28 -040011 slice_deploy_lookup = defaultdict(list)
Tony Mack336e0f92014-11-30 15:53:08 -050012 for slice_controller in slice_controllers:
13 slice_deploy_lookup[slice_controller.slice].append(slice_controller.controller)
Sapan Bhatia337aacb2014-09-03 15:38:28 -040014
Tony Macka7dbd422015-01-05 22:48:11 -050015 network_controllers = ControllerNetwork.objects.all()
Sapan Bhatia337aacb2014-09-03 15:38:28 -040016 network_deploy_lookup = defaultdict(list)
Tony Mack336e0f92014-11-30 15:53:08 -050017 for network_controller in network_controllers:
18 network_deploy_lookup[network_controller.network].append(network_controller.controller)
Sapan Bhatia337aacb2014-09-03 15:38:28 -040019
Tony Mack336e0f92014-11-30 15:53:08 -050020 expected_controllers = slice_deploy_lookup[network.owner]
21 for expected_controller in expected_controllers:
Sapan Bhatia337aacb2014-09-03 15:38:28 -040022 if network not in network_deploy_lookup or \
Tony Mack336e0f92014-11-30 15:53:08 -050023 expected_controller not in network_deploy_lookup[network]:
Tony Macka7dbd422015-01-05 22:48:11 -050024 nd = ControllerNetwork(network=network, controller=expected_controller)
Sapan Bhatia337aacb2014-09-03 15:38:28 -040025 nd.save()