blob: d9d138d5f2cac7b4b736045d4b1b0111272b38db [file] [log] [blame]
Sapan Bhatia337aacb2014-09-03 15:38:28 -04001from core.models import *
2
3def handle(network):
Tony Mack06c8e472014-11-30 15:53:08 -05004 from core.models import ControllerSlices,ControllerNetworks
Sapan Bhatia0e5be032014-09-15 03:48:20 -04005 from collections import defaultdict
Tony Mack06c8e472014-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 Mack06c8e472014-11-30 15:53:08 -05008 slice_controllers = ControllerSlices.objects.all()
Sapan Bhatia337aacb2014-09-03 15:38:28 -04009 slice_deploy_lookup = defaultdict(list)
Tony Mack06c8e472014-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 Mack06c8e472014-11-30 15:53:08 -050013 network_controllers = ControllerNetworks.objects.all()
Sapan Bhatia337aacb2014-09-03 15:38:28 -040014 network_deploy_lookup = defaultdict(list)
Tony Mack06c8e472014-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 Mack06c8e472014-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 Mack06c8e472014-11-30 15:53:08 -050021 expected_controller not in network_deploy_lookup[network]:
22 nd = ControllerNetworks(network=network, controller=expected_controller)
Sapan Bhatia337aacb2014-09-03 15:38:28 -040023 nd.save()