blob: f822bf2b28456e0426c4bd468f3bf546853d5da3 [file] [log] [blame]
Sapan Bhatia337aacb2014-09-03 15:38:28 -04001from core.models import *
2
3def handle(network):
Tony Macka7dbd422015-01-05 22:48:11 -05004 from core.models import ControllerSlice,ControllerNetwork
Sapan Bhatia728acce2014-09-15 03:48:20 -04005 from collections import defaultdict
Tony Mack336e0f92014-11-30 15:53:08 -05006 # network controllers are not visible to users. We must ensure
Sapan Bhatia337aacb2014-09-03 15:38:28 -04007 # networks are deployed at all deploymets available to their slices.
Tony Macka7dbd422015-01-05 22:48:11 -05008 slice_controllers = ControllerSlice.objects.all()
Sapan Bhatia337aacb2014-09-03 15:38:28 -04009 slice_deploy_lookup = defaultdict(list)
Tony Mack336e0f92014-11-30 15:53:08 -050010 for slice_controller in slice_controllers:
11 slice_deploy_lookup[slice_controller.slice].append(slice_controller.controller)
Sapan Bhatia337aacb2014-09-03 15:38:28 -040012
Tony Macka7dbd422015-01-05 22:48:11 -050013 network_controllers = ControllerNetwork.objects.all()
Sapan Bhatia337aacb2014-09-03 15:38:28 -040014 network_deploy_lookup = defaultdict(list)
Tony Mack336e0f92014-11-30 15:53:08 -050015 for network_controller in network_controllers:
16 network_deploy_lookup[network_controller.network].append(network_controller.controller)
Sapan Bhatia337aacb2014-09-03 15:38:28 -040017
Tony Mack336e0f92014-11-30 15:53:08 -050018 expected_controllers = slice_deploy_lookup[network.owner]
19 for expected_controller in expected_controllers:
Sapan Bhatia337aacb2014-09-03 15:38:28 -040020 if network not in network_deploy_lookup or \
Tony Mack336e0f92014-11-30 15:53:08 -050021 expected_controller not in network_deploy_lookup[network]:
Tony Macka7dbd422015-01-05 22:48:11 -050022 nd = ControllerNetwork(network=network, controller=expected_controller)
Sapan Bhatia337aacb2014-09-03 15:38:28 -040023 nd.save()