blob: 9dc00f23d3959f3b72be321b74ec613eaaf040be [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):
Sapan Bhatiae7e4ca12014-07-22 01:27:02 -040019 if (deletion):
20 return []
21
Sapan Bhatia511ea5f2014-07-21 22:53:58 -040022 deployment = Deployment.objects.filter(Q(name="Amazon EC2"))[0]
23 current_site_deployments = SiteDeployments.objects.filter(Q(deployment=deployment))
24
25 zone_ret = aws_run('ec2 describe-availability-zones')
26 zones = zone_ret['AvailabilityZones']
27
28 # collect local nodes
29 instance_types = 'm1.small | m1.medium | m1.large | m1.xlarge | m3.medium | m3.large | m3.xlarge | m3.2xlarge'.split(' | ')
30
31 all_new_nodes = []
32 for sd in current_site_deployments:
33 s = sd.site
34 current_fqns = [n.name for n in s.nodes.all()]
35 all_fqns = ['.'.join([n,s.name]) for n in instance_types]
36 new_node_names = list(set(all_fqns) - set(current_fqns))
37
38 new_nodes = []
39 for node_name in new_node_names:
40 node = Node(name=node_name,
41 site=s,deployment=deployment)
42 new_nodes.append(node)
43
44 all_new_nodes.extend(new_nodes)
45
46 return all_new_nodes
47
48
49 def sync_record(self, node):
50 node.save()
51