blob: 37936c1e5fbbcb0cce0059375e61629a690101e9 [file] [log] [blame]
Scott Bakeraf599eb2017-03-21 12:43:26 -07001from synchronizers.new_base.modelaccessor import *
Scott Baker46a3ee92017-05-30 16:44:56 -07002from synchronizers.new_base.policy import Policy
Scott Bakerb63ea792016-08-11 10:24:48 -07003
Scott Baker46a3ee92017-05-30 16:44:56 -07004class ImagePolicy(Policy):
5 model_name = "Image"
Scott Bakerb63ea792016-08-11 10:24:48 -07006
Scott Baker46a3ee92017-05-30 16:44:56 -07007 def handle_create(self, image):
8 return self.handle_update(image)
Scott Bakera0a688a2017-03-28 11:59:56 -07009
Scott Baker46a3ee92017-05-30 16:44:56 -070010 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 Bakerb63ea792016-08-11 10:24:48 -070024