blob: 6ee53fe81caf398a667fee3828c9a0f747fafa18 [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]
Tony Mackbf39d9f2014-05-06 21:42:36 -040022
23 for image_name in available_images:
24 #remove file extension
25 clean_name = ".".join(image_name.split('.')[:-1])
26 if image_name not in image_names:
27 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()