sync images across deployments
diff --git a/planetstack/observer/steps/sync_images.py b/planetstack/observer/steps/sync_images.py
index 2dbd74d..6ee53fe 100644
--- a/planetstack/observer/steps/sync_images.py
+++ b/planetstack/observer/steps/sync_images.py
@@ -10,20 +10,28 @@
requested_interval=0
def fetch_pending(self):
+ # get list of images on disk
+ images_path = Config().observer_images_directory
+ available_images = {}
+ for f in os.listdir(images_path):
+ if os.path.isfile(os.path.join(images_path ,f)):
+ available_images[f] = os.path.join(images_path ,f)
+
images = Image.objects.all()
image_names = [image.name for image in images]
+
+ for image_name in available_images:
+ #remove file extension
+ clean_name = ".".join(image_name.split('.')[:-1])
+ if image_name not in image_names:
+ image = Image(name=clean_name,
+ disk_format='raw',
+ container_format='bare',
+ path = available_images[image_name])
+ image.save()
- new_images = []
- glance_images = self.driver.shell.glance.get_images()
- for glance_image in glance_images:
- if glance_image['name'] not in image_names:
- image = Image(image_id=glance_image['id'],
- name=glance_image['name'],
- disk_format=glance_image['disk_format'],
- container_format=glance_image['container_format'])
- new_images.append(image)
-
- return new_images
+
+ return Image.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
def sync_record(self, image):
image.save()