Tony Mack | 46c2d50 | 2013-10-09 13:04:28 -0400 | [diff] [blame] | 1 | import os |
| 2 | import base64 |
| 3 | from django.db.models import F, Q |
| 4 | from planetstack.config import Config |
| 5 | from observer.openstacksyncstep import OpenStackSyncStep |
| 6 | from core.models.image import Image |
| 7 | |
| 8 | class SyncImages(OpenStackSyncStep): |
| 9 | provides=[Image] |
| 10 | requested_interval=0 |
| 11 | |
| 12 | def fetch_pending(self): |
| 13 | images = Image.objects.all() |
| 14 | image_names = [image.name for image in images] |
| 15 | |
| 16 | new_images = [] |
| 17 | glance_images = self.driver.shell.glance.get_images() |
| 18 | for glance_image in glance_images: |
| 19 | if glance_image['name'] not in image_names: |
| 20 | image = Image(image_id=glance_image['id'], |
| 21 | name=glance_image['name'], |
| 22 | disk_format=glance_image['disk_format'], |
| 23 | container_format=glance_image['container_format']) |
| 24 | new_images.append(image) |
| 25 | |
| 26 | return new_images |
| 27 | |
| 28 | def sync_record(self, image): |
| 29 | image.save() |