blob: 2c24e83618ad537e292d4fbb148321af25f05c72 [file] [log] [blame]
Tony Mack46c2d502013-10-09 13:04:28 -04001import os
2import base64
3from django.db.models import F, Q
4from planetstack.config import Config
5from observer.openstacksyncstep import OpenStackSyncStep
6from core.models.image import Image
7
8class SyncImages(OpenStackSyncStep):
9 provides=[Image]
10 requested_interval=0
11
12 def fetch_pending(self):
Tony Mackbf39d9f2014-05-06 21:42:36 -040013 # get list of images on disk
14 images_path = Config().observer_images_directory
15 available_images = {}
16 for f in os.listdir(images_path):
17 if os.path.isfile(os.path.join(images_path ,f)):
18 available_images[f] = os.path.join(images_path ,f)
19
Tony Mack46c2d502013-10-09 13:04:28 -040020 images = Image.objects.all()
21 image_names = [image.name for image in images]
Scott Baker6721c0a2014-06-02 23:19:38 -070022
Tony Mackbf39d9f2014-05-06 21:42:36 -040023 for image_name in available_images:
Scott Baker6721c0a2014-06-02 23:19:38 -070024 #remove file extension
Tony Mackbf39d9f2014-05-06 21:42:36 -040025 clean_name = ".".join(image_name.split('.')[:-1])
Scott Baker6721c0a2014-06-02 23:19:38 -070026 if clean_name not in image_names:
Tony Mackbf39d9f2014-05-06 21:42:36 -040027 image = Image(name=clean_name,
28 disk_format='raw',
29 container_format='bare',
30 path = available_images[image_name])
31 image.save()
Tony Mack46c2d502013-10-09 13:04:28 -040032
Tony Mackbf39d9f2014-05-06 21:42:36 -040033
34 return Image.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
Tony Mack46c2d502013-10-09 13:04:28 -040035
36 def sync_record(self, image):
37 image.save()