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):
15 images = Image.objects.all()
16 image_names = [image.name for image in images]
21 aws_images = json.loads(open('/opt/planetstack/aws-images').read())
23 aws_images = aws_run('ec2 describe-images --owner 099720109477')
24 open('/opt/planetstack/aws-images','w').write(json.dumps(aws_images))
28 aws_images=aws_images['Images']
29 aws_images=filter(lambda x:x['ImageType']=='machine',aws_images)[:50]
32 for aws_image in aws_images:
36 desc = aws_image['Description']
39 desc = aws_image['ImageLocation']
45 desc_ok = desc and desc not in names and desc not in image_names and '14.04' in desc
49 if desc_ok and aws_image['ImageType']=='machine':
50 image = Image(disk_format=aws_image['ImageLocation'],
52 container_format=aws_image['Hypervisor'],
53 path=aws_image['ImageId'])
54 new_images.append(image)
60 def sync_record(self, image):