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 ImagePolicy(Policy): |
| 5 | model_name = "Image" |
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, image): |
| 8 | return self.handle_update(image) |
Scott Baker | a0a688a | 2017-03-28 11:59:56 -0700 | [diff] [blame] | 9 | |
Scott Baker | 46a3ee9 | 2017-05-30 16:44:56 -0700 | [diff] [blame] | 10 | def handle_update(self, image): |
| 11 | if (image.kind == "container"): |
| 12 | # container images do not get instantiated |
| 13 | return |
| 14 | |
| 15 | controller_images = ControllerImages.objects.filter(image_id=image.id) |
| 16 | existing_controllers = [cs.controller for cs in controller_images] |
| 17 | existing_controller_ids = [c.id for c in existing_controllers] |
| 18 | |
| 19 | all_controllers = Controller.objects.all() |
| 20 | for controller in all_controllers: |
| 21 | if controller.id not in existing_controller_ids: |
| 22 | sd = ControllerImages(image=image, controller=controller) |
| 23 | sd.save() |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 24 | |