Scott Baker | af599eb | 2017-03-21 12:43:26 -0700 | [diff] [blame] | 1 | from synchronizers.new_base.modelaccessor import * |
Scott Baker | 46a3ee9 | 2017-05-30 16:44:56 -0700 | [diff] [blame] | 2 | from synchronizers.new_base.policy import Policy |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 3 | |
Scott Baker | 46a3ee9 | 2017-05-30 16:44:56 -0700 | [diff] [blame] | 4 | class InstancePolicy(Policy): |
| 5 | model_name = "Instance" |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 6 | |
Scott Baker | 46a3ee9 | 2017-05-30 16:44:56 -0700 | [diff] [blame] | 7 | def handle_create(self, instance): |
| 8 | return self.handle_update(instance) |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 9 | |
Scott Baker | 46a3ee9 | 2017-05-30 16:44:56 -0700 | [diff] [blame] | 10 | def handle_update(self, instance): |
| 11 | networks = [ns.network for ns in NetworkSlice.objects.filter(slice_id=instance.slice.id)] |
| 12 | controller_networks = ControllerNetwork.objects.filter(controller_id=instance.node.site_deployment.controller.id) |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 13 | |
Scott Baker | 46a3ee9 | 2017-05-30 16:44:56 -0700 | [diff] [blame] | 14 | # a little clumsy because the API ORM doesn't support __in queries |
| 15 | network_ids = [x.id for x in networks] |
| 16 | controller_networks = [x for x in controller_networks if x.network.id in network_ids] |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 17 | |
Scott Baker | 46a3ee9 | 2017-05-30 16:44:56 -0700 | [diff] [blame] | 18 | for cn in controller_networks: |
| 19 | if (cn.lazy_blocked): |
| 20 | self.logger.info("MODEL POLICY: instance %s unblocking network %s" % (instance, cn.network)) |
| 21 | cn.lazy_blocked=False |
| 22 | cn.backend_register = '{}' |
| 23 | cn.save() |