blob: 06347c5d6edd6583c30c6c43e576bf719b5d57e8 [file] [log] [blame]
Scott Bakerb63ea792016-08-11 10:24:48 -07001from core.models import *
2
3def handle(network):
4 from core.models import ControllerSlice,ControllerNetwork, Network
5 from collections import defaultdict
6
7 print "MODEL POLICY: network", network
8
9 # network = Network.get(network_id)
10 # network controllers are not visible to users. We must ensure
11 # networks are deployed at all deploymets available to their slices.
12 slice_controllers = ControllerSlice.objects.all()
13 slice_deploy_lookup = defaultdict(list)
14 for slice_controller in slice_controllers:
15 slice_deploy_lookup[slice_controller.slice].append(slice_controller.controller)
16
17 network_controllers = ControllerNetwork.objects.all()
18 network_deploy_lookup = defaultdict(list)
19 for network_controller in network_controllers:
20 network_deploy_lookup[network_controller.network].append(network_controller.controller)
21
22 expected_controllers = slice_deploy_lookup[network.owner]
23 for expected_controller in expected_controllers:
24 if network not in network_deploy_lookup or \
25 expected_controller not in network_deploy_lookup[network]:
26 lazy_blocked=True
27
28 # check and see if some instance already exists
29 for networkslice in network.networkslices.all():
30 if networkslice.slice.instances.filter(node__site_deployment__controller=expected_controller).exists():
31 print "MODEL_POLICY: network, setting lazy_blocked to false because instance on controller already exists"
32 lazy_blocked=False
33
34 nd = ControllerNetwork(network=network, controller=expected_controller, lazy_blocked=lazy_blocked)
35 print "MODEL POLICY: network", network, "create ControllerNetwork", nd, "lazy_blocked", lazy_blocked
36 if network.subnet:
37 # XXX: Possibly unpredictable behavior if there is
38 # more than one ControllerNetwork and the subnet
39 # is specified.
40 nd.subnet = network.subnet
41 nd.save()