3 from django.db.models import F, Q
4 from planetstack.config import Config
5 from ec2_observer.syncstep import SyncStep
6 from core.models.image import Image
7 from ec2_observer.awslib import *
10 class SyncImages(SyncStep):
12 requested_interval=3600
14 def fetch_pending(self,deletion):
18 images = Image.objects.all()
19 image_names = [image.name for image in images]
24 aws_images = json.loads(open('/opt/planetstack/aws-images').read())
26 aws_images = aws_run('ec2 describe-images --owner 099720109477')
27 open('/opt/planetstack/aws-images','w').write(json.dumps(aws_images))
31 aws_images=aws_images['Images']
32 aws_images=filter(lambda x:x['ImageType']=='machine',aws_images)[:50]
35 for aws_image in aws_images:
39 desc = aws_image['Description']
42 desc = aws_image['ImageLocation']
48 desc_ok = desc and desc not in names and desc not in image_names and '14.04' in desc
52 if desc_ok and aws_image['ImageType']=='machine':
53 image = Image(disk_format=aws_image['ImageLocation'],
55 container_format=aws_image['Hypervisor'],
56 path=aws_image['ImageId'])
57 new_images.append(image)
63 def sync_record(self, image):