blob: b66eb2e8fd90c229a61b64eaa1f25fdd0ae32f8c [file] [log] [blame]
Sapan Bhatia511ea5f2014-07-21 22:53:58 -04001import os
2import base64
3import random
4import time
5from datetime import datetime
6from django.db.models import F, Q
7from planetstack.config import Config
8from ec2_observer.syncstep import SyncStep
9from core.models.node import Node
10from core.models.site import *
11from ec2_observer.awslib import *
12import pdb
13
14class SyncNodes(SyncStep):
15 provides=[Node]
16 requested_interval=0
17
18 def fetch_pending(self, deletion):
19 deployment = Deployment.objects.filter(Q(name="Amazon EC2"))[0]
20 current_site_deployments = SiteDeployments.objects.filter(Q(deployment=deployment))
21
22 zone_ret = aws_run('ec2 describe-availability-zones')
23 zones = zone_ret['AvailabilityZones']
24
25 # collect local nodes
26 instance_types = 'm1.small | m1.medium | m1.large | m1.xlarge | m3.medium | m3.large | m3.xlarge | m3.2xlarge'.split(' | ')
27
28 all_new_nodes = []
29 for sd in current_site_deployments:
30 s = sd.site
31 current_fqns = [n.name for n in s.nodes.all()]
32 all_fqns = ['.'.join([n,s.name]) for n in instance_types]
33 new_node_names = list(set(all_fqns) - set(current_fqns))
34
35 new_nodes = []
36 for node_name in new_node_names:
37 node = Node(name=node_name,
38 site=s,deployment=deployment)
39 new_nodes.append(node)
40
41 all_new_nodes.extend(new_nodes)
42
43 return all_new_nodes
44
45
46 def sync_record(self, node):
47 node.save()
48