Sapan Bhatia | 337aacb | 2014-09-03 15:38:28 -0400 | [diff] [blame] | 1 | from core.models import * |
| 2 | |
| 3 | def handle(network): |
Sapan Bhatia | 7a8b7e9 | 2014-11-11 21:43:31 -0500 | [diff] [blame^] | 4 | from core.models import SliceDeployment,NetworkDeployments |
Sapan Bhatia | 728acce | 2014-09-15 03:48:20 -0400 | [diff] [blame] | 5 | from collections import defaultdict |
Sapan Bhatia | 337aacb | 2014-09-03 15:38:28 -0400 | [diff] [blame] | 6 | # network deployments are not visible to users. We must ensure |
| 7 | # networks are deployed at all deploymets available to their slices. |
Sapan Bhatia | 7a8b7e9 | 2014-11-11 21:43:31 -0500 | [diff] [blame^] | 8 | slice_deployments = SliceDeployment.objects.all() |
Sapan Bhatia | 337aacb | 2014-09-03 15:38:28 -0400 | [diff] [blame] | 9 | slice_deploy_lookup = defaultdict(list) |
| 10 | for slice_deployment in slice_deployments: |
| 11 | slice_deploy_lookup[slice_deployment.slice].append(slice_deployment.deployment) |
| 12 | |
| 13 | network_deployments = NetworkDeployments.objects.all() |
| 14 | network_deploy_lookup = defaultdict(list) |
| 15 | for network_deployment in network_deployments: |
| 16 | network_deploy_lookup[network_deployment.network].append(network_deployment.deployment) |
| 17 | |
| 18 | expected_deployments = slice_deploy_lookup[network.owner] |
| 19 | for expected_deployment in expected_deployments: |
| 20 | if network not in network_deploy_lookup or \ |
| 21 | expected_deployment not in network_deploy_lookup[network]: |
| 22 | nd = NetworkDeployments(network=network, deployment=expected_deployment) |
| 23 | nd.save() |